1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-17 01:58:29 +02:00
Commit Graph

117 Commits

Author SHA1 Message Date
Misa
b480d5e5a9 De-duplicate Flip Mode code for custom levels' CREW page
Instead of copy-pasting everything and changing a few parts, just have
something that handles that tiny part. This reduces the amount of code
size the custom level CREW page takes up by half.
2020-06-21 20:50:39 -04:00
Misa
9d20f754bc Add macro-like inline func FLIP()
This will be used to keep some text positions the same when in Flip
Mode, instead of having to copy and paste code.

This function being at the very top of the file kind of violates
locality, but it has to be done because it can't be a macro.
2020-06-21 20:50:39 -04:00
Misa
6876dbf70c De-duplicate menu tab rendering
Previously, the code to print all tab names was copied to every single
tab, resulting in 12 more superfluous print statements than needed. This
commit uses graphics.map_tab to de-duplicate all the code.
2020-06-21 20:50:39 -04:00
Misa
92ff6ac8fc Fix editor ghosts being added multiple times per frame
This just results in a messy splotchy effect. Instead, move the ghost
adding outside of the render function.
2020-06-19 09:05:48 -04:00
Misa
694e8f42ab Add VSync graphics option, off by default
This is if you want delta-timesteps to go as quickly as possible. Also
it seems like on Windows this only has an effect in exclusive fullscreen
mode.
2020-06-19 09:05:48 -04:00
Misa
7f526f3ef2 Add being able to toggle over/fixed-30-FPS, off by default
There is now an option in "graphic options" named "toggle fps", which
toggles whether the game visually runs at 1000/34 FPS or over 1000/34
FPS. It is off by default.

I've had to put the entire game loop in yet another set of braces, I'll
indent it next commit.
2020-06-19 09:05:48 -04:00
Misa
ad6adcb3c0 Refactor how "hidden names" work
By "hidden names", I'm referring to "Dimension VVVVVV" and "The Ship"
popping up on the quit/pause/teleporter screens, even though those rooms
don't have any roomnames.

Apparently my commit to fix roomname re-draw bleed on the
quit/pause/teleporter screens exposed yet another hardreset()-caused
bug. The issue here is that since hardreset() sets game.roomx and
game.roomy to 0, map.area() will no longer work properly, and since the
hidden roomname check is based on map.area(), it will no longer display
"Dimension VVVVVV" or "The Ship" once you press ACTION to quit. It used
to do this due to the re-draw bleed, but now it doesn't.

I saw that roomnames didn't get reset in hardreset(), so the solution
here is to re-factor hidden names to be an actual variable, instead of
being implicit. map.hiddenname is a variable that's set in
mapclass::loadlevel(), and if isn't empty, it will be drawn on the
quit/pause/teleporter screens. That way it will still display "Dimension
VVVVVV" and "The Ship" when you press ACTION to quit to the menu.

EDIT: Since PR #230 got merged, this commit is no longer strictly
necessary, but it's still good to refactor hidden names like this.
2020-06-19 09:05:48 -04:00
Misa
69b3a5dff2 Fix roomname being continuously drawn on top of itself
This is only noticeable if you have a font with translucent pixels, like
I do. But it gets really noticeable really quickly with this over-30-FPS
patch because the render functions are continuously called every
delta-timestep. To prevent this, just fill the backbuffer with black
before rendering anything.
2020-06-19 09:05:48 -04:00
Misa
9256b4da56 Smoothly interpolate "[Press ENTER to return to editor]" fadeout
Now it'll be real smooth at 60 FPS. Or above. Or whichever one you want
above 30.
2020-06-19 09:05:48 -04:00
Misa
5daad95f1d Move "return to editor" alpha timer update to logic functions
Otherwise it'll go by too quickly.

