Factor out "between" calculation to macro and func

FILESYSTEM_mountAssets() has a big comment describing the magic numbers
needed to grab FILENAME from a string that looks like
"levels/FILENAME.vvvvvv".

Instead of doing that (and having to write a comment every time the
similar happens), I've written a macro (and helper function) instead
that does the same thing, but clearly conveys the intent.

I mean, just look at the diff. Using VVV_between() is much better than
having to read that comment, and the corresponding SDL_strlcpy().
This commit is contained in:
Misa
2021-05-20 14:14:08 -07:00
committed by Ethan Lee
parent 29d2637abd
commit 153a5c4c3a
3 changed files with 38 additions and 14 deletions

View File

@@ -325,25 +325,12 @@ void FILESYSTEM_loadZip(const char* filename)
void FILESYSTEM_mountAssets(const char* path)
{
const size_t path_size = SDL_strlen(path);
char filename[MAX_PATH];
char zip_data[MAX_PATH];
const char* zip_normal;
char dir[MAX_PATH];
/* path is going to look like "levels/LEVELNAME.vvvvvv".
* We want LEVELNAME, which entails starting from index 7
* (which is how long "levels/" is)
* and then grabbing path_size-14 characters
* (14 chars because "levels/" and ".vvvvvv" are both 7 chars).
* We also add 1 when calculating the amount of bytes to grab
* to account for the null terminator.
*/
SDL_strlcpy(
filename,
&path[7],
VVV_min((path_size - 14) + 1, sizeof(filename))
);
VVV_between(path, "levels/", filename, ".vvvvvv");
SDL_snprintf(
zip_data,