From 5b05386bb07736098a3a7adb2d10667c73cf29ea Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Mon, 6 Jan 2025 21:19:26 +0300 Subject: [PATCH] changes to twn.toml specification of resolution, make it optional as well --- apps/demos/bunnymark/data/twn.toml | 3 +- apps/demos/platformer/data/twn.toml | 3 +- apps/demos/scenery/data/twn.toml | 5 ++- apps/template/data/twn.toml | 3 +- apps/twnlua/data/twn.toml | 3 +- src/twn_loop.c | 55 ++++++++++++++++------------- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/apps/demos/bunnymark/data/twn.toml b/apps/demos/bunnymark/data/twn.toml index 5b2d491..fc73c62 100644 --- a/apps/demos/bunnymark/data/twn.toml +++ b/apps/demos/bunnymark/data/twn.toml @@ -5,7 +5,6 @@ app_id = "bunnymark" dev_id = "morshy" [game] -base_render_width = 640 -base_render_height = 480 +resolution = [ 640, 480 ] [engine] diff --git a/apps/demos/platformer/data/twn.toml b/apps/demos/platformer/data/twn.toml index debaf73..abbf88c 100644 --- a/apps/demos/platformer/data/twn.toml +++ b/apps/demos/platformer/data/twn.toml @@ -5,7 +5,6 @@ app_id = "platformer-demo" dev_id = "townengine-team" [game] -base_render_width = 640 -base_render_height = 360 +resolution = [ 640, 360 ] [engine] diff --git a/apps/demos/scenery/data/twn.toml b/apps/demos/scenery/data/twn.toml index a874c07..cf6499c 100644 --- a/apps/demos/scenery/data/twn.toml +++ b/apps/demos/scenery/data/twn.toml @@ -1,11 +1,10 @@ [about] title = "Serene Scenery" developer = "Townengine Team" -app_id = "platformer-demo" +app_id = "scenery-demo" dev_id = "townengine-team" [game] -base_render_width = 640 -base_render_height = 360 +resolution = [ 640, 360 ] [engine] diff --git a/apps/template/data/twn.toml b/apps/template/data/twn.toml index c95e4b4..2752b58 100644 --- a/apps/template/data/twn.toml +++ b/apps/template/data/twn.toml @@ -13,8 +13,7 @@ dev_id = "you" # Game runtime details [game] -base_render_width = 640 -base_render_height = 480 +resolution = [ 640, 480 ] #debug = true # Engine tweaks. You probably don't need to change these diff --git a/apps/twnlua/data/twn.toml b/apps/twnlua/data/twn.toml index d22c227..a822d96 100644 --- a/apps/twnlua/data/twn.toml +++ b/apps/twnlua/data/twn.toml @@ -5,7 +5,6 @@ app_id = "twnlua" dev_id = "somebody" [game] -base_render_width = 640 -base_render_height = 360 +resolution = [ 640, 360 ] [engine] diff --git a/src/twn_loop.c b/src/twn_loop.c index 5c12be2..0c194ba 100644 --- a/src/twn_loop.c +++ b/src/twn_loop.c @@ -423,11 +423,7 @@ static bool initialize(void) { /* debug mode defaults to being enabled */ /* pass --debug or --release to force a mode, ignoring configuration */ toml_datum_t datum_debug = toml_bool_in(game, "debug"); - if (!datum_debug.ok) { - ctx.game.debug = true; - } else { - ctx.game.debug = datum_debug.u.b; - } + ctx.game.debug = datum_debug.ok ? datum_debug.u.b : true; #ifdef EMSCRIPTEN /* emscripten interpretes those as GL ES version against WebGL */ @@ -454,10 +450,9 @@ static bool initialize(void) { /* init got far enough to create a window */ { toml_datum_t datum_title = toml_string_in(about, "title"); - if (!datum_title.ok) { - CRY("Initialization failed", "Valid about.title expected in configuration file"); - goto fail; - } + if (!datum_title.ok) + datum_title.u.s = "townengine project"; + /* not yet used toml_datum_t datum_developer = toml_string_in(about, "developer"); if (!datum_developer.ok) { @@ -465,32 +460,44 @@ static bool initialize(void) { goto fail; } */ - toml_datum_t datum_base_render_width = toml_int_in(game, "base_render_width"); - if (!datum_base_render_width.ok) { - CRY("Initialization failed", "Valid game.base_render_width expected in configuration file"); - goto fail; - } - ctx.base_render_width = datum_base_render_width.u.i; - ctx.game.resolution.x = (float)ctx.base_render_width; - toml_datum_t datum_base_render_height = toml_int_in(game, "base_render_height"); - if (!datum_base_render_height.ok) { - CRY("Initialization failed", "Valid game.base_render_height expected in configuration file"); - goto fail; + toml_array_t *datum_resolution = toml_array_in(game, "resolution"); + if (datum_resolution) { + toml_datum_t datum_base_render_width = toml_int_at(datum_resolution, 0); + if (!datum_base_render_width.ok) { + CRY("Initialization failed", "Valid game.resolution expected in configuration file"); + goto fail; + } + + toml_datum_t datum_base_render_height = toml_int_at(datum_resolution, 1); + if (!datum_base_render_height.ok) { + CRY("Initialization failed", "Valid game.resolution expected in configuration file"); + goto fail; + } + + ctx.base_render_width = datum_base_render_width.u.i; + ctx.base_render_height = datum_base_render_height.u.i; + + } else { + ctx.base_render_width = 640; + ctx.base_render_height = 360; } - ctx.base_render_height = datum_base_render_height.u.i; + + ctx.game.resolution.x = (float)ctx.base_render_width; ctx.game.resolution.y = (float)ctx.base_render_height; ctx.window = SDL_CreateWindow(datum_title.u.s, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - (int)datum_base_render_width.u.i, - (int)datum_base_render_height.u.i, + (int)ctx.base_render_width, + (int)ctx.base_render_height, //SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); - SDL_free(datum_title.u.s); + if (datum_title.ok) + SDL_free(datum_title.u.s); + //SDL_free(datum_developer.u.s); }