From e9f8dbebbf08262660518e37e470ce68b6f63266 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Mon, 10 Feb 2025 14:36:57 +0300 Subject: [PATCH] refactor toml reading a bit --- src/twn_loop.c | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/twn_loop.c b/src/twn_loop.c index d159065..93f3bc8 100644 --- a/src/twn_loop.c +++ b/src/twn_loop.c @@ -560,37 +560,22 @@ static bool initialize(void) { /* engine configuration */ { toml_datum_t datum_texture_atlas_size = toml_int_in(engine, "texture_atlas_size"); - if (!datum_texture_atlas_size.ok) { + if (!datum_texture_atlas_size.ok || datum_texture_atlas_size.u.i < 32) { ctx.texture_atlas_size = TEXTURE_ATLAS_SIZE_DEFAULT; - } else { - if (datum_texture_atlas_size.u.i < 32) { - ctx.texture_atlas_size = TEXTURE_ATLAS_SIZE_DEFAULT; - } else { - ctx.texture_atlas_size = datum_texture_atlas_size.u.i; - } - } + } else + ctx.texture_atlas_size = datum_texture_atlas_size.u.i; toml_datum_t datum_font_texture_size = toml_int_in(engine, "font_texture_size"); - if (!datum_font_texture_size.ok) { + if (!datum_font_texture_size.ok || datum_font_texture_size.u.i < 1024) { ctx.font_texture_size = TEXT_FONT_TEXTURE_SIZE_DEFAULT; - } else { - if (datum_font_texture_size.u.i < 1024) { - ctx.font_texture_size = TEXT_FONT_TEXTURE_SIZE_DEFAULT; - } else { - ctx.font_texture_size = datum_font_texture_size.u.i; - } - } + } else + ctx.font_texture_size = datum_font_texture_size.u.i; toml_datum_t datum_font_oversampling = toml_int_in(engine, "font_oversampling"); - if (!datum_font_oversampling.ok) { + if (!datum_font_oversampling.ok || datum_font_oversampling.u.i < 0) { ctx.font_oversampling = TEXT_FONT_OVERSAMPLING_DEFAULT; - } else { - if (datum_font_oversampling.u.i < 0) { - ctx.font_oversampling = TEXT_FONT_OVERSAMPLING_DEFAULT; - } else { - ctx.font_oversampling = datum_font_oversampling.u.i; - } - } + } else + ctx.font_oversampling = datum_font_oversampling.u.i; toml_datum_t datum_font_filtering = toml_string_in(engine, "font_filtering"); if (!datum_font_filtering.ok) { @@ -619,15 +604,10 @@ static bool initialize(void) { /* input */ toml_datum_t datum_keybind_slots = toml_int_in(engine, "keybind_slots"); - if (!datum_keybind_slots.ok) { + if (!datum_keybind_slots.ok || datum_keybind_slots.u.i < 1) { ctx.keybind_slots = KEYBIND_SLOTS_DEFAULT; - } else { - if (datum_keybind_slots.u.i < 1) { - ctx.keybind_slots = KEYBIND_SLOTS_DEFAULT; - } else { - ctx.keybind_slots = datum_keybind_slots.u.i; - } - } + } else + ctx.keybind_slots = datum_keybind_slots.u.i; } input_state_init(&ctx.input);