From 2398e60e89609ee35e45840a5435fc9f9df6b2ae Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 14 Aug 2024 14:10:16 +0200 Subject: [PATCH 1/7] fix director lol --- src/k_director.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/k_director.c b/src/k_director.c index fdf636d46..a39e88292 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -37,12 +37,12 @@ struct directorinfo INT32 boredom[MAXPLAYERS]; // how long has a given position had no credible attackers? } directorinfo; -static boolean race_rules(void) +static inline boolean race_rules(void) { - return gametype = GT_RACE; + return gametype == GT_RACE; } -static fixed_t P_ScaleFromMap(fixed_t n, fixed_t scale) +static fixed_t ScaleFromMap(fixed_t n, fixed_t scale) { return FixedMul(n, FixedDiv(scale, mapobjectscale)); } @@ -90,7 +90,7 @@ static fixed_t K_GetDistanceToFinish(player_t player) break; } } - else + else // crappy optimization weeeee { for (mo = waypointcap; mo != NULL; mo = mo->tracer) { @@ -155,7 +155,7 @@ static void K_UpdateDirectorPositions(void) continue; } - directorinfo.gap[position] = P_ScaleFromMap(K_GetFinishGap(directorinfo.sortedplayers[position], directorinfo.sortedplayers[position + 1]), FRACUNIT); + directorinfo.gap[position] = ScaleFromMap(K_GetFinishGap(directorinfo.sortedplayers[position], directorinfo.sortedplayers[position + 1]), FRACUNIT); if (directorinfo.gap[position] >= BREAKAWAYDIST) { @@ -173,7 +173,7 @@ static void K_UpdateDirectorPositions(void) return; } - directorinfo.maxdist = P_ScaleFromMap(K_GetDistanceToFinish(players[directorinfo.sortedplayers[0]]), FRACUNIT); + directorinfo.maxdist = ScaleFromMap(K_GetDistanceToFinish(players[directorinfo.sortedplayers[0]]), FRACUNIT); } static boolean K_CanSwitchDirector(void) From 5bdf8698bd85bb7bee204232a5bc0d941d04e3d0 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 14 Aug 2024 14:44:22 +0200 Subject: [PATCH 2/7] completely disable director in splitscreen will eventually get to splitscreen support lul --- src/k_director.c | 7 ++++++- src/st_stuff.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/k_director.c b/src/k_director.c index a39e88292..001e553ad 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -49,7 +49,7 @@ static fixed_t ScaleFromMap(fixed_t n, fixed_t scale) static boolean K_DirectorIsEnabled(void) { - return cv_director.value && (gamestate == GS_LEVEL && (!playeringame[consoleplayer] || players[consoleplayer].spectator || demo.playback)); + return cv_director.value && (gamestate == GS_LEVEL && (!playeringame[consoleplayer] || players[consoleplayer].spectator || demo.playback)) && !splitscreen; } void K_InitDirector(void) @@ -188,6 +188,11 @@ static boolean K_CanSwitchDirector(void) static void K_DirectorSwitch(INT32 player, boolean force) { + if (!K_DirectorIsEnabled()) + { + return; + } + if (P_IsDisplayPlayer(&players[player])) { return; diff --git a/src/st_stuff.c b/src/st_stuff.c index df4ba7db9..afbf74b8f 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -662,7 +662,7 @@ static void ST_overlayDrawer(void) // Countdown timer for Race Mode // ...moved to k_kart.c so we can take advantage of the LAPS_Y value - if (demo.playback || !P_IsLocalPlayer(stplyr)) + if ((demo.playback || !P_IsLocalPlayer(stplyr)) && !splitscreen) { char directortext[20] = {0}; From 94714fe57141691b0e28d7c44939ed9a49f17e62 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 14 Aug 2024 16:08:29 +0300 Subject: [PATCH 3/7] Fix increasing number of viewpoints in replays by more than 1 (like pressing '3' with only one viewpoint) crashing game --- src/g_game.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/g_game.c b/src/g_game.c index bc2937838..743fa52d5 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2130,6 +2130,7 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) { for (viewd = splits+1; viewd < viewnum; ++viewd) { + displayplayers[viewd-1] = G_FindView(displayplayers[viewd-1], viewd, onlyactive, playernum < olddisplayplayer); G_FixCamera(viewd); } } From 35f54822be55854e6b0b73b5eaa1a3228bbef99b Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 15 Aug 2024 16:38:05 +0200 Subject: [PATCH 4/7] smol cleanup HWR_RenderPlane --- src/hardware/hw_main.c | 43 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ba8d8cef1..ed2c1b0ef 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -667,31 +667,33 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta) // Render a floor or ceiling convex polygon void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap) { - polyvertex_t * pv; - float height; //constant y for all points on the convex flat polygon - FOutVector *v3d; - INT32 nrPlaneVerts; //verts original define of convex flat polygon - INT32 i; - float flatxref,flatyref; - float fflatsize; - INT32 flatflag; + FSurfaceInfo Surf; + FOutVector *v3d; + polyvertex_t *pv; + pslope_t *slope = NULL; + INT32 shader = SHADER_NONE; + + size_t nrPlaneVerts; + INT32 i; + + float height; // constant y for all points on the convex flat polygon + float flatxref, flatyref = 0.0f; + float fflatsize = 64.0f; + INT32 flatflag = 63; size_t len; + + float tempxsow, tempytow; float scrollx = 0.0f, scrolly = 0.0f; angle_t angle = 0; - FSurfaceInfo Surf; - fixed_t tempxsow, tempytow; - pslope_t *slope = NULL; static FOutVector *planeVerts = NULL; static UINT16 numAllocedPlaneVerts = 0; - - INT32 shader = SHADER_NONE; // no convex poly were generated for this subsector if (!xsub->planepoly) return; - pv = xsub->planepoly->pts; + pv = xsub->planepoly->pts; nrPlaneVerts = xsub->planepoly->numpts; if (nrPlaneVerts < 3) //not even a triangle ? @@ -800,12 +802,6 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc { angle = InvAngle(angle)>>ANGLETOFINESHIFT; - // This needs to be done so that it scrolls in a different direction after rotation like software - /*tempxsow = FLOAT_TO_FIXED(scrollx); - tempytow = FLOAT_TO_FIXED(scrolly); - scrollx = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - scrolly = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));*/ - // This needs to be done so everything aligns after rotation // It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does tempxsow = FLOAT_TO_FIXED(flatxref); @@ -838,7 +834,7 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc vert->y = FIXED_TO_FLOAT(fixedheight);\ }\ } - for (i = 0, v3d = planeVerts; i < nrPlaneVerts; i++,v3d++,pv++) + for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++,pv++) SETUP3DVERT(v3d, pv->x, pv->y); if (slope) @@ -949,7 +945,7 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc vx = (horizonpts[3].x - gr_viewx) * farrenderdist / renderdist + gr_viewx; vy = (horizonpts[3].z - gr_viewy) * farrenderdist / renderdist + gr_viewy; SETUP3DVERT((&horizonpts[4]), vx, vy); - horizonpts[4].y = gr_viewz; + horizonpts[4].y = gr_viewz; // Draw HWR_ProcessPolygon(&Surf, horizonpts, 6, PolyFlags, shader, true); @@ -1325,7 +1321,7 @@ static void HWR_DrawSkyWallList(void) // Draw walls into the depth buffer so that anything behind is culled properly void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf) { - //HWD.pfnSetTexture(NULL); + //HWR_SetCurrentTexture(NULL); // no texture wallVerts[3].t = wallVerts[2].t = 0; wallVerts[0].t = wallVerts[1].t = 0; @@ -1569,7 +1565,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom HWR_DrawSkyWall(wallVerts, &Surf); } - // Sky Floors wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(INT32_MIN); From 808f7baf536b0128f763e451c52a2c8bbd7d3334 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 15 Aug 2024 13:41:20 +0200 Subject: [PATCH 5/7] move this in coindition --- src/k_director.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_director.c b/src/k_director.c index 001e553ad..a0cb6f961 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -49,7 +49,7 @@ static fixed_t ScaleFromMap(fixed_t n, fixed_t scale) static boolean K_DirectorIsEnabled(void) { - return cv_director.value && (gamestate == GS_LEVEL && (!playeringame[consoleplayer] || players[consoleplayer].spectator || demo.playback)) && !splitscreen; + return cv_director.value && !splitscreen && (gamestate == GS_LEVEL && (!playeringame[consoleplayer] || players[consoleplayer].spectator || demo.playback)); } void K_InitDirector(void) From 5393ac526ab6e03af4453d51f5427e962ed72838 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 15 Aug 2024 15:19:11 +0200 Subject: [PATCH 6/7] move this in hw_main --- src/hardware/hw_cache.c | 1 - src/hardware/hw_main.c | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 98034970d..c079f2110 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -573,7 +573,6 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) // If hardware does not have the texture, then call pfnSetTexture to upload it if (!grtex->mipmap.downloaded) HWD.pfnSetTexture(&grtex->mipmap); - HWR_SetCurrentTexture(&grtex->mipmap); // The system-memory data can be purged now. diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ed2c1b0ef..821233dc8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5548,16 +5548,14 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe HWD.pfnSetTransform(&atransform); validcount++; - - if (cv_grbatching.value) - HWR_StartBatching(); - - HWR_AddPrecipitationSprites(); ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; PS_START_TIMING(ps_bsptime); + if (cv_grbatching.value) + HWR_StartBatching(); + if (!rootportal && portallist.base && !skybox)// if portals have been drawn in the main view, then render skywalls differently gr_collect_skywalls = true; @@ -5567,11 +5565,15 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe if (gr_portal != GRPORTAL_OFF) // if we already haven't hit the recursion limit or we already ended our portal shenanigans gr_portal = GRPORTAL_INSIDE; // TURN IT OFF + // Recursively "render" the BSP tree. HWR_RenderBSPNode((INT32)numnodes-1); + // woo we back gr_portal = oldgl_portal_state; + HWR_AddPrecipitationSprites(); + PS_STOP_TIMING(ps_bsptime); if (cv_grbatching.value) From e100fff23025ea9cac1092f05a9994fa85a75744 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 15 Aug 2024 15:47:10 +0200 Subject: [PATCH 7/7] check for changed state before everything else --- src/hardware/hw_batching.c | 54 ++++++++++++++++++++------------------ src/hardware/hw_batching.h | 2 +- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 7dde8b3bd..a4984a905 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -424,38 +424,40 @@ void HWR_RenderBatches(void) if (stopFlag) break; // change state according to change bools and next vars, update current vars and reset bools - if (changeShader) + if (changeState) { - HWD.pfnSetShader(nextShader); - currentShader = nextShader; - changeShader = false; + if (changeShader) + { + HWD.pfnSetShader(nextShader); + currentShader = nextShader; + changeShader = false; - ps_hw_numshaders.value.i++; - } - if (changeTexture) - { - // texture should be already ready for use from calls to SetTexture during batch collection - HWD.pfnSetTexture(nextTexture); - currentTexture = nextTexture; - changeTexture = false; + ps_hw_numshaders.value.i++; + } + if (changeTexture) + { + // texture should be already ready for use from calls to SetTexture during batch collection + HWD.pfnSetTexture(nextTexture); + currentTexture = nextTexture; + changeTexture = false; - ps_hw_numtextures.value.i++; - } - if (changePolyFlags) - { - currentPolyFlags = nextPolyFlags; - changePolyFlags = false; + ps_hw_numtextures.value.i++; + } + if (changePolyFlags) + { + currentPolyFlags = nextPolyFlags; + changePolyFlags = false; - ps_hw_numpolyflags.value.i++; - } - if (changeSurfaceInfo) - { - currentSurfaceInfo = nextSurfaceInfo; - changeSurfaceInfo = false; + ps_hw_numpolyflags.value.i++; + } + if (changeSurfaceInfo) + { + currentSurfaceInfo = nextSurfaceInfo; + changeSurfaceInfo = false; - ps_hw_numcolors.value.i++; + ps_hw_numcolors.value.i++; + } } - // and that should be it? } // reset the arrays (set sizes to 0) polygonArraySize = 0; diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 7c108a4bd..22a4cc4c0 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -17,7 +17,7 @@ #include "hw_data.h" #include "hw_drv.h" -typedef struct +typedef struct { FSurfaceInfo surf;// surf also has its own polyflags for some reason, but it seems unused unsigned int vertsIndex;// location of verts in unsortedVertexArray