1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-01 00:39:41 +01:00
Commit graph

1127 commits

Author SHA1 Message Date
Misa
5b9a8e5f08 Allow calling flipgravity() on duplicate player entities
This is a followup to b7cf6855b0 and
10ed0058fd.

In 2.2, if you had a duplicate player entity, there'd be no way to get
rid of it. Except for the recently-discovered Arbitrary Entity
Manipulation glitch, where you set `i` to the indice of the entity and
call flipgravity() on it, turning its rule to 7 and making it no longer
a player entity.

However, I patched this useful mechanic out when I made it so that you'd
no longer be able to convert entities with rule 0 to rule 6
(10ed0058fd, upheld in
b7cf6855b0), because doing so would mean
being able to softlock the game by not having any player entity.

So, in this patch, I'm making it so that you CAN convert duplicate
player entities to crewmates (and thus basically destroy them), but you
can't do that to the TRUE player entity (i.e. the first entity indice
that has rule 0, which is basically always indice 0).
2020-09-17 23:49:00 -04:00
Misa
42010f8f42 Fix default Graphics::setcol() value having no alpha
This patch fixes a regression caused by commit
6b1a7ebce6.

When you spawn a crewmate with an invalid color, by doing something like
`createentity(100,100,18,-1,0)` (here the color is -1, which is
invalid), a white crewmate with the color of solid white (255, 255, 255)
would appear.

That is, until AllyTally came along and committed commit
6b1a7ebce6 (Make "[Press ENTER to
return to editor]" fade out after a bit) (PR #158). Then after that
commit, it would seem like the crewmate didn't appear, but in reality
they were just invisible, because they had an invisible color.

As part of Ally's changes, to properly support drawing text with a
certain amount of alpha, she made BlitSurfaceColoured() account for the
alpha of the color given instead of only caring about the RGB of the
color, discarding the alpha, and using the alpha of the surface it was
drawing instead. This effectively made it so the alpha of whatever it
was drawing would be 255 all the time, except for if you had custom
textures and your custom textures had translucent pixels.

However, the default color set by Graphics::setcol() if you didn't
provide a valid color index was 0xFFFFFF. Which is only (255, 255, 255)
but ends up having an alpha value of 0 (because it's actually
0x00FFFFFF). And all colors drawn with alpha 0 end up being drawn with
alpha 0 after 6b1a7ebce6. So
invalid-colored entities will end up being invisible.

