From d7a612302ec79a5ddd45088a7ddc695f24f64822 Mon Sep 17 00:00:00 2001 From: Matthew Coppola Date: Sun, 17 Nov 2024 03:44:03 -0500 Subject: [PATCH 01/17] Discard player momentum during autowalk sequences Prevents potential softlock during The Duel. --- src/game/player.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/game/player.c b/src/game/player.c index b2fdf891b..b9bb2f83c 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -3107,6 +3107,9 @@ void playerAutoWalk(s16 aimpad, u8 walkspeed, u8 turnspeed, u8 lookup, u8 dist) { playerSetTickMode(TICKMODE_AUTOWALK); + // Prevents momentum from being preserved. Fixes potential softlock during The Duel. + g_Vars.currentplayer->resetheadpos = true; + g_Vars.currentplayer->autocontrol_aimpad = aimpad; g_Vars.currentplayer->autocontrol_walkspeed = walkspeed; g_Vars.currentplayer->autocontrol_turnspeed = turnspeed; From 23864940306d9f30c7af098f593d22dfb9772c76 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 2 Dec 2024 13:43:28 +0100 Subject: [PATCH 02/17] port: 64-bit: fix mema end marker (fixes #545) --- src/lib/mema.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/lib/mema.c b/src/lib/mema.c index d0676ccff..62adbd6ed 100644 --- a/src/lib/mema.c +++ b/src/lib/mema.c @@ -39,7 +39,7 @@ struct memaspace { uintptr_t addr; - u64 size; + uintptr_t size; }; /** @@ -56,7 +56,7 @@ struct memaheap { }; uintptr_t g_MemaHeapStart; -u64 g_MemaHeapSize; +uintptr_t g_MemaHeapSize; struct memaheap g_MemaHeap; #if VERSION == VERSION_PAL_BETA @@ -125,7 +125,7 @@ struct memaspace *memaMakeSlot(struct memaheap *heap) { struct memaspace *curr = &heap->spaces[0]; struct memaspace *best; - u32 min; + uintptr_t min; s32 i; // Do 124 passes over the list. This ensures the list is in order by the @@ -162,7 +162,7 @@ struct memaspace *memaMakeSlot(struct memaheap *heap) // Find the smallest run of free space and use that instead. // The caller will overwrite it with its own free allocation, causing the // original run of free space to be unusable until the mema heap is reset. - min = 0xffffffff; + min = (uintptr_t)-1; best = curr; while (curr <= &heap->spaces[MAX_SPACES - 1]) { @@ -193,7 +193,7 @@ void _memaFree(uintptr_t addr, u64 size) } // If we reached the end of the spaces list, go backwards instead - if (curr->addr == -1) { + if (curr->addr == (uintptr_t)-1) { curr = &g_MemaHeap.spaces[index]; while (curr->size != 0) { @@ -235,10 +235,10 @@ void memaReset(void *heapaddr, u64 heapsize) g_MemaHeap.start.addr = 0; g_MemaHeap.start.size = 0; - g_MemaHeap.end1.addr = 0xffffffff; + g_MemaHeap.end1.addr = (uintptr_t)-1; g_MemaHeap.end1.size = 0; - g_MemaHeap.end2.addr = 0xffffffff; - g_MemaHeap.end2.size = 0xffffffff; + g_MemaHeap.end2.addr = (uintptr_t)-1; + g_MemaHeap.end2.size = (uintptr_t)-1; for (space = &g_MemaHeap.spaces[0]; space <= &g_MemaHeap.spaces[MAX_SPACES - 1]; space++) { space->addr = 0; @@ -411,7 +411,7 @@ void *memaAlloc(u64 size) if (1); curr = &g_MemaHeap.spaces[0]; - bestdiff = 0xffffffff; + bestdiff = (uintptr_t)-1; best = NULL; // Iterate up to the first 16 spaces, looking for the @@ -421,7 +421,7 @@ void *memaAlloc(u64 size) continue; } - if (curr->addr == 0xffffffff) { + if (curr->addr == (uintptr_t)-1) { // Reached the end break; } @@ -446,13 +446,13 @@ void *memaAlloc(u64 size) if (best == NULL) { // Keep iterating until we find a space that is big enough to fit. - // The last space is marked as size 0xffffffff which prevents this loop + // The last space is marked as size -1 which prevents this loop // from iterating past the end of the spaces array. while (curr->size < size) { curr++; } - if (curr->addr == 0xffffffff) { + if (curr->addr == (uintptr_t)-1) { // There was no space, so attempt to free up some space // by doing several defrag passes for (i = 0; i < 8; i++) { @@ -465,7 +465,7 @@ void *memaAlloc(u64 size) curr++; } - if (curr->addr == 0xffffffff) { + if (curr->addr == (uintptr_t)-1) { return NULL; } } @@ -491,7 +491,7 @@ uintptr_t memaGrow(uintptr_t addr, u64 amount) { struct memaspace *curr = &g_MemaHeap.spaces[0]; - while (curr->addr != -1) { + while (curr->addr != (uintptr_t)-1) { if (curr->addr == addr && curr->size >= amount) { goto found; } @@ -535,7 +535,7 @@ u64 memaGetLongestFree(void) curr = &g_MemaHeap.spaces[0]; - while (curr->addr != -1) { + while (curr->addr != (uintptr_t)-1) { if (curr->size > biggest) { biggest = curr->size; } From 0e1a7e136a42a730e38d3e1944ee72c781c4487d Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 4 Dec 2024 10:42:48 +0100 Subject: [PATCH 03/17] port: fix uninitialized var in aiIfPresetsTargetIsNotMyTarget (fixes #542) --- src/game/chraicommands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/chraicommands.c b/src/game/chraicommands.c index efcbf5ecf..805fd739c 100644 --- a/src/game/chraicommands.c +++ b/src/game/chraicommands.c @@ -5948,7 +5948,7 @@ bool aiSetTarget(void) */ bool aiIfPresetsTargetIsNotMyTarget(void) { - s32 mypresetchrstarget; + s32 mypresetchrstarget = -1; u8 *cmd = g_Vars.ailist + g_Vars.aioffset; if (g_Vars.chrdata->chrpreset1 != -1) { From a1ca69d9ee414ce2092c32043f6851a7cea867f1 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 4 Dec 2024 16:27:53 +0100 Subject: [PATCH 04/17] port: fix issues mentioned in #530 and #532 --- port/src/input.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/port/src/input.c b/port/src/input.c index 3912e28d8..59a842d71 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -802,8 +802,12 @@ static inline void inputUpdateMouse(void) mouseWheel = 0; + s32 mdx = 0; + s32 mdy = 0; + SDL_GetRelativeMouseState(&mdx, &mdy); if (mouseLocked) { - SDL_GetRelativeMouseState(&mouseDX, &mouseDY); + mouseDX = mdx; + mouseDY = mdy; } else { mouseDX = mx - mouseX; mouseDY = my - mouseY; From a2e362caeac90676106ad006039b04911093fa33 Mon Sep 17 00:00:00 2001 From: Matthew Coppola Date: Wed, 4 Dec 2024 21:23:21 -0500 Subject: [PATCH 05/17] Forbid mousescroll if dialog is dimmed --- src/game/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/menu.c b/src/game/menu.c index 694b4fc63..e2bf7d9a6 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -4539,7 +4539,7 @@ void dialogTick(struct menudialog *dialog, struct menuinputs *inputs, u32 tickfl if ((dialog->focuseditem->flags & MENUITEMFLAG_00010000) == 0) { #ifndef PLATFORM_N64 - if (g_MenuUsingMouse) { + if (g_MenuUsingMouse && !dialog->dimmed) { dstscroll = dialog->dstscroll - inputs->mousescroll * LINEHEIGHT; } else #endif From cb449bf7cee9f05e028ee8ab1d7619d562b05b6f Mon Sep 17 00:00:00 2001 From: Matthew Coppola Date: Fri, 6 Dec 2024 22:15:24 -0500 Subject: [PATCH 06/17] Increase precision for mouse speed options --- port/src/optionsmenu.c | 50 +++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 2b845ebe0..45877ee2b 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -169,15 +169,17 @@ static MenuItemHandlerResult menuhandlerMouseSpeedX(s32 operation, struct menuit if (x < 0.f) { data->slider.value = 0; } else if (x > 10.f) { - data->slider.value = 100; + data->slider.value = 1000; } else { - data->slider.value = x * 10.f + 0.5f; + data->slider.value = x * 100.f + 0.5f; } break; case MENUOP_SET: inputMouseGetSpeed(&x, &y); - inputMouseSetSpeed((f32)data->slider.value / 10.f, y); + inputMouseSetSpeed((f32)data->slider.value / 100.f, y); break; + case MENUOP_GETSLIDERLABEL: + sprintf(data->slider.label, "%.2f", (f32)data->slider.value / 100.f); } return 0; @@ -193,15 +195,17 @@ static MenuItemHandlerResult menuhandlerMouseSpeedY(s32 operation, struct menuit if (y < 0.f) { data->slider.value = 0; } else if (y > 10.f) { - data->slider.value = 100; + data->slider.value = 1000; } else { - data->slider.value = y * 10.f + 0.5f; + data->slider.value = y * 100.f + 0.5f; } break; case MENUOP_SET: inputMouseGetSpeed(&x, &y); - inputMouseSetSpeed(x, (f32)data->slider.value / 10.f); + inputMouseSetSpeed(x, (f32)data->slider.value / 100.f); break; + case MENUOP_GETSLIDERLABEL: + sprintf(data->slider.label, "%.2f", (f32)data->slider.value / 100.f); } return 0; @@ -214,14 +218,16 @@ static MenuItemHandlerResult menuhandlerMouseAimSpeedX(s32 operation, struct men if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx < 0.f) { data->slider.value = 0; } else if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx > 10.f) { - data->slider.value = 100; + data->slider.value = 1000; } else { - data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx * 10.f + 0.5f; + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx * 100.f + 0.5f; } break; case MENUOP_SET: - g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx = (f32)data->slider.value / 10.f; + g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedx = (f32)data->slider.value / 100.f; break; + case MENUOP_GETSLIDERLABEL: + sprintf(data->slider.label, "%.2f", (f32)data->slider.value / 100.f); } return 0; @@ -234,14 +240,16 @@ static MenuItemHandlerResult menuhandlerMouseAimSpeedY(s32 operation, struct men if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy < 0.f) { data->slider.value = 0; } else if (g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy > 10.f) { - data->slider.value = 100; + data->slider.value = 1000; } else { - data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy * 10.f + 0.5f; + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy * 100.f + 0.5f; } break; case MENUOP_SET: - g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy = (f32)data->slider.value / 10.f; + g_PlayerExtCfg[g_ExtMenuPlayer].mouseaimspeedy = (f32)data->slider.value / 100.f; break; + case MENUOP_GETSLIDERLABEL: + sprintf(data->slider.label, "%.2f", (f32)data->slider.value / 100.f); } return 0; @@ -254,14 +262,16 @@ static MenuItemHandlerResult menuhandlerRadialMenuSpeed(s32 operation, struct me if (g_PlayerExtCfg[0].radialmenuspeed < 0.f) { data->slider.value = 0; } else if (g_PlayerExtCfg[0].radialmenuspeed > 10.f) { - data->slider.value = 100; + data->slider.value = 1000; } else { - data->slider.value = g_PlayerExtCfg[0].radialmenuspeed * 10.f + 0.5f; + data->slider.value = g_PlayerExtCfg[0].radialmenuspeed * 100.f + 0.5f; } break; case MENUOP_SET: - g_PlayerExtCfg[0].radialmenuspeed = (f32)data->slider.value / 10.f; + g_PlayerExtCfg[0].radialmenuspeed = (f32)data->slider.value / 100.f; break; + case MENUOP_GETSLIDERLABEL: + sprintf(data->slider.label, "%.2f", (f32)data->slider.value / 100.f); } return 0; @@ -313,7 +323,7 @@ struct menuitem g_ExtendedMouseMenuItems[] = { 0, MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, (uintptr_t)"Mouse Speed X", - 100, + 1000, menuhandlerMouseSpeedX, }, { @@ -321,7 +331,7 @@ struct menuitem g_ExtendedMouseMenuItems[] = { 0, MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, (uintptr_t)"Mouse Speed Y", - 100, + 1000, menuhandlerMouseSpeedY, }, { @@ -329,7 +339,7 @@ struct menuitem g_ExtendedMouseMenuItems[] = { 0, MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, (uintptr_t)"Crosshair Speed X", - 100, + 1000, menuhandlerMouseAimSpeedX, }, { @@ -337,7 +347,7 @@ struct menuitem g_ExtendedMouseMenuItems[] = { 0, MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, (uintptr_t)"Crosshair Speed Y", - 100, + 1000, menuhandlerMouseAimSpeedY, }, { @@ -345,7 +355,7 @@ struct menuitem g_ExtendedMouseMenuItems[] = { 0, MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, (uintptr_t)"Radial Menu Speed", - 100, + 1000, menuhandlerRadialMenuSpeed, }, { From 903dd82ebfa175e6d045e8697020c004b1973cc9 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 8 Dec 2024 13:39:21 +0100 Subject: [PATCH 07/17] port: alternate fix for #548 --- port/src/optionsmenu.c | 2 ++ src/game/player.c | 16 ++++++++++++++++ src/include/game/player.h | 1 + 3 files changed, 19 insertions(+) diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 2b845ebe0..ae988425b 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -9,6 +9,7 @@ #include "game/mainmenu.h" #include "game/menu.h" #include "game/gamefile.h" +#include "game/player.h" #include "video.h" #include "input.h" #include "config.h" @@ -990,6 +991,7 @@ static MenuItemHandlerResult menuhandlerFieldOfView(s32 operation, struct menuit g_PlayerExtCfg[g_ExtMenuPlayer].fovy = data->slider.value; if (g_PlayerExtCfg[g_ExtMenuPlayer].fovzoom) { g_PlayerExtCfg[g_ExtMenuPlayer].fovzoommult = g_PlayerExtCfg[g_ExtMenuPlayer].fovy / 60.f; + playerClampGunZoomFovY(g_ExtMenuPlayer); } } break; diff --git a/src/game/player.c b/src/game/player.c index 8ca1fc4f5..a0983ef36 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -2103,6 +2103,22 @@ f32 playerGetCutsceneBlurFrac(void) return g_CutsceneBlurFrac; } +void playerClampGunZoomFovY(s32 playernum) +{ + struct player *player = g_Vars.players[playernum]; + if (!player) { + return; + } + + for (s32 index = 0; index < ARRAYCOUNT(player->gunzoomfovs); ++index) { + if (player->gunzoomfovs[index] < ADJUST_ZOOM_FOV(2)) { + player->gunzoomfovs[index] = ADJUST_ZOOM_FOV(2); + } else if (player->gunzoomfovs[index] > ADJUST_ZOOM_FOV(60)) { + player->gunzoomfovs[index] = ADJUST_ZOOM_FOV(60); + } + } +} + void playerSetZoomFovY(f32 fovy, f32 timemax) { g_Vars.currentplayer->zoomintime = 0; diff --git a/src/include/game/player.h b/src/include/game/player.h index 81840b813..9c7a9cf90 100644 --- a/src/include/game/player.h +++ b/src/include/game/player.h @@ -21,6 +21,7 @@ void playerStartCutscene(s16 anim_id); void playerReorientForCutsceneStop(s32 tweenduration60); void playerTickCutscene(bool arg0); f32 playerGetCutsceneBlurFrac(void); +void playerClampGunZoomFovY(s32 playernum); void playerSetZoomFovY(f32 fovy, f32 timemax); f32 playerGetZoomFovY(void); void playerTweenFovY(f32 targetfovy); From c43f550a7ef6170ea23fb8abb4372e14e1ac3912 Mon Sep 17 00:00:00 2001 From: Matthew Coppola Date: Mon, 9 Dec 2024 16:20:56 -0500 Subject: [PATCH 08/17] Prevent crash when copying player data --- src/game/filemgr.c | 2 +- src/include/game/filemgr.h | 2 +- src/include/types.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/filemgr.c b/src/game/filemgr.c index ab0e15ef9..e82d7af15 100644 --- a/src/game/filemgr.c +++ b/src/game/filemgr.c @@ -913,7 +913,7 @@ const char var7f1b31ec[] = "Multiplayer %d was using that file...\n"; * * Return true if it worked, otherwise false. */ -bool filemgrSaveOrLoad(struct fileguid *guid, s32 fileop, u32 playernum) +bool filemgrSaveOrLoad(struct fileguid *guid, s32 fileop, uintptr_t playernum) { s32 device; diff --git a/src/include/game/filemgr.h b/src/include/game/filemgr.h index 80695df9d..389299af2 100644 --- a/src/include/game/filemgr.h +++ b/src/include/game/filemgr.h @@ -25,7 +25,7 @@ void filemgrEraseCorruptFile(void); char *filemgrMenuTextInsertOriginalPak(struct menuitem *item); void filemgrRetrySave(s32 arg0); bool filemgrAttemptOperation(s32 device, bool closeonsuccess); -bool filemgrSaveOrLoad(struct fileguid *guid, s32 fileop, u32 playernum); +bool filemgrSaveOrLoad(struct fileguid *guid, s32 fileop, uintptr_t playernum); void filemgrDeleteCurrentFile(void); void func0f1097d0(s32 device); void filemgrSaveGameToDevice(s32 device); diff --git a/src/include/types.h b/src/include/types.h index da5d058b4..79f553fc9 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -3816,7 +3816,7 @@ struct menudata_filemgr { /*0xe42*/ u8 fileop; union { void *unke44; - s32 mpplayernum; + intptr_t mpplayernum; }; /*0xe48*/ u32 fileid; /*0xe4c*/ u32 deviceserial; From 615e9267d80bab86c47f66003bb8a399bb580d0e Mon Sep 17 00:00:00 2001 From: Matthew Coppola Date: Fri, 6 Dec 2024 20:23:58 -0500 Subject: [PATCH 09/17] Make mouse aim speed resolution-independent --- src/game/bondmove.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/game/bondmove.c b/src/game/bondmove.c index f82e88dee..23e774562 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -2204,8 +2204,10 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i #ifndef PLATFORM_N64 if (allowmcross) { // joystick is inactive, move crosshair using the mouse - const f32 xscale = PLAYER_EXTCFG().mouseaimspeedx * 320.f / (f32)videoGetWidth(); - const f32 yscale = PLAYER_EXTCFG().mouseaimspeedy * 240.f / (f32)videoGetHeight(); + const f32 xcoeff = 320.f / 1080.f; + const f32 ycoeff = 240.f / 1080.f; + const f32 xscale = (PLAYER_EXTCFG().mouseaimspeedx * xcoeff) / videoGetAspect(); + const f32 yscale = PLAYER_EXTCFG().mouseaimspeedy * ycoeff; f32 x = g_Vars.currentplayer->swivelpos[0] + movedata.freelookdx * xscale; f32 y = g_Vars.currentplayer->swivelpos[1] + movedata.freelookdy * yscale; x = (x < -1.f) ? -1.f : ((x > 1.f) ? 1.f : x); From a14e9ed97ef3e02b48bbd899f0e17c6161831b54 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 11 Dec 2024 14:06:44 +0100 Subject: [PATCH 10/17] port: retry creating SDL window when trying different GL versions --- port/fast3d/gfx_sdl2.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/port/fast3d/gfx_sdl2.cpp b/port/fast3d/gfx_sdl2.cpp index c6b67eebb..043a7e2f2 100644 --- a/port/fast3d/gfx_sdl2.cpp +++ b/port/fast3d/gfx_sdl2.cpp @@ -83,7 +83,6 @@ static void gfx_sdl_init(const struct GfxWindowInitSettings *set) { SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); if (sysArgCheck("--debug-gl")) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); } @@ -100,7 +99,8 @@ static void gfx_sdl_init(const struct GfxWindowInitSettings *set) { fullscreen_flag = SDL_WINDOW_FULLSCREEN; } - Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL; + // we will unhide the window once the GL context is successfully created + Uint32 flags = SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL; // if fullscreen was requested, start the window in fullscreen right away if (set->fullscreen) { @@ -119,11 +119,6 @@ static void gfx_sdl_init(const struct GfxWindowInitSettings *set) { } #endif - wnd = SDL_CreateWindow(set->title, posX, posY, window_width, window_height, flags); - if (!wnd) { - sysFatalError("Could not open SDL window:\n%s", SDL_GetError()); - } - // ideally we need 3.0 compat // if that doesn't work, try 3.2 core in case we're on mac, 2.1 compat as a last resort static u32 glver[][3] = { @@ -152,32 +147,42 @@ static void gfx_sdl_init(const struct GfxWindowInitSettings *set) { ctx = NULL; u32 vmin = 0, vmaj = 0, vprof = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY; const char *vprofstr = ""; - for (u32 i = verstart; i < verend; ++i) { + for (u32 i = verstart; i < verend && !ctx; ++i) { vmaj = glver[i][0]; vmin = glver[i][1]; vprof = glver[i][2]; - vprofstr = (glver[i][2] == SDL_GL_CONTEXT_PROFILE_CORE ? "core" : - (glver[i][2] == SDL_GL_CONTEXT_PROFILE_ES ? "es" : "")); + vprofstr = (vprof == SDL_GL_CONTEXT_PROFILE_CORE ? "core" : + (vprof == SDL_GL_CONTEXT_PROFILE_ES ? "es" : "")); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, vmaj); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, vmin); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, glver[i][2]); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, vprof); + + wnd = SDL_CreateWindow(set->title, posX, posY, window_width, window_height, flags); + if (!wnd) { + sysLogPrintf(LOG_WARNING, "SDL: could not open SDL window for GL%d.%d%s:\n%s", vmaj, vmin, vprofstr, SDL_GetError()); + continue; + } + ctx = SDL_GL_CreateContext(wnd); if (!ctx) { - sysLogPrintf(LOG_WARNING, "GL: could not create GL%d.%d%s context: %s", vmaj, vmin, vprofstr, SDL_GetError()); - } else { - break; + sysLogPrintf(LOG_WARNING, "SDL: could not create GL%d.%d%s context: %s", vmaj, vmin, vprofstr, SDL_GetError()); + SDL_DestroyWindow(wnd); + wnd = nullptr; } } - if (!ctx) { - sysFatalError("Could not create an OpenGL context of any supported version.\nSDL error: %s", SDL_GetError()); + if (!wnd || !ctx) { + sysFatalError("Could not open SDL window with an OpenGL context of any supported version:\n%s", SDL_GetError()); } else { - sysLogPrintf(LOG_NOTE, "GL: created GL%d.%d%s context", vmaj, vmin, vprofstr); + sysLogPrintf(LOG_NOTE, "SDL: created GL%d.%d%s context", vmaj, vmin, vprofstr); } SDL_GL_MakeCurrent(wnd, ctx); SDL_GL_SetSwapInterval(1); + SDL_ShowWindow(wnd); + qpc_freq = SDL_GetPerformanceFrequency(); } From 1e76f6af69e3a1b83dd633dcfe3bd57d184331fa Mon Sep 17 00:00:00 2001 From: fgsfds Date: Tue, 17 Dec 2024 10:44:33 +0100 Subject: [PATCH 11/17] port: actually parse allocation strings; double gfx buffer size on 64-bit --- port/src/pdmain.c | 2 ++ src/game/gfxmemory.c | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/port/src/pdmain.c b/port/src/pdmain.c index 959574d4c..58d37b192 100644 --- a/port/src/pdmain.c +++ b/port/src/pdmain.c @@ -225,6 +225,8 @@ void mainInit(void) joyInit(); joyReset(); + var8005d9b0 = rmonIsDisabled(); + g_Is4Mb = (osGetMemSize() <= 0x400000); g_VmShowStats = 0; diff --git a/src/game/gfxmemory.c b/src/game/gfxmemory.c index 79e61f9bd..be47a8fa5 100644 --- a/src/game/gfxmemory.c +++ b/src/game/gfxmemory.c @@ -36,6 +36,15 @@ * marker for the end of the second element's allocation. */ +/** + * On 64-bit platforms the Gfx struct is twice as large. +*/ +#ifdef PLATFORM_64BIT +#define GFX_SIZE_MULTIPLIER 2 +#else +#define GFX_SIZE_MULTIPLIER 1 +#endif + u8 *g_GfxBuffers[NUM_GFXTASKS + 1]; u32 var800aa58c; u8 *g_VtxBuffers[NUM_GFXTASKS + 1]; @@ -44,10 +53,10 @@ u8 g_GfxActiveBufferIndex; u32 g_GfxRequestedDisplayList; u32 g_GfxSizesByPlayerCount[] = { - 0x00010000, - 0x00018000, - 0x00020000, - 0x00028000, + 0x00010000 * GFX_SIZE_MULTIPLIER, + 0x00018000 * GFX_SIZE_MULTIPLIER, + 0x00020000 * GFX_SIZE_MULTIPLIER, + 0x00028000 * GFX_SIZE_MULTIPLIER, }; u32 g_VtxSizesByPlayerCount[] = { @@ -94,7 +103,7 @@ void gfxReset(void) // ******** Original Amount required = %dK ber buffer\n // ******** Extra Amount required = %dK ber buffer\n // ******** Total of %dK (Double Buffered)\n - g_GfxSizesByPlayerCount[PLAYERCOUNT() - 1] = gfx + gfxtra; + g_GfxSizesByPlayerCount[PLAYERCOUNT() - 1] = (gfx + gfxtra) * GFX_SIZE_MULTIPLIER; } if (argFindByPrefix(1, "-mvtx")) { From afd432444b65e81c9fd6e49f936803008d970ad8 Mon Sep 17 00:00:00 2001 From: Catherine Reprobate Date: Sun, 15 Dec 2024 14:19:22 -0800 Subject: [PATCH 12/17] add editorconfig --- .editorconfig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..d37de28e9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# Top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +# Matches all C source files +[*.c] +indent_style = tab +tab_width = 2 +charset = utf-8 +trim_trailing_whitespace = true + +# Matches all header files +[*.h] +indent_style = tab +tab_width = 2 +charset = utf-8 +trim_trailing_whitespace = true + +# Matches Makefiles +[Makefile] +indent_style = tab + +# Matches Markdown files +[*.md] +max_line_length = off +trim_trailing_whitespace = false From 701c854cedaa4190c508ab0b131b919e7ade94ad Mon Sep 17 00:00:00 2001 From: Catherine Reprobate Date: Sun, 15 Dec 2024 12:35:04 -0800 Subject: [PATCH 13/17] func0f0d5484 -> savebufferWriteData --- src/game/gamefile.c | 2 +- src/game/mplayer/mplayer.c | 4 ++-- src/game/savebuffer.c | 6 +++--- src/include/game/savebuffer.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/game/gamefile.c b/src/game/gamefile.c index 3f334ace9..e17411d6b 100644 --- a/src/game/gamefile.c +++ b/src/game/gamefile.c @@ -578,7 +578,7 @@ void gamefileGetOverview(char *arg0, char *name, u8 *stage, u8 *difficulty, u32 { struct savebuffer buffer; - func0f0d5484(&buffer, arg0, 15); + savebufferWriteData(&buffer, arg0, 15); savebufferReadString(&buffer, name, false); *stage = savebufferReadBits(&buffer, 5); diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index 4d72e22a7..df78ced21 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -3610,7 +3610,7 @@ void mpplayerfileGetOverview(char *arg0, char *name, u32 *playtime) { struct savebuffer buffer; - func0f0d5484(&buffer, arg0, 15); + savebufferWriteData(&buffer, arg0, 15); savebufferReadString(&buffer, name, 0); *playtime = savebufferReadBits(&buffer, 28); @@ -3974,7 +3974,7 @@ void mpsetupfileGetOverview(char *arg0, char *filename, u16 *numsims, u16 *stage { struct savebuffer buffer; - func0f0d5484(&buffer, arg0, 15); + savebufferWriteData(&buffer, arg0, 15); savebufferReadString(&buffer, filename, 0); diff --git a/src/game/savebuffer.c b/src/game/savebuffer.c index 48255d723..f9d4705fd 100644 --- a/src/game/savebuffer.c +++ b/src/game/savebuffer.c @@ -459,7 +459,7 @@ void savebufferClear(struct savebuffer *buffer) } } -void func0f0d5484(struct savebuffer *buffer, u8 *data, u8 len) +void savebufferWriteData(struct savebuffer *buffer, u8 *data, u8 len) { s32 i; @@ -536,7 +536,7 @@ void func0f0d564c(u8 *data, char *dst, bool addlinebreak) { struct savebuffer buffer; - func0f0d5484(&buffer, data, 10); + savebufferWriteData(&buffer, data, 10); savebufferReadString(&buffer, dst, addlinebreak); } @@ -547,7 +547,7 @@ void func0f0d5690(u8 *dst, char *src) bool done = false; s32 i; - func0f0d5484(&buffer, dst, 10); + savebufferWriteData(&buffer, dst, 10); for (i = 0; i < 10; i++) { if (!done) { diff --git a/src/include/game/savebuffer.h b/src/include/game/savebuffer.h index 3975a51c0..9529248ce 100644 --- a/src/include/game/savebuffer.h +++ b/src/include/game/savebuffer.h @@ -15,7 +15,7 @@ void savebufferOr(struct savebuffer *buffer, u32 arg1, s32 arg2); void savebufferWriteBits(struct savebuffer *buffer, u32 value, s32 numbits, u8 *dst); u32 savebufferReadBits(struct savebuffer *buffer, s32 offset); void savebufferClear(struct savebuffer *buffer); -void func0f0d5484(struct savebuffer *buffer, u8 *data, u8 len); +void savebufferWriteData(struct savebuffer *buffer, u8 *data, u8 len); void func0f0d54c4(struct savebuffer *buffer); void savebufferReadString(struct savebuffer *buffer, char *dst, bool addlinebreak); void func0f0d55a4(struct savebuffer *buffer, char *src); From 23d5a5771a149bb1b18b0ec4e33caa20c21bfdf0 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Fri, 20 Dec 2024 13:38:19 +0100 Subject: [PATCH 14/17] port: fix mouse X speed using wrong aspect in split screen --- src/game/bondmove.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/bondmove.c b/src/game/bondmove.c index 23e774562..552dd0f83 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -2206,7 +2206,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i // joystick is inactive, move crosshair using the mouse const f32 xcoeff = 320.f / 1080.f; const f32 ycoeff = 240.f / 1080.f; - const f32 xscale = (PLAYER_EXTCFG().mouseaimspeedx * xcoeff) / videoGetAspect(); + const f32 xscale = (PLAYER_EXTCFG().mouseaimspeedx * xcoeff) / g_Vars.currentplayer->aspect; const f32 yscale = PLAYER_EXTCFG().mouseaimspeedy * ycoeff; f32 x = g_Vars.currentplayer->swivelpos[0] + movedata.freelookdx * xscale; f32 y = g_Vars.currentplayer->swivelpos[1] + movedata.freelookdy * yscale; From 721b9b004efb3e5d0a4bbf6a567b376ba6d7fea8 Mon Sep 17 00:00:00 2001 From: Matthew Coppola Date: Sat, 21 Dec 2024 05:02:14 -0500 Subject: [PATCH 15/17] Allow skipping credits for the port --- src/game/credits.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/game/credits.c b/src/game/credits.c index e47cca554..f95fbdf96 100644 --- a/src/game/credits.c +++ b/src/game/credits.c @@ -24,6 +24,9 @@ #include "lib/vi.h" #include "data.h" #include "types.h" +#ifndef PLATFORM_N64 +#include "input.h" +#endif /** * Credits @@ -1876,11 +1879,22 @@ Gfx *creditsDraw(Gfx *gdl) } } - // Exit the alternative title if a button is pressed (other than L or R) +#ifdef PLATFORM_N64 #if VERSION >= VERSION_NTSC_1_0 + // Exit the alternative title if a button is pressed (other than L or R) if (g_CreditsUsingAltTitle && joyGetButtonsPressedThisFrame(0, 0xffcf)) #else if (g_CreditsUsingAltTitle && joyGetButtons(0, 0xffff)) +#endif +#else +#if VERSION >= VERSION_NTSC_1_0 + // Exit to CI if a button is pressed (other than L or R), for the port + if (joyGetButtonsPressedThisFrame(0, 0xffcf) || + inputKeyJustPressed(VK_ESCAPE)) +#else + if (joyGetButtons(0, 0xffff) || + inputKeyJustPressed(VK_ESCAPE)) +#endif #endif { g_TitleNextStage = STAGE_CITRAINING; From 7f105f1dcb844a645387b02d2af07a473a26ec8f Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 29 Dec 2024 13:56:44 +0100 Subject: [PATCH 16/17] port: on ARM, only enable DO_YIELD() if ARMv7 or ARM64 --- port/src/system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/src/system.c b/port/src/system.c index 60d94f592..0f0cdc218 100644 --- a/port/src/system.c +++ b/port/src/system.c @@ -40,7 +40,7 @@ __attribute__((dllexport)) u32 AmdPowerXpressRequestHighPerformance = 1; // but if it doesn't we'll have to use __builtin_ia32_pause() or something #include #define DO_YIELD() _mm_pause() -#elif defined(PLATFORM_ARM) +#elif defined(PLATFORM_ARM) && (defined(PLATFORM_64BIT) || PLATFORM_ARM == 7 || PLATFORM_ARM == 8) // same as YieldProcessor() on ARM Windows #define DO_YIELD() __asm__ volatile("dmb ishst\n\tyield":::"memory") #else From 0443c708ddf70d5e44dd97493afab3b143e92af4 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 29 Dec 2024 14:47:42 +0100 Subject: [PATCH 17/17] port: align size of bg light block to 4 this avoids unaligned accesses on ARM --- port/src/preprocess/filebg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/src/preprocess/filebg.c b/port/src/preprocess/filebg.c index 6ff407310..56b750e4a 100644 --- a/port/src/preprocess/filebg.c +++ b/port/src/preprocess/filebg.c @@ -224,7 +224,7 @@ static void convertPrimaryLights(u8 *dst, u32 *dstpos, u8 *src, u32 *srcpos, u32 } *srcpos += sizeof(*n64_lights) * num_lights; - *dstpos += sizeof(*host_lights) * num_lights; + *dstpos += ALIGN(sizeof(*host_lights) * num_lights, 4); } #define BLOCK_LEAF 0