1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-25 22:18:30 +02:00
Commit Graph

1904 Commits

Author SHA1 Message Date
Misa
a50e8ecf48 Replace roomnames/hiddennames/glitchnames with const char*
Since those are all downstream recipients of either static storage or
memory that doesn't move for the duration of the custom level, it's okay
to make these be `const char*`s without having to redo any of the RAII
memory management.

mapclass::currentarea() is included in this as well. I also cleaned up
Tower.cpp's headers to fix some transitive includes because I was
removing UtilityClass.h includes from all other level files too.

The "Untitled room" names no longer show any coordinates, because doing
so would require complicated memory management that's completely
unneeded. No one will ever see them, and if they do they already know
they have a problem anyway. The only time they might be able to see them
is if they corrupted the areamap, but this was only possible in 2.2 and
previous by dying outside the room deaths array in Outside Dimension
VVVVVV, which has since been patched out. Besides, sometimes the
"Untitled room" gets overwritten by something else anyway (especially in
Finalclass.cpp), so it really, really doesn't matter.
2021-09-12 21:06:26 -07:00
Misa
a10342f5e6 Replace setblockcolour() argument with const char*
There's no reason it needs to be an std::string here.

Although, realistically, we should be using an enum instead of
string-typing, but, eh, that can be fixed later.
2021-09-12 21:06:26 -07:00
Misa
2991b2341a Fix regression with companions not spawning
Companions would not spawn if you didn't load the current room via a
room transition. This meant that companions wouldn't spawn if you loaded
a save file with a companion, at least not until you moved to a
different room and triggered a screen transition. But most importantly,
it meant that the Intermission 1 supercrewmate would never spawn,
because going to Intermission 1 does a straight gotoroom, and does not
do a room transition.

Turns out the roomchange refactor broke things, because of course it
did. The companion logic was implicitly relying on that bool to be set,
because...? Either way, it doesn't make sense. Using roomchange implied
that the code wanted to be ran only when doing a room transition, which
is clearly not the case here. The best thing to do here is to just move
it to a separate function that gets called at the end of
mapclass::gotoroom().
2021-09-11 22:53:07 -07:00
Misa
a7ae3e0fb0 Remove scmmoveme
So, I ended up breaking supercrewmate spawning with that roomchange
refactor. However, upon investigating how to fix it, I was running into
a weird interpolation issue due to scmmoveme, as well as the companion
spawning in the ground in "Very Good". And I was wondering why I or no
one else ended up running into them.