To fix this, I just decided to add alpha to the default value instead.
In addition, I used getRGB() to be consistent with all the other colors
in the function.
2020-09-17 10:13:46 -04:00
MAO3J1m0Op
03abe10f67
Add space after lines terminated by a colon in scripts (#479) 2020-09-14 20:34:12 -04:00
Misa
dcf1a81e80 Fix duplicate levels in levelstats if you don't have a higher score
This is a regression from 25779606b4
(PR #74).

On the one hand, I should've thought this through carefully when
implementing the fix for the lower-score overwrite bug. On the other
hand, flibit didn't seem to notice either. And on the third hand, no one
else seems to have noticed, when they have had over 8 months to do so.
Not even the person who originally reported the lower-score overwrite
bug and also reported other bugs I hadn't noticed (e.g. the "You have
rescued a crewmate!" in Flip Mode) noticed this bug, which I believe was
weee50. But to be fair, he does seem to be less active nowadays.

On the fourth hand, I only realized the cause of the duplicate bug after
stepping through it in GDB, instead of just looking at it and going "hey
wait a minute" earlier. I'm surprised it didn't take me longer to
realize the problem.

I'm not sure what all these hands mean anymore, or where I'm getting
extra hands from. Whatever. This regression is fixed now.
2020-09-13 01:33:13 -04:00
Misa
1d40bbdbc7 Restore pre-2.1 warp bypass glitch in glitchrunner mode
So, I was staring at VVVVVV code one day, as I usually do, and I noticed
that warp lines had this curious code in entityclass::updateentities()
that set their statedelay to 2, and I thought, hm, maybe the pre-2.1
warp line bypass is caused by this statedelay. And, it doesn't seem like
this is the primary code used to detect if the player collides with warp
lines, the actual code is commented with "Rewritten system for mobile
update" and bolted-on in gamelogic() instead of properly being in
entityclass::entitycollisioncheck().

So, after getting tripped up on the misleading indentation of that
"Rewritten system" block, I removed the rewritten system, re-added
collision detection for rule 7 (horizontal warp lines), and after
checking the resulting behavior, it appears to be nearly identical to
that of warp lines in 2.0.

You see, if you use warp lines to flip up from the top of the screen
onto the bottom of the screen, close to the edge of the bottom of the
screen, Viridian's head will display on the top of the screen in 2.0. In
2.1 and later, this doesn't happen, confirming that my theory is
correct. I also performed warp line bypass multiple times in 2.0 and
with my restored code, and it is pretty much the exact same behavior.

So now, the pre-2.1 warp line bypass glitch has been re-enabled in
glitchrunner mode.
2020-09-09 22:05:43 -04:00
Misa
23434f0842 Fix misleading indentation in obj.customwarpmode block
This misleading indentation makes it really easy to misanalyze this
block as only containing the statements up to obj.customwarplinecheck(),
when in reality it contains everything up to the modifying of
map.warpx/map.warpy. I have made this misanalysis just now in my attempt
to figure out the pre-2.1 warp line bypass glitch, and I don't like it.
So I'm fixing this indentation now.
2020-09-09 22:05:43 -04:00
Misa
b7cf6855b0 Restore entity-to-crewmate conversion trick
So there's this trick that I recently discovered, since many script
commands don't initialize `i` it's possible to use them to manipulate
arbitrary entities by specifying their indice.

This means in 2.2 you can convert entities to pseudo-crewmates by
changing their rule to 6. Except in 2.3, this was fixed when I fixed the
command to work on flipped crewmates as well. So I'm restoring this
functionality, but I recognize the protection that my previous change to
the command did in preventing levels from destroying the player entity
by changing the player's rule to something nonzero, so instead of
removing the if-conditional entirely, I'm making it so that it will only
set the rule if the entity's rule isn't 0.
2020-09-09 10:02:09 -04:00
Misa
760f1e8e5a Don't hardcode SDL_CreateRGBSurface BitsPerPixel/mask args
For some reason, GetSubSurface() and ApplyFilter() were hardcoding the
bits-per-pixel and/or mask arguments to SDL_CreateRGBSurface(). I've
made them simply re-use the bits-per-pixel and masks of the input
surfaces they operate on, but the bits-per-pixel should always be 32 and
masks should always go first-byte alpha, second-byte red, third-byte
green, fourth-byte blue.
2020-09-08 16:16:40 -04:00
Misa
8af9007b5f Axe SDL_BYTEORDER checks
The game usually runs on little-endian anyways, but even if it did run
on big-endian, it doesn't check endianness everywhere so these checks
are useless. Furthermore, the code should be written so that endianness
doesn't matter in the first place.
2020-09-08 16:16:40 -04:00
Misa
68a54d2594 Axe endian_swap() function and template
Neither of these were used anywhere, so to simplify the code and prevent
having potentially broken code that's never shown to be broken because
it's never tested, I'm removing these.
2020-09-08 16:16:40 -04:00
Misa
90150a9fad Use clamp() macro to clamp colors in Graphics::bigrprint()
All other graphics functions use this macro instead of writing out the
clamping manually, so this one should, too.
2020-09-08 16:15:50 -04:00
Misa
efc9d4ea80 Remove duplicate color-clamping code from Graphics::bigrprint()
For some reason, there's some color-clamping code in this function
directly after already-existing color-clamping code. This code dates
back to 2.2. And also, there's a smaller lower-bound of -1 for the red
channel, despite the fact that this smaller value doesn't matter because
the red would get clamped to 0 by the first code anyway.

So even if this was put here for some strange reason, it doesn't matter
because it doesn't do anything anyway.
2020-09-08 16:15:50 -04:00
Misa
a6a8173e20 Prevent same-frame infinite loops in scripts
It's trivially easy to send the scripting system into an infinite loop
on the same frame (i.e. without any script delay in between, i.e. within
the same execution of script.run()). Just take a look at these two
scripts:

    a:
    iftrinkets(0,b)
    #

    b:
    iftrinkets(0,a)
    #

The hashes are to prevent the scripting system from parsing iftrinkets()
using the internal version instead of the simplified version, because
after doing a simplified iftrinkets(), the parser will (to oversimplify)
execute the last line of the script as internal.

Anyway, sending the game into an infinite loop like this will cause the
Not Responding dialog on Windows.

So to prevent this from happening, I've added an execution counter to
scriptclass::run(). If it gets too high, we're in an infinite loop and
so we stop running the script.
2020-09-08 15:57:21 -04:00
Misa
662a658cf6 Optimize entity collision checking to O(n)
I noticed that if I have a large amount of entities in the room, the
game starts to freeze and one frame would take a very long time. I
identified an obvious cause of this, which is that the entity collision
checking in entityclass::entitycollisioncheck() is O(n²), n being the
number of entities in the room.

But it doesn't need to be O(n²). The only entities you need to check
against all other entities are the player and the supercrewmate. You
don't need to "test entity to entity" if 99% of the pairs of entities
you're checking don't involve the player or supercrewmate.

How do we make it O(n)? Well, just hoist the rule 0 and type 14 checks
out of the inner for-loop. That way, the inner for-loop won't be
unconditionally ran, meaning that in most cases it will always be O(n).
However, if you start having large amounts of duplicate player or
supercrewmate entities (I don't know why you would), it would start
approaching O(n²), but I feel like that's fair in that case. But most of
the time, it will be O(n).

So that's how collision checking is now O(n) instead.
2020-09-07 23:03:34 -04:00
Misa
d4336b9a33 Hoist Enter check out of script.running clause
This fixes the fact that an Enter release during a "- Press ACTION to
advacne text -" prompt wouldn't be properly registered.
2020-09-07 20:47:33 -04:00
Misa
69337009b8 Remove fademode conditional from map screen
There's not really any good reason to prevent this action during a fade
animation. That just makes the fade timer one more potential contributor
to a softlock.

I'm leaving the fademode conditional on the Time Trial quick restart,
though - removing it would mean being able to quick restart during a
fade-in, and thus being able to spam Enter over and over to keep
re-starting the fade animation, which looks goofy.
2020-09-07 20:47:33 -04:00
Misa
fd19b4e5d8 Hoist Enter/Esc presses out of player entity for-loop
The hooks to bring up the map screen, pause screen, quit from Super
Gravitron, restart Time Trial, and commit suicide have now been hoisted
out of the for-loop that checked for a player entity. None of these
actions require a player entity, and there's no good reason to take away
your control from any of these actions, especially being able to quit to
the menu. The only actions inside the for-loop now are activating a
terminal and activating a teleporter, both of which require a player
entity to be standing in front of a terminal or teleporter, and both of
which have good reasons to be temporarily disabled.
2020-09-07 20:47:33 -04:00
Misa
610f4e7782 Move crewmate drawframe fix to entity creation instead of loadlevel
This makes it so the fix for crewmates' drawframes being wrong for
1-frame is fixed for all crewmates regardless of when they get created.
Sure, crewmates created in mapclass::loadlevel() have their drawframes
fixed there, but for crewmates that get created from scripting (such as
Violet when gotorooming to the Ship teleporter room after Space Station
1), this fix doesn't apply to them. But now it does, and Violet will no
longer be facing the wrong way for 1 frame when teleporting to the Ship
teleporter room in the Space Station 1 Level Complete cutscene.
2020-09-07 20:46:01 -04:00
Terry Cavanagh
f014ed6fe8
Merge pull request #467 from InfoTeddy/general-improvements
Remove checks to prevent having both warp lines/BGs in editor
2020-09-06 14:46:56 +10:30
Misa
9de3aba94b Fix sprite of player if they are stuck in a wall
If the player is stuck in a wall (which shouldn't happen in the first
place), their sprite would always default to being flipped, even if they
were unflipped.

Being stuck in a wall is characterized by having both positive onfloor
and onground.
2020-09-06 00:13:16 -04:00
Misa
d677ba3837 Remove checks to prevent having both warp lines/BGs in editor
It's perfectly acceptable to have both warp lines and a warping
background in the same room. Many levels do this exact thing, I would
say at least 30 or so levels, many of them popular and played by many,
and this has never caused any issues at all.

All that having both warp lines and warp BG does is make it so the
warping of the warping background gets overriden by the warp lines, but
make it so the background is still a warp background. So in effect, you
can have a warp background without any warping. This is perfectly
defined behavior. Except, for whatever reason, it's unintentional, and
the editor tries to prevent you from doing it.

Key word being "tries". The code to prevent having both warp types is
bugged (at least when you change the warp BG. The check when you place
warp lines seems to be solid). It compares the p1 and p2 attributes of
warp lines to the x-coordinate and y-coordinate of the room, despite p1
and p2 having nothing to do with room coordinates. p1 is the type of the
warp line and should be treated as an enum, and p2 is the offset of the
warp line from the top/left of the screen. This results in this check
sometimes working if you're unlucky, but never actually working properly
most of the time. This means people can first place warp lines, and then
change the warp background later, to have both warp lines and a warp
background.

Having these checks just further complicates the code, makes it more
error-prone, and just inconveniences people when they want to do
something that's perfectly fine to do. So it's best if we just remove
these checks.
2020-09-05 20:02:27 -07:00
Misa
6658a46b2e Fix 1-frame render glitch with running teleport scripts
Fixes #402 (Violet appearing 1 frame after the Ship teleporter room
appears).

The root cause of this bug is due to the game loop order changes made
with the over-30-FPS patch. 2.2's game loop order was gameinput(),
gamerender(), then gamelogic(). In 2.3, gamerender() was moved to the end
as it required special code to render more than 30 frames a second. So
2.3's game loop order is gameinput(), gamelogic(), then gamerender().

In hindsight, I could have preserved the game loop order, but this would
require some more complex code in the game loop than what is there
currently. Fixing it now would fix rendering glitches such as this one
(along with being able to remove script.dontrunnextframe with the
two-frame-delay fix), but it could also introduce new rendering glitches
we don't yet know about. After discussing this in Discord DMs with
flibit, we agreed that the game loop order should be fixed in 2.4
instead.

When the game teleports you, gamelogic() runs script.teleport(). This
function will gotoroom to the teleporter destination, then it loads the
teleport script. Some teleport scripts (such as levelonecomplete, which
creates Violet) expect that their entities will be created, and more
generally that their script will be ran, on the same frame that the
gotoroom happens, i.e. by the time that the next gamerender() happens,
i.e. script.run() should be ran before the next gamerender() happens.
This would be true on the old game loop order, but with the new game
loop order, gamerender() gets ran directly after gamelogic() with no
script.run() in between.

To fix this, I did the same thing I did with the two-frame-delay fix
(#317), where I ran the script for that frame, but in order to prevent
running it twice I set script.dontrunnextframe to true.
2020-09-05 18:17:59 -04:00
Misa
c29d7c7d14 De-duplicate activity zone rendering, don't ignore act_fade
This is a follow-up to #421.

The game would draw the activity zone if there was one active at all,
and would ignore game.act_fade. Normally this wouldn't be a problem, but
since #421, it's possible that there could be an active activity zone
but game.act_fade would still be 5. This would happen if you entered a
new activity zone while a cutscene was running.

To fix this, just make it so that the prompt gets drawn on its own and
only depends on the state of game.act_fade (or game.prev_act_fade), and
won't be unconditionally drawn if there's an active activity zone. As a
bonus, this de-duplicates the drawing of the activity prompt, so it's no
longer copy-pasted.
2020-08-24 22:02:58 -04:00
Misa
cf53de9ed5 Move text entry start to script open instead of script list open
This fixes a bug where opening a script, then closing the script but not
exiting the script list, then opening a script again (it can be the same
script as before) would result in you being unable to type in the
script. You would have to close the script, then close the script list,
then re-open the script list in order to be able to type properly.

This was caused by the fact that key.enabletextentry() was being called
when the script list was opened, but key.disabletextentry() was being
called when closing a script. So the fix for this is to simply move the
key.enabletextentry() to its proper place, which is when the script is
being opened, and not when the script list is.
2020-08-17 19:30:09 -04:00
Misa
743eb3f3d6 Add custommode check to mapclass::twoframedelayfix()
This is to ensure that this function only has an effect inside custom
levels. It might do something weird or bad in the main game.
2020-08-17 15:14:22 -04:00
Misa
77b47a3c7e Fix compatibility with levels that rely on gamestate-based script boxes
Some levels rely specifically on the fact that certain script boxes are
loaded using gamestates, instead of directly loading the script and
bypassing the gamestate system. Then weird things could happen. This
restores compatibility with those levels.

mapclass::twoframedelayfix() doesn't need to be updated because the
point of that function is to bypass the gamestate system entirely
anyways.
2020-08-17 15:14:22 -04:00
Misa
fb6635abec Remove script.hardreset() when restarting Time Trial
There's not really any need for it to be there. It gets called when the
Time Trial restarts, as restarting the Time Trial calls
script.startgamemode(), which calls script.hardreset() anyway.

Furthermore, since script.hardreset() is removed, we can also remove two
lines that are meant to work around the fact that everything gets reset,
which is now no longer the case.

Fixes #367.
2020-08-14 23:07:02 -04:00
Misa
c95b95f5b7 Check rw in musicclass::init()
It's possible that SDL_RWFromMem could return NULL, and if this is the
case, then we really shouldn't be passing it to MusicTrack().
2020-08-14 09:51:19 -04:00
Misa
6bed5fc88c Check divisor in musicclass::play()
Previously, it was assuming that the number of PPPPPP/MMMMMM tracks
would always be 16, since if that wasn't the case... then the game would
rudely and abruptly segfault when attempting to load the file. Huh.

But now that the game properly deals with invalid headers, it's possible
for the number of tracks to be 0. So I'll need to remove this
assumption.
2020-08-14 09:51:19 -04:00
Misa
4bfd9de371 Check index of tracks in musicclass::init()
It's possible that musicReadBlob.getIndex() could return the sentinel
value of -1 in case the header with that name is invalid, in which case
we should simply not do anything. Otherwise it'll lead to segfaults. I
opted to do the full bounds check just to be safe, too.

For further safety, I hardcoded the max number of headers, 128, less, so
128 is copy-pasted less and in the future if it needs to be changed
it'll only have to be changed in one place.
2020-08-14 09:51:19 -04:00
Misa
e481c75404 Use SDL stdlib funcs for free/malloc/strcmp
It's always good to have less of a dependency on a libc.
2020-08-14 09:51:19 -04:00
Misa
cf8442b12c Add bounds checks to getSize() and getAddress()
It's all too easy for someone to pass in a bad index and index out of
bounds, so we need to prevent that from happening.
2020-08-14 09:51:19 -04:00
Misa
6991b2045d Set valid to false if size is bogus
This is to prevent callers from parsing bogus sizes. If they listen to
the -1 sentinel value, at least...
2020-08-14 09:51:19 -04:00
Misa
7903b8967e Check valid in binaryBlob::getIndex()
The binary blob shouldn't return an index if it ends up being invalid.
That could cause a whole lot of issues if musicclass ends up parsing the
resulting struct.

With all that said, though, musicclass doesn't check the -1 sentinel
value anyway, even though it should, but that'll be fixed later.
2020-08-14 09:51:19 -04:00
Misa
751e621c14 Fix aggressive glitchrunner hardreset causing issues quitting to menu
This fixes the bug where in glitchrunner mode, quitting to the menu
would always put you back at the play menu on the first option, instead
of the menu you entered the game from.

The problem is the script.hardreset() that gets called before the game
actually quits to the menu, so when Game::quittomenu() gets called to
quit to the menu, all the variables that keep track of whether you're in
a certain gamemode, such as game.insecretlab and map.custommode, all get
prematurely reset before that function can read them and put you back to
the correct menu.

The solution here is to simply reset only what's needed when quitting to
the menu. Specifically, in order for credits warp to work,
script.running needs to be set to false and all the text boxes need to
be removed. Text boxes need to be gone so the "- Press ACTION to advance
text -" prompt will stay up without a text box, enabling the player to
increment the gamestate at will by pressing ACTION, and the script needs
to stop running so further text boxes don't spawn in.

Fixes #389.
2020-08-13 23:51:43 -04:00
Misa
d7040b23d0 Axe manual state trackers and use SDL_IsTextInputActive()
After looking at pull request #446, I got a bit annoyed that we have TWO
variables, key.textentrymode and ed.textentry, that we rolled ourselves
to track the state of something SDL already provides us a function to
easily query: SDL_IsTextInputActive(). We don't need to have either of
these two variables, and we shouldn't.

So that's what I do in this patch. Both variables have been axed in
favor of using this function, and I just made a wrapper out of it, named
key.textentry().

For bonus points, this gets rid of the ugly NO_CUSTOM_LEVELS and
NO_EDITOR ifdef in main.cpp, since text entry is enabled when entering
the script list and disabled when exiting it. This makes the code there
easier to read, too.

Furthermore, apparently key.textentrymode was initialized to *true*
instead of false... for whatever reason. But that's gone now, too.

Now, you'd think there wouldn't be any downside to using
SDL_IsTextInputActive(). After all, it's a function that SDL itself
provides, right?

Wrong. For whatever reason, it seems like text input is active *from the
start of the program*, meaning that what would happen is I would go into
the editor, and find that I can't move around nor place tiles nor
anything else. Then I would press Esc, and then suddenly become able to
do those things I wanted to do before.

I have no idea why the above happens, but all I can do is to just insert
an SDL_StopTextInput() immediately after the SDL_Init() in main.cpp. Of
course, I have to surround it with an SDL_IsTextInputActive() check to
make sure I don't do anything extraneous by stopping input when it's
already stopped.
2020-08-13 17:51:38 -04:00
AllyTally
48313169b6 Don't fade music out when returning to the menu if it's Presenting VVVVVV
Otherwise, the Presenting VVVVVV for the menu wouldn't play at all.
2020-08-13 10:08:20 -04:00
Nichole Mattera
d865c37951 Fixed the title screen showing up when going to graphics options while playtesting. 2020-08-13 10:03:48 -04:00
Nichole Mattera
ab323a7550 Simplified the fixes. 2020-08-12 23:07:13 -04:00
Nichole Mattera
51119d4394 Adding myself as a contributor. 2020-08-12 23:07:13 -04:00
Nichole Mattera
2ddd7a96fb Fix issues with hotkey during text inputs. 2020-08-12 23:07:13 -04:00
Misa
4d5a0e2cb0 Fix other array decay too
Whoops.
2020-08-09 13:39:12 -04:00
Nichole Mattera
b4da818e8c Missed adding the option to the createmenu method. 2020-08-08 19:10:31 -04:00
Nichole Mattera
1376e65b5d Added ability to bind restart to a controller. 2020-08-08 19:02:14 -04:00
Misa
af88aee7c0 Disable pressing R in No Death Mode
All that pressing R does in No Death Mode is end your run. As a result,
it'll only be pressed by accident, so it's better to just disable it
instead.

It's not even useful to quick-restart, because it's faster to quit and
go through the menu again than it is to wait through the Game Over
screen.

Additionally, I removed the `game.deathseq<=0` conditional because it's
unnecessary due to the if-statement already being inside a
`game.deathseq == -1` conditional.
2020-08-08 16:42:19 -04:00
Nichole Mattera
f4d247f7b6 Fixed controllers not being able to navigate the map and menu with up and down buttons. 2020-08-08 16:41:53 -04:00
Misa
688f759967 Fix array decay in PLATFORM_getOSDirectory()
Whoops.
2020-08-07 17:55:18 -04:00
Misa
609ceb782c Clean up strcat()s/strcpy()s, EXCEPT for migrateSaveData()
strcat()s and strcpy()s have been replaced with SDL_snprintf() where
possible, to clearly convey the intent of just building a string that
looks a certain way, instead of spanning it out over multiple lines.

Where there's not really a good way to avoid strcat()/strcpy() (e.g. in
PLATFORM_getOSDirectory()), they will at least be replaced with
SDL_strlcat() and SDL_strlcpy(), which are safer functions and are less
likely to have issues with null termination.

I decided not to bother with PLATFORM_migrateSaveData(), because it's
going to be axed in 2.4 anyways.
2020-08-07 10:36:39 -04:00
Misa
ce2eba1649 Fix inefficient baseDir non-empty check
There's no need to call a string function and have function call
overhead if you remember how C strings work: they have a null
terminator. So if the first char in a string is a null terminator, then
the string is completely empty. So you don't need to call that function.
2020-08-07 10:36:39 -04:00
Misa
7478b68dd7 Fix basedir trailing path separator check
The previous check by mwpenny had a few issues:

(a) It was completely overcomplicated for no good reason, and was
basically a Rube Goldberg machine. The original check was...

   (1) Creating an std::string of the last char of 'output'...
   (2) ...except instead of using the normal std::string constructor, it
       was using the one where you pass in a number and a char to create
       a string that's just that char repeated N times... except this
       was only used to create a 1-length string.
   (3) Converted that std::string to a C string.
   (4) Then passed it to strcmp(), despite the string at this point
       being only one byte and you could just compare the char values
       directly.

    The original check could've just been:
        output[SDL_strlen(output) - 1] == *pathSep

(b) Use of libc strcmp() and strlen() instead of SDL_strcmp() and
    SDL_strlen().

Now, actually, PHYSFS_getDirSeparator() happens to be a char array and
not a single char, so mwpenny was going in the right direction by using
strcmp() after all. Except it doesn't seem like he thought about the
fact that PHYSFS_getDirSeparator() could be multiple bytes instead of
one, and so he ended up making the first argument to strcmp() always be
a one-byte char array.

So there's issue (c), which is that it assumes the path separator is one
byte instead of multiple.

This commit fixes all of these issues with the trailing path separator
check.
2020-08-07 10:36:39 -04:00
Misa
d1938a151f Add fallback parameter to UtilityClass::Int()
If necessary, the caller can provide a fallback to be returned in case
the input given isn't a valid integer, instead of having to duplicate
the is_number() check.
2020-08-07 01:00:49 -04:00
Misa
78e87effe7 Replace all usages of atoi() with help.Int()
This will prevent any undefined behavior that might occur as a result of
having invalid input passed into atoi().
2020-08-07 01:00:49 -04:00
Misa
037065910f Add UtilityClass::Int()
This is simply a wrapper function around SDL_atoi(), because SDL_atoi()
could call libc atoi(), and whether or not invalid input passed into the
libc atoi() is undefined behavior depends on the given libc. So it's
safer to just add a wrapper function that checks that the string given
isn't bogus.
2020-08-07 01:00:49 -04:00
Misa
502d597aeb Add is_number()
This will be used to check if a string is a valid integer. So negative
numbers are accepted, unlike is_positive_num().
2020-08-07 01:00:49 -04:00
Misa
b8b616e282 Replace std::is[x]digit() with non-STL versions
std::isdigit() can be replaced with SDL_isdigit(), but there's no
equivalent for std::isxdigit() in the SDL standard library. So we'll
just use libc isxdigit() instead, it's fine.
2020-08-07 01:00:49 -04:00
Misa
43cf3c4f19 Remove allowspecial, replace with opaqueness check
When I added the over-30-FPS mode, I kept running into this problem
where the special images of text boxes would render during the
deltaframes of fade-in/fade-out animations, even though they shouldn't
be. So I simply added a flag to the text box that enables drawing these
special images.

However, this doesn't solve the problem fully, and there's still a small
chance that a special-image text box could draw another special image
during its deltaframes. It's really rare and you have to have your
deltaframe luck juuuuuust right (or you could use libTAS, probably), but
it helps to be in 40% slowmode and have a high refresh rate (which, if
it isn't a multiple of 30, you should disable VSync, too, in order to
not have a low framerate).

So instead, special images will only be drawn if the text box has fully
faded in completely. That solves the issue completely.
2020-08-06 22:12:15 -04:00
Misa
2710ebeff9 Fix silent music saves playing MMMMMM track 15 if...
This commit fixes a bug that's existed since MMMMMM was added (so, 2.2),
where if you quicksaved in a custom level while no music was playing,
then quit and loaded that quicksave, and you were using PPPPPP while
having MMMMMM available, it would play MMMMMM track 15, even though the
game intends for the music to simply be silent.

This is due to the same bug that lets you play MMMMMM tracks if you're
on PPPPPP - musicclass::play() does a modulo, but C++ modulo is not
guaranteed to be positive given negative inputs, so the 16-track offset
is added to a negative number, resulting in targeting the MMMMMM
soundtrack instead of PPPPPP.

That exploit doesn't harm anyone and shouldn't be fixed, EXCEPT it
causes a problem in this specific case. But this bug can be fixed
without removing that exploit.

Note that I made the check do not-equal to -1 instead of greater-than
-1, so levels that intend on using track -2, -3, -4, etc. upon loading a
quicksave will still work as their creator intended. It's just that
specifically -1 is patched out, just to fix this issue.
2020-08-06 22:11:11 -04:00
Misa
79fd3e1d36 Remove -1,-1 offset from ScaleSurface()
For some reason, ScaleSurface() was drawing each pixel one pixel up and
to the left from its actual position. I have no idea why.

But this was causing an issue where pixels would just be dropped,
because they would be drawn outside of the temporary SDL_Surface from
which the scaled surface would be drawn onto. Also, the offset just
creates a visual one-pixel offset in the result for no reason. So I'm
just removing it.

Big Viridian also suffered from this one-pixel offset, so now they will
no longer look like they're floating above the ground when standing on
the floor.
2020-08-06 22:10:47 -04:00
Misa
5f776faba7 Ax ScaleSurfaceSlow() in favor of ScaleSurface()
ScaleSurfaceSlow() uses DrawPixel() instead of SDL_FillRect() to scale a
given surface, which is slow and inefficient, and makes it less likely
that the game could be moved to SDL_Render.

Unfortunately, it has this weird -1,-1 offset, but that will be fixed in
the next commit.
2020-08-06 22:10:47 -04:00
Misa
57dca99a4e Ax OverlaySurfaceKeyed(), set proper foregroundBuffer blend mode
So, earlier in the development of 2.0, Simon Roth (I presume)
encountered a problem: Oh no, all my backgrounds aren't appearing! And
this is because my foregroundBuffer, which contains all the drawn tiles,
is drawing complete black over it!

So he had a solution that seems ingenius, but is actually really really
hacky and super 100% NOT the proper solution. Just, take the
foregroundBuffer, iterate over each pixel, and DON'T draw any pixel
that's 0xDEADBEEF. 0xDEADBEEF is a special signal meaning "don't draw
this pixel". It is called a 'key'.

Unfortunately, this causes a bug where translucent pixels on tiles
(pixels between 0% and 100% opacity) didn't get drawn correctly. They
would be drawn against this weird blue color.

Now, in #103, I came across this weird constant and decided "hey, this
looks awfully like that weird blue color I came across, maybe if I set
it to 0x00000000, i.e. complete and transparent black, the issue will be
fixed". And it DID appear to be fixed. However, I didn't look too
closely, nor did I test it that much, and all that ended up doing was
drawing the pixels against black, which more subtly disguised the
problem with translucent pixels.

So, after some investigation, I noticed that BlitSurfaceColoured() was
drawing translucent pixels just fine. And I thought at the time that
there was something wrong with BlitSurfaceStandard(), or something.
Further along later I realized that all drawn tiles were passing through
this weird OverlaySurfaceKeyed() function. And removing it in favor of a
straight SDL_BlitSurface() produced the bug I mentioned above: Oh no,
all the backgrounds don't show up, because my foregroundBuffer is
drawing pure black over them!

Well... just... set the proper blend mode for foregroundBuffer. It
should be SDL_BLENDMODE_BLEND instead of SDL_BLENDMODE_NONE.

Then you don't have to worry about your transparency at all. If you did
it right, you won't have to resort this hacky color-keying business.

*sigh*
2020-08-06 22:10:30 -04:00
Misa
1a64e9c528 Remove unnecessary cursor toggling when toggling fullscreen
For some reason, the cursor would be either disabled and re-enabled if
you switched to windowed mode, or it would be always enabled if you
switched to fullscreen mode. This only happened when you toggled
fullscreen using the Alt+Enter, Alt+F, or F11 keybinds, and the
fullscreen option in graphic options doesn't have this problem.

This cursor toggling business seems like an arcane incantation back in
the days of SDL1.2, now since no longer necessary with SDL2. However,
after some testing, it seems like removing these indecipherable runes
don't cause any harm, so I'm going to remove them.

Fixes #371.
2020-08-06 22:08:20 -04:00
Misa
5de6f22175 Use SDL_max/min instead of std::max/min in Graphics::Hitest()
In an effort to reduce STL usage, this should be done.
2020-08-04 15:59:21 -04:00
Misa
2d71881321 Clean up superfluous no-intersection return logic
It's not necessary to say 'return false' twice.
2020-08-04 15:59:21 -04:00
Misa
627e971e90 Remove unnecessary intersectRect() function
This function checked the intersection of rectangles, but it used floats
for some reason when its only caller used ints. There's already an
intersection function (UtilityClass::intersects()), so we should be
using that one instead in order to minimize code duplication.

Graphics::Hitest() is used for per-pixel collision detection, directly
checking the pixels of both entities' sprites. I checked with one of my
TASes and it still syncs, so I'm pretty sure this won't cause any
issues.
2020-08-04 15:59:21 -04:00
Misa
154e81292e Crop bottom tower spikes so they don't get drawn behind room name
If you have the translucent room name option enabled, you'd always be
seeing the spikes at the bottom of the screen hidden behind the room
name. This patch makes it so that the spikes get carefully cropped so
they only appear above the room name when the player gets close to the
bottom of the screen.
2020-08-04 00:06:45 -04:00
Misa
f544e95e85 Fix INBOUNDS() check for Graphics::drawtile3()
The function was not actually checking the number that would end up
being used to index the tiles3 vector, and as a result there could
potentially be out-of-bounds indexing. But this is fixed now.
2020-08-03 22:42:21 -04:00
Misa
6704675189 Remove half-second delay when exiting to menu in glitchrunner mode
The half-second delay comes from the fact that the game uses
graphics.resumegamemode to go back to GAMEMODE. This system waits for
graphics.menuoffset to reach a certain threshold before actually going
back (this is the animation of the map screen being brought down). To
speed it up, I'll just set graphics.menuoffset directly.

I could've directly set game.gamestate to GAMEMODE, but I wanted to be
safe and use the existing system instead.
2020-08-03 01:07:42 -04:00
Misa
690929d29a Fix dupe stack frame when creating unlock notif menu
The samemenu argument to createmenu() just has to be set to true so
another stack frame doesn't get added.

Fixes #415.
2020-08-03 01:06:54 -04:00
Misa
30123e700d Print error and return if given invalid command-line arg
This is helpful to know if the user either spelled an arg wrong, or
spelled it right but nothing is happening.
2020-08-03 00:39:58 -04:00
Misa
8af37bc693 Remove zeroed arrays from tower functions in M&P
This removes the arrays of zeroes that still take up space in the
binary. It doesn't seem like the compiler optimizes or compresses these
zeroes anyway, so just remove them instead, and make
load()/loadminitower()/loadminitower2() no-op functions. The
minitower/contents arrays are already initialized zeroed-out, anyway, so
there's no need to keep these other arrays around.

This saves exactly 72 kilobytes of memory and binary size.
2020-08-03 00:29:15 -04:00
Misa
f07a8d2143 Move tele/activity/trophytext conds to collision detection
This moves the teleporter, activity prompt, and trophy text "don't draw"
conditionals to the part where the game checks collision with them,
instead of whenever the game draws them.

This makes it so that the game smoothly does the fade-in/fade-out
animation instead of suddenly stopping rendering them whenever their
"don't draw" conditions apply. Now, the "Press ENTER to activate
terminal" prompt will no longer suddenly disappear whenever you activate
one, and the "- Press ENTER to Teleport -" prompt will smoothly fade
back in after teleporting, instead of suddenly popping in on screen.
2020-08-03 00:12:15 -04:00
Misa
95d4465e3e Fix bounding logic for enemies
When I refactored custom level entity creation logic earlier, I forgot
to account for enemy bounds, so enemies would take on the same bounds as
platforms. But this is fixed now.
2020-08-02 23:57:55 -04:00
Misa
70ad0003e1 Initialize bx1/by1/bx2/by2 in custom entity creation
When I compile in release mode, GCC complains that these variables MAY
be uninitialized when it comes time to create the moving platform
entity. I can't think of any way that it could be uninitialized and
testing my release build seemed to be fine, but I'm initializing these
variables just to be sure.
2020-08-02 23:57:55 -04:00
Misa
a35bc9d8dc Remove unnecessary externs from network func forward decls
Forward declarations are already externed, there's no need to have an
extern keyword here.
2020-08-02 23:43:55 -04:00
Misa
bf64b95416 Ifdef out network code for M&P
M&P contains network code despite M&P not being a Steam/GOG release (as
Steam/GOG releases are full releases of the game, not
custom-levels-only releases).

While unlocking achievements is already ifdef'd out in M&P, let's remove
the network code entirely to make sure people can't do other shenanigans
with M&P builds, and also to have a smaller binary size.
2020-08-02 23:43:55 -04:00
Misa
cec1a99d3b Don't draw activity zone or trophy text when cutscene is running
This fixes a possible graphical issue where the "Press ENTER to activate
terminal" prompt gets drawn on top of the "- Press ACTION to advance
text -" prompt, which looks bad. Trophy text gets drawn on top, too, so
there's a check there as well.

I've also made it so the activity prompt doesn't get drawn if the player
doesn't have control. After all, what use is it to say "press ENTER" if
the player isn't allowed to?
2020-08-02 22:48:06 -04:00
Dav999-v
4adcf7013c Reposition game time and trinket count in game save box
The game time is moved a little to the left, and the trinket count a
little to the right. To fix #376 for real, the trinket count is now
positioned automatically based on its length. The trinket icon is now
also displayed at the far right (instead of to the left of the count)
for better symmetry, and so that switching between tele save and quick
save doesn't make the trinket icon move if the trinket counts have
different lengths.
2020-08-02 20:22:23 -04:00
Dav999-v
6c02095d99 Make game save box 16 pixels wider
While I'm going to fix #376 anyway to make longer numbers (like Seventy
Eight) fit, I decided to also make the box a little wider in advance of
the game being localized, those extra chars could be a lifesaver, while
you wouldn't really notice the difference if you play the game in
English.
2020-08-02 20:22:23 -04:00
Misa
3aa407e981 Add catch-all softlock protection
What this simply does is make it so that in the event that
game.hascontrol is somehow set to false when there isn't a cutscene
running (i.e. when game.state is 0 and script.running is false), it gets
set back to true again.

There's many ways to interrupt a gamestate and/or a running script, most
notably telejumping and doing a screen transition in the middle of the
animation, interrupting it.

This implements the first part of my idea in this comment:
https://github.com/TerryCavanagh/VVVVVV/issues/391#issuecomment-659757071
2020-08-02 20:21:02 -04:00
Dav999-v
563b10b666 Fix Direct Mode selection square not moving with tile selection drawer
Closes TerryCavanagh#386.
2020-08-01 17:36:32 -04:00
AllyTally
d813956879 add newline at the end of game.cpp 2020-08-01 16:09:24 -04:00
AllyTally
0cc765ce7d replace stray tab with spaces
whoops, recently reinstalled windows so my editor settings still arent perfect yet
2020-08-01 16:09:24 -04:00
AllyTally
48d7523e34 fix tab instead of spaces 2020-08-01 16:09:24 -04:00
AllyTally
06e5eb38d9 Fix #380
Achievements could be unlocked in custom levels/make and play, so this adds the wrapper function `game.unlockAchievement` which calls `NETWORK_unlockAchievement` if `map.custommode` is false.
Also, this function and `Game::unlocknum` have both been `ifdef`ed to be empty if MAKEANDPLAY is defined.
2020-08-01 16:09:24 -04:00
AllyTally
c8b4c0f1e7 Fix #199
This makes the modifiers for removing tiles only work if you're using tools 0 or 1 (wall or background). In the future it might be worth it to add some extra subtools for spikes, but for now this should be fine.
Also, there was a small inconsistency with the tool drawn and the tool used. If you started holding down V, then started holding down Z, you would place tiles like you're holding V (9x9) but your cursor would look like you're holding Z (3x3). The `if` chain for drawing the resized cursors has been flipped around for this.
2020-08-01 16:09:24 -04:00
AllyTally
720cd7642a fix #382 and fix #370 2020-08-01 16:09:24 -04:00
AllyTally
cf5ad166e3 Fix #400 2020-08-01 16:09:24 -04:00
tzann
a4c1ffee12 Fix checkpoint starts in editor 2020-07-29 14:45:28 -04:00
Tynan Richards
8aac6a758d
Wrap entities (#408)
Make entities able to wrap both vertically and horizontally, also add a case for when entities are wrapping both directions at the same time
2020-07-29 12:17:28 -04:00
tzann
178951e5e1 Added myself to contributors list 2020-07-29 10:04:27 -04:00
tzann
11ef68bea2 Change back the order of entity creation 2020-07-29 10:04:27 -04:00
tzann
b4bac64361 Also change oldyp so there's no deltaframe issues 2020-07-29 10:04:27 -04:00
tzann
e48fef4fe5 Fix the 'Game Complete' trophy stand so it no longer hovers above the ground. Also update comments in Otherlevel.cpp to reflect what entities are actually being created. 2020-07-29 10:04:27 -04:00
tzann
e2321f84b9 Add check for singular trinkets and crewmates in NDM game over screen 2020-07-28 21:54:35 -04:00
Misa
6c04f56099 Don't savestats() every frame of New Record animation
Otherwise, this would cause immense slowdown during the New Record
animation that plays when you die, as the game would be writing
unlock.vvv every frame.

To fix this, I just put it under the same if-guard as the
music.playef(), since the sound effect also only plays once. But I have
to watch out for frame ordering and make sure the record is actually set
before I call game.savestats(), and then of course I have to move
game.swnmessage = 1 over because that's the variable being checked in
the conditional.
2020-07-27 19:21:18 -04:00
Misa
18b7d1ca14 Set oldxp/oldyp when player teleports through warp token
This fixes the bug where it would appear as if they "zipped" to the
destination from the warp token.

Fixes #384.
2020-07-21 18:13:50 -04:00
Misa
ff8d616438 Use INBOUNDS() check for mapclass::warpto()
There's a lot of places where the INBOUNDS() check is spelled out
instead of using the macro, before the macro was introduced. Also the
macro should probably be renamed INBOUNDS_VEC() to be consistent.
2020-07-21 18:13:50 -04:00
Misa
fdb01adc68 Set oldxp/oldyp when being teleported around during teleport
This fixes the bug where Viridian would appear to "zip" when they would
be teleported to the position of the teleporter before being flung out
of it.

As discussed in #393, I've also set the oldxp/oldyp when Viridian is
temporarily positioned in the center of the room, even though at this
point they should already be invisible. This is just to be safe.

Fixes #393.
2020-07-21 18:06:41 -04:00
Misa
52f7a587fe Separate includes into sections and alphabetize them
Okay, so basically here's the include layout that this game now
consistently uses:

[The "main" header file, if any (e.g. Graphics.h for Graphics.cpp)]
[blank line]
[All system includes, such as tinyxml2/physfs/utfcpp/SDL]
[blank line]
[All project includes, such as Game.h/Entity.h/etc.]

And if applicable, another blank line, and then some special-case
include screwy stuff (take a look at editor.cpp or FileSystemUtils.cpp,
for example, they have ifdefs and defines with their includes).
2020-07-19 21:37:40 -04:00
Misa
b108e28c5a Remove unnecessary EditorData constructor stub
It's useless anyway because `std::string`s get initialized
automatically.
2020-07-19 21:37:40 -04:00