From f96e7da00fcbceb1386ca169d1cce875ff1db5b1 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 3 Dec 2023 21:10:41 +0100 Subject: [PATCH 1/4] port: use proper aspect for 2D elements this means that now scaling at most 4:3 resolutions will be a bit mangled, since the real base resolution is 320x220 --- port/fast3d/gfx_api.h | 1 + port/fast3d/gfx_pc.cpp | 11 ++++++----- port/src/video.c | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/port/fast3d/gfx_api.h b/port/fast3d/gfx_api.h index 17a1a1310..1f53f0ed4 100644 --- a/port/fast3d/gfx_api.h +++ b/port/fast3d/gfx_api.h @@ -27,6 +27,7 @@ extern struct XYWidthHeight gfx_current_game_window_viewport; // The area of the window the game is drawn to, (0, 0) is top-left corner extern uint32_t gfx_msaa_level; extern struct XYWidthHeight gfx_current_native_viewport; // The internal/native video mode of the game +extern float gfx_current_native_aspect; // The aspect ratio of the above mode extern bool gfx_framebuffers_enabled; void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAPI* rapi, const char* game_name, diff --git a/port/fast3d/gfx_pc.cpp b/port/fast3d/gfx_pc.cpp index 5b2dcc0e3..a5c997a31 100644 --- a/port/fast3d/gfx_pc.cpp +++ b/port/fast3d/gfx_pc.cpp @@ -217,6 +217,7 @@ struct GfxDimensions gfx_current_dimensions; static struct GfxDimensions gfx_prev_dimensions; struct XYWidthHeight gfx_current_game_window_viewport; struct XYWidthHeight gfx_current_native_viewport; +float gfx_current_native_aspect = 4.f / 3.f; bool gfx_framebuffers_enabled = true; static bool game_renders_to_framebuffer; @@ -1652,12 +1653,12 @@ static void gfx_sp_geometry_mode(uint32_t clear, uint32_t set) { static inline void gfx_update_aspect_mode(void) { const uint32_t side = rsp.aspect_mode & G_ASPECT_CENTER_EXT; - rsp.aspect_scale = rsp.aspect_mode ? (4.f / 3.f) : gfx_current_window_dimensions.aspect_ratio; + rsp.aspect_scale = rsp.aspect_mode ? gfx_current_native_aspect : gfx_current_window_dimensions.aspect_ratio; if (side == G_ASPECT_LEFT_EXT) { - rsp.aspect_ofs = 1.f - 3.f * gfx_current_dimensions.aspect_ratio / 4.f; + rsp.aspect_ofs = 1.f - gfx_current_dimensions.aspect_ratio / gfx_current_native_aspect; } else if (side == G_ASPECT_RIGHT_EXT) { - rsp.aspect_ofs = 3.f * gfx_current_dimensions.aspect_ratio / 4.f - 1.f; + rsp.aspect_ofs = gfx_current_dimensions.aspect_ratio / gfx_current_native_aspect - 1.f; } else { rsp.aspect_ofs = 0.f; } @@ -1685,8 +1686,8 @@ static void gfx_adjust_viewport_or_scissor(XYWidthHeight* area, bool preserve_as area->y = SCREEN_HEIGHT - area->y; area->y *= RATIO_Y; if (preserve_aspect) { - // preserve 4:3 - const float ratio = (4.f / 3.f) / gfx_current_dimensions.aspect_ratio; + // preserve native aspect ratio + const float ratio = gfx_current_native_aspect / gfx_current_dimensions.aspect_ratio; const float midx = gfx_current_dimensions.width * 0.5f; area->x = midx + (area->x - midx) * ratio; area->x += rsp.aspect_ofs * gfx_current_dimensions.width * 0.5f; diff --git a/port/src/video.c b/port/src/video.c index afe485f5b..075546218 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -39,7 +39,8 @@ s32 videoInit(void) renderingAPI = &gfx_opengl_api; gfx_current_native_viewport.width = 320; - gfx_current_native_viewport.height = 240; + gfx_current_native_viewport.height = 220; + gfx_current_native_aspect = 320.f / 220.f; gfx_framebuffers_enabled = (bool)vidFramebuffers; gfx_msaa_level = vidMSAA; @@ -110,6 +111,7 @@ void videoUpdateNativeResolution(s32 w, s32 h) { gfx_current_native_viewport.width = w; gfx_current_native_viewport.height = h; + gfx_current_native_aspect = (float)w / (float)h; } s32 videoGetNativeWidth(void) From d89735602991f755ec6a32b655cd0b39bcc79e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Agust=C3=ADn=20Moreno=20Larios?= Date: Sun, 3 Dec 2023 16:28:02 -0500 Subject: [PATCH 2/4] Changed 'codeclean' so that it doesn't try to delete inexistent directories. --- Makefile.port | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.port b/Makefile.port index 2b123e83b..e3386022f 100644 --- a/Makefile.port +++ b/Makefile.port @@ -316,4 +316,4 @@ allclean: rm -rf src/generated codeclean: - find $(B_DIR)/game $(B_DIR)/inflate $(B_DIR)/lib $(B_DIR)/port -name '*.o' -delete + find $(B_DIR)/port -name '*.o' -delete From 13b23de6d33ee736f42132886a030cb7017fe97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Agust=C3=ADn=20Moreno=20Larios?= Date: Sun, 3 Dec 2023 16:38:18 -0500 Subject: [PATCH 3/4] Simplified the 'codeclean' rule to find all *.o files and delete them --- Makefile.port | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.port b/Makefile.port index e3386022f..db1d2bbd9 100644 --- a/Makefile.port +++ b/Makefile.port @@ -316,4 +316,4 @@ allclean: rm -rf src/generated codeclean: - find $(B_DIR)/port -name '*.o' -delete + find $(B_DIR)/ -name '*.o' -delete From d1be171939cecc4b0cdc71b92ec1875406ba6804 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 4 Dec 2023 18:22:37 +0100 Subject: [PATCH 4/4] port: only use SDL_CONTROLLER_TYPE_VIRTUAL when available --- port/src/input.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/port/src/input.c b/port/src/input.c index a6306e14f..a4b14d0e5 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -12,6 +12,11 @@ #include "system.h" #include "fs.h" +#if !SDL_VERSION_ATLEAST(2, 0, 14) +// this was added in 2.0.14 +#define SDL_CONTROLLER_TYPE_VIRTUAL SDL_CONTROLLER_TYPE_UNKNOWN +#endif + #define CONTROLLERDB_FNAME "gamecontrollerdb.txt" #define MAX_BIND_STR 256