1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-28 23:48:30 +02:00
Commit Graph

2150 Commits

Author SHA1 Message Date
Misa
63bc71b796 Always add null terminator when loading files
This removes the `addnull` argument from `FILESYSTEM_loadFileToMemory`
and `FILESYSTEM_loadAssetToMemory`, and makes it so a null terminator is
always appended no matter what.

This simplifies things and removes the need for callers to make the
decision about null termination and what its implications are. Then you
get cases where null termination might not happen when it should be,
such as the one df577c59ef (#947) fixed.

When FIQ added the `addnull` argument in
5862af4445 (#117), I'm guessing he did it
because he wanted to be cautious about adding the null terminator to
every file, so he only did it for XML files, which was the only case
needed at the time. But really, there's no downsides to always appending
a null terminator. In fact, it's already always done whenever the STDIN
buffer is loaded.
2023-03-18 15:12:24 -07:00
AllyTally
fb15a0b515 Fix the game texture clearing during menu shaking
Because of how `blackout` works, screen shaking must clear the gameplay
buffer. `blackout` simply pauses rendering, so if the gameplay buffer
gets cleared, then the screen will just be black, otherwise it'll look
like the game is "frozen". VVVVVV only uses `blackout` during screen
shaking, so it works as intended. However, when reimplementing this
behavior in the move to using the SDL_Renderer system, I failed to
notice that since my implementation always clears the gameplay buffer
when shaking, if you open the menu during a shake, instead of seeing
gameplay during the transition animation, you only see black. This has
been fixed with a simple `game.blackout` check before clearing the
gameplay buffer.
2023-03-18 13:53:36 -07:00
Misa
acfa085fd1 Remove reference from customlevelclass::load arg
For some reason, originally, this function mutated the std::string
passed into it by reference. So calling the function could potentially
mutate whatever got passed in, and callers potentially could have relied
on that behavior.

Now that the surrounding callsites have all been cleaned up, though
(especially scriptclass::startgamemode), it's clear that it's only used
in two places: Loading the level in the editor, and loading the level in
live gameplay. In both cases, the passed-in string isn't used ever again
afterwards.

So, it's safe to delete the mutable reference without any undesirable
effects, making the code cleaner and easier to understand. The function
now mutates a copy instead of mutating whatever the caller has.
2023-03-16 21:09:41 -07:00
Dav999-v
79f5e7a05c Fix loading font .txt files that contain null bytes
An example is Maximally Misleading Miserable Misadventure, which has a
font.txt which includes all ASCII characters starting with a 0x00 byte.
This would accidentally null-terminate the string too early.

Instead, we now use the total length of the file again, and keep
getting the next UTF-8 codepoint until the file ends. We still need to
null-terminate it - it protects against incomplete sequences getting
the UTF-8 decoder to read out of bounds.
2023-03-16 14:01:31 -07:00
Dav999-v
df577c59ef Fix font .txt files not being null-terminated
This was an oversight when we migrated to the new UTF-8 system - it
expects a null-terminated string, but the utfcpp implementation worked
with a pointer to the end of the file instead.

I also added an assert in FILESYSTEM_loadFileToMemory() so this is less
likely to happen again - because there should be no valid reason to
have a NULL pointer for the total file size, as well as not wanting a
null terminator to be added at the end of the file.
2023-03-16 12:42:54 -07:00
Dav999-v
310f3489d2 Remove key casts from hashmap function calls
We don't need the (char*) or (void*) casts anymore. You may need to
`git submodule update --init`.
2023-03-05 13:21:43 -08:00
AllyTally
188fc996bd Fix hardestroom not being translated
`hardestroom` currently stores the current roomname, but it was missing
a call to get the translated string. This has been added, fixing the
hardest room appearing as untranslated.
2023-03-05 11:33:16 -08:00
Dav999-v
d112dee72c Change font::len text argument from std::string to const char*
See the previous two commits, a lot of the time we don't need
std::string objects to be passed to these functions because we already
have C strings.

   Commit 1/3: font::print_wrap
   Commit 2/3: font::print
-> Commit 3/3: font::len
2023-03-04 16:10:17 -08:00
Dav999-v
5e3a4e69ce Overload font::print text argument for both std::string and const char*
Turns out I was overplaying my hand a little when changing font::print
from std::string to const char*, so instead, I'll overload the
function: it can take either a const char* (the main function) or a
std::string (a wrapper). This means any C string that's printed
everywhere else (which is common, especially because loc::gettext gives
them) no longer needs to be converted to a std::string object each call.

   Commit 1/3: font::print_wrap
-> Commit 2/3: font::print
   Commit 3/3: font::len
2023-03-04 16:10:17 -08:00
Dav999-v
264b6474be Change font::print_wrap text argument from std::string to const char*
We no longer need to pass a std::string object to the print and len
functions - in fact, we often only have a C string that we want to
print or get the visual width of (that C string most often comes from
loc::gettext), and it's a bit wasteful to wrap it in a new std::string
object on every print/len call.

This does mean adding a few more .c_str()s, but there's not many places
where a std::string is being passed to these functions, and we already
use .c_str() sometimes.

-> Commit 1/3: font::print_wrap
   Commit 2/3: font::print
   Commit 3/3: font::len
2023-03-04 16:10:17 -08:00
Misa
58d21e956b Fix analogue filter allocating/freeing surfaces every frame
This removes memory churn caused by using analogue mode.

The surfaces are only allocated if analogue mode is turned on, and kept
after they are initialized. Otherwise, if analogue mode is never turned
on (which will be the case for the vast majority of the time the game is
played), then no extra memory is used.
2023-03-04 14:02:47 -08:00
Misa
5eecc2a21d Don't draw texture onto itself for scrolling
Drawing a texture onto itself seems to produce issues on Metal.

To fix this, use a temporary texture instead, that then gets drawn onto
the original texture.

Fixes #927.
2023-03-03 20:21:53 -08:00
Misa
33fa0750be Destroy gameScreen after all other graphics are destroyed
This is because destroying the renderer causes use-after-frees since the
renderer destroys all textures when it gets destroyed.

This fixes a Valgrind error where an invalid read occurs because the
font textures get destroyed again after the renderer is destroyed.
2023-03-03 16:46:15 -08:00
Dav999-v
faff8bba5f Fix possible dangling pointers in FontContainer.map_name_idx
The hashmap would get populated with the name of each font, as each
font was being added. Unfortunately, adding a font would also realloc
the storage for fonts, in which the names are also stored... Possibly
invalidating the pointers to the names. This is now fixed by populating
the hashmap after all the fonts are added.
2023-03-03 16:38:53 -08:00
Misa
04743abe91 Destroy towerbg and titlebg textures in destroy_buffers
For consistency, since they are created in create_buffers as well. I
checked with Valgrind (which is very noisy on Wayland, it turns out),
but I didn't see anything about them not being freed. It doesn't hurt to
use VVV_freefunc here anyway, though, since it does a NULL check and
nulls the pointer afterwards, which should prevent double-freeing and
use-after-frees.
2023-03-03 15:34:13 -08:00
Misa
d1e9bdc284 Rename tempTexture to menuoffTexture
I'm going to soon be creating an actually temporary texture, so having
two textures named "temp" would get confusing. This is also a good
chance to correct the name of this texture, because it's not really
temporary, but it's used for map menu animation rendering.
2023-03-03 15:25:15 -08:00
Misa
e31344c68c Remove trailing whitespace in create_buffers
This was added in by AllyTally in
19b2a317f1.
2023-03-03 15:23:55 -08:00
AllyTally
5beaf973ce Strip out old special roomname system
This commit replaces the old system with the new one, making it much
easier to edit the transforming and glitchy roomnames. Additionally,
this syncs flag 72 to finalstretch.

Co-authored-by: Misa Elizabeth Kai <infoteddy@infoteddy.info>
2023-03-02 22:58:12 -08:00
AllyTally
dd108a035f Animated roomnames, setroomname command
This commit adds a better system for animated roomnames.

The old system, like many other systems, were very hardcoded, and can be
described as mostly else-if chains, with some fun string comparisons.
The new system uses lists of text for transformations and glitchy names,
making it much easier to add new cases if needeed.

This commit implements the system but does not replace the old system,
where that is done in the next commit.

The settings for special roomnames can be read from level XML, and
`setroomname()` can be used from commands to set a new, static name.
2023-03-02 22:58:12 -08:00
Dav999-v
368b9f1b3d Replace use of PHYSFS UTF-8 functions by UTF8.h
This is a massive simplification of the UTF-8 work there, lol
2023-02-27 23:00:41 -08:00
Dav999-v
a91c85d92e Fix UTF-8 handling in next_wrap
Finally this FIXME can be removed!
2023-02-27 23:00:41 -08:00
Dav999-v
f34aa65faa Replace utfcpp by UTF8.h in Font.cpp
I'm also planning to change the argument types of font::len,
font::print and font::print_wrap from const std::string&s to
const char*s, but I'll do that separately.
2023-02-27 23:00:41 -08:00
Dav999-v
8a011c3061 Replace utfcpp by UTF8.h in Textbox.cpp 2023-02-27 23:00:41 -08:00
Dav999-v
736ce3ecbf Replace utfcpp by UTF8.h in Localization.cpp 2023-02-27 23:00:41 -08:00
Dav999-v
a545384677 Replace utfcpp by UTF8.h in KeyPoll.cpp 2023-02-27 23:00:41 -08:00
Dav999-v
c5a48776c9 Replace utfcpp by UTF8.h in Editor.cpp 2023-02-27 23:00:41 -08:00
Dav999-v
393c5ac4fe Replace utfcpp by UTF8.h in CustomLevels.cpp 2023-02-27 23:00:41 -08:00
Dav999-v
2474623b59 Remove #include <utf8/unchecked.h> from Graphics.cpp
Turns out the last utfcpp function had already been removed from this
file, so the include can simply be removed.
2023-02-27 23:00:41 -08:00
Dav999-v
3ce4735d50 Add UTF8.c
This is a small library I wrote to handle UTF-8.

Usage is meant to be as simple as possible - see for example decoding
a UTF-8 string:

  const char* str = "asdf";
  uint32_t codepoint;
  while ((codepoint = UTF8_next(&str)))
  {
      // you have a codepoint congrats
  }

Or encoding a single codepoint to add it to a string:

  std::string result;
  result.append(UTF8_encode(0x1234).bytes);

There are some other functions (UTF8_total_codepoints() to get the
total number of codepoints in a string, UTF8_backspace() to get the
length of a string after backspacing one character, and
UTF8_peek_next() as a slightly less fancy version of UTF8_next()), but
more functions could always be added if we need them.

This will allow us to replace utfcpp (utf8::unchecked) and also fix
some less-than-ideal code:

- Some places have to resort to ignoring UTF-8 (next_wrap) or using
  UCS-4→UTF-8 functions (VFormat had to use PHYSFS ones, and one other
  place has four lines of code including a std::back_inserter just for
  one character)

- The iterator stuff is kinda confusing and verbose anyway
2023-02-27 23:00:41 -08:00
Dav999-v
32e14755dd Fix centering of translated "Level Complete!" and "Game Complete!"
Operator precedence meant that `sc == 2 ? PR_2X : PR_1X | PR_CEN`
didn't work how I expected it to. So I added some parentheses.
2023-02-24 18:48:24 -08:00
Fussmatte
00279c0e04 Fix minor visual issue in int1yellow_5
Originally the changedir command was used here, making
Vitellary look left and then immediately snap back to
looking right. Now the changeai command is used instead
to make him actually look left, and then look back to
the right on his last textbox.
2023-02-24 17:54:29 -08:00
Misa
ede52ccc48 Add Jules de Sartiges to Credits.h
I noticed this name was present in CONTRIBUTORS.txt but missing in
Credits.h. Their contribution was PR #782.
2023-02-21 12:28:57 -08:00
Misa
abab6864d7 Add iliana etaoin to contributor list
PR #931 was merged, so this adds xer to CONTRIBUTORS.txt and Credits.h.
2023-02-21 12:27:50 -08:00
iliana etaoin
5d719d3e90 Add magic string to the start of the game global
The `-addresses` command-line option added in 64be99d4 helps
autosplitters on platforms where VVVVVV is not built as a
position-independent executable. macOS has made it increasingly
difficult, or impossible, to build binaries without PIE.

Adding an obvious string to search for will help tools that need to deal
with versions of VVVVVV built with PIE. The bytestring to search for is
`[vVvVvV]game`, followed by four null bytes (to avoid finding it in the
program code section). This identifies the beginning of the game object;
addresses to other objects can be figured out by relative offsets
printed by `-addresses`, since ASLR can only change where the globals
begin.

Partially fixes #928; it may still be advisable to figure out how to
explicitly disable PIE on Windows/Linux.
2023-02-21 12:24:20 -08:00
Dav999-v
086b157152 Allow multiple lines and wordwrapping in activity zone prompts
Activity zone prompts have always been limited to a single line,
because the text box had a hardcoded size. A translator requested for
the possibility to add a subtitle under music names for the jukebox,
and the easiest solution is to make it possible to translate a prompt
with multiple lines. This is possible now, and the textbox even
wordwraps automatically.

(I wouldn't really like to see translations using multiple lines for
stuff like "Press ENTER to talk to Vitellary", especially if it wraps
with one name and not with another, but if a string is too long,
wordwrapping will look better than text running out of the box.)
2023-02-20 19:43:39 -08:00
Dav999-v
a320ee3b4d Deduplicate font::print for activity zone prompts
There were two print calls, one for the transparent case, and one for
a regular textbox. The print calls were nearly the same except for the
color, and for some reason the transparent case didn't have PR_CJK_LOW
(that one is on me).
2023-02-20 19:43:39 -08:00
Dav999-v
28e9df7f47 Move line width addition in next_wrap to be after switch block
There is no overlap in side effects between this line and the switch
statement after it, but it did result in adding the width of a final
null terminator or newline to the width of the current line, which is
a waste because those widths both 1) require trying to find
non-existent characters in the font and 2) will not be used.