Well, as it turns out, scmmoveme ends up doing absolutely nothing. There
are only two instances where scmmoveme is used. The first is if you
respawn in "Very Good", and somehow have your scmprogress set to that
room. But that's impossible, because whenever you respawn, your
scmprogress is always set to the one after the room you respawn in. Even
if you respawned in the room previous to "Very Good" (which is "Don't
Get Ahead of Yourself!"), it still wouldn't work, since the logic always
kicks in when a gotoroom happens, and not only when a supercrewmate is
actually spawned. Since the scmprogress doesn't match, that case never
gets triggered, and we get to the second time scmmoveme is used, which
is in the catch-all case that always executes.

This second instance... also does nothing, because since we just
respawned, and our scmprogress got set to the room ahead of us, there is
no supercrewmate on screen. Then getscm() returns 0, and the player is
always indice 0, so the only thing we end up doing is setting the
player's x-position to their own x-position. Brilliant.

Anyway, this code results in interpolation issues and the supercrewmate
spawning in the ground on "Very Good" if you die, when my fix is
applied, because my fix moves this logic around to a different frame
order, and that actually ends up making scmmoveme no longer dead code.

So to recap: we have dead code, which looks like it does something, but
doesn't. But if you move it around in a certain way, it ends up having
harmful effects. One of the joys of working on this game...

It's also hilarious that it gets saved to the save file. Why? The only
time this variable is true, it is for literally less than a frame,
because it always gets set to false, because you always respawn using a
gotoroom whenever the supercrewmate dies, because you never respawn in
the same room as a supercrewmate, because Intermission 1 was
deliberately designed that way (else you'd keep continually dying since
the supercrewmate wouldn't move out of the way).
2021-09-11 22:23:47 -07:00
Misa
029463ad47 Remove unused or useless SDL_Rects from Graphics
These were bfont_rect, bg_rect, foot_rect, and images_rect.

bg_rect was only used once to draw the ghost buffer in the editor, but
that was only because Ally didn't know you could just pass NULL in, cuz
the ghost buffer is the same size as the backbuffer.
2021-09-11 02:24:55 -07:00
Misa
d3a868b566 Axe RGBflip() in favor of getRGB()
RGBflip() does the exact same thing as getRGB(), now that all the
surface masks have been fixed. This axes RGBflip() and changes all
callers to use getRGB() instead. It is more readable that way.

By doing this, there is less copy-pasting. Additionally, it is now
easier to search for RGBf() - which is an ENTIRELY different function
than RGBflip() - now that the name of RGBf is no longer the first four
characters of some different, unrelated function. Previously I would've
had to do `rg 'RGBf[^\w]'` which was stupid and awful and I hated it.
2021-09-11 02:15:20 -07:00
Misa
f237f41d8e Remove useless arguments from drawimagecol()
Turns out, the r, g, and b arguments don't actually do anything!

There was a call to RGBf() in the function. RGBf() is just getRGB() but
first adds 128 and then divides by 3 to each of the color channels
beforehand. Unfortunately, RGBf() does not have any side effects, and
the function threw away the return value. Bravo.

This also reveals that the website images drawn in the credits in the
main menu are only recolored because of a stale `ct` set by the previous
graphics.bigprint(), and not because any color values were passed in to
drawimagecol()... What fun surprises the game has in store for me every
day.
2021-09-11 02:12:03 -07:00
Misa
58ae93c4cc Music: Do not do fades if not playing
This fixes a regression where entering playtesting while a track was
fading out (by exiting out of playtesting with a track playing and then
immediately entering back in with the level start music set) would
result in no music.

The cause is the game doing fades even though nothing is playing, which
puts it in a confusing state.
2021-09-10 19:37:33 -07:00
Misa
8e02b90b76 Move Mix_PausedMusic() call into wrapper function
This wrapper function is for (a) future-proofing (b) proactive
prevention of future copy-pasting (c) to clarify that we never actually
halt music in the SDL_mixer sense, we only pause it, so to check if the
music is halted we actually check if the music is paused instead. This
is important because Mix_PlayingMusic() does not check if the music is
paused and Mix_PausedMusic() does not check if the music is halted.
2021-09-10 19:37:31 -07:00
Misa
06a88eff39 Kludge-fix being able to play music in editor
When you're on the music changing screen in the editor, it plays the
current track. When you return, it stops playing the track. However, if
you press escape, it doesn't stop playing the track. This is because
pressing escape just returns to the previous menu without stopping
playing the track.

To fix this, I just added some kludge in the return menu function. This
is kinda super bad but it works for now and is just something to clean
up later. Maybe like each menu having exit callbacks or something, I
dunno.

This is kinda a regression, kinda sorta not. In 2.2 and previous,
pressing escape would just close the settings menu entirely, which also
bypassed the music fadeout. 2.3 made it so pressing escape doesn't
entirely close the settings menu, and just returns to the previous menu,
which fails in a different way. But the intended way is definitely to
select the return option and having the music fade out.
2021-09-10 18:56:12 -07:00
Misa
e3bfc79d4a Reset some stats that weren't being reset in deletestats
This function now properly deletes the Super Gravitron record, the Super
Gravitron rank, and the best game deaths. They were not being properly
reset previously, meaning you would have to go into your save file to
properly clean out your save data.
2021-09-10 18:02:52 -07:00
Misa
74b7ce9d80 Reset fade booleans when silencing music
This fixes a bug where the music would keep playing when a collection
prompt appeared if the music was still fading in at that time.
2021-09-10 17:02:24 -07:00
Misa
6f499abef0 Fix platv values outside map size being saved as 67372036
If the map size was less than 20x20, platv values outside the map would
end up being saved as 67372036.

This happens because SDL_memset() operates on the byte level, and not
the multi-byte level. So it takes only the lower 8 bits of 4 and repeats
it for each byte in each integer, creating 67372036.
2021-09-10 16:58:53 -07:00
Misa
07bbc5b2de Don't check !muted when fading music after completion prompt
This was done in 2.2 and previous probably to fix the fact that there
were multiple conflicting audio controls (the player wants to mute the
audio but the game wants to fade in the audio), but is now actively
harmful since 2.3, because muting the game while finishing the
completion prompt means the music will never come back in, even after
unmuting.

I also notice that when collecting a custom crewmate, the game checks
for the level's start music instead of if there's actually a current
song playing right now. I don't know why this was done, because it
would've been better to copy-paste the trinket collection logic here.
It's entirely possible for the audio to just be muted and never come
back if the level has no start music but plays a song by using a script.
Anyways, leaving it alone because it's quite possible that a level might
be intentionally designed around this, I can't really tell the
intentions of every level creator, and it's easy to work around (either
don't use custom crewmates, which every modern level basically does
nowadays, or just set the start music).
2021-09-10 15:48:18 -07:00
Misa
3185d88776 Don't touch music when completing custom level
For some reason, when completing a custom level and fading to the menu,
the game attempts to fade the music in and also fade the music out at
the same time. This results in nothing happening at all, and in 2.2 and
previous, results in audio fading out from max volume while the game is
frozen on a black screen after the fadeout.

To avoid any potential badness, just remove these.
2021-09-10 15:42:25 -07:00
Misa
91b63e7f88 Fix dying during collection prompt persisting effects
In the main game, if you press R during the trinket collection prompt
after collecting a trinket, AND you have never entered Comms Relay, and
you respawn in a different room, the trinket collection gamestate will
be interrupted, but you will still be left with the advance text prompt,
cutscene bars, and muted music.

The previous workaround to fix the music would be to mute and then
unmute the game, but due to the new music changes, this workaround
(which in and of itself is a bug) no longer works. Instead, the music
would have to be restarted by going into another zone on the map.

Having an advance text prompt outside of a cutscene results in the
player being unable to flip, but they can still move around left and
right.

Speedrunners previously used the no-Comms-Relay interrupting behavior to
skip certain trinket collection prompts entirely with a frame-perfect R
press, so I can't patch that out. Having an advance text prompt outside
of a cutscene is (ab)used in custom levels to intentionally prevent the
player from flipping, and furthermore, it's also used in credits warp
runs of the main game to increment the gamestate; so I cannot patch that
out. The ability to press R everywhere even during cutscenes was added
for good reason - to make it less likely that a softlock can happen - so
I don't want to revert it.

But I still think this is worth fixing because previously, the
punishment for missing the frame-perfect window late was simply not
skipping the trinket prompt (since the R-press would be ignored), but
now the punishment is basically having to reset because of the advance
text prompt.

I would usually handle this in gamestate 0, but awful custom levels
might want to intentionally interrupt the gamestate to do, I don't know,
something. No level does that so far, but I'd like to do the least
invasive thing.

So what I've done is made it so the effects of interruption are undone
if you press R and the gamestate is interrupted. This is handled in
mapclass::resetplayer().
2021-09-10 11:49:46 -07:00
Misa
c83a360dd3 Fix unused variable warning on non-Emscripten
Otherwise, the compiler would warn that `sync` is unused.
2021-09-08 11:43:23 -07:00
leo60228
7560b8b60b Handle lost focus on Emscripten
This was previously disabled, since it didn't seem to work. However, the
previous commit fixes the root issue.
2021-09-07 09:43:48 -07:00
leo60228
d40af63aa3 Split Func_input and Func_delta when unfocused
Without this, `fixedloop` will loop infinitely until focus is regained.
However, Emscripten won't actually know that focus is regained until
`fixedloop` returns.
2021-09-07 09:43:48 -07:00
Misa
7430be69e3 Remove getBGR
getBGR, when used in FillRect, was actually passing colors in RGB order.
But now the masks are fixed, so remove it, and fix up all existing
getBGR colors to use getRGB instead.
2021-09-06 20:12:48 -07:00
Misa
f6c9ff848f Fix all FillRect getRGB calls to be passed in RGB order
Due to the mask inconsistencies, getRGB calls that were passed to
FillRect ended up actually being passed in BGR order. But now that the
masks are fixed, all these BGR colors look wrong. So, fix up all of them
(...that's a _lot_ of copy-pasted code...) to be passed in RGB order.
2021-09-06 20:12:48 -07:00
Misa
d0b81d8eff Simplify clearing surface in preloader with ClearSurface()
It conveys intent better.
2021-09-06 20:12:48 -07:00
Misa
37b7615b71 Fix surface color masks
This fixes the color ordering of every SDL_Surface in the game.

Basically, images need to be loaded in ABGR format (except if they don't
have alpha, then you use RGB? I'm not sure what's going on here), and
then they will be converted to RGB/RGBA afterwards.

Due to the surfaces actually being BGR/BGRA, the game used to use
getRGBA/getRGB to swap the colors back around to BGRA/BGR, but I've
fixed those too.
2021-09-06 20:12:48 -07:00
Misa
2c0d6920e8 bprintalpha: Call PrintAlpha with a false cen
Whoops.

This fixes it so the outlines actually show up on the horizontal sides
of the outlined text.
2021-09-06 19:50:24 -07:00
Misa
c64fd89325 Untabify every single file
YOLO.

This is a repeat of #642. As before, I just did

    rg -l '\t' | xargs -n 1 sed -i -e 's/\t/    /g'

inside the desktop_version/ folder.
2021-09-06 18:56:39 -07:00
Misa
b3f437fe55 Rename respawncolour to savecolour
Since it's a variable like saverx/savery/savex/savey, it should be
renamed to savecolour and placed with all of them.
2021-09-06 18:28:28 -07:00
Misa
8e61a04937 Add changerespawncolour() script command
This command simply changes the color that the player respawns with upon
death. The respawn color also persists through custom save files.

Closes #830.
2021-09-06 16:11:19 -07:00
Misa
33c5b8b7c0 Use const std::string& where possible in function params
If it's at all possible to use `const std::string&` when passing
`std::string`s around, then we use it. This is to limit the amount of
memory usage as a result of the frequent use of `std::string`s, so the
game no longer unnecessarily copies strings when it doesn't need to.
2021-09-06 15:43:59 -07:00
Misa
ff07f9c268 De-duplicate text printing functions
I've made a new function, Graphics::do_print(), that does the actual
text printing itself. All the interfaces of the other functions have
been left alone, but now just call do_print() instead.

I also removed PrintOffAlpha() and just calculated the center x-position
in bprintalpha() itself (like bigbprint() does) to make it easier to
de-duplicate code.
2021-09-06 15:43:59 -07:00
Misa
730c935218 Textboxes: Don't use separate RGB variables
Text boxes have `r`, `g`, and `b`, and `tr`, `tg`, and `tb`. `tr`, `tg`,
and `tb` are the real colors of the text box, and `r`, `g`, and `b` are
merely the colors of the text box as the text box's alpha value is
applied to them.

Compare this with, say, activity zones (which are drawn like text boxes
but aren't text boxes): There is `activity_r`, `activity_g`, and
`activity_b`, and when they're drawn they're all multiplied by
`act_alpha`.

So just do the same thing here. Ditch the `tr`, `tg`, and `tb`
variables, and make `r`, `g`, and `b` the new `tr`, `tg`, and `tb`
variables. That way, there's simply less state to have to update
separately. So we can get rid of `textboxclass::setcol()` as well.
2021-09-06 00:56:49 -07:00
Misa
13a0c1282d drawgui: Don't declare loop vars in for initializers
Sneaky no-code-and-declarations-mixing fix.
2021-09-06 00:56:49 -07:00
Misa
a7aa92232f Remove redundant FillRect when drawing text boxes
This was already done in the drawtextbox function... so we were just
double-drawing the text box backing for absolutely no reason.
2021-09-06 00:56:49 -07:00
Misa
e9c3b03eba Remove unused SDL.h include from Textbox.h
Really unsure why it was included here. Not even any downstream users of
Textbox.h use any SDL functions from this include.
2021-09-06 00:56:49 -07:00
Misa
69fcdf9217 Remove useless variable lw from textboxclass
This variable is only assigned to, but never read from. Hence, it is
useless, and should be removed to make code analysis less complicated.
2021-09-06 00:56:49 -07:00
Misa
e47ff8131b Move max off of textboxclass
This is a variable that's only used in one method, and it's always
initialized beforehand. No need to carry it around, taking up memory,
and making code analysis more complicated.
2021-09-06 00:56:49 -07:00
Misa
9a637d0c0f Clean up style of drawcoloredtile
All unmutated parameters have been made const.

Declarations and code are no longer mixed.

Spacing has been made consistent.
2021-09-06 00:56:49 -07:00
Misa
1b236d5ec7 Clean up style of drawtextbox/drawpixeltextbox
All parameters are now made const, to aid in the reader in knowing that
they aren't ever changed.

Useless comments have been removed and been replaced with helpful
comments.

Useless parentheses have been removed.

Spacing has been made consistent.

Declarations and code are no longer mixed.
2021-09-06 00:56:49 -07:00
Misa
36d0056c2c drawtextbox: Use drawpixeltextbox
Since these two are so similar, why not just use this one for the other?
Saves on copy-pasting code.
2021-09-06 00:56:49 -07:00
Misa
9767eb91f4 drawpixeltextbox: Remove now-unused parameters
They go bye-bye.

This is a friendly reminder that the map menu rendering code is heavily
copy-pasted, dear god...
2021-09-06 00:56:49 -07:00
Misa
31844eabc6 Axe drawcustompixeltextbox in favor of drawpixeltextbox
I'm honestly not too sure why drawcustompixeltextbox ever existed? All
it seemed to do was draw even more horizontal/vertical tiles to finish
any gaps in the tiling... which was all completely unnecessary and
wasteful, because even the previous drawpixeltextbox implementation
covered all gaps in all custom level map sizes that I tried.

Anyway, that at least gets rid of one copy-pasted function.
2021-09-06 00:56:48 -07:00
Misa
02b1fedeb1 drawpixeltextbox: Draw remaining horz/vert tile if non-multiple-8
This draws the remaining horizontal/vertical tile just beside the final
corner if the width/height is not a multiple of 8. (It'd be wasteful to
draw it if the width/height was a perfect multiple of 8, and result in
double-drawing translucent pixels if there were any.)

This has an advantage over the previous system of shifting the
horizontal/vertical tiling, in that custom corner textures don't look
weird due to overlapping like this. Now, custom horizontal/vertical
tiles _can_ look weird if they don't completely tile correctly (or if
they have translucent pixels), but that's better than mucking up the
corners.
2021-09-06 00:56:48 -07:00
Misa
1eb3e73c00 drawpixeltextbox: Don't use unneeded variables
`w` and `h` are provided alongside `w2` and `h2`. `w2` and `h2` are in
blocks of 8, while `w` and `h` are in pixels. Therefore, `w2` and `h2`
can just be figured out by diving `w` and `h` by 8.

Also, `xo` and `yo` were used to slide the horizontal/vertical tiling of
the text box a bit into one set of corners, so the horizontal/vertical
tiling wouldn't visibly overlap with the other corners, if using default
textures. This requires hardcoding it for each width/height of text box,
which isn't something that's generalizable. Also, it results in corners
that look weird if the corners have custom textures that don't adhere to
the same shape as default textures.

In the next commit I'll fix the non-multiple-of-8 text box dimensions
differently. Can't do it in this commit or the diff looks weird (at
least with my diff algorithm).
2021-09-06 00:56:48 -07:00
Misa
651cd4b674 Use drawtextbox() to draw text boxes
I have no idea why this perfectly good function was unused in favor of
copy-pasting all of its code.
2021-09-06 00:56:48 -07:00
Misa
fc2de88b03 Use SDL_BlitScaled in ScaleSurface
Why do all this error-prone per-pixel work when you can just use an SDL
function instead?
2021-09-05 20:07:18 -07:00
Misa
77696c0d55 Don't check map.extrarow when opening map
This is just to make sure there aren't any more inconsistencies with
regards to the value of graphics.menuoffset. Can't hurt to be sure.
2021-09-05 17:04:26 -07:00
Misa
edf949bd9c Use resumegamemode to track menu animation
This fixes a bug where the player could bring up the map on the very
first frame of a gamemode(game) animation. This is because the menu
animation checked graphics.menuoffset, but graphics.menuoffset wouldn't
have changed at that point because it only set graphics.resumegamemode.

Instead, just check for graphics.resumegamemode directly. We also need
to assign it to false whenever the map is closed so the player won't be
prevented from using the map screen again.
2021-09-05 16:59:05 -07:00
Misa
da6c524db5 Don't use map.extrarow for menu animations
This fixes all the headaches about map.extrarow having to be the correct
value and which way it should be and whatnot. The latest headache was
the detection that prevent user-initiated menu animations while an
animation was already happening being tripped because
graphics.menuoffset would be 230 (due to closing the menu while being in
a room without a room name), but then going to a room with a room name
would check for 240 instead, and 230 is less than 240. (The numbers are
the wrong way round because I got the ternaries the wrong way round, but
even if the numbers are the correct way round, the bug would still
happen, but it would just be reversed.)

So instead, I've just made it 240 for both. This doesn't change the
duration of the menu animation (because the animation moves in
increments of 25, and 230 / 25 == 240 / 25 under integer division). It
might change the animation slightly, but it was already inconsistent
anyway because map.extrarow was always set to be 1 in custom levels, and
I legitimately would not be able to tell the difference without
recording the animations and nitpicking it frame-by-frame.

Fixes #841.
2021-09-03 17:13:03 -07:00
Misa
727400ff27 Only reset fade booleans when music is actually played
Otherwise, the block that fades existing music out if m_doFadeOutVol is
true will never execute, because m_doFadeOutVol would always be false!
2021-09-03 16:38:34 -07:00
Misa
4339bbadbb Add message when player is kicked out of Super Gravitron
The player gets kicked out of the Super Gravitron if they have
invincibility or slowdown enabled. However, this can be confusing if no
message pops up
( https://steamcommunity.com/app/70300/discussions/0/3039355280230178910/ )
. So I've made it so that a text box will pop up when they get kicked
out.
2021-09-03 12:08:31 -07:00
leo60228
d64608ecaa Correct onground/onroof check 2021-09-02 16:09:06 -07:00
leo60228
72ade2ce49 Only execute flip logic when has_control 2021-09-02 16:09:06 -07:00
leo60228
58098dc748 Only apply flip momentum to player entities on ground/roof 2021-09-02 16:09:06 -07:00
Misa
e30fc4500e gamemode(teleporter): Set gamestate to GAMEMODE
This makes it so gamemode(teleporter) will always do an animation, even
if the game is already in TELEPORTERMODE.

I used this script to test:

    gamemode(teleporter)
    delay(5)
    gamemode(teleporter)
    delay(5)
    gamemode(teleporter)

In 2.2, this script starts the map menu bringing-up animation three
times.

In previous 2.3, this script starts the map menu bringing-up animation
once, but then the next gamemode(teleporter) immediately finishes the
animation, and the third gamemode(teleporter) does nothing.

This commit restores it to 2.2 behavior.
2021-09-02 12:23:17 -07:00
Misa
5b10164659 Prevent user-initiated map menu changes during menu animations
This makes it so it's not even possible to stay on the TELEPORTERMODE
screen by opening the map while it's being brought down. It also makes
it so the map animation is able to be canceled when being brought up
just by opening the map and closing it.

Fixes #833.
2021-09-02 12:21:46 -07:00
Misa
e9ec34e1f5 Call teleporterrenderfixed in TELEPORTERMODE
This restores it to 2.2 behavior, where the cutscene bars timer also
ticked in TELEPORTERMODE. It was a 2.3 regression that the cutscene bars
timer didn't tick there.

This makes it so if you manage to get stuck in TELEPORTERMODE when a
cutscene ends, the cutscene won't be stuck on untilbars() waiting for
the cutscene bars to go away, since the cutscene bars timer now ticks.
2021-09-02 11:46:56 -07:00
leo60228
be2b1564a8
Call FS.syncfs on Emscripten (#838)
Also, add a sync parameter to avoid calling syncfs too often.

Calling syncfs twice in a row is both inefficient and leads to errors
displaying twice. This allows us to bypass it when saving unlock.vvv as
part of savestatsandsettings.
2021-09-02 13:19:51 -04:00
Misa
3c318814a4 Remove EditorData and put its attributes on customlevelclass
This object basically had no reason to exist... it was just more verbose
to use, which really reminded me of Java. Anyway, this is the last thing
named after the editor for no reason when it should be a part of the
customlevelclass, so I moved its attributes to customlevelclass.
2021-09-01 15:30:02 -07:00
Misa
8bff287907 Rename edentity to customentities
This fixes the fact that the name of the singular type is plural, but
the name of the plural array is singular. Which has always annoyed me,
too. Also this makes it more clear that custom entities don't have much
to do with the editor.
2021-09-01 15:30:02 -07:00
Misa
47d01277bf Rename edentities to CustomEntity
That's what it is - it's an entity in a custom level. Not something to
do with the editor, necessarily. Like before, the name of the XML
element will remain the same.
2021-09-01 15:30:02 -07:00
Misa
3c30d9b7f0 Rename cl.level to cl.roomproperties
I mean, that's what they are. Room properties are within a level, not a
level themselves. So...
2021-09-01 15:30:02 -07:00
Misa
d549a535e0 Rename edlevelclass to RoomProperty
That's what edlevelclass is... so that's what it should be named. (Also
removes that "ed", too, making this less coupled to the in-game editor.)

Unfortunately, for compatibility reasons, the name of the XML element
will still remain the same.
2021-09-01 15:30:02 -07:00
Misa
86b47878f9 Fix number of spaces of indentation of CustomLevels.h
CustomLevels.h now uses 4-space indents - like all other space-indented
files - instead of 2-space indents. This has bugged me for a while and I
decided to just fix it now.
2021-09-01 15:30:02 -07:00
Misa
a23014350f Move all editor-specific attributes to a new editorclass
This is a pretty hefty commit! But essentially, I made a new editorclass
object, and moved all functions and variables that only get used in the
in-game level editor to that class. This cleanly demarcates which things
are in the editor and which things are just general custom level stuff.

Then I fixed up all the callers. I also fixed up some NO_CUSTOM_LEVELS
and NO_EDITOR ifdefs, too, in several places.
2021-09-01 15:30:02 -07:00
Misa
987ae88909 Remove comment from top of editorclass
There's no need for this comment; it's quite obvious that editorclass is
a class about the editor and will contain editor variables.
2021-09-01 15:30:02 -07:00
Misa
6df182b38d Remove getLevelDirFileNames() from editorclass
As far as I can tell, this function has never been implemented, and only
existed in this header file. FILESYSTEM_getLevelDirFileNames() already
exists (well, used to exist; it's been changed and renamed to
FILESYSTEM_enumerateLevelDirFileNames()), so I'm removing this now.
2021-09-01 15:30:02 -07:00
Misa
83cccbed07 Remove contents memset from editorclass constructor
It gets (re-) initialized in editorclass::reset() anyway, so I'm just
removing this for code clarity.
2021-09-01 15:30:02 -07:00
Misa
6f0177ec04 Move editor functions to separate header
Editor functions now live in Editor.h, which is a new file - the
existing editor.h has been renamed to CustomLevels.h.
2021-09-01 15:30:02 -07:00
Misa
3e380e23fb Rename editor.h to CustomLevels.h
This accompanies the editor.cpp -> CustomLevels.cpp change; I'll be
splitting out the editor functions in the next commit. The name of the
include guard has been changed as well, but not anything else.
2021-09-01 15:30:02 -07:00
Misa
3fe0f01bcc Move editor functions to separate file
This moves editorrenderfixed(), editorrender(), editorinput(),
editorlogic(), and their associated functions to a new file named
Editor.cpp - which is exactly what it says on the tin; it stores all the
functions related to the actual in-game editor loop. Also, the existing
editor.cpp has been renamed to CustomLevels.cpp.
2021-09-01 15:30:02 -07:00
Misa
3ef5248db9 Simplify and print XML errors from TinyXML-2
All XML functions now check the return value of
tinyxml2::XMLDocument::Error() after each document gets loaded in to
TinyXML-2. If there's an error, then all functions return. This isn't
strictly necessary, but printing the error message that TinyXML-2 is the
bare minimum we could do to be useful.

Additionally, I've standardized the error messages of missing or
corrupted XML files.

Also, the way the game went about making the XML handles was... a bit
roundabout. There were two XML handles, one for the document and one for
the root element - although only one XML handle suffices. So I've
cleaned that up too.

I could've gone further and added error checking for a whole bunch of
things (e.g. missing elements, missing attributes), but this is good
enough.

Also, if unlock.vvv or settings.vvv don't exist yet, the game is
guaranteed to no-op instead of continuing with the function. Nothing bad
seems to happen if the function continues, but the return statements
should be there anyway to clearly indicate intent.
2021-09-01 15:09:40 -07:00
Misa
cbc84edb0e Remove superfluous message if settings.vvv/unlock.vvv don't exist
If settings.vvv doesn't exist, loadsettings() calls savesettings(), but
savesettings() already prints a message if settings.vvv doesn't exist.
So then the output would look like

    No settings.vvv found. Creating new file
    No settings.vvv found

Which is clearly redundant.

The same thing happens with unlock.vvv, but in that case the following
prints instead

    No unlock.vvv found. Creating new file
    No Stats found. Assuming a new player
2021-09-01 15:09:40 -07:00
Misa
73535b4342 De-duplicate loadsummary parsing and move to different function
I will need to be able to return from this function if there's an XML
error, otherwise writing out the control flow manually gets really
nasty. And while I'm at it, it's some a nice de-duplication as well.

To do this, we create a temporary struct that bundles up all the
information we want for the summary, and pass it in to the intermediate
load function.

Furthermore, we can get rid of reading map.finalstretch - it affects
nothing. map.finalmode is still needed, however, because of the usage of
map.area().
2021-09-01 15:09:40 -07:00
Misa
bbc2f06d81 De-duplicate quick/telesummary fetching in Game::init()
The less copy-pasted code, the less work for me later.
2021-09-01 15:09:40 -07:00
Misa
c58c357a81 Simplify Flip Mode rendering code with SDL_RenderCopyEx
Previously, Flip Mode rendering had to be complicated and allocate
another buffer to call FlipSurfaceVerticle, and it was just a mess.

Instead, why not just do SDL_RenderCopyEx, and let SDL flip the screen
for us? This ends up pretty massively simplifying the rendering code.
2021-09-01 14:44:59 -07:00
Misa
23a2f57a70 Replace some info logs with debug logs
These are a bit noisy, so I've replaced them instead.
2021-09-01 14:34:55 -07:00
Misa
b652d327dc Add debug logs
These are disabled by default, because they're noisy. To enable them,
pass -debug.
2021-09-01 14:34:55 -07:00
Misa
2eb9e23ecc Allow disabling output/fine-tuning output
-nooutput disables output completely (both STDOUT and STDERR). -noinfo
disables INFO lines.  -nowarn disables WARN lines. -noerror disables
ERROR lines.
2021-09-01 14:34:55 -07:00
Misa
c68a274c4f Add command-line options to force-enable/disable color
`-forcecolor` will force color to be on. `-nocolor` will force color to
be off.

And just because I'm a nice person, I've also added British versions of
those flags. As a treat.
2021-09-01 14:34:55 -07:00
Misa
ac85f57441 Add colors to logging
This includes the bold as well.

INFO is just default, WARN is yellow, ERROR is red.

We try to automatically detect if the output is a TTY (and thus supports
colors), and don't emit colors if so. Windows 10 supports ANSI color
codes starting with a specific build, but we don't care to emit whatever
garbage Microsoft invented for builds older than that.
2021-09-01 14:34:55 -07:00
Misa
96539f891c Replace all print calls with vlog calls
This is pretty straight-forward to do.
2021-09-01 14:34:55 -07:00
Misa
d9737589de Add logging functions
Named "vlogs" because they're logs for VVVVVV. Also it's a funny name.
2021-09-01 14:34:55 -07:00
Misa
5abe615507 Fix Pauli Kohberger's name stopping being drawn too early
This is because the y-position of the graphics.onscreen() check was a
little too high. Then their name (under Beta Testing) would suddenly
disappear too early. You'd have to look real close to spot it, but it
does happen. It's cuz the credits are all kinda hardcoded, which is
probably bad, but fixing that would have to come later...
2021-08-31 23:23:27 -07:00
Misa
4c69281738 Move Misa to C++ credits
I talked with Ethan earlier about this. For 2.3, he wanted me in GitHub
contributors (well, still separate from the rest), to really highlight
the source-code-release community-driven nature of 2.3, but he said it'd
be fine to put me in C++ credits in 2.4.
2021-08-31 23:22:22 -07:00
Misa
0028e314e4 Suppress unused i warning if NUM_BACKENDS is 0
Else this warning would pop up if not compiling an OFFICIAL_BUILD.
2021-08-31 23:12:38 -07:00
Ethan Lee
342dfcb48d Minor VS buildfix 2021-08-31 19:07:24 -04:00
leo60228
14c24069fd Fix indentation consistency 2021-08-31 15:37:52 -07:00
leo60228
52fceb3f69 Allow any player entity to be on the ground/roof to flip
This re-adds the midair flip glitch.
2021-08-31 15:37:52 -07:00
leo60228
1e8b5a6ba7 Actually move checks out of loop
How did this ever work?
2021-08-31 15:37:52 -07:00
leo60228
cd4ce05cb3 Split out tap_left and tap_right from player input loop
The game will freeze the player immediately if they release a
directional button within 3 frames of pressing it. Similar to flipping,
this involves global state, and will only apply to the first player
entity.
2021-08-31 15:37:52 -07:00
leo60228
1eb8570329 Split flip logic from player input logic
Closes #484

Flipping only applies momentum to the player entity currently being
processed. This normally wouldn't be a problem. However, flipping
involves global state, and only one flip can occur per frame. This means
that additional player entities don't get this boost of momentum, which
feels somewhat unnatural during gameplay.

This commit fixes this by splitting flip logic out of the loop over
player entities, and applying the flip momentum to all player entities.
2021-08-31 15:37:52 -07:00
Misa
416fe00c9d Fix not-Flip-Mode flag turning off when returning from options menu
We need to check for graphics.setflipmode, not graphics.flipmode,
because graphics.flipmode only gets assigned at the end of the frame
(due to the deferred callback). Otherwise, returning from the options
menu would always turn flag 73 on, which would make you ineligible to
get the Flip Mode trophy, even if you're in Flip Mode.
2021-08-31 15:33:20 -07:00
leo60228
668c3d91d6 Return false from unPackBinary if no tracks are valid 2021-08-31 15:30:23 -07:00
leo60228
f86a67456b Remove data/ from track name list, refactor music loading, and support loose ogg music
(these should be separate commits but they're annoying to split after
the fact, oh well)
2021-08-31 15:30:23 -07:00
Ally
64be7dbd53
Refactor colors in internal commands
Originally this started as a "deduplicate a bunch of duplicated code in script commands" PR,
but as I was working on that, I discovered there's a lot more that needs to be done than
just deduplication.
Anything which needs a crewmate entity now calls `getcrewmanfromname(name)`, and anything which
just needs the crewmate's color calls `getcolorfromname(name)`. This was done to make sure that
everything works consistently and no copy/pasting is required. Next is the fallback; instead of
giving up and doing various things when it can't find a specific color, it now attempts to treat
the color name as an ID, and if it can't then it returns -1, where each individual command handles
that return value. This means we can keep around AEM -- a bug used in custom levels -- by not
doing anything with the return value if it's -1.

Also, for some reason, there were two `crewcolour` functions, so I stripped out the one in
entityclass and left (and modified) the one in the graphics class, since the graphics class also
has the `crewcolourreal` function.
2021-08-31 15:09:51 -07:00
Ethan Lee
8ebf8a21e4 Default to VSync being enabled 2021-08-31 15:08:46 -04:00
AllyTally
1c34dc2533 Reset new variables in hardreset 2021-08-31 11:17:00 -07:00
AllyTally
656941202a Fix formatting and add an INBOUNDS_VEC
If `setactivitytext` was the last line in a script,
the command would index the vector out of bounds.

I also modified the formatting to keep consistent
with the rest of the codebase.
2021-08-31 11:17:00 -07:00
AllyTally
b15e25f106 Add setactivitycolour(colour) and setactivitytext() commands
These commands will change the colour and text of the next
activity zone that gets spawned. `setactivitycolour` takes all
textbox colors, and `setactivitytext` will take the text on
the next line. These commands were designed this way
to avoid breaking forwards compatibility.
2021-08-31 11:17:00 -07:00
AllyTally
0685cade69 Change the text of custom activity zones
When an activity zone is spawned through the
use of `createactivityzone`, and `i` is 35,
then it'll change the activity zone text to
"Press ENTER to interact".
2021-08-31 11:17:00 -07:00
leo60228
1cbc3bdc7c Treat __unix__ define as generic Unix 2021-08-31 10:35:20 -07:00
leo60228
6abf87f1e4 Explicitly use void in emscriptenloop declaration
Co-authored-by: Misa <infoteddy@infoteddy.info>
2021-08-31 10:28:55 -07:00
leo60228
46ee84d6ef Disable unfocus on Emscripten 2021-08-31 10:28:55 -07:00
leo60228
0063e1c3bc Use Emscripten's main loop
On Emscripten, SDL_Delay is implemented as a busy loop. In addition,
everything happens on a single thread. This effectively means that
you have to let Emscripten manage the main loop, since if you do it
yourself the browser will just be frozen.
2021-08-31 10:28:55 -07:00
leo60228
6d57ccc25b Support Emscripten in FileSystemUtils 2021-08-31 10:28:55 -07:00
Misa
62cff254b7 Bump version to 2.4 2021-08-31 10:25:29 -07:00
Misa
c97b28f238 Don't hardcode destroy() arguments in loadcustom()
Otherwise, the new arguments to destroy(), which are 'moving' and
'disappear', would be thrown away by the simplified parser. Let's create
less work for ourselves to do and simply not have a hardcoded list of
allowed arguments for destroy() in the parser.
2021-08-31 09:26:39 -07:00
Misa
08971b3311 Fix destroy(platforms), implement under different names
destroy(platforms) has been bugged since 2.0. The problem with it is
that it removes the platform entity, but doesn't remove its block. This
results in essentially turning the platorm invisible and stopping it
from moving.

This error should be fixed, but some levels (including my own) rely on
the invisible platform trick. So instead, the fixed version will be
implemented under a different name, destroy(moving).

There's also another problem with destroy(platforms), which is that the
name is misleading and it doesn't additionally destroy disappearing
platforms. I would also fix this, but in order to not run the risk of
breakage, it will have to be implemented under a different name, too. So
this will be destroy(disappear). As an added benefit, it's also more
granular to have platform-destroying functions under different names
than it is to consolidate them under the same name.
2021-08-31 09:26:39 -07:00
Misa
bca8d39bd7 Axe save file migration
The chances of someone using 2.0, then directly jumping to 2.4, are
pretty low - 2.0 is almost a decade old at this point.
2021-08-31 09:26:14 -07:00
Misa
85dc6db85b Axe screen_transition variable in favor of roomchange
When I added the two-frame delay fix, I didn't realize that Game had a
roomchange variable that was being used as a temporary variable here.
Now that it's fully spelled out and obvious (just look at the top of
gamelogic()), I realize that the variable exists and is being used, and
other readers will realize it's being used too - so now that I know it
exists, I can axe the screen_transition variable I added in favor of
using roomchange instead.
2021-08-31 09:25:47 -07:00
Misa
7a598f5811 Move roomchange off of Game
The purpose of this variable was to keep track of if gamelogic() called
map.gotoroom() at any point during its execution. So map.gotoroom()
always unconditionally set it to true, and then gamelogic() would check
it later.

Well, there's no need to put that in a global variable and do it like
that! It makes it less clear when you do that.

So what I've done instead is made a temporary macro wrapper around
map.gotoroom() that also sets roomchange to true. I've also made it so
any attempt to use map.gotoroom() directly results in failure (and since
then using map.gotoroom() in the wrapper macro would also fail, I've had
to make a gotoroom wrapper function around map.gotoroom() so the wrapper
macro itself doesn't fail).
2021-08-31 09:25:47 -07:00
Misa
75ed9f9631 Move linecrosskludge off of entityclass
This is a temporary vector that only gets used in mapclass::gotoroom().
It's always guaranteed to be cleared, so it's safe to move it off.

I'm fine with using references here because, like, it's a C++ STL vector
anyway - when we switch away from the STL (which is a precondition for
moving to C), we'll be passing around raw pointers here instead, and
won't be using references here anyway.
2021-08-31 09:25:47 -07:00
Misa
382b83a54d Move roomchangedir off of Game
This is a temporary variable that doesn't need to be on Game. It is
guaranteed to be initialized every time mapclass::gotoroom() gets
called, so it's safe to move it off.
2021-08-31 09:25:47 -07:00
Misa
48cddf57a6 Reset obj.customscript in hardreset()
This prevents yet another place where stale level data from one level
could have affected another level...
2021-08-31 07:55:40 -07:00
Misa
fea2010204 Fix enemy/plat bounds not being drawn if any side touches a screen edge
Enemy/platform bounds are intended to not be drawn if they cover the
whole screen, since that's what their default bounds are.

However, the code inadvertently made it so if ANY of the bounds touched
a screen edge, the bounds wouldn't be drawn. This is because the
conditionals used "and"s instead of "or"s. The proper way to write the
positive conditional is "x1 is 0 and y1 is 0 and x2 is 320 and y2 is
240", and when you invert that conditional, you need to also invert all
"and"s to be "or"s. This is not the first time that the game developers
failed to properly negate conjunctional statements...
2021-08-28 13:03:04 -07:00
Misa
fd4415317d Replace Gravitron RNG with seeded Xoshiro
This is to make it so RNG is deterministic when played back with the
same inputs in a libTAS movie even if screen effects or backgrounds are
disabled.

That way, Gravitron RNG is on its own system (seeded in hardreset()),
separate from the constant fRandom() calls that go to visual systems and
don't do anything of actual consequence.

The seed is based off of SDL_GetTicks(), so RTA runners don't get the
same Gravitron RNG every time. This also paves the way for a future
in-built input-based recording system, which now only has to save the
seed for a given recording in order for it to play back
deterministically.
2021-08-27 12:28:35 -07:00
Misa
c591b79daf Reset words array in hardreset()
Otherwise, levels could leave stale arguments in the array, and then the
behavior of another level loaded right after might end up being
different because of that.
2021-08-25 11:12:23 -07:00
Misa
580096dded Update comments about contributor ordering
I reordered them but forgot to update these comments...
2021-08-24 09:42:23 -07:00
Misa
d472363542 Fix positioning of "Thanks for playing!"
When the screen reached the bottom of the credits, it ended up being 10
pixels higher (and not perfectly centered) than in 2.2 and previous.
2021-08-24 09:39:20 -07:00
Misa
676294332f Add Vee to credits
He did say to feel free to not credit him, but I'd like to add him
anyways just for completeness's sake.
2021-08-24 09:39:19 -07:00
Misa
e69fd80bac Add KyoZM to Credits.h
They were in CONTRIBUTORS.txt but not Credits.h.

In the future we ought to just parse CONTRIBUTORS.txt directly somehow,
but This Works Okay for now.
2021-08-24 09:38:36 -07:00
Misa
b9c028fd9b Alphabetically sort contributors by first name, not last
This is done for consistency with Terry's patrons, which are sorted by
first name and not last.

Also some people go with their usernames and so don't have a last name
to speak of, which ended up being pretty weird.
2021-08-24 09:37:36 -07:00
Misa
9bdd45b7e1 Update Misa's name in credits
Kai is my last name. Elizabeth is my middle name. I went with my middle
name as last name for a while before figuring out what I wanted my last
name to be.
2021-08-24 09:13:07 -07:00
Misa
749a885d9a Actually finally fix createentity default args
Third time's the charm.

The fundamental problem with the previous attempts was that they ended
up saying arguments existed due to stale `words` anyway. So to actually
know if an argument exists or not, we need to assign to `argexists` _as_
we parse the line.

And make sure to take care of that last argument too.

Also I thoroughly tested this this time around. I'm done pulling my hair
out over this.
2021-08-22 22:47:47 -07:00
Misa
01ae5c6c70 Allow custom levels to use 2 billion tile numbers once again
Ever since tilesheets got expanded, custom levels could use as many
tiles as they wanted, as long as it fit under the 32-bit signed integer
limit.

Until 6c85fae339 happened and they were
reduced to 32,767 tiles.

So I'm being generous again and changing the type of the contents array
(in mapclass and editorclass) back to int. This won't affect the
existing tilemaps of the main game, they'll still stay short arrays. But
it means level makers can use 2 billion tiles once again.
2021-08-22 21:30:53 -07:00
Misa
92aace50f6 Don't assume tilesheet size in Direct Mode
This lets users place down tiles above 1199 in Direct Mode, if their
tilesheet has more than 1200 tiles.

I don't like the copy-pasted code here but it'll have to make do.
2021-08-22 21:13:28 -07:00
Misa
731fb89c90 Add being able to use Lab rainbow background in editor
If you use Lab tilecol 6, you get the rainbow background. However, this
is unintended, because the associated autotiling is... not very good.

To combat that, Ved disallows using the Lab rainbow background outside
of Direct Mode. We will follow Ved here and only allow switching to the
rainbow background if you're in Direct Mode. Also make sure if someone
is disabling Direct Mode with the rainbow background that it gets reset
properly.
2021-08-22 20:56:47 -07:00
Misa
3947949ebb Add being able to use Shift+W to change warp dir backwards
A minor convenience, but a convenience is a convenience.
2021-08-22 20:51:51 -07:00
Misa
d2153aee87 Refactor warp dir switching to separate function
This is so the same code can be used to go in reverse instead of
copy-pasting it.
2021-08-22 20:51:21 -07:00
Misa
0489293885 Remove default arguments from ed switch_* funcs
I don't like default arguments and if we're going to be moving to C
we'll need to remove them anyway.
2021-08-22 20:44:18 -07:00
Misa
52918ba510 Increment total flips for flip tokens and flipgravity(player)
They flip the player, they should count towards total flips like gravity
lines do.
2021-08-22 20:39:05 -07:00
Misa
8329afc6df Replace main game music with music area map
The main game used a set of copy-pasted code to set the music of each
area. There WAS some redundancy built-in, but only three rooms in each
direction from the entrance of a zone.

Given this, it's completely possible for players to mismatch the music
of the area and level. In fact, it's easy to do it even on accident,
especially since 2.3 now lets you quicksave and quit during cutscenes.
Just play a cutscene that has Pause music, then quicksave, quit, and
reload. Also some other accidental ways that I've forgotten about.

To fix this, I've done what mapclass has and made an areamap. Except for
music. This map is the map of the track number of every single room,
except for three special cases: -1 for do nothing and don't change music
(usually because multiple different tracks can be played in this room),
-2 for Tower music (needs to be track 2 or 9 depending on Flip Mode),
and -3 for the start of Space Station 2 (track 1 in time trials, track 4
otherwise).

I've thoroughly tested this areamap by playing through the game and
entering every single room. Additionally I've also thoroughly tested all
special cases (entering the Ship through the teleporter or main
entrance, using the Ship's jukebox, the Tower in Flip Mode and regular
mode, and the start of Space Station 2 in time trial and in regular
mode).

Closes #449.
2021-08-22 20:35:06 -07:00
Misa
5bb12a7fc1 Set Secret Lab/Super Gravitron hidden names
It seems appropriate that these rooms should have their names shown on
the map screen.
2021-08-22 20:33:03 -07:00
Misa
2af04ad0fa Make fade out duration proportional to volume
This is the same behavior as SDL_mixer. Else, a fadeout would last the
same amount of time no matter the volume, which is a regression.
2021-08-22 16:57:13 -07:00
Misa
ad88939dbb Fix regression with niceplay() moving back and forth between zones
2.3 has a regression where if you move back and forth between a zone,
you can get the wrong music playing in a zone. An example is the
Overworld and Lab. Just walk in to the Lab and immediately walk back
out, and you'll get Potential for Anything playing in the Overworld.

This regression was caused by facb079b35.
That commit removed assigning -1 to currentsong when a fadeout was
called.

Basically, the previous behavior was: currentsong is 4, we enter Lab and
nicechange gets queued to 3 but currentsong gets set to -1, then going
back nicechange gets queued to 4 again.

However, if we don't assign -1, then going back will keep nicechange at
3. Why? Because niceplay() checks for currentsong before assigning
nicechange. If currentsong is still the same then it doesn't assign
nicechange.

To fix this, just always unconditionally assign nicechange.
2021-08-22 16:57:11 -07:00
Misa
1c3274645d Fix up style in musicclass::play()
- Multiline comment instead of single-line.
- Spacing fixes.
- Long line broken up into smaller ones.
2021-08-22 15:27:39 -07:00
mothbeanie
1ec06c6f5c Standardize punctuation and style for the new options menu 2021-08-19 17:17:36 -07:00
Misa
4f881b9e26 Fix enemy movement types 10/12 causing memory leaks
If spawned as a custom enemy (createentity entry 56), or spawned outside
of the rooms they spawn in in the main game, they will repeatedly clone
themselves every frame, which profusely leaks memory. In fact it quickly
causes a crash in 2.2 and previous, but 2.3 fixes that crash, so it just
keeps spawning enemies endlessly, which eventually lags the game, and
eventually can out-of-memory your system (bad!).

The problem is those movement types rely on entclass::setenemyroom() to
change their `behave` to be 11 or 13. Else, the new entity created will
still have `behave` 10 or 12, which will create ANOTHER entity in the
same way, and so on, and so forth.

So to fix this, just make it so if an enemy is still `behave` 10 or 12
by the end, then, just set it to -1. That way it'll stay still and won't
cause any harm.

I considered setting the `behave` to 11 or 13 respectively, but, that's
probably going farther than just fixing a memory leak, and anyways, it's
not that much useful for me as a custom level maker, and the entities
spawned aren't really controllable.
2021-08-19 16:50:44 -07:00
Misa
7c18123327 Wrap level dir enumerate callback pointer in struct
In order to let callers provide their OWN callback functions through the
callback function WE provide to PhysFS, we casted the function pointer
to a void pointer.

Unfortunately, this is apparently undefined behavior... if your compiler
doesn't have an extension for it. And most compilers on most
architectures do. (In fact compilers on POSIX systems most certainly
have it due to dlsym() returning a void* which could actually be a
pointer to a function sometimes.)

But imo, it's better to be safe than sorry in this regard. Especially
when given GCC's approach to optimizing int + 100 > int (spoilers: they
remove it entirely! It's faster, but also broken!).

I've decided to wrap it in a struct. And as a nice side effect, if we
ever need more data to be passed through... well we already have this
struct.

Technically, it's also standards-compliant to cast a _pointer to_ a
function pointer to a void pointer. But that extra layer of pointer
indirection would get real confusing to conceptualize real fast (or at
least is more confusing than just putting it in a struct).
2021-08-19 00:48:05 -07:00
Misa
8bade56841 Fix regression with regaining focus resuming music
Since you've been able to resume music stopped by stopmusic() with
resumemusic(), if a track was stopped by stopmusic(), the unfocus pause
itself would end up resuming the track when regaining focus.

The solution is to simply check for if music.currentsong is -1 or not.
2021-08-18 20:50:02 -07:00
Misa
208382a8d1 Fix regression with platv values not parsed as 2.2-and-prev
So, platv is a room property that controls the speed of custom entity
platforms in the room (unless, of course, they're created with
createentity). Problem is, this is how 2.2-and-previous coding standards
were:

    ed.level[game.roomx-100+((game.roomy-100)*ed.maxwidth)]

Overly long, verbose, not entirely clear unless you already know what it
means? Copy-pasted over and over due to all of the above? Surely a
recipe for not making any coding errors!

Ironically enough, copy-pasting is basically the best approach here
(short of refactoring the whole thing, like I did in
945d5f244a), since if you don't ACTUALLY
copy-paste and just re-type it on your own, you'll end up making more
mistakes. Like what happened here:

    ed.level[game.roomx-100+((game.roomy-100)*ed.mapwidth)].platv

Do you see the mistake...? Yeah, mapwidth (with a P) instead of maxwidth
(with an X). You'd have to look closely to find it.

So what does this mean for platv? Well, it means that it multiples the
y-coordinate of the room by the map width instead of the max width (20),
like every other room property. So that means if your map width is less
than 20, like say, map width 10, the platv value for (2,2) will be
stored in (2,1)'s room properties instead of (2,2)'s. Because if you go
off of map width, the room index for (2,2) is 2 + 2 * 10 = 22, but if
you go off of max width, the room index for (2,1) is 2 + 1 * 20 = 22.

Now this wouldn't be bad, except for another 2.2-and-previous
standard... kind of just not exposing things directly to the end user.
Whether that's simply not documenting something (as in the case of
ifwarp and warpdir, which by all measures were completely intended to be
used in custom levels but just simply were never known properly until I
discovered how to use them in 2019), or in this case, not giving any way
for the user to fiddle with platv from the in-game editor. Because if
there was a way to do that, and someone decided to test to see if platv
worked okay, they would discover something was up.

So... since I refactored room properties in
945d5f244a, I kind of broke platv by
fixing it. Now levels that relied on platv being the broken way don't
work.

How do I fix it, and thus break it again? Well, I'll do what I did for
scripts - handle the scrambling when reading and writing the level, and
keep things sane at least internally.

Thus: editorclass::load() will unscramble platv data in the right way,
and editorclass::save() will re-scramble platv in the right way too.
2021-08-18 19:19:33 -07:00
Misa
a13d26d866 Add option to delete all custom level save data
To match the option to nuke all main game save data, there is also now
an option to nuke all custom level save data separately (which is just
all custom level quicksaves, along with stars for level completion). It
has its own confirmation menu too. It does not delete any levels from
the levels folder.
2021-08-18 16:02:11 -07:00
Misa
3a2265ef0d Add being able to delete a custom level quicksave
Custom level quicksaves are NOT affected by the clear data menu, so the
player should be able to delete quicksaves this way. The quicksave
confirmation menu now has an extra option to delete the save (and that
option also has its own confirmation menu before deleting).
2021-08-18 16:02:11 -07:00
Ethan Lee
12e8924efc Similar to unmountAssets, avoid printing a message when custom assets don't exist 2021-08-18 16:26:13 -04:00
Misa
bc47b86645 If loaded level assets fail to mount, print message to non-console users
This error case can happen, but if it does, non-console users get an
ERROR page with no further information. So use setLevelDirError if this
failure mode happens. And Menu::errorloadinglevel needs to be changed to
accomodate that.
2021-08-18 10:08:39 -07:00
Misa
124d77c041 Don't use PHYSFS_getRealDir() to check for .zip
Not sure why the original implementation decided to do things this way
instead of snprintf'ing a path to the .zip itself. Otherwise, if the
level is from data.zip, PHYSFS_getRealDir() will return the path of
data.zip, which then fails to mount for separate reasons.
2021-08-18 09:57:55 -07:00
Misa
a1df4c1383 Revert "Fix loading levels that are... uh, just levels."
This reverts commit ea74b93f38.

This is reverted for being a bit of a hack in my opinion.
2021-08-18 09:52:38 -07:00
Misa
0fd4f21710 Remove unused dir string
Since 4154066c26 reduced the memory
footprint, it's now unused.
2021-08-18 09:45:07 -07:00
Misa
b60bfc6bd8 Remove level menu rendering code in NO_CUSTOM_LEVELS builds
Should have been done earlier, imo. But now that we introduce `ed` the
NO_CUSTOM_LEVEL build fails because of it. So just ifdef it out
entirely.
2021-08-18 09:26:14 -07:00
Misa
9b3ae770fb Account for lack of prev/next options if only one page of levels
Otherwise the seventh and eighth levels would be grouped with the return
menu button.

Fixes #826.
2021-08-18 09:17:41 -07:00
Ethan Lee
d50367ac62 When custom assets aren't mounted, unmount should be quiet 2021-08-18 11:02:45 -04:00