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

580 Commits

Author SHA1 Message Date
Misa
2bb64198fe Use game.returnmenu() for all "return" menu options
This is to not reset your cursor position every time you return on
something. It's also to automatically keep track of which menu was the
previous menu instead of manually hardcoding said previous menu.
2020-04-17 15:41:48 -04:00
Misa
224585d774 Fix being able to mismatch summary and menu color
You were able to mismatch the color of the quicksave/telesave summary
and the text/background by pressing Esc when in the "continue" menu,
then pressing ACTION on "no, return".

This commit fixes that bug by putting the map.settowercolour(3) inside
the Menu::continuemenu creation code itself. However, since the
Menu::youwannaquit code does map.nexttowercolour() right after it does
the game.createmenu(), we also need to put the map.nexttowercolour()
before the game.createmenu() beforehand so it doesn't mess up the cyan
color that Menu::continuemenu sets.

Additionally, I removed the map.settowercolour() from the input handling
of Menu::play, as it's superfluous.
2020-04-17 15:41:48 -04:00
Misa
250be2dbb7 Mark same menus in levels list, credits, and unlock menus
This marks pressing ACTION on "next page" in the levels list, credits,
pressing ACTION on "continue" in "You have unlocked" menus, and pressing
ACTION on an unlock option in the unlock menu and time trial unlock menu
as being the same menu.

This is to prevent creating unnecessary stack frames when using said
menu options in those menus.
2020-04-17 15:41:48 -04:00
Misa
80ae625585 Remove unnecessary createmenu(Menu::graphicoptions) calls
These aren't necessary, the menu will update regardless. There isn't
even such a call for the mouse cursor toggle option, that's how
unnecessary it is.
2020-04-17 15:41:48 -04:00
Misa
bf4427c75a Add function Game::returnmenu()
It simply goes to the previous menu stack frame.
2020-04-17 15:41:48 -04:00
Misa
de0205e09b Push a stack frame when Game::createmenu() is called
Unless it's the main menu, or unless it's not the same menu. Whether or
not the menu is the same is left up to the caller, because some menus
could be the same but use different names, so we can't simply
automatically check that the names are different and assume that they
aren't the same menu.
2020-04-17 15:41:48 -04:00
Misa
58b9941d73 Add vector of MenuStackFrame menustack to Game
We need a stack to put our stack frames inside.
2020-04-17 15:41:48 -04:00
Misa
13d2d6b623 Add struct MenuStackFrame
This will be pushed onto a stack when going to a different menu so the
game can dynamically keep track of which menu option got you to which
menu.
2020-04-17 15:41:48 -04:00
Misa
503b3f1692 Move temp int off of Game
This temp variable isn't used anywhere else, and even if it was it's set
to something every time it's used, so there's no risk of this commit
breaking any backwards compatibility.
2020-04-17 15:41:48 -04:00
Misa
56a168eed6 Remove ABCDEFG comment
I assume it was so a dev could mark the spot where they needed to put in
the analogue toggle, and they found a unique yet easy to remember
sequence of characters to Ctrl+F as a marker.
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
ceb8d3f3d8 Remove unused variable Game::menuselection
I presume it was meant to have the text of the currently-selected menu
option inside it, before the code switched over to using the indice of
the currently-selected menu instead? Would've been more error-prone to
use the text name directly.
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
83ca75a831 Change "else if"-chain in editormenuactionpress to case-switch
It makes it better so you don't have to deal with that dangling first
"if" that doesn't have an 'else'.
2020-04-17 15:41:48 -04:00
Misa
78169cdc1c Move editor menu option rendering to separate function
Just like before, it makes editorrender() easier to read and reduces the
indentation level of the option rendering by one level.
2020-04-17 15:41:48 -04:00
Misa
0b5d7b1fef Move editor menu ACTION press handling to separate function
This removes a whopping four indentation levels from the ACTION
handling, and makes editorinput() easier to read.
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
cbd7ef94ba Gray out play modes if disabled due to enabled accessibility options
If you have invincibility mode or slowdown enabled, the game will not
let you select the Secret Lab, Time Trials, or No Death Mode. To make
this clearer, this commit grays out said options if they are disabled
for that reason.
2020-04-17 15:41:48 -04:00
Misa
38d749f536 Prevent selecting Secret Lab if game isn't at full speed
The game won't let you select the Secret Lab if you're in invincibility
mode, probably so you can't set illegitimate Super Gravitron records
just by standing there and doing nothing.

However, for some reason, it'll still let you select the Secret Lab even
if you've slowed down the game. For consistency, let's prevent selecting
the Secret Lab if the game isn't running at fullspeed, too.
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
678ade88b9 De-duplicate "secret lab" menu option in "play" menu
Instead of creating an entirely new menu for it, just dynamically add
the Secret Lab menu option as needed.
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
bf62233b60 Fix compile failure if both MAKEANDPLAY and NO_CUSTOM_LEVELS are defined
I don't know why you would have to have both defined simultaneously, but
now you can.

The compile fail was caused by the fact that if both were defined, then
there would be an expression like this in Map.cpp:

    switch (t)
    {
    case 0:
    }

which is an invalid expression.

