make textures_dump_atlases work again and expose it as a utility function

This commit is contained in:
2024-09-26 21:32:08 -03:00
parent 0e68ecbc88
commit f4b52b5450
6 changed files with 42 additions and 28 deletions

View File

@ -300,31 +300,6 @@ void textures_cache_deinit(TextureCache *cache) {
}
void textures_dump_atlases(TextureCache *cache) {
PHYSFS_mkdir("/dump");
const char string_template[] = "/dump/atlas%zd.png";
char buf[2048]; /* larger than will ever be necessary */
size_t i = 0;
for (; i < arrlenu(cache->atlas_surfaces); ++i) {
SDL_snprintf(buf, sizeof buf, string_template, i);
SDL_RWops *handle = PHYSFSRWOPS_openWrite(buf);
if (handle == NULL) {
CRY("Texture atlas dump failed.", "File could not be opened");
return;
}
/* TODO: */
// IMG_SavePNG_RW(cache->atlas_surfaces[i], handle, true);
CRY("Unimplemented", "textures_dump_atlases dumping is not there, sorry");
log_info("Dumped atlas %s", buf);
}
}
static enum TextureMode infer_texture_mode(SDL_Surface *surface) {
const uint32_t amask = surface->format->Amask;
if (amask == 0)

View File

@ -50,9 +50,6 @@ typedef struct TextureKey { uint16_t id; } TextureKey;
void textures_cache_init(struct TextureCache *cache, SDL_Window *window);
void textures_cache_deinit(struct TextureCache *cache);
/* for debugging */
void textures_dump_atlases(struct TextureCache *cache);
/* loads an image if it isn't in the cache, otherwise a no-op. */
/* can be called from anywhere at any time after init, useful if you want to */
/* preload textures you know will definitely be used */

View File

@ -165,6 +165,30 @@ char *file_to_str(const char *path) {
}
void textures_dump_atlases(void) {
PHYSFS_mkdir("/dump");
/* TODO: png instead of bmp */
const char string_template[] = "/dump/atlas%zd.bmp";
size_t i = 0;
for (; i < arrlenu(ctx.texture_cache.atlas_surfaces); ++i) {
char *buf = NULL;
SDL_asprintf(&buf, string_template, i);
SDL_RWops *handle = PHYSFSRWOPS_openWrite(buf);
if (handle == NULL) {
CRY("Texture atlas dump failed.", "File could not be opened");
return;
}
SDL_SaveBMP_RW(ctx.texture_cache.atlas_surfaces[i], handle, true);
log_info("Dumped atlas %zu to %s", i, buf);
}
}
bool strends(const char *str, const char *suffix) {
size_t str_length = SDL_strlen(str);
size_t suffix_length = SDL_strlen(suffix);