Commit Graph

1277 Commits

Author SHA1 Message Date
Misa ebe074e308 Add commit hash and date to title screen
The commit hash and date are now shown above the version number in the
bottom-right of the title screen. They both automatically go away when
compiled in release mode.

https://cdn.discordapp.com/attachments/717089363896434719/779525976689213480/vvvvvv_with_interim_commit_and_date.png

This is useful to easily figure out which commit someone is on whenever
they report an issue, without having to ask them to do `git show` or
whatever.
2020-11-20 21:18:29 -05:00
leo60228 2b6d8b8090 Include math.h instead of cmath 2020-11-17 12:17:04 -05:00
leo60228 c646360961 Include SDL2 as system header 2020-11-17 12:17:04 -05:00
Misa 12e3c579ed Don't set music.usingmmmmmm to true when (un)loading custom assets
For some reason, music.usingmmmmmm automatically gets set to true in
musicclass::init(). I assume this was because it would get re-assigned
by game.usingmmmmmm in the game startup code anyway, but now that
musicclass::init() can be called more than once, this variable will just
get set to true when it shouldn't be, causing a confusing desync just
like the one I described in my previous commit, where you would have
PPPPPP or MMMMMM on the title screen, but closing the game and
re-launching it would play the other soundtrack instead.

Again, these duplicate variables should be removed, but that's going to
be a separate patch. In the meantime, I'm removing this variable
assignment.
2020-11-12 19:11:13 -05:00
Misa 98ef7a8675 Don't reset entire musicclass when mounting and unmounting assets
musicclass::init() re-initializes every attribute of musicclass
unnecessarily, when initialization should be put in a constructor
instead. This is bad, because music.init() gets called whenever we enter
and exit a custom level that has assets.

Otherwise, this would result in a bug where music.usingmmmmmm would be
reset, causing you to revert to PPPPPP on the title screen whenever you
enter a level with MMMMMM selected and exit it.

This also causes a confusing desync between game.usingmmmmmm and
music.usingmmmmmm since the values of the two variables are now
different (these duplicate variables should probably be removed, too,
and a lot of other duplicate variables like these exist, too, which are
a real headache). Which means despite MMMMMM playing on the title
screen, exiting the game and re-launching it will play PPPPPP instead.
What's even more is that going to game options and switching to PPPPPP
will play PPPPPP, but afterwards launching and re-entering will play
MMMMMM. Again, having duplicate variables is very bad, and should
probably be fixed, but that's a separate patch.
2020-11-12 19:11:13 -05:00
Misa f93ce4ea4a Fix Prize for the Reckless moving platform losing its block when...
...you die and the platform's x-coordinate is to the left of x=152.
Which means if you die and the platform isn't completely clear of the
space of its adjacent disappearing platform.

The block needs to be updated accordingly with calls to
obj.nocollisionat() and obj.moveblockto(), else the block will simply be
left behind and the platform will no longer have any collision. This is
in contrast to 2.2 behavior, where the platform would simply
unconditionally create a new block, which would actually end up with a
duplicate block since the previous block didn't get cleaned up, but this
didn't cause any problems because the room was carefully designed so you
would never be able to touch that previous block after you died and
respawned at the checkpoint. But it's still there.

I also added comments to document what this kludge code did, because
otherwise it would be mysterious to readers who are unfamiliar with it.

