# HG changeset patch # User Michael Pavone # Date 1497579856 25200 # Node ID 458df351af06043dbaf2cc93bc5f99a4eb15e4c8 # Parent b56c8c51ca5dc10a22f578bc25b2113fd0cec981 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified diff -r b56c8c51ca5d -r 458df351af06 blastem.c --- a/blastem.c Thu Jun 15 09:45:21 2017 -0700 +++ b/blastem.c Thu Jun 15 19:24:16 2017 -0700 @@ -357,7 +357,7 @@ loaded = 1; } - int def_width = 0; + int def_width = 0, def_height = 0; char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval; if (config_width) { def_width = atoi(config_width); @@ -365,8 +365,15 @@ if (!def_width) { def_width = 640; } - width = width < 320 ? def_width : width; - height = height < 240 ? (width/320) * 240 : height; + char *config_height = tern_find_path(config, "video\0height\0", TVAL_PTR).ptrval; + if (config_height) { + def_height = atoi(config_height); + } + if (!def_height) { + def_height = -1; + } + width = width < 1 ? def_width : width; + height = height < 1 ? def_height : height; char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval; if (config_fullscreen && !strcmp("on", config_fullscreen)) { diff -r b56c8c51ca5d -r 458df351af06 default.cfg --- a/default.cfg Thu Jun 15 09:45:21 2017 -0700 +++ b/default.cfg Thu Jun 15 19:24:16 2017 -0700 @@ -134,6 +134,9 @@ #special value "stretch" will cause aspect to match window aspect ratio aspect 4:3 width 640 + #height is normally calculated automatically from width using the aspect setting + #if you would like to set it explicitly, uncomment the line below + #height 480 vertex_shader default.v.glsl fragment_shader default.f.glsl scanlines off diff -r b56c8c51ca5d -r 458df351af06 render_sdl.c --- a/render_sdl.c Thu Jun 15 09:45:21 2017 -0700 +++ b/render_sdl.c Thu Jun 15 19:24:16 2017 -0700 @@ -276,6 +276,28 @@ } } +static float config_aspect() +{ + static float aspect = 0.0f; + if (aspect == 0.0f) { + char *config_aspect = tern_find_path_default(config, "video\0aspect\0", (tern_val){.ptrval = "4:3"}, TVAL_PTR).ptrval; + if (strcmp("stretch", config_aspect)) { + aspect = 4.0f/3.0f; + char *end; + float aspect_numerator = strtof(config_aspect, &end); + if (aspect_numerator > 0.0f && *end == ':') { + float aspect_denominator = strtof(end+1, &end); + if (aspect_denominator > 0.0f && !*end) { + aspect = aspect_numerator / aspect_denominator; + } + } + } else { + aspect = -1.0f; + } + } + return aspect; +} + static void update_aspect() { //reset default values @@ -283,20 +305,9 @@ main_clip.w = main_width; main_clip.h = main_height; main_clip.x = main_clip.y = 0; - //calculate configured aspect ratio - char *config_aspect = tern_find_path_default(config, "video\0aspect\0", (tern_val){.ptrval = "4:3"}, TVAL_PTR).ptrval; - if (strcmp("stretch", config_aspect)) { - float src_aspect = 4.0f/3.0f; - char *end; - float aspect_numerator = strtof(config_aspect, &end); - if (aspect_numerator > 0.0f && *end == ':') { - float aspect_denominator = strtof(end+1, &end); - if (aspect_denominator > 0.0f && !*end) { - src_aspect = aspect_numerator / aspect_denominator; - } - } + if (config_aspect() > 0.0f) { float aspect = (float)main_width / main_height; - if (fabs(aspect - src_aspect) < 0.01f) { + if (fabs(aspect - config_aspect()) < 0.01f) { //close enough for government work return; } @@ -304,16 +315,16 @@ if (render_gl) { for (int i = 0; i < 4; i++) { - if (aspect > src_aspect) { - vertex_data[i*2] *= src_aspect/aspect; + if (aspect > config_aspect()) { + vertex_data[i*2] *= config_aspect()/aspect; } else { - vertex_data[i*2+1] *= aspect/src_aspect; + vertex_data[i*2+1] *= aspect/config_aspect(); } } } else { #endif - main_clip.w = aspect > src_aspect ? src_aspect * (float)main_height : main_width; - main_clip.h = aspect > src_aspect ? main_height : main_width / src_aspect; + main_clip.w = aspect > config_aspect() ? config_aspect() * (float)main_height : main_width; + main_clip.h = aspect > config_aspect() ? main_height : main_width / config_aspect(); main_clip.x = (main_width - main_clip.w) / 2; main_clip.y = (main_height - main_clip.h) / 2; #ifndef DISABLE_OPENGL @@ -334,6 +345,10 @@ fatal_error("Unable to init SDL: %s\n", SDL_GetError()); } atexit(SDL_Quit); + if (height <= 0) { + float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; + height = ((float)width / aspect) + 0.5f; + } printf("width: %d, height: %d\n", width, height); windowed_width = width; windowed_height = height;