implement game configuration file

this integrates https://github.com/cktan/tomlc99 into the repo as a dependency
This commit is contained in:
2024-09-30 21:13:58 -03:00
committed by veclavtalica
parent ec15d8ec4b
commit 57fe5e8946
165 changed files with 4797 additions and 92 deletions

View File

@ -132,7 +132,7 @@ static SDL_Surface *create_surface(int width, int height) {
/* adds a new, blank atlas surface to the cache */
static void add_new_atlas(TextureCache *cache) {
SDL_Surface *new_atlas = create_surface(TEXTURE_ATLAS_SIZE, TEXTURE_ATLAS_SIZE);
SDL_Surface *new_atlas = create_surface((int)ctx.texture_atlas_size, (int)ctx.texture_atlas_size);
arrput(cache->atlas_surfaces, new_atlas);
arrput(cache->atlas_textures, create_gpu_texture(TEXTURE_FILTER_NEAREAST, true));
}
@ -269,7 +269,7 @@ void textures_cache_init(TextureCache *cache, SDL_Window *window) {
cache->window = window;
sh_new_arena(cache->hash);
cache->node_buffer = SDL_calloc(TEXTURE_ATLAS_SIZE, sizeof *cache->node_buffer);
cache->node_buffer = SDL_calloc(ctx.texture_atlas_size, sizeof *cache->node_buffer);
add_new_atlas(cache);
recreate_current_atlas_texture(cache);
@ -341,7 +341,7 @@ static TextureKey textures_load(TextureCache *cache, const char *path) {
};
/* it's a "loner texture," it doesn't fit in an atlas so it's not in one */
if (surface->w >= TEXTURE_ATLAS_SIZE || surface->h >= TEXTURE_ATLAS_SIZE) {
if (surface->w >= ctx.texture_atlas_size || surface->h >= ctx.texture_atlas_size) {
if (ctx.game.debug) {
if (surface->w > 2048 || surface->h > 2048)
log_warn("Unportable texture dimensions for %s, use 2048x2048 at max", path);
@ -368,10 +368,10 @@ void textures_update_atlas(TextureCache *cache) {
/* this function makes a lot more sense if you read stb_rect_pack.h */
stbrp_context pack_ctx; /* target info */
stbrp_init_target(&pack_ctx,
TEXTURE_ATLAS_SIZE,
TEXTURE_ATLAS_SIZE,
ctx.texture_atlas_size,
ctx.texture_atlas_size,
cache->node_buffer,
TEXTURE_ATLAS_SIZE);
ctx.texture_atlas_size);
stbrp_rect *rects = create_rects_from_cache(cache);
@ -493,7 +493,7 @@ Rect textures_get_dims(const TextureCache *cache, TextureKey key) {
if (cache->hash[key.id].value.loner_texture != 0)
return cache->hash[key.id].value.srcrect;
else
return (Rect){ .w = TEXTURE_ATLAS_SIZE, .h = TEXTURE_ATLAS_SIZE };
return (Rect){ .w = ctx.texture_atlas_size, .h = ctx.texture_atlas_size };
} else {
CRY("Texture lookup failed.",
"Tried to get texture that isn't loaded.");