Fixes #543.
2020-11-12 17:06:31 -05:00
Misa 434a672ac4 Fix edentities not rendering at all in the editor
What's the difference between a slash sign and a percent sign? Well, a
percent sign is just a slash sign with two extra oranges in between, but
those two oranges make a huuuuge difference...
2020-11-07 20:14:18 -05:00
Misa 7687440273 Use SDL_abs() instead of libc abs() in ApplyFilter()
Always good to use the SDL stdlib where possible.
2020-11-07 19:41:25 -05:00
Misa 1a2dd787f3 Interpolate scrolling in Analogue Mode filter
I can't really make the filter update only every timestep, because it's
per-pixel and operates on deltaframes too, so it TECHNICALLY runs faster
in over-30-FPS mode than not. That said, it's not really noticeable, the
filter doesn't look bad for updating more often or anything. However, I
can at least interpolate the scrolling, so it's smooth in over-30-FPS
mode.
2020-11-07 19:41:25 -05:00
Misa 65a5dbe3a3 De-duplicate titleupdatetextcol() in gamecompletelogic()
Originally this function was made because it needed to be exported to
gameinput(), but this piece of code is actually also used in
gamecompletelogic(). So it's good to de-duplicate it here, too.
2020-11-07 18:26:50 -05:00
Misa bf29c48640 Remove unneeded titlebg assignments when going to in-game settings
These were needed when the title and tower background shared the same
buffer, but since #522 got merged, these are no longer necessary.
2020-11-07 16:36:06 -05:00
Misa 6f4e89e336 Remove unneeded tdrawback/backgrounddrawn assigns in returntopausemenu
Assigning these variables is now wholly unnecessary ever since #522 got
merged, and in fact setting graphics.backgrounddrawn to false actually
causes the warp background to "skip" when the map screen gets closed. So
this fixes that bug, too.
2020-11-07 16:25:04 -05:00
Misa 5759408ded Remove Game::shouldreturntopausemenu
This kludge variable was used to re-set the warp background after coming
back from the in-game settings menus. But since #522 got merged, this
has no longer been necessary.
2020-11-07 16:25:04 -05:00
Misa d997fae27a Use SDL_fmodf() instead of libc fmodf()
Always good to use the SDL stdlib where possible.
2020-11-06 20:53:05 -05:00
Misa 5faa86baae Add x-room = 13 check to entity 1 `behave` 13
This check is clearly meant for destroying the factory clouds in the
room "Level Complete!" in the main game, but it covers all rooms on row
8, instead of only (13,8). Adding an x-room check restricts this
behavior to only (13,8).

Trinket9 reported that this weird behavior of destroying specifically
above y-position 60 was undesirable, since they were creating an enemy
with this `behave` in a room on row 8 and it kept disappearing
instantly.
2020-11-06 15:06:11 -05:00
Misa 05b7a38f76 Clean up don't-quick-fade signaling
First, the variable has been inverted, because it's bad practice to have
booleans with negative names. Secondly, instead of magically setting a
signaling variable when calling fadeout(), fadeout() now has a parameter
to set the quick_fade attribute, which is much cleaner than doing the
magical assignment that could potentially look unrelated.
2020-11-06 06:09:31 -05:00
Misa 87af9bba04 Merge fadeoutqueuesong into nicechange
fadeoutqueuesong basically does the same thing as nicechange - they both
queue a song to be played when the current track is done fading out.
Except, for some reason, I decided to add fadeoutqueuesong instead of
using the existing nicechange/nicefade system.

This has consequences where fadeoutqueuesong would step on the toes of
nicechange. In the case of #390, nicechange would say "let's play
Potential for Anything" when entering the Super Gravitron, but
fadeoutqueuesong had previously said "let's play Pipe Dream" because of
the player having just exited the Super Gravitron. fadeoutqueuesong took
priority because it came first in musicclass::processfade(), and when it
called play(), the Mix_PlayingMusic() in the nicechange check afterwards
would say music would already be playing at that point, so the
nicechange wouldn't take effect.

In the end, the solution is to just merge the new system into the
already-existing system.