Also something subtle here - I didn't make it conditional on
game.advancetext, so now it'll still decrement even if you have
advancetext up.
2020-06-19 09:05:48 -04:00
Misa
68fe5bd72d Move glitch roomname updating to logic functions
Otherwise they go by so fast that it's basically impossible to see them.
2020-06-19 09:05:48 -04:00
Misa
90280b0f92 Interpolate end picture reveal scroll
This is so it looks smooth at framerates above 30.
2020-06-19 09:05:48 -04:00
Misa
82a7ff0357 Fix off-by-one in "- Press ENTER to Teleport -" interpolation
Otherwise it would be clipped off too early, if it was even noticeable
without using slowmode.
2020-06-19 09:05:48 -04:00
Misa
52f4799405 Fix off-by-one in trophy text interpolation
Otherwise it would appear to be clipped off too early, if that was even
noticeable.
2020-06-19 09:05:48 -04:00
Misa
c3df1bcc3f Fix off-by-one in activity zone prompt fading interpolation
Otherwise it would appear to cut off too early when fading away. This is
only noticeable in slowmode, if even that.
2020-06-19 09:05:48 -04:00
Misa
a884bb1dc1 Fix off-by-one in menuoffrender interpolation
Otherwise, when you brought down the quit/pause/teleporter screen, it
would appear to cut off too early.
2020-06-19 09:05:48 -04:00
Misa
11803b0229 Fix colors updating too fast in TITLEMODE/MAPMODE/GAMECOMPLETEMODE
These colors were of the colors of each crewmate, the inactive crewmate
color, and the color of the trinket and clock on the quicksave/summary
screens.

These colors all used fRandom() and so kept updating too quickly because
they would be recalculated every time the delta-timestep render function
got called, which isn't ideal. Thus, I've had to add attributes onto the
Graphics class to store these colors and make sure they're only
recalculated in logic functions instead.

Thankfully, the color used for the sprites on the time trial results
screen doesn't use fRandom(), so I don't have to worry about those.

There's a new version of Graphics::drawsprite() that takes in a pre-made
color already, instead of a color ID. As well, I've also added
Graphics::updatetitlecolours() to update these colors on the title
screen.
2020-06-19 09:05:48 -04:00
Misa
e1fdfb7cdb Interpolate credits position
So that it's as smooth as possible, especially when holding down ACTION
to make it go really fast.
2020-06-19 09:05:48 -04:00
Misa
b4142976f2 Move crewframedelay to titlelogic() and maplogic()
Incidentally enough, this de-duplicates the amount of times this code
has been copy-pasted from 4 times to 2.

Anyways, this makes it so the crew don't go lightning fast on the
summary screen, the NDM game-over screen, the NDM win screen, and the
pause screen in the main game. It was slightly hilarious seeing them go
really quickly, actually. It was like they were running away from a
giant monster or something.
2020-06-19 09:05:48 -04:00
Misa
1d669dffeb Interpolate "- Press ENTER to Teleport -" prompt
This is only really noticeable in slowmode, but if you're playing in
slowmode it'll be pretty smooth.
2020-06-19 09:05:48 -04:00
Misa
9d104b68ee Simplify "else if" braces and indentation in activity prompt rendering
No need for it to be inside another whole indented block if it's just an
"else if".
2020-06-19 09:05:48 -04:00
Misa
f53ed222d3 Interpolate activity zone prompt fading in and out
To make it real smooth, just in case it was noticeable that it only
updated at 1000/34 FPS before (well, except in slowmode, it's really
noticeable THERE).

Also this removes the re-typing out of (game.act_fade/10.0f) for every
single R, G, and B in gamerender().
2020-06-19 09:05:48 -04:00
Misa
4ba9954eb8 Move cursor delay update logic to maplogic()
Otherwise it'll go really really fast.

Incidentally this also basically de-duplicates it and results in less
copy-pasted code overall.
2020-06-19 09:05:48 -04:00
Misa
45c7292096 Simplify menu-off rendering/logic code
Since "if (graphics.resumegamemode)" and "if (menuoffset > 0)" both do
the same thing, they've been combined with an "or" conjunction.

