mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Use levelDirError for graphics errors too
This will actually do several things:
(1) Make the tile size checks apply to the appropriate graphics files
once again.
(2) Make the game print a fallback error message if the error message
hasn't been set on the levelDirError error screen.
(3) Use levelDirError for graphics errors too.
(4) Make the error message for tile size checks failing specify both
width and height, not just a square dimension.
(5) Make the error messages mentioned above translatable.
It turns out that (1) didn't happen after #923 was merged, since #923
removed needing to process a tilesheet into a vector of surfaces for all
graphics files except sprites.png and flipsprites.png. Thus, the game
ended up only checking the correct tile sizes for those files only.
In the process of fixing this, I also got rid of the PROCESS_TILESHEET
macros and turned them into two different functions: One to make the
array, and one to check the tile size of the tilesheet.
I also did (2) just in case FILESYSTEM_levelDirHasError() returns false
even though we know we have an error.
And (3) is needed so things are unified and we have one user-facing
error message system when users load levels. To facilitate this, I
removed the title string, since it's really not needed.
Unfortunately, (1) doesn't apply to font.png again, but that's because
of the new font stuff and I'm not sure what Dav999 has in store for
error checking. But that's also why I did (4), because it looks like
tile sizes in font.png files can be different (i.e. non-square).
This commit is contained in:
@@ -151,9 +151,6 @@ void Graphics::init(void)
|
||||
levelcomplete_mounted = false;
|
||||
flipgamecomplete_mounted = false;
|
||||
fliplevelcomplete_mounted = false;
|
||||
|
||||
SDL_zeroa(error);
|
||||
SDL_zeroa(error_title);
|
||||
}
|
||||
|
||||
void Graphics::destroy(void)
|
||||
@@ -238,65 +235,6 @@ void Graphics::updatetitlecolours(void)
|
||||
col_trinket = getcol(18);
|
||||
}
|
||||
|
||||
#define PROCESS_TILESHEET_CHECK_ERROR(tilesheet, tile_square) \
|
||||
if (grphx.im_##tilesheet == NULL) \
|
||||
{ \
|
||||
/* We have already asserted; just no-op. */ \
|
||||
} \
|
||||
else if (grphx.im_##tilesheet->w % tile_square != 0 \
|
||||
|| grphx.im_##tilesheet->h % tile_square != 0) \
|
||||
{ \
|
||||
static const char error_fmt[] = "%s.png dimensions not exact multiples of %i!"; \
|
||||
static const char error_title_fmt[] = "Error with %s.png"; \
|
||||
\
|
||||
SDL_snprintf(error, sizeof(error), error_fmt, #tilesheet, tile_square); \
|
||||
SDL_snprintf(error_title, sizeof(error_title), error_title_fmt, #tilesheet); \
|
||||
\
|
||||
vlog_error("%s", error); \
|
||||
\
|
||||
return false; \
|
||||
}
|
||||
|
||||
#define PROCESS_TILESHEET_RENAME(tilesheet, vector, tile_square, extra_code) \
|
||||
PROCESS_TILESHEET_CHECK_ERROR(tilesheet, tile_square) \
|
||||
\
|
||||
else \
|
||||
{ \
|
||||
int j; \
|
||||
for (j = 0; j < grphx.im_##tilesheet->h / tile_square; ++j) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = 0; i < grphx.im_##tilesheet->w / tile_square; ++i) \
|
||||
{ \
|
||||
SDL_Surface* temp = GetSubSurface( \
|
||||
grphx.im_##tilesheet, \
|
||||
i * tile_square, j * tile_square, \
|
||||
tile_square, tile_square \
|
||||
); \
|
||||
vector.push_back(temp); \
|
||||
\
|
||||
extra_code \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
VVV_freefunc(SDL_FreeSurface, grphx.im_##tilesheet); \
|
||||
}
|
||||
|
||||
#define PROCESS_TILESHEET(tilesheet, tile_square, extra_code) \
|
||||
PROCESS_TILESHEET_RENAME(tilesheet, tilesheet, tile_square, extra_code)
|
||||
|
||||
bool Graphics::MakeSpriteArray(void)
|
||||
{
|
||||
PROCESS_TILESHEET(sprites_surf, 32, {})
|
||||
PROCESS_TILESHEET(flipsprites_surf, 32, {})
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef PROCESS_TILESHEET
|
||||
#undef PROCESS_TILESHEET_RENAME
|
||||
#undef PROCESS_TILESHEET_CHECK_ERROR
|
||||
|
||||
|
||||
void Graphics::map_tab(int opt, const char* text, bool selected /*= false*/)
|
||||
{
|
||||
@@ -3433,14 +3371,76 @@ bool Graphics::onscreen(int t)
|
||||
return (t >= -40 && t <= 280);
|
||||
}
|
||||
|
||||
bool Graphics::checktexturesize(
|
||||
const char* filename, SDL_Texture* texture,
|
||||
const int tilewidth, const int tileheight
|
||||
) {
|
||||
int texturewidth;
|
||||
int textureheight;
|
||||
if (query_texture(texture, NULL, NULL, &texturewidth, &textureheight) != 0)
|
||||
{
|
||||
/* Just give it the benefit of the doubt. */
|
||||
vlog_warn(
|
||||
"Assuming the dimensions of %s are exact multiples of %i by %i!",
|
||||
filename, tilewidth, tileheight
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool valid = texturewidth % tilewidth == 0 && textureheight % tileheight == 0;
|
||||
if (!valid)
|
||||
{
|
||||
FILESYSTEM_setLevelDirError(
|
||||
loc::gettext("{filename} dimensions not exact multiples of {width} by {height}!"),
|
||||
"filename:str, width:int, height:int",
|
||||
filename, tilewidth, tileheight
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void make_array(
|
||||
SDL_Surface** tilesheet,
|
||||
std::vector<SDL_Surface*>& vector,
|
||||
const int tile_square
|
||||
) {
|
||||
int j;
|
||||
for (j = 0; j < (*tilesheet)->h / tile_square; j++)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (*tilesheet)->w / tile_square; i++)
|
||||
{
|
||||
SDL_Surface* temp = GetSubSurface(
|
||||
*tilesheet,
|
||||
i * tile_square, j * tile_square,
|
||||
tile_square, tile_square
|
||||
);
|
||||
vector.push_back(temp);
|
||||
}
|
||||
}
|
||||
|
||||
VVV_freefunc(SDL_FreeSurface, *tilesheet);
|
||||
}
|
||||
|
||||
bool Graphics::reloadresources(void)
|
||||
{
|
||||
grphx.destroy();
|
||||
grphx.init();
|
||||
|
||||
MAYBE_FAIL(checktexturesize("tiles.png", grphx.im_tiles, 8, 8));
|
||||
MAYBE_FAIL(checktexturesize("tiles2.png", grphx.im_tiles2, 8, 8));
|
||||
MAYBE_FAIL(checktexturesize("tiles3.png", grphx.im_tiles3, 8, 8));
|
||||
MAYBE_FAIL(checktexturesize("entcolours.png", grphx.im_entcolours, 8, 8));
|
||||
MAYBE_FAIL(checktexturesize("sprites.png", grphx.im_sprites, 32, 32));
|
||||
MAYBE_FAIL(checktexturesize("flipsprites.png", grphx.im_flipsprites, 32, 32));
|
||||
MAYBE_FAIL(checktexturesize("teleporter.png", grphx.im_teleporter, 96, 96));
|
||||
|
||||
destroy();
|
||||
|
||||
MAYBE_FAIL(MakeSpriteArray());
|
||||
make_array(&grphx.im_sprites_surf, sprites_surf, 32);
|
||||
make_array(&grphx.im_flipsprites_surf, flipsprites_surf, 32);
|
||||
|
||||
images[IMAGE_LEVELCOMPLETE] = grphx.im_image0;
|
||||
images[IMAGE_MINIMAP] = grphx.im_image1;
|
||||
|
||||
Reference in New Issue
Block a user