Fixes #390.
2020-11-06 06:09:31 -05:00
Misa 410d80b731 Fix song 0/7 check using num_pppppp_tracks instead of num_mmmmmm_tracks
Just looked over this and had to do a double-take. It should be
num_mmmmmm_tracks, not num_pppppp_tracks, because MMMMMM comes first in
the vector of music tracks.
2020-11-06 06:09:31 -05:00
Misa 9698b42432 Initialize nicechange to -1 for consistency
The game uses -1 to denote "no song" elsewhere, especially when a
niceplay() has finished processing and it sets nicechange to -1 there,
too.
2020-11-06 06:09:31 -05:00
Misa c1ca57e096 Change nicefade to bool instead of int
If it's treated like a bool, why shouldn't it be one?
2020-11-06 06:09:31 -05:00
Misa f0b9bdc007 Fix niceplay() check having hardcoded number of MMMMMM tracks
The number of MMMMMM tracks is no longer guaranteed to be 16 anymore,
and instead it should use num_mmmmmm_tracks.
2020-11-06 06:09:31 -05:00
Misa 93775ecde2 Fix ACTION press processing on same frame as fade ticks to 0
Here's what causes #401: After the fade to menu delay ticks down to 0,
the game calls game.quittomenu(), but the rest of mapinput() still
executes. This means that the block that detects your ACTION press gets
executed, because there's a check that fadetomenudelay is less than or
equal to 0, and, well, it is.