As well, the map.extrarow check in maplogic() has been refactored to use
a variable instead of duplicating the entire code block. Not that it
matters anyway, because the difference between 240 and 230 is only 10
pixels, far short of the 25 pixel increment that bringing the menu up
and down uses, and both 240 and 230 integer-divided by 25 have the same
non-remainder value of 9.
2020-06-19 09:05:48 -04:00
Misa
a22a872886 Move menu offset logic to maplogic()
This is the logic that handles the timer that brings up and down the
teleporter, pause screen, and Esc screen. So now it doesn't go crazy
fast.
2020-06-19 09:05:48 -04:00
Misa
905696c263 Update trophy text timer in fixed-timestep gamelogic()
Otherwise it, too, goes by too quickly.
2020-06-19 09:05:48 -04:00
Misa
92ee33043d Update activity prompt fade in fixed-timestep gamelogic()
Otherwise it goes by too quickly.
2020-06-19 09:05:48 -04:00
Misa
298aa95259 Move onground/onroof/animateentities logic to start of gamelogic()
For some reason, it was put near the start of gamerender(), even though
since it handles edge-flipping it seems like it should be in the logic
function already.

This makes sure entity animations don't animate as fast as possible, and
also fixes edge-flipping on normal surfaces.
2020-06-19 09:05:48 -04:00
Misa
beab344267 Guard all cases obj.getplayer() is used unchecked
obj.getplayer() can return -1, which can cause out-of-bounds indexing of
obj.entities, which is really bad. This was by far the most changes, as
obj.getplayer() is the most used entity-getting function that returns
-1, as well as the most-used function whose sentinel value goes
unchecked.

To deal with the usage of obj.getplayer() in mapclass::warpto(), I just
added general bounds checks inside that function instead of changing all
the callers.
2020-06-12 23:55:48 -04:00
AllyTally
3b76713441 Only add editor ghosts if the editor exists 2020-06-12 19:11:48 -04:00
AllyTally
1b0b1d32e8 Remove accidental whitespace
Whoops, must have accidentally pressed tab
2020-06-12 19:11:48 -04:00
AllyTally
eb52657c23 Add a player trail to the editor (ghosts)
A few months ago, I added ghosts to the VVVVVV: Community Edition editor. I was told recently I should think
about upstreaming it, and with Terry saying go ahead I finally ported them into VVVVVV. There's one slight
difference however--you can choose whether you have them or not in the editor's settings menu. They're off by
default, and this is saved to the save file.
Anyway, when you're playtesting, the game saves the players position, color, room coordinates and sprite every 3
frames. The max is 100, where if it tries to add more, the oldest one gets removed.
When you exit playtesting, the saved positions appear one at a time, and you can use the Z key to speed it up.