The solution is to put 'case 0:' into the MAKEANDPLAY ifdef-guard as
well.
2020-04-17 15:41:48 -04:00
Misa
4ace8d15be Fix NO_CUSTOM_LEVELS builds breaking after command-line playtesting 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
1e3879b8fe De-duplicate "You have unlocked" menu input and options
They all have the same input handling and menu options, so condense them
into one block instead of duplicating the same block of code multiple
times.
2020-04-17 15:41:48 -04:00
Misa
119d2ad25f Condense indentation levels of else-if chain in "play" menu
Previously, the code looked something like:

    else { if (...) {...} else { if (...) {...} else { etc. } }

And kept indenting every time there was an else-if.

This commit puts all else-ifs on the same indentation level, so it
doesn't slowly push the code to the right.
2020-04-17 15:41:48 -04:00
Misa
be64d4f704 Move menu ACTION press handling to separate function
This takes out 3 indentation levels from the ACTION press handling,
making titleinput() easier to read as a whole.

Unfortunately, we have to put menuactionpress() first, even though I'd
want it the other way around, otherwise titleinput() won't know what it
is.
2020-04-17 15:41:48 -04:00
Misa
fe178f817b Remove outdated commented-out graphics options code
If we need it (which I don't think we will be anytime soon) we can
always just get it back through source control. Otherwise, it simply
gets in the way.
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
a0d2be6362 Add Game::option()
This simply adds a menu option to the list of menu options, and is neat
and tidy and not messy.
2020-04-17 15:41:48 -04:00
Misa
c5db440318 Add struct MenuOption
This fully represents an actual menu option object, instead of having
both attributes of a menu option go off and be in separate vectors.
2020-04-17 15:41:48 -04:00
Misa
5fdbaa0076 Remove unused function entityclass::cblocks()
Just noticed this was unused, so I'm removing it.
2020-04-14 22:54:16 -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
4f7290440b Remove now-unused parameter 't' from mapclass::settrinket()
This parameter used to be used to set the trinket based on indice, but
now that we push_back it's no longer used.
2020-04-14 22:54:16 -04:00
Misa
d43daa5fae Dynamically add shinytrinkets instead of using indices
That is, instead of doing shinytrinkets[t] = ..., do
shinytrinkets.push_back(...).
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
5b9c6a9680 Remove now-unused parameter 't' from mapclass::setteleporter()
This was previously used to set the indice of the teleporter, but now
that we do push_back() it's no longer necessary and is now unused.
2020-04-14 22:54:16 -04:00
Misa
fd7d6076e0 Dynamically add teleporters instead of using indices
That is, instead of doing the following:

    teleporters[0] = ...;
    teleporters[1] = ...;
    teleporters[2] = ...;
    ...

Instead do:

    teleporters.push_back(...);
    teleporters.push_back(...);
    teleporters.push_back(...);
    ...
2020-04-14 22:54:16 -04:00
Misa
d4034661e2 Don't use std::count() in Game::crewmates()
The less STL usage, the better.
2020-04-09 19:20:31 -04:00
Misa
3774ec390c Don't use std::count() in Game::trinkets()
The less STL, the better.
2020-04-09 19:20:31 -04:00
Misa
45e7a9db3e Use for-loop in Game::crewrescued()
It's better to not use an STL function here.
2020-04-09 19:20:31 -04:00
Misa
a37715abb6 Put trinkets() and crewmates() declaration on their own lines
Done to improve readability.
2020-04-09 19:20:31 -04:00
Misa
17a64aee7a Make obj.customcollect a vector of bools
It's already treated as a vector of bools, so might as well formally
declare it as that.
2020-04-09 19:20:31 -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
7493129044 Remove unused function entityclass::confirmflags()
Same as before, flags can never be the number 2, and never could be even
before I changed all flags to be bools. Also this function is unused.
2020-04-09 19:20:31 -04:00
Misa
ee5f8dce78 Remove unused function entityclass::resetflags()
This looks like a weird hack, but there's no way a flag will ever end up
being 2, not even before I changed all flags to be bools instead.
2020-04-09 19:20:31 -04:00
Misa
0648d6bb0f Remove unused function entityclass::changecustomcollect()
Looks like all accesses on obj.customcollect are done manually, so this
function is unused.
2020-04-09 19:20:31 -04:00
Misa
a6340f356e Remove unused function entityclass::changecollect()
Looks like all access on obj.collect are done manually, so this function
is unused.
2020-04-09 19:20:31 -04:00
Misa
c24e2abfad Remove now-unused function entityclass::changeflag()
It's now unused after I changed it so that every obj.flags access is
done directly, instead of going through this function.
2020-04-09 19:20:31 -04:00
Misa
2ba9a0e67b Don't use obj.changeflag() to set flags
The way I see it, that function is basically an unnecessary middleman.
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
2f1c400c9a Remove temporary UtilityClass from Game::savestats()
Looks like it was here from that arg passing stuff from earlier, as a
workaround to not pass args around. Well, there's no need to create an
extra UtilityClass now either, just use the one in the global namespace.
2020-04-09 19:20:31 -04:00
Misa
699af342e8 Refactor Game::crewrescued() to use std::count() instead
Makes the code less hardcoded, take up less lines, and is way easier to
read.
2020-04-09 19:20:31 -04:00
Misa
588a49dbc8 Remove useless variable game.timerStartTime
It sometimes gets set to SDL_GetTicks(), but without being checked or
actually used, it's useless and does nothing.
2020-04-09 19:20:31 -04:00
Misa
6428a14244 Declare game.teleport as a bool instead of an int
This should affect nothing, but it's a bit confusing to have it declared
an int. Everywhere in the code treats it as a bool anyway.
2020-04-09 19:20:31 -04:00
Misa
c5803863bf Remove unused variables temp_unlock and temp_unlocknotify
Have no idea why they're here, so removing them.
2020-04-09 19:20:31 -04:00
Misa
1110d46c8b Remove unused stat_* variables
Looks like all variables other than stat_trinkets are unused.
2020-04-09 19:20:31 -04:00
Misa
317eece28d Remove useless variable game.coins
It kept getting set to 0 and getting incremented sometimes, but without
it ever actually getting checked, it's a useless variable.
2020-04-09 19:20:31 -04:00
Misa
756c409d1d Remove unused variable game.trinkencollect
Don't know why it's here. Looks like a typo of 'trinketcollect' maybe?
2020-04-09 19:20:31 -04:00
Misa
fb9791a4c7 Remove now-useless function editorclass::countstuff()
Previously, it existed solely to count the number of trinkets and
crewmates when loading a level, because we were keeping track of the
amount of them manually, incrementing and decrementing every time a
trinket or crewmate was added or removed, but loading a new level
represented a case that could potentially not be an increment or
decrement.

However, since the amount tracking is now handled automatically, this
function now does nothing, and can be safely removed.
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
leo60228
94b2ebd55c
Implement command-line playtesting (#163) 2020-04-09 15:03:24 -04:00
Misa
4511ea172e Don't boot user back to main menu after toggling using MMMMMM
It's a bit rude to put the user back at the main menu after toggling
something. Maybe they also wanted to do something else in the menu while
they're toggling MMMMMM, there's no reason to immediately put them back
there.
2020-04-06 15:41:52 -04:00
Misa
5a9cd861ef Don't update game.stat_trinkets in custom levels
Whenever you collect a trinket, game.stat_trinkets gets updated (if
applicable) to signify the greatest amount of trinkets you have ever
collected in the game. However, custom levels shouldn't be able to
affect this, as their trinkets are not the same trinkets as the main
game.
2020-04-05 18:31:03 -04:00
Misa
7f0db19abd Fix memory leak from warping moving platforms
It turns out that when the game warps moving platforms, it won't remove
the block from the position before they warped. Eventually, these blocks
will pile up and will never be removed, causing a memory leak.
2020-04-04 16:26:15 -04:00
Misa
79a54f23e6 De-dupe screen transition / warping logic
I noticed that the code for going to the adjacent room when offscreen
and for warping instead if the room is warping was a bit
copy-and-pasted. To clean up the code a bit, there's now 5 separate
checks in gamelogic():

if (map.warpx)
if (map.warpy)
if (map.warpy && !map.warpx)
if (!map.warpy)
if (!map.warpx)

I made sure to preserve the previous weird horizontal warping behavior
that happens with vertical warping (thus the middle one), and to
preserve the frame ordering just in case there's something dependent on
the frame ordering.

The frame ordering is that first it will warp you horizontally, if
applicable, then it will warp you vertically, if applicable. Then if you
have vertical warping only, that weird horizontal warp. Then it will
screen transition you vertically, if applicable. Then it will screen
transition you horizontally, if applicable.

To explain the weird horizontal warp with the vertical warp: apparently
if an entity is far offscreen enough, and if that entity is not the
player, it will be warped horizontally during a vertical warp. The
points at which it will warp is 30 pixels farther out than normal
horizontal warping.

I think someone ran into this before, but my memory is fuzzy. The best I
can recall is that they were probably createentity()ing a high-speed
horizontally-moving enemy in a vertically warping room, only to discover
that said enemy kept warping horizontally.
2020-04-04 16:26:15 -04:00
Misa
7899cb8088 Condense some nested else-if statements
It's better to write 'else if' than 'else { if }'.
2020-04-04 16:26:15 -04:00
Misa
e6c6c7cf60 Condense some nested if-statements in gamelogic()
It's better to write if (cond1 && cond2) than it is to write if (cond1)
{ if (cond2) }.
2020-04-04 16:26:15 -04:00
Misa
3818340011 Clean up some indentation in gamelogic()
This is just a miscellaneous indentation cleanup to fix some places
where it is indented with 2 spaces instead of 4.
2020-04-04 16:26:15 -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
Misa
97e340b5a7 Fix typo "Your have unlocked" to "You have unlocked"
Looks like this was copy-pasted for every single unlock message, too.
Either everyone is THAT blind, or everyone is too lazy, or both.
2020-04-04 00:20:45 -04:00
Misa
168fa53f7c Refactor scriptclass txt to not use a separate length-tracker
This removes the variable txtnumlines off of scriptclass, in favor of
using txt.size() instead.
2020-04-03 23:28:47 -04:00
Misa
31321ee19c Remove textboxclass's firstcreate and clear, simplify initializations
As a result of the previous commit, textboxclass::clear() is now unused.
textboxclass::firstcreate() was already useless. So remove both those
functions and initialize the values in the textboxclass constructor.
2020-04-03 23:28:47 -04:00
Misa
09c9a6b862 Refactor text box contents to not use a separate length-tracker
This removes the variable numlines from each text box object, in favor
of using line.size().
2020-04-03 23:28:47 -04:00
Misa
2ec1080b3d Remove remnant of 'active' if-conditional
This commit removes that 'if (true)' and unindents everything in
drawgui() by one level.
2020-04-03 23:28:47 -04:00
Misa
bc0d22eec6 Refactor text boxes to not use the 'active' system
This removes the variables graphics.ntextbox, as well as removing
'active' from each text box object. Thus, all text boxes are really
real, and you don't have to check its 'active' variable.
2020-04-03 23:28:47 -04:00
Misa
0127a84698 Move text box fadeout removal to Graphics::drawgui()
Something that's slightly annoying is that in order to make the vector
of text boxes be properly used, the text box cannot remove itself.
Because the text box does not know it's in a vector. So move the removal
of the text box to drawgui() instead.
2020-04-03 23:28:47 -04:00
Misa
313c2661af Fix nested if-statements relating to blocks in Entity.cpp
Just like earlier, these are of the form
if (cond1) { if (cond2) { if (cond3) { thing; } } }
and are really annoying to read.

Also this removes the remnants of the 'active' system that have been
replaced with 'if (true)' conditionals in order to not add noise to the
diff.
2020-04-03 23:28:47 -04:00
Misa
9de5b57989 Remove blockclass::clear(), simplify blockclass initializations
Previously, it was used in order to clear a block and deactivate it, and
the constructor function simply called clear() in order to not duplicate
code. However, clear() is no longer necessary (just remove the block
from the blocks vector), and so we can put initialization right back in
the constructor function.
2020-04-03 23:28:47 -04:00
Misa
b027a3ddc6 Fix mixed indentation in Enter-handling code when playtesting
It was indenting with 2 spaces instead of 4 spaces like the surrounding
code.
2020-04-03 23:28:47 -04:00
Misa
2a80c80f6c Fix undefined behavior when removing activity zones
It turns out the game engaged in pseudo-UB when removing activity zones,
which got turned into actual UB due to the previous commit.

There were three places where this could happen:
 - Pressing ENTER on an activity zone in normal gameplay
 - Pressing ENTER on an activity zone in in-editor playtesting (because
   the code is duped here)
 - Pressing ESC and quitting to menu while standing inside an activity
   zone

In all cases, game.activeactivity would still be pointing to a
non-existent activity zone. This activity zone in the previous system
would simply be a block with a false 'active', and in the system where
C++ vectors are used properly, would index past the blocks array.

In fact, it is a bug that when you press ENTER on an activity zone, the
activity zone prompt suddenly turns to black, then immediately
disappears. It was pointing to a block that had its clear() method
called, which is why it was all black, and it was an inactive block!
This commit makes it so pressing ENTER on an activity zone smoothly
fades out the activity zone prompt instead of being sudden black.
2020-04-03 23:28:47 -04:00
Misa
f10ac88c1a Refactor blocks to not use the 'active' system
This removes the variables obj.nblocks, as well as removing the 'active'
attribute from the block object. Now every block is guaranteed to be
real without having to check the 'active' variable.

Removing a block while iterating now uses the removeblock_iter() macro.
2020-04-03 23:28:47 -04:00
Misa
7689241d3a Add macro removeblock_iter()
When we switch blocks to not use 'active', we'll need this macro to
remove blocks while iterating through the vector, one at a time,
forwards.
2020-04-03 23:28:47 -04:00
Misa
7edbebac92 Move entityclass::setblockcolour() to blockclass::setblockcolour()
This moves the function setblockcolour(), so I can directly call it on a
particular block without having to have it be inside obj.blocks.
2020-04-03 23:28:47 -04:00
Misa
2cb90afbda Remove entclass::clear(), simplify entclass initializations
Previously there was an entclass::clear(), and initialization of an
entclass was done by calling clear() in order to not duplicate code. But
now there's no need for an entclass::clear(), and it is in fact unused
(just call entityclass::removeentity() instead), so I'm removing this
function.
2020-04-03 23:28:47 -04:00
Misa
ecf556dc55 Remove 'if (entities[i].state == 0) { }'
That's right, it's an if-conditional that does absolutely nothing.
Classic.
2020-04-03 23:28:47 -04:00
Misa
1b78db9079 Remove two '//Active' comments
I guess these were here earlier when there were 'active' conditionals,
but then I removed those, so now they look weird next to the 'i != j'
conditionals, so I'm removing them.
2020-04-03 23:28:47 -04:00
Misa
2f3eeccdf0 Fix nested if-statement chains relating to entities in Entity.cpp
These would be of the form
if (cond1) { if (cond2) { if (cond3) { thing; } } }
which is really annoying to read and could've been written as
if (cond1 && cond2 && cond3) { thing; }
so that's what I'm fixing here.

There will be another commit later that fixes this but in places related
to blocks.
2020-04-03 23:28:47 -04:00
Misa
e40a4c3948 Remove some more outdated comments from Entity.cpp
Most of these won't work if you uncomment them without any additional
changes, so it's best to just remove them.
2020-04-03 23:28:47 -04:00
Misa
0fb37352ce Make entityclass::updateentities() no longer a bool
It always returns true anyway, so why bother? And it doesn't look like
any code uses its return value, anyway.
2020-04-03 23:28:47 -04:00
Misa
46c17052c6 Remove unused function entityclass::gettype()
Not sure why this function is here. It makes sense if you know that the
game will only do certain moving platform things if you already have a
moving platform in the room, however apparently this function has
absolutely nothing to do with it.
2020-04-03 23:28:47 -04:00
Misa
744c685614 Remove entityclass::cleanup()
This function's sole purpose was to make sure obj.nentity was in sync,
and that obj.nentity-1 pointed to the last 'active' entity in
obj.entities. But now that obj.nentity is removed and we use
obj.entities.size() instead, it is no longer necessary.
2020-04-03 23:28:47 -04:00
Misa
fd417d6a8c Remove remnants of entity 'active' conditionals
In the previous commit, if an if-statement consisted solely of checking
the active attribute of an entity, I temporarily changed it to 'true'
and put a comment to remove it later, because it would add too much
noise to unindent everything in the same commit.
2020-04-03 23:28:47 -04:00
Misa
b1b1474b7b Refactor entities and linecrosskludge to not use the 'active' system
This removes the variables obj.nentity and obj.nlinecrosskludge, as well
as removing the 'active' attribute from the entity class object. Now
every entity you access is guaranteed to be real and you don't have to
check the 'active' variable.

The biggest part of this is changing createentity() to modify a
newly-created entity object and push it back instead of already
modifying an indice in obj.entities.

As well, removing an entity now uses the new obj.removeentity() function
and removeentity_iter() macro.
2020-04-03 23:28:47 -04:00
Misa
a67ab8e3a7 Add macro removeentity_iter()
Also when we switch everything to not use 'active', we'll need this
macro to remove entities while iterating forwards through the vector one
at a time.
2020-04-03 23:28:47 -04:00
Misa
1156582ceb Add entityclass::removeentity()
Ok, once we switch everything over to not use the 'active' system, it's
easier to read removeentity(t) than it is to read
entities.erase(entities.begin() + t).
2020-04-03 23:28:47 -04:00
Misa
ae84de2c7e Move entityclass::settreadmillcolour() to entclass::settreadmillcolour()
This moves settreadmillcolour() onto the entity object, so I can invoke
it independent of an indice in obj.entities.
2020-04-03 23:28:47 -04:00
Misa
f5a84d7972 Move entityclass::setenemyroom() to entclass::setenemyroom()
This moves the setenemyroom() function onto the entity object itself, so
I can more easily change all 'entities[k].' to 'entity.' in
entityclass::createentity() later.

Additionally, I've had to move the rn() macro from Entity.h to Ent.h, or
else entclass::setenemyroom() won't know what it is.
2020-04-03 23:28:47 -04:00
Misa
d4cffed176 Move entityclass::setenemy() to entclass::setenemy()
This moves the setenemy() function onto the entity object itself,
instead of having to give the indice of the entity in obj.entities. This
makes the code more object-oriented so later I can simply change all
'entities[k]' to 'entity.' in entityclass::createentity().
2020-04-03 23:28:47 -04:00
Misa
c278f05397 Remove duplicate function musicclass::stopmusic()
It is an exact duplicate of musicclass::haltdasmusik(), so use that
function instead and update callers. Looks like
musicclass::haltdasmusik() came first, anyway (musicclass::stopmusic()
was only used in editor.cpp).
2020-04-03 19:19:45 -04:00
Misa
34395435f0 Remove unused function musicclass::loopmusic()
Maybe back in the Flash days, you had to loop music manually instead of
having SDL_mixer handle it? Or something?
2020-04-03 19:19:45 -04:00
Misa
dc6d38276c Remove another outdated comment in Music.cpp
Looks like musicfade is an unused variable, anyway. I might remove it,
but I have some plans in the future that involve repairing what it was
intended for, so I'll hold off on removing it (and some other unused
variables in Music.cpp) for now.
2020-04-03 19:19:45 -04:00
Misa
e571081f92 Un-fix using-PPPPPP-while-MMMMMM-present for custom levels
As discussed earlier, some custom levels have taken advantage of the
fact that songs 0 and 7 loop and also fade in when using PPPPPP while
having an mmmmmm.vvv file present.
2020-04-03 19:19:45 -04:00
Misa
7b1388f85c Fix undefined behavior when backspacing in script list with 0 scripts
The problem is that it would index out-of-bounds if you did this, but
this UB hasn't caused an exception until my change to refactor
script-related vectors by removing their separate length-trackers.
2020-04-03 16:57:52 -04:00
Misa
dafadf158a Remove outdated comments from preloader.cpp
Was just skimming through my diffs, looks like I missed these comments
in preloader.cpp.
2020-04-03 10:40:50 -04:00
Misa
134510d26a Remove remnants of screen recording stuff
Most of the code was already commented out, and those comments were
removed in earlier commits, but this removes all recording variables
from Game and simplifies the game-gamestate handling in main.cpp a
little bit.
2020-04-03 10:40:50 -04:00
Misa
fd21fbb341 Remove outdated comments from main.cpp
Mostly comments from all the global args were not-so-global args, along
with input recording.
2020-04-03 10:40:50 -04:00
Misa
04d14000ec Remove global 'temp' variable from titlerender.cpp
Just a miscellaneous code cleanup.

There's no glitches that take advantage of the previous situation,
namely that 'temp' was a global variable in Logic.cpp and editor.cpp.
Even if there were, it seems like it would easily lead to some undefined
behavior. So it's good to clean this up.
2020-04-03 10:40:50 -04:00
Misa
d3cdd33605 Remove unused function musicclass::processmusicfade()
It's a function that does nothing, and is also used by nothing.
2020-04-03 10:40:50 -04:00
Misa
eea2232c12 Remove outdated comments from Music.h and Music.cpp
Lots of stuff from the Flash version, especially in Music.h.
2020-04-03 10:40:50 -04:00
Misa
4c2ecac0e0 Remove outdated comments from Input.cpp
There's a commented-out recording input option, which sounds
interesting.
2020-04-03 10:40:50 -04:00
Misa
d13c24b9b0 Realign logic update trio comments
This is the "Behavioral logic", "Basic Physics", and "Collisions with
walls" trio.

They were originally aligned but then I removed global args, thus
misaligning them. So now I'm re-aligning them back again.
2020-04-03 10:40:50 -04:00
Misa
07573ad738 Remove outdated comments from Logic.cpp
Earlier design decisions that have been commented out and are now
obselete.
2020-04-03 10:40:50 -04:00
Misa
9817e19150 Remove outdated comments from Map.cpp
Surprisingly not that many. It looks like at one point in development,
damage blocks were created for every single spike in the Tower, before
it was too laggy so they switched to directly checking collision with
the tile instead.
2020-04-03 10:40:50 -04:00
Misa
d1661c20a8 Remove outdated comments from Script.cpp
Some of these seem to be copy-pasting stuff and then commenting it out
if it doesn't fit the pasted case.
2020-04-03 10:40:50 -04:00
Misa
92544cbdbb Remove outdated comments from editor.cpp
A lot of these seem to be based on an earlier version of the C++ port,
but they left some Flash stuff (like the buffer lock/unlocking) in, too.
2020-04-03 10:40:50 -04:00
Misa
69364736ff Remove outdated comments from titlerender.cpp
Lots of these are from the Flash version!
2020-04-03 10:40:50 -04:00
Misa
b4937ff8d5 Remove outdated comments from Graphics.cpp
This removes a bunch of commented-out code that was clearly kept from
the Flash version, even though the Flash graphics API is much different
than SDL's. Also removes a bunch of TODOs that either say nothing, or
say something whose meaning has been totally lost to time due to being
completely vague, or something that's already been done and someone
forgot to remove the TODO.
2020-04-03 10:40:50 -04:00
Misa
b061051297 Remove outdated comments from Game.cpp
Most of this is telecookie/quickcookie stuff, which was used in the
Flash version, but there's no longer any such thing as a save cookie.

Also one TODO that says to make a function that's now been made.
2020-04-03 10:40:50 -04:00
Misa
f7ff076074 Move tempstring off of Graphics, Game, and UtilityClass
Unlike, say, the scriptclass i/j/k stuff, these tempstrings are only
purely visual, and there's no known glitches to manipulate them anyway.
Thus I think it's safe to make this cleanup.
2020-04-03 10:40:50 -04:00
Misa
ff449a2c3a Remove game.test and game.teststring
It looks like this may have been used earlier in development, judging
from the name, obviously, but right now it seems like it's used as an
error message if a main game level is asked for an invalid room (well,
only two of them - the Lab and Warp Zone). It should probably be
formalized into an error system, if we want to keep teststring, and also
people would never see it anyway because I don't think there's a
reliable and consistent way to trigger loading a non-existent room.

I have seen someone manage to load a non-existent Warp Zone room only
one time, but even then this teststring didn't pop up. So this
teststring doesn't even trigger in the right circumstances.

Also, when it does pop up, as far as I can tell it will stay onscreen,
which is kinda annoying. So I'm just removing this ancient relic from
the code.
2020-04-03 10:40:50 -04:00
Misa
9a3a8bf2be Fix mixed indentation in main.cpp
Also fix the indentation of preprocessor statements.
2020-04-03 10:40:50 -04:00
Misa
e73966f2b7 Fix only one line of mixed indentation in Music.cpp
And this is the winner for having the least amount of mixed indentation
that is nonzero.
2020-04-03 10:40:50 -04:00
Misa
b0e1079611 Fix mixed indentation in Scripts.cpp
Only 3 lines, which is really impressive and the lowest amount of mixed
indentation so far.
2020-04-03 10:40:50 -04:00
Misa
c33caefae8 Fix mixed indentation in preloader.cpp
Not that much, but only because it's not a big file to begin with.
2020-04-03 10:40:50 -04:00
Misa
31410a2d64 Remove one trailing whitespace in preloader.cpp
Only one.
2020-04-03 10:40:50 -04:00
Misa
a31a6ef614 Fix mixed indentation in titlerender.cpp
There's a lot, looks like mainly because of the person who added MMMMMM
and M&P.
2020-04-03 10:40:50 -04:00
Misa
dd8cf0f200 Fix mixed indentation in Input.cpp
There is a lot to be had for this one.
2020-04-03 10:40:50 -04:00
Misa
e56b0d9f39 Fix mixed indentation in Logic.cpp
It's clear that there was another person who added achievements and did
some warp line stuff.
2020-04-03 10:40:50 -04:00
Misa
079544c0b1 Fix mixed indentation in Entity.cpp and Entity.h
That guy who indents with 2-wide tabs to match 4-wide spaces strikes
again...
2020-04-03 10:40:50 -04:00
Misa
7c511b1550 Fix mixed indentation in GraphicsUtil.cpp
To be fair, it was more on the level of entire functions using different
indentation than the surrounding code, but it's not consistent enough
for me to justify leaving it alone.
2020-04-03 10:40:50 -04:00
Misa
0947840365 Remove unused variable Screen::glScreen
Not sure what this was meant to be - a flag for if the screen is OpenGL
or not? Either way, unused.
2020-04-03 10:40:50 -04:00
Misa
ef234d3fc0 Fix mixed indentation in Screen.cpp
Screen.cpp now consistently uses tabs.
2020-04-03 10:40:50 -04:00
Misa
4657760c2d Fix mixed indentation in Script.cpp and Script.h
Looks like the person who added starting a custom level indented with
spaces instead of tabs.
2020-04-03 10:40:50 -04:00
Misa
1310896191 Remove semi-useless function editorclass::weirdloadthing()
Looks like this function was created because editorclass::load() takes
in a string by reference, not by value, and thus mutates it afterwards,
so if you passed a string in when you didn't want it to be mutated, bad
things would happen.

However, a better workaround for the above issue would simply to
duplicate the string and pass that string instead, thus the original
string wouldn't be affected.
2020-04-03 10:40:50 -04:00
Misa
5ba1cf7571 Fix mixed indentation in Map.h and Map.cpp
Again, not that much. These files more-or-less consistently use their
respective indentation.
2020-04-03 10:40:50 -04:00
Misa
3943e160de Fix mixed indentation in Graphics.cpp
To reiterate, I just want to remove the mixed indentation that just
randomly pops up in the middle of a file, because it gets annoying.
Thus, the indentation of a particular piece of code should simply match
the surrounding code. And I consider it completely fine that this file
switches from indenting 4-wide spaces to tabs starting from
Graphics::setcol() onwards. I don't think it's worth it to untabify
Graphics::setcol() and below.
2020-04-03 10:40:50 -04:00
Misa
88c16cdae8 Fix mixed indentation in Game.cpp and Game.h
This removes all indentation that suddenly switches in the middle of a
function. Most particularly egregious offenses are the ones made by the
person who has 2-wide tabs, but keeps tabbing up to make each
indentation level match up with the 4-wide spaces, so to them (and only
them) it will look just fine, but since by default tabstop is 8-wide,
their lines are pushed off all the way to the right.
2020-04-03 10:40:50 -04:00
Misa
12d5433efc Remove trailing whitespace from all files
Surprisingly, there's not a lot of it. There is, however, a lot of mixed
indentation in this project.
2020-04-03 10:40:50 -04:00
Misa
6c6b6c68ff Change all UtilityClass::something to help.something
This changes something like UtilityClass::String to help.String,
basically. It takes less typing this way, and is a neat effect of having
global args actually be global variables.
2020-04-03 10:40:50 -04:00
Misa
c8906d97f5 Remove usages of second argument of playef() script command
Just to be in line with the removal of the argument in the actual
function itself.
2020-04-03 10:40:50 -04:00
Misa
16c3966ace Remove unused argument from musicclass::playef()
Apparently the 'offset' argument did something in the 1.x Flash
versions, but now it does nothing.
2020-04-03 10:40:50 -04:00
Misa
253d44ac0b Remove unused function musicclass::initefchannels()
It's a function that does nothing, used by no one.
2020-04-03 10:40:50 -04:00
Misa
e722251ebe Remove useless function Screen::ClearScreen()
This function does not clear the screen at all, it does absolutely
nothing.
2020-04-03 10:40:50 -04:00
Misa
691673ed30 Remove useless function updategraphicsmode()
Now that it does nothing due to some earlier changes, it's a useless
function that does nothing. (Well, it was already a useless function,
but those earlier changes made it clearer just exactly how useless it
is.) So remove that function and remove all its callsites.
2020-04-03 10:40:50 -04:00
Misa
297f1b6e3a Remove now-unused class Stage
Since I removed the useless variables 'stage' and 'swfStage' earlier,
now this class is unused. So I'm removing it, too.
2020-04-03 10:40:50 -04:00
Misa
16df287c90 Remove useless variables 'swfStage' and 'stage'
'swfStage' gets set to 'stage' in updategraphicsmode() but... that does
absolutely nothing, because they both contain exactly the same thing.
And these variables aren't referenced anywhere else. So I'm removing
both of these variables.
2020-04-03 10:40:50 -04:00
Misa
606c740b4f Remove useless variable Game::quickcookieexists
Even though it keeps getting set to true and false everywhere, it never
once gets checked. So it's a variable that does nothing.
2020-04-03 10:40:50 -04:00
Misa
340f57762d Remove useless variable Game::telecookieexists
Although it keeps getting set to true and false in various places, it
never once gets checked, essentially deeming it a variable that's used
but does nothing.
2020-04-03 10:40:50 -04:00
Misa
9cec63bcf7 Remove unused variable Game::sfpsmode
This variable does absolutely nothing, so I'm removing it.
2020-04-03 10:40:50 -04:00
Misa
66b3c32899 Remove useless function Game::telegotoship()
This function does absolutely nothing. It is, however, called once in
gamecompletelogic2(), making it technically used.
2020-04-03 10:40:50 -04:00
Misa
4f318e1ee1 Remove unused function entityclass::checkdirectional()
This function is never used anywhere in the game.
2020-04-03 10:40:50 -04:00
Misa
6a28c5de30 Remove unused arguments from Graphics::drawtile2()
The 'r', 'g', and 'b' arguments do absolutely nothing. Except unlike
Graphics::drawtile(), there's only one version of Graphics::drawtile2(),
so just remove those args and update callers.
2020-04-03 10:40:50 -04:00
Misa
5c60b8df5f Remove unused arguments from Graphics::drawtile()
The 'r', 'g', and 'b' arguments do absolutely nothing, even though
they're used in the version of Graphics::drawtile() that's more used. So
delete the other version without those extra arguments, and then remove
the extra arguments from the remaining version. And then update callers.
2020-04-03 10:40:50 -04:00
Misa
af8d7345c9 Remove unused arguments from Graphics::Hitest()
The two arguments 'col' and 'col2', both the only integer arguments of
the function, do absolutely nothing. Remove those and update callers.
2020-04-03 10:40:50 -04:00
Misa
7abf40881a Remove unused argument of entityclass::getcompanion()
The argument provided to entityclass::getcompanion() does absolutely
nothing. Remove it, and update all callers.
2020-04-03 10:40:50 -04:00
Misa
d910800423 Remove global args from main game loadlevel() functions
This removes global args from Finalclass.cpp, Labclass.cpp,
Otherlevel.cpp, Spacestation2.cpp, and WarpClass.cpp.
2020-04-03 10:40:50 -04:00
Misa
cef111d35b Remove global args from preloader.cpp
This removes all global args from preloader.cpp, and changes all 'dwgfx'
to 'graphics'.
2020-04-03 10:40:50 -04:00
Misa
07a0c74b01 Remove global args from titlerender.cpp
This removes all global args in all functions in titlerender.cpp.
Additionally, all 'dwgfx' has been renamed to 'graphics' in that file
(there are a lot of them, as you might guess).
2020-04-03 10:40:50 -04:00
Misa
a1fd4c6f02 Remove global args from Input.cpp
This removes all global args from functions in Input.cpp. Additionally,
'dwgfx' has been renamed to 'graphics' in Input.cpp.
2020-04-03 10:40:50 -04:00
Misa
2c138a4a60 Remove global args from Logic.cpp
This commit removes the passing around of global args in the logic
functions. Additionally, all 'dwgfx' has been replaced with 'graphics'
in Logic.cpp.
2020-04-03 10:40:50 -04:00
Misa
9bc45c586e Remove global args from editorclass
This removes global arg passing from all functions on editorclass.
Callers have been updated correspondingly. Additionally, all 'dwgfx' has
been replaced with 'graphics' in editor.cpp.
2020-04-03 10:40:50 -04:00
Misa
ea3c778b84 Remove global args from scriptclass
This commit removes all global args from the parameters of each function
on the scriptclass object, and updates all places they are called
accordingly. It also changes all instances of 'dwgfx' to 'graphics' in
Script.cpp.

Interestingly enough, it looks like editor.h depended on Script.h's
class define of the musicclass. I've temporarily placed the class define
in editor.h, but by the end of this patchset it'll be gone.
2020-04-03 10:40:50 -04:00
Misa
2826bd828c Remove global args from Graphics
This removes global args from all functions on the Graphics class.
Callers of those functions in other files have been updated accordingly.

Of course, since Graphics.cpp is already in the Graphics namespace,
I do not need to change all 'dwgfx' to 'graphics' in Graphics.cpp.
2020-04-03 10:40:50 -04:00
Misa
35d9bcce05 Remove global args from mapclass
This commit removes the global args being passed around from the
function args on the mapclass object, as well as updating all callers in
other files to not have those args. Furthermore, 'dwgfx' has been
renamed to 'graphics' in Map.cpp.
2020-04-03 10:40:50 -04:00
Misa
cac1a9e3ab Remove global args from entityclass
This commit removes all global args from functions on the entityclass
object, and updates the callers of those functions in other files
accordingly (most significantly, the game level files Finalclass.cpp,
Labclass.cpp, Otherlevel.cpp, Spacestation2.cpp, WarpClass.cpp, due to
them using createentity()), as well as renaming all instances of 'dwgfx'
in Entity.cpp to 'graphics'.
2020-04-03 10:40:50 -04:00
Misa
0e561f23f8 Remove global args from Game
I've decided to call dwgfx/game/map/obj/key/help/music the "global args".
Because they're essentially global variables that are being passed
around in args.

This commit removes global args from all functions on the Game class,
and deals with updating the callsites of said functions accordingly. It
also renames all usages of 'dwgfx' in Game.cpp to 'graphics', since the
global variable is called 'graphics' now.

Interesting to note, I was removing the class defines from Game.h, but
it turns out that Graphics.h depends on the mapclass and entityclass
defines from Game.h. And also Graphics.h spelled mapclass wrong (it
forgot the "class") so I just decided to use that existing line instead.
This is only temporary and after all is said and done, at the end of
this pull request those class defines will be gone.
2020-04-03 10:40:50 -04:00
Misa
1be398319c Make commands, sb, and hooklist not use separate length-trackers
This is a refactor that turns the script-related arrays `ed.sb`, and
`ed.hooklist` into C++ vectors (`script.commands` was already a vector, it was
just misused). The code handling these vectors now looks more like idiomatic
C++ than sloppily-pasted pseudo-ActionScript. This removes the variables
`script.scriptlength`, `ed.sblength`, and `ed.numhooks`, too.

This reduces the amount of code needed to e.g. simply remove something from
any of these vectors. Previously the code had to manually shift the rest of
the elements down one-by-one, and doing it manually is definitely error-prone
and tedious.

But now we can just use fancy functions like `std::vector::erase()` and
`std::remove()` to do it all in one line!

Don't worry, I checked and `std::remove()` is in the C++ standard since at least
1998.

This patch makes it so the `commands` vector gets cleared when
`scriptclass::load()` is ran. Previously, the `commands` vector never actually
properly got cleared, so there could potentially be glitches that rely on the
game indexing past the bounds set by `scriptlength` but still in-bounds in the
eyes of C++, and people could potentially rely on such an exploit...

However, I checked, and I'm pretty sure that no such glitch previously existed
at all, because the only times the vector gets indexed are when `scriptlength`
is either being incremented after starting from 0 (`add()`) or when it's
underneath a `position < scriptlength` conditional.

Furthermore, I'm unaware of anyone who has actually found or used such an
exploit, and I've been in the custom level community for 6 years.

So I think it's fine.
2020-03-24 20:20:53 -04:00
Misa
cfd355bf4d Don't let custom levels tamper with main game save data
Someone being mean could've overwritten the telesaves of unsuspecting
players, or unlocked a bunch of stuff which they shouldn't have for
those players, using things like the telesave() command and gamestates.
To prevent this, return early in Game::savequick(), Game::savetele(),
and Game::unlocknum() if we are in custommode.
2020-03-15 12:29:26 -04:00
Misa
cad0b4fcc4 Do proper error handling inside Screen::ResizeScreen()
Instead of passing the error codes out of the function, just handle the
errors directly as they happen, and fail gracefully if something goes
wrong instead of continuing.
2020-03-13 19:05:56 -04:00
Misa
9175c08763 Don't print useless false error message when toggling fullscreen
Whenever you would press Alt+Enter, or Alt+F, or on macOS Command+Enter,
or on macOS Command+F, or F11, the game would print this useless error
message to console, every single time: "Error: failed: " and it would
concatenate SDL_GetError() after it, but most of the time SDL_GetError()
is blank, so it would print just that.

Instead, what the fullscreen shortcut will now do is check the result of
the relevant SDL functions, BEFORE it decides to print an error message.
And when it DOES print an error message, it will be less vague and will
say instead "Error: toggling fullscreen failed: <output of
SDL_GetError()>".

This means Screen::ResizeScreen() and Screen::toggleFullScreen() are now
int-returning functions. Ideally, every function interfacing with SDL
would return an error code, but that's too much for this simple patch.

Additionally, I took the opportunity to clean up the surrounding
formatting of the code a bit, most notably dedenting the
keypress-clearing stuff by one tab level, converting the
shortcut-handling code to spaces, and removing commented-out code.
2020-03-13 08:40:59 -04:00
Misa
8fa916c55d Make the toggle fullscreen conditional more readable
Each check has been put in its own variable, so the final conditional is
more readable, and the ifdef is no longer right smack in the middle of
an if-statement.

Also the control flow has been changed (the "else" has been removed from
the shortcut-checking conditional) so I could put the variables closer
to the actual conditional itself. I don't think it affects anything,
though.
2020-03-12 21:20:25 -04:00
Misa
e23682615d Allow using F11 and (on macOS) RCmd+Enter/F to toggle fullscreen
This patch allows the use of pressing F11 to toggle fullscreen, as well as
allowing the use of Right Command when using the Command+Enter/F shortcut on
macOS. Apparently Alt+Enter isn't the only shortcut to toggle fullscreen,
Alt+F also works, which I didn't know before.

I'm adding F11 as a shortcut because it's a far more natural shortcut to
toggle fullscreen than this Alt+Enter or Alt+F business, which seems to be a
relic mimicking some other games and some Microsoft stuff?

I'm also adding RCommand+Enter/F because I see no reason not to. If you can
use RAlt on non-macOS, why can't you use RCommand on macOS, too?

I also cleaned up the formatting relating to the shortcut code, and made sure
the closing parenthesis was outside the ifdef so my text editor wouldn't
highlight the parenthesis inside the non-macOS ifdef-branch as a dangling
closing parenthesis, because it assumes the one in the branch above is the
actual closing parenthesis and doesn't parse macros.
2020-03-12 21:20:25 -04:00
AlexApps99
aff0c06458 Fixes #112: Backbuffer is always 32bpp 2020-03-12 10:06:23 -04:00
Misa
c322ae131e Fix unfocusing the game while in fullscreen mode
If you Alt+Tabbed while in fullscreen mode, the game would stay in
fullscreen instead of switching to windowed, but there was a chance it
would EITHER use the same internal resolution which would mismatch the
window resolution (don't know when exactly this happens, but still) and
stay being in an actual windowed mode, OR switch between
fullscreen/windowed every other time you re-focused the window, which is
annoying.

Now, whenever you Alt+Tab in fullscreen, the game will be in windowed
mode, and then when you re-focus it will go back to fullscreen.
Consistently.
2020-03-05 00:22:18 -05:00
Misa
a46d5b126c Write unlock.vvv when pressing Alt+F4
Previously, the only way to guarantee that the game actually saved your
unlock.vvv after changing an option, was to ensure you pressed ACTION on
the "quit game" menu option.

This makes Alt+F4 graceful in that pressing it will also save
unlock.vvv, as it should. Now truly UN-graceful ways of exiting the
game, such as SIGSEGV, SIGABRT, or pkill -9 or pkill -15 will not save
unlock.vvv, as should be the case.
2020-03-04 17:20:42 -05:00
Misa
5a25cad74b Don't draw text outline for roomtext in the editor
Text outline is not drawn on roomtext when you're actually playing the
game, so don't draw the outline in the editor, either.

FIQ mistakenly added text outline to roomtext in
ca9f577fc4.
2020-03-04 15:50:52 -05:00
Misa
b82a8a0925 Fix undefined behavior with left-click logic in editor
There's an if-else chain that first deals with figuring out if there's
an entity where your left-click happened, and to do this it uses
edentat(), which returns a sentinel value of -1 if there is NOT an
entity where your cursor is.

It's very important to check that the value returned ISN'T -1 before you
start indexing the 'edentity' vector, since if you DO index it with that
-1, it'll result in Undefined Behavior because you're doing an
out-of-bounds array access.

Now, here's what the if-else chain looked like before:

    if(tmp==-1 && ed.free(ed.tilex,ed.tiley)==0)
    {
        ...
    }
    else if(edentity[tmp].t==1)

The bug here is very subtle but it was an easy oversight. Basically, if
'ed.free' ended up not being zero, control flow would jump to the next
"else if" over, which then ends up asking for the -1th index of
'edentity', which is Undefined Behavior.

This undefined behavior has now resulted in a crash on my system after
TerryCavanagh/VVVVVV#172, due it shuffling things around juuuuust enough
such that this UB would end up resulting in a segfault instead of
chugging along and working fine. For me and my system, this meant that
if my first left-click in the editor upon opening the game was me
placing down a tile and not placing down an entity, the game would
crash. But, it would be fine if I first placed down an entity and then
afterwards placed down tiles, because it's UB.

And I'm almost certain this was the cause of the very strange bug where
you couldn't hold down left-click for the foreground-placing tool (but
you COULD for the background-placing tool) that seemed to occur most
often on Windows (TerryCavanagh/VVVVVV#25).

The solution to this is to stick in another conditional in the tree
before any indexing occurs, such that there's no way any other
conditionals with the indexing in the conditional tree could end up
being hit. In summary, the if-else chain looks like this now:

    if(tmp==-1 && ed.free(ed.tilex,ed.tiley)==0)
    {
        ...
    }
    else if(tmp == -1)
    {
        //Important! Do nothing, or else Undefined Behavior will happen
    }
    else if(edentity[tmp].t==1)
2020-03-02 08:22:08 -05:00
Misa
8d44d9387b Refactor edentities to not use separate length-trackers
This turns the array 'edentity' into a proper vector, and removes the need to
use a separate length-tracking variable and manually keep track of the actual
amount of edentities in the level by using the long-winded
'EditorData::GetInstance().numedentities'. This manual tracking was more
error-prone and much less maintainable.

editorclass::naddedentity() has been removed due to now functionally being the
same as editorclass::addedentity() (there's no more
'EditorData::GetInstance().numedentities' to not increment) and for also being
unused in the first place.

editorclass::copyedentity() has been removed because it was only used to shift
the rest of the edentities up manually, but now that we let C++ do all the
hard work it's no longer necessary.
2020-03-01 15:47:01 -05:00
Misa
a4d7fc017c Refactor roomtext to not use ad-hoc objects / separate length trackers
This refactors the roomtext code to (1) not use ad-hoc objects and (2)
not use a separate length-tracking variable to keep track of the actual
amount of roomtext in a room.

What I mean by ad-hoc object is, instead of formally creating a
fully-fledged struct or class and storing one vector containing that
object, this game instead hacks together an object by storing each
attribute of an object in different vectors.

In the case of roomtext, instead of making a Roomtext object that has
attributes 'x', 'y', and 'text', the 'text' attribute of each is stored
in the vector 'roomtext', the 'x' attribute of each is stored in the
vector 'roomtextx', and the 'y' attribute of each is stored in the
vector 'roomtexty'. It's only an object in the sense that you can grab
the attributes of each roomtext by using the same index across all three
vectors.

This makes it somewhat annoying to maintain and deal with, like when I
wanted add sub-tile positions to roomtext in VVVVVV: Community Edition.
Instead of being able to add attributes to an already-existing
formalized Roomtext object, I would instead have to add two more
vectors, which is inelegant. Or I could refactor the whole system, which
is what I decided to do instead.

Furthermore, this removes the separate length-tracking variable
'roomtextnumlines', which makes the code much more easy to maintain and
deal with, as the amount of roomtext is naturally tracked by C++ instead
of us having to keep track of the actual amount of roomtext manually.
2020-02-29 23:02:52 -05:00
Misa
f7e71bd668 Fix left-clicking on script boxes
You can now left-click on script boxes in order to change their script.
2020-02-21 18:15:26 -05:00
Misa
ea8053303d Initialize x to 0 in ss_toi()
This fixes a source of undefined behavior, where the int returned by
ss_toi() would be random garbage memory if the string passed into it
would be empty. That's because if the string is empty, there are no
characters to parse, so nothing simply gets put into x.

The easiest way to pass an empty string in to ss_toi() would be to use
script commands with empty arguments.
2020-02-20 00:05:55 -05:00
Ethan Lee
0531ee9b19 SDL_Init after FILESYSTEM_init, for gamecontrollerdb.txt 2020-02-19 12:44:36 -05:00
Misa
e18dd195ba Fix typo: "quiting" (one T) to "quitting" (two Ts) 2020-02-17 13:17:36 -05:00
Misa
1b04cb5dd6 Fix crewmate-found text boxes overlapping in flip mode
The problem was that the code seemed to be wrongly copy-pasted from the
code for generating the trinket-found text boxes (to the point where
even the comment for the crewmate-found text boxes didn't get changed
from "//Found a trinket!").

For the trinket-found text boxes, they use y-positions 85 and 135 if not
in flip mode, and y-positions 105 and 65 if the game IS in flip mode.
These text boxes are positioned correctly in flip mode.

However, for the crewmate-found text boxes, they use y-positions 85 and
135 if not in flip mode, as usual, but they use y-positions 105 and 135
if the game IS in flip mode. Looks like someone forgot to change the
second y-position when copy-pasting code around.

Which is actually a bit funny, because I can conclude from this that it
seems like the code to position these text boxes in flip mode was
bolted-on AFTER the initial code of these text boxes was written.

I can also conclude (hot take incoming) that basically no one actually
ever tested this game in flip mode (but that was already evident, given
TerryCavanagh/VVVVVV#140, less strongly TerryCavanagh/VVVVVV#141, and
TerryCavanagh/VVVVVV#142 is another flip-mode-related bug which I guess
sorta kinda doesn't really count since text outline wasn't enabled until
2.3?).

So I fixed the second y-position to be 65, just like the y-position the
trinket text boxes use. I even took the opportunity to fix the comment
to say "//Found a crewmate!" instead of "//Found a trinket!".
2020-02-16 09:30:00 -05:00
Stelpjo
c665d5b8c8 Fixed some music bugs
Previously, when MMMMMM is installed but the user is using PPPPPP, niceplay would still restart the song even if it's the same. That has been fixed. In addition, Plenary and Path Complete no longer loop when MMMMMM is installed but PPPPPP is in use.
2020-02-12 21:52:25 -05:00
Matt Penny
df1c1303bf
Use dynamic credits lists for main menu credits screens (and add GitHub contributors) (#160)
Also added GitHub contributors to the credits on the main menu
(previously they were only present in the credits at the end of the
game)
2020-02-11 23:45:58 -05:00
Matt Penny
4ccb48f440 Use uint32_t instead of char32_t 2020-02-11 06:02:35 -05:00
Matt Penny
e7252888b6 Support pre-C++11 compilers 2020-02-11 06:02:35 -05:00
Matt Penny
9adcbaed6c Fix NO_CUSTOM_LEVELS compile after #158
ifdef out the code that draws the "return to editor" text in
NO_CUSTOM_LEVELS builds now that it accesses variables in the
editor class (PR #158)
2020-02-11 05:59:28 -05:00
Misa
9b125ad8df Prevent removing line if there is only one line
This fixes another way you could end up typing on a non-existent line in
the script editor.

In a script with only 1 line, which is empty, the game would let you
press backspace on it, removing the line. This results in you typing on
a non-existent line.

You will keep typing on it until you either close the script or press
Up. If you press Up, you will be unable to get back to the non-existent
line, for it doesn't exist - but the text you typed on the non-existent
line will still be there, until you close the script and re-open it.
2020-02-10 22:57:00 -05:00
Terry Cavanagh
172ab9195d
Merge pull request #158 from AllyTally/entertoreturn
Make "[Press ENTER to return to editor]" fade out after a bit
2020-02-10 18:41:13 +01:00
Matt Penny
1b00d12600 Add option to allow custom levels when the editor is disabled 2020-02-09 23:31:44 -05:00
Matt Penny
7d35c5ce4e Add option to compile without the level editor 2020-02-09 23:31:44 -05:00
AllyTally
6b1a7ebce6 Make "[Press ENTER to return to editor]" fade out after a bit
This makes the "[Press ENTER to return to editor]" fade out after a few frames, allowing screenshots of custom levels to be cleaner and to make sure nothing is obscured while the user is editing their level.
This commit also adds alpha support in BlitSurfaceColoured, where it takes into account the alpha of the pixel *and* the alpha of the color.
`graphics::getRGBA(r,g,b,a)` was added to help with this.
2020-02-09 22:31:33 -04:00
Info Teddy
3273b4ab55 Re-comment out #define MAKEANDPLAY
Silly me forgot to remove it after testing the MAKEANDPLAY define.
2020-02-09 10:42:03 -05:00
Info Teddy
9642921a64 Initialize level data with 0s in M&P
Following discussion on TerryCavanagh/VVVVVV#153, I suggested that
instead of reverting my M&P guards from TerryCavanagh/VVVVVV#124 (which
would only revert it for The Final Level, The Lab, Overworld, and The
Tower, leaving Space Station 1 & 2 and The Warp Zone alone which could
potentially cause the same problem that motivated
TerryCavanagh/VVVVVV#153), we should initialize the map data with 0s
instead.
2020-02-08 23:54:20 -05:00
Matt Penny
dd7170dc59
Add -basedir option to specify base user directory (#154)
Useful for maintaining multiple save files or for debugging
2020-02-08 18:49:03 -05:00
AllyTally
93ec5783d5 Fix undefined behavior when activating scripts
It turns out that the line `tstring=tstring[tstring.size()-1];` also appears once in Scripts.cpp.
This causes the game to segfault after activating a terminal with an empty line at the end of it.
I added a quick `if` around this line, and set `tstring` to an empty string when needed.
2020-02-08 00:10:56 -05:00
AllyTally
19de5ec59d Add self to CONTRIBTORS.txt and githubfriends 2020-02-07 23:30:49 -05:00
AllyTally
ca0bfcfa80 Fix undefined behavior while loading scripts
In `editor.cpp`, there's a few sections of code that try and index stuff using `string.length()-1`.
This causes issues where if the string is empty, the result is -1, causing undefined behavior.
Flibit fixed a few of these cases, like on line `375` of editor.cpp:
`if((int) tstring.length() - 1 >= 0) // FIXME: This is sketchy. -flibit`
It turns out that one of these weren't caught, over at line `471`.
`tstring=tstring[tstring.length()-1];`
This causes builds compiled on Windows to segfault if you load more than one level in the editor.
I added a quick `if` around it, setting `tstring` to an empty string, which seems to fix the problem.
2020-02-07 23:30:49 -05:00
Info Teddy
e3025a6b27 Render screen shaking in towers
It's really obvious that screen shaking is not processed in towers if
you bring up the pause menu then quickly quicksave and bring it back
down. The screen won't shake, but it will suddenly start shaking if you
exit the tower, finishing off the stalled screenshake timer.
2020-02-06 16:34:43 -05:00
Terry Cavanagh
4e378b6057
Merge pull request #147 from InfoTeddy/general-bug-fixes-5
Make hardest room "Dimension VVVVVV" if it has no room name
2020-02-06 16:37:37 +01:00
Terry Cavanagh
3d8c84bbbf
Merge pull request #149 from FredrIQ/master
Make tiles in tower mode consistent with tower tileset elsewhere
2020-02-06 16:36:21 +01:00
Info Teddy
6e1197ad64 Fix wrong tiling in top-left corner of Do Try To Keep Up
This commit changes one down-edge tile to be a down-left corner edge
tile.
2020-02-06 10:14:49 -05:00
Info Teddy
d61d4f6120 Draw entities backwards in towermode like non-towermode entities
This fixes a bug where the player was going behind checkpoints in towers
and it looked very weird and cursed.
2020-02-06 10:12:44 -05:00
Info Teddy
a08e731a39 Fix Prize for the Reckless moving platform kludge happening in customs
If you died in (11,7) and a moving platform was to the left of the line
x=152, even if it was moving vertically it would get snapped to x=152,
in custom levels.

Surprised nobody has ran into this before (although people have ran into
the other kludge, which is placing tile 59 at [18,9] if you're in a room
on either the line x=11 or y=7).
2020-02-06 10:12:24 -05:00
Fredrik Ljungdahl
1062113f73 Make tiles in tower mode behave consistently with tower tileset elsewhere
Previously, in tower mode, being inside walls would just kill you, unlike
being inside walls outside tower mode, which was somewhat confusing.

Also, spikes behaved differently with regards to invincibility, being
unsolid in towers but solid outside them.

This does not change the behaviour of the "edge" spikes in towers.
2020-02-05 22:08:48 +01:00
Info Teddy
8ead9db39f Make hardest room "Dimension VVVVVV" if it has no room name
The only places where you can die in a room without a room name is the
Overworld, and I feel that calling it Dimension VVVVVV is appropriate.

You can't naturally die in The Ship nor the Secret Lab, and you can only
do it by pressing R, so I didn't feel it appropriate to add checks to
make the hardest room be "The Ship" or "The Secret Lab" if you managed
to get your hardest room to be a room in either of those areas.
2020-02-03 19:27:49 -08:00
Info Teddy
cefc95d324 Fix centered texts' outline rendering upside-down in flip mode
If you looked at the "- Press ENTER to Teleport -" text in flip mode,
you might have noticed that the outline looked pretty strange and
glitched-out for some reason. It's just the outline rendering
upside-down. To fix this, make PrintOff() use flipbfont instead of
bfont.
2020-02-02 20:52:59 -05:00
Info Teddy
a2ab8e82e1 Account for height of textbox in flipme()
The problem with flipme() was that it WAS properly reflecting
("reflecting" as in mirroring over a given line) the text box over the
line y=120, BUT it forgot to account for the height of the text box.
Thus, the text box position would be off by the length of its own
height. And when the text box got taller, this offset would worsen and
worsen.
2020-02-02 20:41:41 -05:00
Info Teddy
4bc76416f5 Fix discoloration when entities warp in flip mode
In flip mode, warping entities would appear to change color for a brief
moment. This is actually them defaulting to the actual color used in
flipsprites.png, instead of first being whited-out and then re-colored
using graphics.setcol().

To fix this, use BlitSurfaceColoured() and pass `ct` along instead of
using BlitSurfaceStandard().
2020-02-02 18:29:00 -05:00
leo60228
45491a03f3
Add -assets option to specify data.zip (#139)
This is useful for distributions, which may not want to put data.zip in
the same directory as the binary. This can't be distribution-specific
due to the license ("Altered source/binary versions must be plainly
marked as such, and must not be misrepresented as being the original
software.").
2020-02-02 18:28:26 -05:00
Info Teddy
8260bb2696 Fix Prize for the Reckless quicksand fix kludge
If you died in Prize for the Reckless, which is at (11,7), and respawned
in the same room, tile 59 (a solid invisible tile) would be placed at
[18,9] to prevent the moving platform from going back through the
quicksand.

Unfortunately, the way that this kludge was added is poor.

First, the conditional makes it so that it doesn't happen in ONLY
(11,7). Instead of being behind a positive conditional, the tile is
placed in the else-branch of an if-conditional that checks for the
normal case, i.e. if the current room is NOT (11,7), thus being a
negative conditional.

In other words, the positive conditional is "game.roomx == 111 &&
game.roomy == 107". To negate it, all you would have to do is
"!(game.roomx == 111 && game.roomy == 107)".

However, whoever wrote this decided to go one step further, and actually
DISTRIBUTE the negative into both statements. This would be fine, except
if they actually got it right. You see, according to De Morgan's laws,
when you distribute a negative across multiple statements you not only
have to negate the statements themselves, but you have to negate all the
CONJUNCTIONS, too. In other words, you have to change all "and"s into
"or"s and all "or"s into "and"s.

Instead of making the conditional "game.roomx != 111 || game.roomy !=
107", the person who wrote this forgot to replace the "and" with an
"or". Thus, it is "game.roomx != 111 && game.roomy != 107" instead. As a
result, if we re-negate this and take a look at the positive
conditional, i.e. the conditional that results in the else-branch
executing, it turns out to be "game.roomx == 111 || game.roomy == 107".
This ends up forming a cross-shape of rooms where this kludge happens.
As long as your room is either on the line x=11 or on the line y=7, this
kludge will execute.

You can see this if you go to Boldly To Go, since it is (11,13), which
is on the line x=11. Checkpoint in that room, then touch a disappearing
platform, wait for it to fully disappear, then die. Then an invisible
tile will be placed to the left of the spikes on the ceiling.

Anyway, to fix this, it's simple. Just change the "and" in the negative
conditional to an "or".

The second problem was that this kludge was happening in custom levels.
So I've added a map.custommode check to it. I made sure not to make the
same mistake originally made, i.e. I made sure to use an "or" instead of
an "and". Thus, when you re-negate the negative conditional and turn it
into the positive conditional, it reads: "game.roomx == 111 &&
game.roomy == 107 && !map.custommode".
2020-02-02 08:46:14 -05:00
Info Teddy
1e460721bb Fix hardcoded (19,8) all-sides warp happening in custom levels
(19,8) is hardcoded to warp on all-sides no matter what. This is fine,
except for the fact that it was doing this in custom levels, too, even
despite the fact that the warp background and color would be overridden
anyway. The only workaround was to add a warp line to the room in custom
levels. I've added a check for custommode so that this won't happen.
2020-02-02 08:43:28 -05:00
Info Teddy
867e8ff0fe Make obj accessible from everywhere
Looks like in my original pull request I forgot to do this. Oh well.
2020-01-31 15:53:29 -08:00
Info Teddy
4fa62ca0aa Fix text() centering with x=-1
The game uses magic values x=-500 and y=-500 to indicate when a text box
should be centered horizontally or vertically. It does this for x=-1
too, but it's buggy because it only looks at the first line of the text
box to center it. In this commit I fix it so that it will look at all of
the lines of the text box to center it instead.
2020-01-31 13:36:36 -08:00
leo60228
6a17625727
Add support for Unicode rendering (#47)
This uses utfcpp combined with a custom font, in the form of a PNG and text file. By default, the game acts exactly as it did before; custom fonts can be provided by third parties.
2020-01-31 13:25:37 -05:00
Info Teddy
98ac1fdb53 Set customwarpmode when createentitying warp lines
This fixes a bug where warp lines created through createentity wouldn't
work without there already being a warp line present in the room as an
edentity.
2020-01-30 23:17:30 -05:00
Info Teddy
4be6d58b82 Reset warp directions when exiting playtesting
This fixes a bug where if warpdir() was used during in-editor
playtesting, the changed warp direction would persist even when leaving
playtesting.

This would be very annoying to correct back every time you playtested
and warpdir() was used, so I've added some kludge to store the actual
warp direction of each room when entering playtesting, and then set the
warp directions back when leaving playtesting.
2020-01-30 22:15:45 -05:00
Terry Cavanagh
98151b4c2f
Merge pull request #126 from FredrIQ/master
Fix and improve handling of cancelling roomtext/scripttext input
2020-01-30 15:36:18 +01:00
Info Teddy
5a316d65e6 Allow using help/graphics/music/game/key/map/obj everywhere
This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and
`obj` essentially static global objects that can be used everywhere.
This is useful in case we ever need to add a new function in the future,
so we don't have to bother with passing a new argument in which means we
have to pass a new argument in to the function that calls that function
which means having to pass a new argument into the function that calls
THAT function, etc. which is a real headache when working on fan mods of
the source code.

Note that this changes NONE of the existing function signatures, it
merely just makes those variables accessible everywhere in the same way
`script` and `ed` are.

Also note that some classes had to be initialized after the filesystem
was initialized, but C++ would keep initializing them before the
filesystem got initialized, because I *had* to put them at the top of
`main.cpp`, or else they wouldn't be global variables.

The only way to work around this was to use entityclass's initialization
style (which I'm pretty sure entityclass of all things doesn't need to
be initialized this way), where you actually initialize the class in an
`init()` function, and so then you do `graphics.init()` after the
filesystem initialization, AFTER doing `Graphics graphics` up at the
top.

I've had to do this for `graphics` (but only because its child
GraphicsResources `grphx` needs to be initialized this way), `music`,
and `game`. I don't think this will affect anything. Other than that,
`help`, `key`, and `map` are still using the C++-intended method of
having ClassName::ClassName() functions.
2020-01-29 07:58:23 -05:00
Allison Fleischer
906e35244b Display menu text darker if mouse cursor is off 2020-01-29 07:55:50 -05:00
Allison Fleischer
03a4c3362a Add graphics option to toggle mouse cursor
Adds an option to show or hide the system mouse cursor over the game window.
2020-01-29 07:55:50 -05:00
Info Teddy
47ebbf15ab Don't redraw H/V warp BG if gotorooming to same room in customs
This has two benefits:
 (1) The game uses less resources when it is asked to gotoroom to the
     same room because it is no longer redrawing the warp background
     every single frame, which is very wasteful.
 (2) The warp background no longer freezes or flickers if the player is
     standing inside a gotoroom script box (which calls gotoroom every
     frame or every other frame, because every time the gotoroom happens
     the script box gets reloaded).
2020-01-27 14:46:11 -08:00
Fredrik Ljungdahl
3cfa7b0c60 Fix and improve handling of cancelling roomtext/scripttext input
First, two bug fixes. Room text input mode wasn't properly unset
upon pressing Esc, making the prompt get stuck, requiring you to
add roomtext again and finish it to make it go away. Secondly,
escaping script text input would remove the wrong entity.

I also tweaked the handling slightly so that instead of deleting
the entity if it already existed if escaping from text input,
it merely reverts the change in script name/roomtext to what it
was previously.

I considered refactoring the editor text input handler entirely,
but figured such a change would be a bit too extensive for the
purpose of this repository.
2020-01-27 11:15:25 +01:00
Fredrik Ljungdahl
757fd49283 Draw editor entities according to ingame order
Ingame entities are drawn backwards, probably to draw the player on top,
being entity 0 (usually, at least). Make the level editor draw entities
in the same order.
2020-01-26 22:22:10 -05:00
Info Teddy
7f3d16801c Remove from M&P the room data of Final Level/Lab/Overworld/Tower
This is to make sure that the room data of those areas are not
distributed with the M&P binary, even if they are already inaccessible
because of other M&P ifdefs (I tested).
2020-01-26 12:29:20 -05:00
Fredrik Ljungdahl
3697487f47 Fix minor issue with respawning into a tower
When the game enter towermode, it adjusts player amd camera x/y depending
on what screen the player entered it from (The Tower) or the loadlevel
mode ("minitowers"; Panic Room and The Final Challenge). This code didn't
account for respawning to checkpoints. This is unlikely to matter in most
circumstances, but can cause problems in some corner cases, or with R abuse.
This could cause a player to die, respawn outside camera edges and then
immediately die again due to the edge spikes, repositioning the camera
properly. Invincibility would cause further issues, but that's Invincibility
Mode for you -- if this was the only problem I wouldn't bother.

I added a check that repositions the tower camera appropriately if a player
enter a tower as part of the respawn process.
2020-01-25 23:30:29 -05:00
Info Teddy
b79f0daa5f Move y-position assignment into its most intended branch
This is a code style fix.
2020-01-25 23:29:37 -05:00
Info Teddy
2709de9cf0 Make fast path using FillRect() when opaque
FillRect() is similar enough to memset when blending isn't used, so the
game will take a fast path drawing the roomname background when the
background is opaque.
2020-01-25 23:29:37 -05:00
Info Teddy
2f85c2a8dc Draw room names with text outline
This makes it easier to see if you have a translucent room name
background.
2020-01-25 23:29:37 -05:00
Info Teddy
df83c2d494 Add an accessibility option to be able to see through the roomname
This is the variable dwgfx.translucentroomname and <translucentroomname>
in unlock.vvv.

This lets you see through the black background of the roomname at the
bottom of the screen, i.e. it makes the roomname background translucent.
So you can see if someone decides to hide pesky spikes there.
2020-01-25 23:29:37 -05:00
Info Teddy
c49ae404af Convert roomname background to a surface, then draw that
The roomname background used to just be a simple SDL_Rect that was drawn
using SDL_FillRect with a color of 0. Unfortunately, it seems that you
cannot use transparent colors with SDL_FillRect, it just defaults to
being fully opaque. However, you CAN draw surfaces with translucency,
which seems like the easiest thing to do. But the first step is to
convert the roomname background to an SDL_Surface.

This replaces the FillRect()s with SDL_BlitSurface() in the three places
roomnames are drawn: in towerrender, in gamerender, and in editorrender.
2020-01-25 23:29:37 -05:00
Info Teddy
f6fa8dd84c De-duplicate the roomname printing code in the editor
For some reason, there are two lines that have been copy-pasted the
exact same way and in the exact same place, namely being at the end of
each branch of the if-else conditional, which makes them be executed no
matter what. If they're going to be executed no matter what, we might as
well make it clearer and take those two lines out of each branch.
2020-01-25 23:29:37 -05:00
Fredrik Ljungdahl
4ea4a1e615 Move skipblocks default setting to obj.init() 2020-01-24 20:28:15 -05:00
Fredrik Ljungdahl
9296547feb Fix tower quicksave bug (only appeared in some builds)
I ran the game through Valgrind to catch various issues.
One thing caught my attention -- map.resumedelay. This is
used by The Tower/etc to add a delay before the game is
resumed (probably for camera controls delaying it) for
spawning the player. This variable was uninitialized. Notably,
if I explicitly set it to 592851 or similar, it reproduces the
bug, even if I cannot reproduce it with my typical compilation
flags. So fixing this by initializing it to 0, alongside some
other Valgrind warnings, should fix the problem entirely.
2020-01-24 20:28:15 -05:00
Fredrik Ljungdahl
2ec1106741 Fix level editor not using LoadTiXmlDocument 2020-01-24 16:45:18 -05:00
Fredrik Ljungdahl
5862af4445 Add a null terminator to loaded TinyXML files (#117)
* Add a null terminator to loaded TinyXML files

The TinyXML parse() function expect a C-like string, including terminator.
When xml loading was changed, it loaded the file, but included no such thing.
Thus, we load the file, then reallocate the memory so that we can insert a
null terminator to it, before passing it to parse().

* Tweak TinyXML file loading

Instead of first loading the file content into memory, then reallocate it
to add a null pointer, add an argument to the file load function for whether
to append a null terminator or not, defaulting to false. It still returns the
length without the null pointer in case a length ptr is passed.
2020-01-24 15:35:46 -05:00