So if you've pressed ACTION on the exact frame that it counts down to 0,
then the game detects your ACTION press, then processes it accordingly,
and then sets the fadetomenudelay, which means it'll get reactivated the
next time you open the map screen. But at this point, you get sent to
TITLEMODE, because game.quittomenu() set game.gamestate accordingly.
(This is why resetting game.fadetomenu or game.fadetomenudelay in
game.quittomenu() or script.hardreset() won't fix this bug.)

The solution here is to add a game.fadetomenu check to the ACTION press
processing.

Same-frame state transition logic is hard... actually, any sort of thing
where two things happen on the same frame is really annoying.

This also applies to fadetolab and fadetolabdelay, too.

Fixes #401.
2020-11-06 06:06:45 -05:00
Misa 5aa8b99113 Move all settings to settings.vvv
The game previously did this dumb thing where it lumped in all its
settings with its file that tracked your records and unlocks,
`unlock.vvv`. It wasn't really an issue, until 2.3 came along and added
a few settings, suddenly making a problem where 2.3 settings would be
reset by chance if you decided to touch 2.2.

The solution to this is to move all settings to a new file,
`settings.vvv`. However, for compatibility with 2.2, settings will still
be written to `unlock.vvv`.

The game will prioritize reading from `settings.vvv` instead of
`unlock.vvv`, so if there's a setting that's missing from `unlock.vvv`,
no worries there. But if `settings.vvv` is missing, then it'll read
settings from `unlock.vvv`. As well, if `unlock.vvv` is missing, then
`settings.vvv` will be read from instead (I explicitly tested for this,
and found that I had to write special code to handle this case,
otherwise the game would overwrite the existing `settings.vvv` before
reading from it; kids, make sure to always test your code!).

Closes #373 fully.
2020-11-04 12:06:57 -05:00
Misa 9e1ba97f63 Fix style of showmousecursor boolean check
Same-line brace (but not previous-line brace) AND an unnecessary boolean
comparison to constant boolean? Two-for-one whammy.
2020-11-04 12:06:57 -05:00
Misa 27b28ca55e Fix oldreadytotele not being set in gotoroom()
This fixes a deltaframe glitch where the "- Press ENTER to Teleport -"
prompt would show up for a split second if you exited the game while the
prompt was fully faded in, and then re-entered it.
2020-11-04 08:39:26 -05:00
Misa 3ce442459e Fix conveyor check in collisioncheck() always being true
cppcheck said: "Logical disjunction always evaluates to true".

Yes. Yes it does. Whoops. I learned how to specify ranges like this in
high school math and still screw it up...
2020-11-04 08:38:54 -05:00
Misa 3434ad8777 Fix variables shadowing other variables
In C++, when you have two variables in different scopes with the same
name, the inner scope wins. Except you have to be really careful because
sometimes they're not (#507). So it's better to just always have unique
variable names and make sure to never clash a name with a variable in an
outer scope - after all, the C++ compiler and standard might be fine
with it, but that doesn't mean humans can't make mistakes reading or
writing it.

Usually I just renamed the inner variables, but for tx/ty in editor.cpp,
I just got rid of the ridiculous overcomplicated modulo calculations and
replaced them with actual simple modulo calculations, because the
existing ones were just ridiculous. Actually, somebody ought to find
every instance of the overcomplicated modulos and replace them with the
actual good ones, because it's really stupid, quite frankly...
2020-11-04 08:38:19 -05:00
Misa 6de14d95ee Don't unset Flip Mode when deleting all data in M&P
Whenever you delete all your save data, your settings aren't changed at
all, and you could resave them if you fiddled with a setting somewhere.
But the full game doesn't count Flip Mode as a setting, instead it
counts it as an unlock. This means deleting your save data would unset
Flip Mode in M&P, which would seem weird because in M&P it's just a
simple setting.

For consistency, Flip Mode shouldn't be unset when deleting save data in
M&P.
2020-11-04 01:00:49 -05:00
Dav999-v 4ebf89e844 Add error message if quicksave fails 2020-11-03 22:05:26 -05:00
Dav999-v 5dbb90c7fd Add error message if telesave fails
At least, whenever it would say "Game Saved", it now instead gives an
error message if saving is not successful.
2020-11-03 22:05:26 -05:00
Misa 4570140a6a Fix teleporter sprites sometimes being solid colors
This commit fixes a bug that also sometimes occurred in 2.2, where the
teleporter sprite would randomly turn into a solid color and just be a
solid circle with no detail.

Why did this happen? The short answer is an incorrect lower bound when
clamping the teleporter sprite index in `Graphics::drawtele()`. The long
answer is bad RNG with the teleporter animation code. This commit fixes
the short answer, because I do not want to mess with the long answer.

So, here is what would happen: the teleporter's `tile` would be 6. The
teleporter code decrements its `framedelay` each frame. Then when it
reached a `framedelay` of 0, it would call `fRandom()` and essentially
ask for a random number between 0 and 6. If the RNG ended up being
greater than or equal to 4, then it would set its `walkingframe` to -5.
At the end of the routine, the teleporter's `drawframe` ends up being
its `tile` plus its `walkingframe`. So having a `walkingframe` of -5
here is fine, because its `tile` is 6.

Until it isn't. When its `tile` becomes 2, it still keeps its
`walkingframe` around. The code that runs when its `tile` is 2 does have
the possibility of completely resetting its `walkingframe` to be in
bounds (in bounds after its `tile` is added), but that only runs when
its `framedelay` is 0, and in the meantime it'll just use the previous
`walkingframe`.

So you could have a `walkingframe` of -5, plus a `tile` of 2, which
produces a `drawframe` of -3. Then `Graphics::drawtele()` will clamp
that to 0, which just means it'll draw the teleporter backing, and the
teleporter backing is a simple solid color, so the teleporter will end
up being completely and fully solid.

To fix this, I just made `Graphics::drawtele()` clamp to 1 on the lower
bound, instead of 0. So if it ever gets passed a negative teleporter
index, it'll just draw the normal teleporter sprite instead, which is
better.
2020-11-03 19:12:31 -05:00
Misa 25d00b9ba6 Fix crewmates being drawn behind other entities
This fixes the draw order by drawing all other entities first, before
then drawing all humanoids[1] after, including the player afterwards.

This is actually a regression fix from #191. When I was testing this, I
was thinking about where get a crewmate in front of another entity in
the main game, other than the checkpoints in Intermission 1. And then I
thought about the teleporters, because I remember the pre-Deep Space
cutscene in Dimension Open looking funny because Vita ended up being
behind the teleporter. (Actually, a lot of the cutscenes of Dimension
Open look funny because of crewmates standing behind terminals.)

So then I tried to get crewmates in front of teleporters. It actually
turns out that you can't do it for most of them... except for Verdigris.
And then that's what I realized why there was an oddity in WarpClass.cpp
when I was removing the `active` system from the game - for some reason,
the game put a hole in `obj.entities` between the teleporter and the
player when loading the room Murdering Twinmaker. In a violation of
Chesterton's Fence (the principle that you should understand something
before removing it), I shrugged it off and decided "there's no way to
support having holes with my new system, and having holes is probably
bad anyway, so I'm going to remove this and move on". The fact that
there wasn't any comments clarifying the mysterious code didn't help
(but, this *was* 2.2 code after all; have you *seen* 2.2 code?!).