[Here's a video of them in action.](https://o.lol-sa.me/4H21zCv.mp4)
2020-06-12 19:11:48 -04:00
Misa
3a5dd5a616 Clean up all scriptclass externs into one location
I have the feeling that none of the devs understood what extern did, and
they kind of just sprinkled it everywhere until things started working.
But like all other classes, it should just be one line in the class's
respective header file, and shouldn't be so messy.
2020-05-22 09:46:12 -04:00
Misa
610768658e Remove graphics.drawgui() from maprender()
Since this is at the start of maprender(), the text boxes drawn by this
function will get hidden behind everything else being drawn on top of
it. Thus, it'll only result in a glitchy rendering where the text boxes
at the very top of the screen will be rendered in the roomname space of
the map screen.

To fix this rendering glitch, just remove the drawgui(). It's useless
anyway since it's being drawn behind everything else, so no need to have
it here.
2020-05-14 14:40:27 -04:00
Misa
82d19145ae Only draw fading-in and fading-out animations in MAPMODE
This makes it so if you bring up the quit screen during a faded-out
screen, you will at least see the screen and won't see black. And also
the fade-in and fade-out animations will still work on the quit screen.
And more importantly, I tested and there's no 1-frame flicker or
anything.
2020-05-08 08:34:46 -04:00
Misa
b59e5a8346 Move script.hardreset() to after quit to menu
This cleans up a whole lot of kludge variables, because this aggressive
hardreset() right as ACTION is pressed doesn't do anyone any favors.

This aggressive hardreset() was probably here because of the whole fact
that exiting to the menu uses Terry's State Machine, to minimize the
chances of interruption, but it actually causes more issues and allows
towers to interrupt the fadeout. And we should fix the root cause (the
usage of the state machine) instead of patching together some kludge.
2020-05-08 08:34:46 -04:00
Misa
1fd20e5e99 Render screen effects in maprender()
I had forgotten that the game flashed and did screen-shaking when you
pressed ACTION to quicksave.

While testing for my over-30-FPS patch I stumbled across this.
2020-04-29 19:35:00 -04:00
Misa
28db7038fc Merge drawtowerbackgroundsolo() into drawtowerbackground()
It's less code being copied and pasted, especially since for my
over-30-FPS patch I would have to make a separate function for each if
both of them were still there, but if they're unified into one then I
will only have to make one more function.

And since map.scrolldir is now used outside of GAMEMODE, we'll need to
reset it in hardreset() and when exiting playtesting.
2020-04-29 18:08:13 -04:00
Misa
94edfcf87e Only render screen effects on the title screen and in-game
In-game because that's where screen effects are used the most. But on
the title screen, screen effects are used when you press ACTION to start
the game, and when you enable screen effects, too.

Otherwise, we don't need screen effects for any other game-gamestate.
2020-04-27 15:07:58 -04:00
Misa
857937326e Put screen effects render handling inside a function
This de-duplicates the screen effects rendering code by putting it
inside a function, Graphics::renderwithscreeneffects(), and using that
instead of copy-pasted code.
2020-04-27 15:07:58 -04:00
Misa
0e082551b1 De-duplicate screen effects timer decrementing
The code to decrement the timers for flashing and shaking is now handled
outside the game-gamestate case-switch, instead of having to be
duplicated inside each render function.

As a bonus, I made it so the timer decrements even if screen effects are
disabled. This is to prevent any theoretical situation where the timer
can "pile up" due to disabled screen effects not letting it tick down.
2020-04-27 15:07:58 -04:00
Misa
53bad3bcaf Merge towerrender() into gamerender()
This removes a lot of duplicate code, which towerrender() mostly
consisted of, even though the only difference is that it draws a
separate map and screen edge spikes are drawn.
2020-04-26 19:07:40 -04:00
Misa
660f752bae Merge drawtowerentities() into drawentities()
This removes lots of duplicated code that drawtowerentities() did,
because all that really changed was accounting for map.ypos (which can
be done conditionally) and where and when the room wrapped (which can
also be done conditionally).
2020-04-26 19:07:40 -04:00
Misa
85b16b969a Add a "previous page" option to the levels list
This makes it more convenient if you have a large levels directory, as
some people in the VVVVVV custom levels community do.

On the first page, this option will change to be "last page" instead.

Since the addition of another menu option pushes up the list of levels
too close to the selected level data itself, I've had to move the list
of levels down by 4 pixels (but "next page"/"previous page"/"return to
menu" are still in their same position).

This feature was already added to VCE but hasn't been upstreamed until
now.
2020-04-17 15:41:48 -04:00
Misa
7b233a0e69 Rename Menu::setslowdown2 to Menu::setslowdown
Now that setslowdown1 has been removed it's no longer necessary to have
a 2 on the end of setslowdown2.
2020-04-17 15:41:48 -04:00
Misa
1c2cee48a7 Remove unused menu setslowdown1
Looks like it was a remnant from the Flash days, and the "delete your
saves if you want to use slowdown" was a bit too mean so it stopped
being a thing in the C++ version.
2020-04-17 15:41:48 -04:00
Misa
9e99246e02 Turn game.currentmenuname "else-if"s into case-switches
Much more stylistic, you don't need to repeat "game.currentmenuname" for
each case, and you don't need to deal with the dangling first "if" that
doesn't have an "else".
2020-04-17 15:41:48 -04:00
Misa
e8a07f9c3d Convert menu names to be an enum instead of being stringly-typed
Stringly-typed things are bad, because if you make a typo when typing
out a string, it's not caught at compile-time. And in the case of this
menu system, you'd have to do an excessive amount of testing to uncover
any bugs caused by a typo. Why do that when you can just use an enum and
catch compile-time errors instead?

Also, you can't use switch-case statements on stringly-typed variables.

So every menu name is now in the enum Menu::MenuName, but you can simply
refer to a menu name by just prefixing it with Menu::.

Unfortunately, I've had to change the "continue" menu name to be
"continuemenu", because "continue" is a keyword in C and C++. Also, it
looks like "timetrialcomplete4" is an unused menu name, even though it
was referenced in Render.cpp.
2020-04-17 15:41:48 -04:00
Misa
d6d9b505a2 Capitalize "No Death Mode" in "not available" message
It's fully capitalized everywhere else, so why not here?
2020-04-17 15:41:48 -04:00
Misa
256ead4799 Bump version number in bottom-right to 2.3
I think it's about time that this number be updated, yeah? This isn't to
say that 2.3 is finished or almost finished or anything, this is just to
clearly differentiate that this isn't 2.2.
2020-04-17 15:41:48 -04:00
Misa
d9d0748ce3 Use case-switch for menu options where possible
I've converted every "else if"-chain in menu render/input code to be a
case-switch, except for the levels list, the "game options" menu
(because it has the MMMMMM menu option which isn't a compile-time
constant), and the "play" menu (because it has the Secret Lab menu
option which also isn't a compile-time option).

I also did NOT convert some case-switches relating to unlocks in
Input.cpp, mostly because they use a system where the "if we have this
unlocked" conditional is a part of the "if this is the current menu
option" conditional, and they use the 'else' branch to play a sad sound
if that "if we have this unlocked" conditional fails.

I've also converted the game.gameframerate and game.crewrescued() "else
if"-chains to be case-switches instead.
2020-04-17 15:41:48 -04:00
Misa
46d0b3a4e9 Fix indentation of "graphicoptions" in Render.cpp
There was one level that was indented with 2 spaces instead of 4, which
made everything else look weird. Then some lines were randomly indented
further for no reason.

Doing this before the next commit is done so as to not make the next
commit noisier.
2020-04-17 15:41:48 -04:00
Misa
4f6835c485 De-duplicate copy-pasted input/render code in menus
This removes duplicate code that came about as a result of various
possible permutations of menu options, depending on being M&P, having no
custom level support, having no editor support, and having MMMMMM.

The menus with such permutations are the following:

- main menu
  - "start game" is gone in MAKEANDPLAY
  - "player levels" is gone in NO_CUSTOM_LEVELS
  - "view credits" is gone in MAKEANDPLAY

- "game options"
  - "unlock play data" is gone in MAKEANDPLAY
  - "soundtrack" is gone if you don't have an mmmmmm.vvv file

- "player levels"
  - "level editor" is gone in NO_EDITOR

I achieve this de-duplication by clever use of calculating offsets,
which I feel is the best way to de-duplicate the code with the least
amount of work, if a little brittle.

The other options are to (1) put function pointers on each MenuOption
object, which is pretty verbose and would inflate Game::createmenu() by
a lot, (2) switch all game.currentmenuoption checks to instead check for
the text of the currently-selected menu option, which is very
error-prone because if you make a typo it won't be caught at
compile-time, (3) add a unique ID to each MenuOption object that
represents a text but will error at compile-time if you make a typo,
however this just duplicates all the menu option text, which is more
code than was duplicated previously.

So I just went with this one.
2020-04-17 15:41:48 -04:00
Misa
b835ce3927 Move menu rendering to separate function
Just like I moved the menu ACTION press handler, I'm doing this as well.
It only removes one level of indentation, but it makes titlerender()
easier to understand.

Just like before, I have to put the separate function first, else
titlerender() won't know what it is.
2020-04-17 15:41:48 -04:00
Misa
511de0c5c1 Refactor menu creation code
Firstly, menu options are no longer ad-hoc objects, and are added by
using Game::option() (this is the biggest change). This removes the
vector Game::menuoptionsactive, and Game::menuoptions is now a vector of
MenuOption instead of std::string.

Secondly, the manual tracker variable of the amount of menu options,
Game::nummenuoptions, has been removed, in favor of using vectors
properly and using Game::menuoptions::size().

As a result, a lot of copy-pasted code has been removed from
Game::createmenu(), mostly due to having to have different versions of
menus depending on whether or not we have certain defines, or having an
mmmmmm.vvv file inside the VVVVVV directory. In the old days, you
couldn't just add or remove a menu option conveniently, you had to
shuffle around the position of every other menu option too, which
resulted in lots of copy-pasted code. But now this copy-pasted code has
been de-duplicated, at least in Game::createmenu().
2020-04-17 15:41:48 -04:00
Misa
76e3b3ede4 Remove map.numshinytrinkets
This removes map.numshinytrinkets in favor of using
map.shinytrinkets.size(). Having automatic length tracking is much less
error-prone and less tedious.
2020-04-14 22:54:16 -04:00
Misa
d63ba761d5 Remove map.numteleporters
This removes the separate length-tracking variable map.numteleporters,
in favor of using map.teleporters.size().
2020-04-14 22:54:16 -04:00
Misa
8507bdc65d Change obj.collect into a vector of bools
It's already treated like a bunch of bools anyway, so might as well just
formalize it.
2020-04-09 19:20:31 -04:00
Misa
abfae6b4d7 Declare obj.flags a vector of bools instead of ints
It's treated like a bool anyway, so might as well make it one.

This also necessitates updating every single instance where it or an
element inside it is used, too.
2020-04-09 19:20:31 -04:00
Misa
89b6b67a77 Don't use separate variable for number of crewmates in level
Same as previous commit, this time for crewmates.
2020-04-09 19:20:31 -04:00
Misa
0047dc8d81 Don't use separate variable for number of trinkets in level
Same principle as removing the separate variable to track number of
collected trinkets. This means it's less error-prone as we're no longer
tracking number of trinkets separately.

In the function that counts the number of trinkets, I would've liked to
have used std::count_if(). However, the most optimal way would require
using a lambda, and lambdas are too new for the C++ standard we're
using. So I just bit the bullet and counted them manually.
2020-04-09 19:20:31 -04:00
Misa
5661f46a52 Remove unnecessary int casts relating to custom crewmate numbers
I don't know why these are here, but there's never a point where these
integers were at any risk of no longer being integers.
2020-04-09 19:20:31 -04:00
Misa
6b317c5ab9 Remove map.customcrewmates
Same as the previous commit, except for the amount of custom crewmates.
2020-04-09 19:20:31 -04:00
Misa
85bd7d9a2d Remove map.customtrinkets
This variable's sole purpose is to copy ed.numtrinkets, even though ed
has always been a name that's been accessible globally. So let's not
dupe cope.
2020-04-09 19:20:31 -04:00
Misa
c077e51fb4 Don't use separate variable for number of collected crewmates
Same as previous commit, except for crewmates in custom levels instead.
2020-04-09 19:20:31 -04:00
Misa
9510c3c871 Don't use separate variable for number of collected trinkets
game.trinkets is supposed to be correlated with obj.collect, however why
not just count obj.collect directly?

This turns game.trinkets into a function, game.trinkets(), which will
directly count the number of collected trinkets and return it. This will
fix a few corner cases where the number of trinkets can desync with the
actual collection statuses of trinkets.

In order to keep save compatibility with previous versions of VVVVVV,
the game will still write the <trinkets> variable. However, it will not
read the <trinkets> variable from a save file.
2020-04-09 19:20:31 -04:00
Misa
37a3670dde Rename titlerender.cpp to Render.cpp
This also renames titlerender.h to Render.h, and updates all references
to titlerender.cpp accordingly.
2020-04-04 02:05:41 -04:00