From c3fb50c358428efe7eec1f73775898b3d54f79d0 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 14 Aug 2023 17:39:02 +0200 Subject: [PATCH] port; refactor widescreen PR a bit abstract aspect into a video* function re-add gun swivel, but make it slower on hi res --- port/fast3d/gfx_pc.cpp | 21 ++++++--------------- port/include/video.h | 4 ++++ port/src/video.c | 15 +++++++++++++++ src/game/bondmove.c | 13 ++++++++----- src/game/player.c | 8 ++++---- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/port/fast3d/gfx_pc.cpp b/port/fast3d/gfx_pc.cpp index 2da13ee88..c067e7244 100644 --- a/port/fast3d/gfx_pc.cpp +++ b/port/fast3d/gfx_pc.cpp @@ -996,11 +996,8 @@ static float gfx_adjust_x_for_aspect_ratio(float x) { if (fbActive) { return x; } else { -#ifdef PLATFORM_N64 - return x * (4.0f / 3.0f) / ((float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height); -#else - return x * ((float)gfx_current_window_dimensions.width / gfx_current_window_dimensions.height) / ((float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height); -#endif + return x * ((float)gfx_current_window_dimensions.width / gfx_current_window_dimensions.height) / + ((float)gfx_current_dimensions.width / (float)gfx_current_dimensions.height); } } @@ -2586,18 +2583,12 @@ extern "C" void gfx_start_frame(void) { gfx_current_window_dimensions.height = 1; } -#ifdef PLATFORM_N64 - gfx_current_dimensions.aspect_ratio = 4.0f / 3.0f; -#else - // for now ensure that the game renders in a centered 4:3 window - // proper 16:9 support requires some fixes, namely the sky, fullscreen fades and room culling - gfx_current_dimensions.aspect_ratio = (float)gfx_current_window_dimensions.width / gfx_current_window_dimensions.height; -#endif - gfx_current_dimensions.height = gfx_current_window_dimensions.height; - gfx_current_dimensions.width = gfx_current_dimensions.height * gfx_current_dimensions.aspect_ratio; + gfx_current_window_dimensions.aspect_ratio = (float)gfx_current_window_dimensions.width / gfx_current_window_dimensions.height; + + gfx_current_dimensions = gfx_current_window_dimensions; + gfx_current_game_window_viewport.width = gfx_current_dimensions.width; gfx_current_game_window_viewport.height = gfx_current_dimensions.height; - gfx_current_game_window_viewport.x = (gfx_current_window_dimensions.width - gfx_current_dimensions.width) / 2; if (gfx_current_dimensions.height != gfx_prev_dimensions.height) { for (auto& fb : framebuffers) { diff --git a/port/include/video.h b/port/include/video.h index b463a267a..70cba99ac 100644 --- a/port/include/video.h +++ b/port/include/video.h @@ -14,4 +14,8 @@ void *videoGetWindowHandle(void); void videoUpdateNativeResolution(const int w, const int h); +s32 videoGetWidth(void); +s32 videoGetHeight(void); +f32 videoGetAspect(void); + #endif diff --git a/port/src/video.c b/port/src/video.c index c74a0eb15..786e10c36 100644 --- a/port/src/video.c +++ b/port/src/video.c @@ -90,3 +90,18 @@ void videoUpdateNativeResolution(const int w, const int h) gfx_current_native_viewport.width = w; gfx_current_native_viewport.height = h; } + +s32 videoGetWidth(void) +{ + return gfx_current_dimensions.width; +} + +s32 videoGetHeight(void) +{ + return gfx_current_dimensions.height; +} + +f32 videoGetAspect(void) +{ + return gfx_current_dimensions.aspect_ratio; +} diff --git a/src/game/bondmove.c b/src/game/bondmove.c index 4b29f7cf3..4bf0e79ce 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -40,6 +40,7 @@ #include "types.h" #ifndef PLATFORM_N64 #include "input.h" +#include "video.h" #endif void bmoveSetControlDef(u32 controldef) @@ -1827,7 +1828,6 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i bgunSwivelWithDamp(x, y, g_Vars.currentplayer->autoaimdamp); } } else { -#ifdef PLATFORM_N64 // This code moves the crosshair as the player turns and makes // it return to the centre when not affected by anything else. if (g_Vars.currentplayer->autoaimdamp < (PAL ? 0.974f : 0.979f)) { @@ -1838,14 +1838,17 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i g_Vars.currentplayer->autoaimdamp = (PAL ? 0.974f : 0.979f); } +#ifdef PLATFORM_N64 x = g_Vars.currentplayer->speedtheta * 0.3f + g_Vars.currentplayer->gunextraaimx; y = -g_Vars.currentplayer->speedverta * 0.1f + g_Vars.currentplayer->gunextraaimy; +#else + const f32 xscale = 320.f / (f32)videoGetWidth(); + const f32 yscale = 240.f / (f32)videoGetHeight(); + x = g_Vars.currentplayer->speedtheta * 0.3f * xscale + g_Vars.currentplayer->gunextraaimx; + y = -g_Vars.currentplayer->speedverta * 0.1f * yscale + g_Vars.currentplayer->gunextraaimy; +#endif bgunSwivelWithDamp(x, y, PAL ? 0.955f : 0.963f); -#else - bgunSetAimType(0); - bgunSwivelWithoutDamp((movedata.c1stickxraw * 0.65f) / 80.0f, (movedata.c1stickyraw * 0.65f) / 80.0f); -#endif } } else if (movedata.canmanualaim) { // Adjust crosshair's position on screen diff --git a/src/game/player.c b/src/game/player.c index 36a2c0293..d1a7a0897 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -1,7 +1,4 @@ #include -#ifndef PLATFORM_N64 -#include "../fast3d/gfx_api.h" -#endif #include "constants.h" #include "game/bondeyespy.h" #include "game/bondmove.h" @@ -73,6 +70,9 @@ #include "lib/lib_317f0.h" #include "data.h" #include "types.h" +#ifndef PLATFORM_N64 +#include "video.h" +#endif s32 g_DefaultWeapons[2]; f32 g_MpSwirlRotateSpeed; @@ -3002,7 +3002,7 @@ f32 player0f0bd358(void) #ifdef PLATFORM_N64 return result; #else - return result * (((float)gfx_current_window_dimensions.width / gfx_current_window_dimensions.height) / (4.0f / 3.0f)); + return result * (videoGetAspect() / (4.0f / 3.0f)); #endif }