And it turns out that this maneuver was done so Verdigris would fill
that hole when he got created, and Verdigris being first before the
teleporter would mean he would be drawn in front of the teleporter,
instead of being behind it. So ever since
b1b1474b7b got merged, there has actually
been a regression from 2.2 where Verdigris got drawn behind the
teleporter in Murdering Twinmaker, instead of properly being in front of
it like in 2.2 and previous.

This patch fixes that regression, but it actually properly fixes it
instead of hacking around with the `active` system.

Closes #426.

[1]: I'm going to go on a rant here, so hear me out. It's not explicitly
stated that the characters in VVVVVV are human. So, given this
information, what do we call them? Well, the VVVVVV community (at least
the custom levels one, I don't think the speedrunning community does
this or is preoccupied with lore in the first place) decided to call
them "villis", because of the roomname "The Villi People" - which is
only one blunder in a series of awful headcanons based off of the
assumption that the intent of Bennett Foddy (who named the roomnames)
was to decree some sort of lore to the game. Another one being
"Verdigris can't flip" because of "Green Dudes Can't Flip". Then an OC
(original character) got named based off of "The Voon Show" too. And so
on and so forth.
2020-11-03 13:31:56 -05:00
Misa 733d0dad80 Add entclass::ishumanoid()
"Humanoid" is just a word for "crewmate or player" but without having to
say "crewmate or player". This is just to make it so humanoids get drawn
after all other entities get drawn, meaning humanoids will be drawn on
top.
2020-11-03 13:31:56 -05:00
Misa d05fbe8687 Unindent drawentity() from previous commit
This unindent is done in a separate commit to minimize diff noise.
2020-11-03 13:31:56 -05:00
Misa e809cc0615 Factor out entity drawing to separate function
This makes it easy to re-use without duplicating code.
2020-11-03 13:31:56 -05:00
Misa fd53278163 Add bounds check to drawgravityline()
I noticed that this function didn't have a bounds check, so I added one.
Just in case.
2020-11-03 13:31:56 -05:00
Misa 081030fb2f Make some variables const in drawentities()
I'm going to refactor drawing an entity out to a separate function, and
since I'm going to do that, I might as well make some things const to
clarify intent first and foremost and possibly improve performance or
compiler optimization.
2020-11-03 13:31:56 -05:00
Misa 688b23b85d Standardize on using reference to tilesvec/spritesvec instead of pointer
This cleans up the code readability a bit, as it's nicer to use
reference syntax when indexing an array instead of that ugly pointer
syntax.
2020-11-03 13:31:56 -05:00
Misa 5eab074e4d Remember loaded custom level and read from it when saving
My previous custom level forwards compatibility would only work if you
saved to the same filename as you read from. But what if you saved to a
new filename? Well, your extra XML is lost.

Not to worry, I've introduced a variable that remembers the filepath of
the currently-loaded level (the existing `filename` attribute is kind of
weird and not really suited for this purpose, so). I tried to make it a
simple `const char*`, but it turns out that's bad when you take the
`c_str()` of an `std::string` that then gets destroyed, so it's best to
use `std::string` in an `std::string` world.

So now when you save a level, it'll attempt to open the original file,
and if that doesn't exist then your extra XML gets lost anyway, but I
shouldn't be expected to keep your XML if you delete the original file.
2020-11-03 13:30:53 -05:00
Misa 3f954a169a Add XML forwards compatibility to custom level files
Custom level files now have forwards compatibility - except that some
XML objects will simply discard contents and attributes they don't see
fit. For instance, edentities and level properties will not preserve
newer attributes or contents.