I found this out because I added a debug print in find_glyphinfo(), and
something was requesting lots of codepoint 0 from the font.
2023-02-20 17:00:06 -08:00
Dav999-v
d883ff6938 Add support for button glyph fallback fonts
In a button glyph font (like buttons_8x8.fontmeta) you can now specify
<type>buttons</type> to indicate that it's a button glyphs font. In a
normal font, you can specify <fallback>buttons_8x8</fallback>. This
will make it such that if a character is not found in the main font,
it will instead be looked for in buttons_8x8. If not found there
either, the main font's U+FFFD or '?' will be used as before.
2023-02-20 17:00:06 -08:00
Dav999-v
7a06b61f5d Add name->idx hashmap in FontContainer
This makes find_font_by_name() not O(n). It's not really a big deal,
because there won't be many fonts, but it'd make a function in the next
commit (finding the given fallback font for each font by name) O(n^2).
It's easy enough to add the hashmap.
2023-02-20 17:00:06 -08:00
Misa
2ac85e6929 Fix editor selection box not showing up
Whoops.

Also outlined the text for page 2 too.
2023-02-19 12:31:58 -08:00
Misa
6e6cf1bfc3 Draw text outline on editor hotkeys
This makes them stand out more.

The border around the tool has also been moved to be drawn first.
Otherwise, it would be drawn on top of the outline of the text, which
would look bad.
2023-02-19 12:12:02 -08:00
Misa
64be99d496 Add -addresses command-line argument
This prints the address of every global class to the console, and then
exits.

