make textures_dump_atlases work again and expose it as a utility function
This commit is contained in:
parent
0e68ecbc88
commit
f4b52b5450
@ -23,6 +23,9 @@ void game_tick(void) {
|
||||
input_add_action(&ctx.input, "debug_toggle");
|
||||
input_bind_action_scancode(&ctx.input, "debug_toggle", SDL_SCANCODE_BACKSPACE);
|
||||
|
||||
input_add_action(&ctx.input, "debug_dump_atlases");
|
||||
input_bind_action_scancode(&ctx.input, "debug_dump_atlases", SDL_SCANCODE_HOME);
|
||||
|
||||
input_add_action(&ctx.input, "player_left");
|
||||
input_bind_action_scancode(&ctx.input, "player_left", SDL_SCANCODE_A);
|
||||
|
||||
@ -54,6 +57,10 @@ void game_tick(void) {
|
||||
ctx.debug = !ctx.debug;
|
||||
}
|
||||
|
||||
if (input_is_action_just_pressed(&ctx.input, "debug_dump_atlases")) {
|
||||
textures_dump_atlases();
|
||||
}
|
||||
|
||||
state->scene->tick(state);
|
||||
|
||||
/* there's a scene switch pending, we can do it now that the tick is done */
|
||||
|
@ -23,6 +23,9 @@ void game_tick(void) {
|
||||
input_add_action(&ctx.input, "debug_toggle");
|
||||
input_bind_action_scancode(&ctx.input, "debug_toggle", SDL_SCANCODE_BACKSPACE);
|
||||
|
||||
input_add_action(&ctx.input, "debug_dump_atlases");
|
||||
input_bind_action_scancode(&ctx.input, "debug_dump_atlases", SDL_SCANCODE_HOME);
|
||||
|
||||
input_add_action(&ctx.input, "player_left");
|
||||
input_bind_action_scancode(&ctx.input, "player_left", SDL_SCANCODE_A);
|
||||
|
||||
@ -54,6 +57,10 @@ void game_tick(void) {
|
||||
ctx.debug = !ctx.debug;
|
||||
}
|
||||
|
||||
if (input_is_action_just_pressed(&ctx.input, "debug_dump_atlases")) {
|
||||
textures_dump_atlases();
|
||||
}
|
||||
|
||||
state->scene->tick(state);
|
||||
|
||||
/* there's a scene switch pending, we can do it now that the tick is done */
|
||||
|
@ -68,6 +68,10 @@ TWN_API int64_t file_to_bytes(const char *path, unsigned char **buf_out);
|
||||
TWN_API char *file_to_str(const char *path);
|
||||
|
||||
|
||||
/* saves all texture atlases as BMP files in the write directory */
|
||||
TWN_API void textures_dump_atlases(void);
|
||||
|
||||
|
||||
/* returns true if str ends with suffix */
|
||||
TWN_API TWN_API bool strends(const char *str, const char *suffix);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user