This is because preserving them would require having to track the XML
object as part of the edentity internally, because the edentity might
change places or even be deleted throughout the course of editing
someone's level.

I opted to not add support for preserving objects like these, because
frankly, the put-everything-in-one-file level format was and still is a
terrible idea, and we should probably switch to a new format in the
future that isn't single-file. So when that happens, there won't be a
need to preserve XML attributes on edentities.
2020-11-03 13:30:53 -05:00
Misa ab446790e8 Axe BoolToString() in favor of int casts
When I encountered this function, I asked myself, why make a dedicated
function instead of casting to int?

Well, as it turns out, you can't just cast to int, because you have to
convert it to a string by doing help.String(number).c_str(), like all
the other ints. So it's actually more wasteful to do it the normal way
instead of using BoolToString().

That is, until my recent changes came along and made it so that you can
just provide an int and it'll automatically be converted to a string, no
questions asked. Now, it's more optimal to do a straight cast to int
instead of having to go through a middleman function. So this function
is getting axed in favor of casting to int instead.
2020-11-03 13:30:53 -05:00
Misa 58795a1381 Add XML forwards compatibility to custom level quicksaves
Now these files might have things added to them in the future? I'm not
so sure. But at least they're XML forwards-compatible now.
2020-11-03 13:30:53 -05:00
Misa 0eb39644c1 Add XML forwards compatibility to tsave.vvv and qsave.vvv
These files are probably not of much consequence. The main game isn't
going to have things to be added to it anytime soon.
2020-11-03 13:30:53 -05:00
Misa 17b8d0308e Add XML forwards compatibility to unlock.vvv
This file is probably the biggest one, as there will be more settings
added in the future and we don't want people's settings to be erased. Of
course, this file will be migrated to a settings.vvv sometime later in
2.3 in order to prevent 2.2 from erasing 2.3 settings.
2020-11-03 13:30:53 -05:00
Misa 43e57f5483 Add XML forwards compatibility to levelstats.vvv
Not that hard to do for the smallest XML file in the game.
2020-11-03 13:30:53 -05:00
Misa cb2f72fd8e Add XMLUtils.cpp and XMLUtils.h
These XML functions will be useful for de-duplicating copy-pasted XML
handling code, while also making it so elements will get updated in
place instead of being thrown out and starting from scratch every time a
file is saved.
2020-11-03 13:30:53 -05:00
Misa a1957fa518 Remove kludge_to_bg() and bg_to_kludge()
Now that tower, title, and horizontal/veritcal warp backgrounds all use
separate buffers, there's no longer any need to temporarily store
variables as a workaround for the buffers stepping on each other.
2020-11-03 13:25:03 -05:00
Misa bda92ad0bd Move horizontal/vertical warp backgrounds to separate buffers
Instead of using the same tower buffer that gets used for towers, use a
separate buffer instead so there's no risk of stepping on the tower
buffer's toes at the wrong point in time.

This commit combined with the previous one fixes #369.
2020-11-03 13:25:03 -05:00
Misa 70f3d457dd Move title usages of towerbg to titlebg
With the previous commit in place, we can now simply move some usages of
the previous towerbg to use a separate object instead. That way, we
don't have to mess with a monolithic state, or some better way to phrase
what I just said, and we instead have two separate objects that can
coexist side-by-side.
2020-11-03 13:25:03 -05:00
Misa 72c048d71e Refactor tower background to use a separate object instead
Previously, the tower background was controlled by a disparate set of
attributes on Graphics and mapclass, and wasn't really encapsulated. (If
that's what that word means, I don't particularly care about
object-oriented lingo.) But now, all relevant things that a tower
background has has been put into a TowerBG struct, so it will be easy to
make multiple copies without having to duplicate the code that handles
it.
2020-11-03 13:25:03 -05:00