This is useful for autosplitters, which read memory addresses directly.
Any time a new version of the game is shipped, this makes updating the
autosplitters much easier as people don't have to find the addresses of
the global classes themselves.
2023-02-17 20:47:32 -08:00
Misa
acca4747f7 Remove x-position from setactivityposition
After discussing with Ally and Dav, we came to the agreement that this
is basically useless since the prompt will always be centered and take
up most of the horizontal space of the screen.

And the x-position was only added as an offset because at some point,
there was a missing space from the side of the "- Press ENTER to
Teleport -" prompt, and the offset was there so people could mimic the
prompt accordingly. But that was fixed at some point, so it's useless
now.
2023-02-17 20:47:32 -08:00
AllyTally
3d5ba95b96 custom textbox colors
Co-authored-by: Misa Elizabeth Kai <infoteddy@infoteddy.info>
2023-02-15 10:39:20 -08:00
AllyTally
de43005676 Fix screen shake during flip mode not flipping the screen
This fixes a regression introduced by #923 where flip mode no longer flips the screen while the screen is shaking.
2023-02-14 15:33:29 -08:00
Ally
73a80a9b4f Apply suggestions from code review
Co-authored-by: Misa Elizabeth Kai <infoteddy@infoteddy.info>
2023-02-14 14:56:27 -08:00
AllyTally
1183083355 Allow a maximum of 26 lines, with L suffix 2023-02-14 14:56:27 -08:00
Misa
299ed90493 static-qualify mount_pre_datazip
This function is used nowhere else, so it should be made static and
unable to be linked to from other files.
2023-02-14 09:44:31 -08:00
Dav999-v
4b34602eec Improve ordering of font charset loading
Even though it would be a bizarre combination, declaring no character
set (neither via <chars> nor via font.txt) meant that <special>
couldn't be used because the ASCII fallback charset would be loaded
after special ranges were processed. Now, all the methods of loading
the charset are attempted sequentially, and only afterwards, the
special ranges are loaded.
2023-02-13 23:27:00 -08:00
Dav999-v
716a241b79 Replace PR_COLORGLYPH_BRI(a) and PR_ALPHA(a) with PR_BRIGHTNESS(a)
There used to be two ways of fading in/out text in VVVVVV:
- Local code that modifies the R, G and B values of the text
- Keeping the RGB values the same and using the alpha channel

The latter approach is only used once, for [Press ENTER to return to
editor]. The former approach causes problems with colored (button)
glyphs: there's no way for the print function to tell from the RGB
values whether a color is "full Viridian-cyan" or "Viridian-cyan faded
out 50%", so I added the flag PR_COLORGLYPH_BRI(value) to tell the
print function that the color brightness is reduced to match the
brightness of colored glyphs to the brightness of the rest of the text.

However, there were already plans to make the single use of alpha
consistent with the rest of the game and the style, so PR_ALPHA(value)
could be removed, as well as the bit signifying whether the brightness
or alpha value is used. For the editor text, I simply copied the "Press
{button} to teleport" behavior of hiding the text completely if it
becomes darker than 100/255.

Another simplification is to make the print function handle not just
the brightness of the color glyphs while local code handled the
brightness of the normal text color, but to make the print function
handle both. That way, the callsite can simply pass in the full colors
and the brightness flag, and the flag name can be made a lot simpler as
well: PR_BRIGHTNESS(value).
2023-02-13 23:27:00 -08:00