From 23c7aaeff2e528e13cb8fcac3af6f683f1671dbb Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Thu, 21 Dec 2023 10:55:40 +0800 Subject: [PATCH 01/11] Some hardware renderer cleanup GRAH WARNINGS --- src/hardware/hw_main.c | 346 +++++++---------------------------------- 1 file changed, 53 insertions(+), 293 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f0fab7fe5..b760c2a6f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -273,20 +273,24 @@ static fixed_t dup_viewx, dup_viewy, dup_viewz; static angle_t gr_aimingangle; static float gr_viewludsin, gr_viewludcos; -// -// PORTALS -// +// ========================================================================== +// Visual portals (attr. Hannu Hanhi) +// ========================================================================== -#define MAX_GRPORTALS 13 -// Note: portal sorting has not been ported to this -//#define PORTALSORTING // Breaks recursive portals :[ - - -// for porting gonna add stuff from r_portal here with adjustments - -typedef struct portal_s +enum { - struct portal_s *next; + GRPORTAL_OFF, + GRPORTAL_SEARCH, + GRPORTAL_STENCIL, + GRPORTAL_DEPTH, + GRPORTAL_INSIDE, +}; + +static int gr_portal = GRPORTAL_OFF; +static boolean gl_drawing_stencil = false; +typedef struct gl_portal_s +{ + struct gl_portal_s *next; // Viewport. fixed_t viewx; @@ -300,36 +304,38 @@ typedef struct portal_s INT32 drawcount; /**< For OpenGL. */ seg_t *seg; -} portal_t; +} gl_portal_t; -typedef struct portallist_s +typedef struct gl_portallist_s { - portal_t *base; - portal_t *cap; -} portallist_t; + gl_portal_t *base; + gl_portal_t *cap; +} gl_portallist_t; // new thing -portallist_t *currentportallist; +gl_portallist_t *currentportallist; INT32 portalviewside; // Linked list for portals. -portal_t *portal_base_gl, *portal_cap_gl; +gl_portal_t *portal_base_gl, *portal_cap_gl; +/* For now, these aren't used. // maybe at some point these could be organized better -void HWR_Portal_InitList (void) +static void HWR_Portal_InitList (void) { portalrender = 0; portal_base_gl = portal_cap_gl = NULL; } -void HWR_Portal_Remove (portal_t* portal) +static void HWR_Portal_Remove(gl_portal_t* portal) { portal_base_gl = portal->next; Z_Free(portal); } +*/ -void HWR_Portal_Add2Lines (const INT32 line1, const INT32 line2, seg_t *seg) +static void HWR_Portal_Add2Lines(const INT32 line1, const INT32 line2, seg_t *seg) { line_t *start, *dest; @@ -340,17 +346,9 @@ void HWR_Portal_Add2Lines (const INT32 line1, const INT32 line2, seg_t *seg) vertex_t dest_c, start_c; - portal_t *portal; + gl_portal_t *portal; - // check for duplicate - /*if (currentportallist->base && currentportallist->cap->startline == line1 && currentportallist->cap->clipline == line2) - { - if (printportals) - CONS_Printf("Duplicate portal skipped\n"); - return; - }*/ - - portal = Z_Malloc(sizeof(portal_t), PU_STATIC, NULL); + portal = Z_Malloc(sizeof(gl_portal_t), PU_STATIC, NULL); // Linked list. if (!currentportallist->base) @@ -404,7 +402,7 @@ void HWR_Portal_Add2Lines (const INT32 line1, const INT32 line2, seg_t *seg) portal->clipline = line2; } -void HWR_PortalFrame(portal_t* portal) +static void HWR_PortalFrame(gl_portal_t* portal) { viewx = portal->viewx; viewy = portal->viewy; @@ -429,42 +427,6 @@ void HWR_PortalFrame(portal_t* portal) } } -enum -{ - GRPORTAL_OFF, - GRPORTAL_SEARCH, - GRPORTAL_STENCIL, - GRPORTAL_DEPTH, - GRPORTAL_INSIDE, -}; - -void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, player_t *player); - -#ifdef PORTALSORTING -static portal_t gr_portals[MAX_GRPORTALS]; -static size_t gr_numportals = 0; - -static void HWR_AddPortal(portal_t *portal); -static void HWR_SortPortals(player_t *player, float fpov, INT32 viewnumber, postimg_t *ptype); -#endif - -static int gr_portal = GRPORTAL_OFF; -static boolean gl_drawing_stencil = false; - -// Culling -typedef struct -{ - seg_t *seg; - sector_t *frontsector; - sector_t *backsector; -} gr_portalcullinfo_t; - -static gr_portalcullinfo_t gr_portalsegs[MAX_GRPORTALS]; -static size_t gr_numportalsegs = 0; - -static sector_t *gr_portalcullsectors[MAX_GRPORTALS]; -static size_t gr_numportalcullsectors = 0; - // ========================================================================== // Lighting // ========================================================================== @@ -566,7 +528,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col } } -void HWR_ClearLightTableCache() +void HWR_ClearLightTableCache(void) { if (rendermode == render_opengl) HWD.pfnClearLightTableCache(); @@ -1427,12 +1389,12 @@ int skyWallVertexArrayAllocSize = 65536;// what a mouthful boolean gr_collect_skywalls = false; -void HWR_SkyWallList_Clear() +static void HWR_SkyWallList_Clear(void) { skyWallVertexArraySize = 0; } -void HWR_SkyWallList_Add(FOutVector *wallVerts) +static void HWR_SkyWallList_Add(FOutVector *wallVerts) { if (!skyWallVertexArray) { @@ -1451,7 +1413,7 @@ void HWR_SkyWallList_Add(FOutVector *wallVerts) skyWallVertexArraySize++; } -void HWR_DrawSkyWallList() +static void HWR_DrawSkyWallList(void) { int i; FSurfaceInfo surf; @@ -1491,68 +1453,6 @@ void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf) // PF_Occlude is set in HWR_ProjectWall to draw into the depth buffer } -// HWR_DrawPortalClipWall -// Draws an invisible wall that extends to nowhere, -// so that portals can be clipped correctly. -static void HWR_DrawPortalClipWall(line_t *line) -{ - FOutVector wallVerts[4]; - FSurfaceInfo Surf; - v2d_t vs, ve; - fixed_t length = 1000*FRACUNIT; - fixed_t temp = 0; - - angle_t angle = R_PointToAngle2(line->v1->x, line->v1->y, line->v2->x, line->v2->y); - angle_t lineangle = 0; - - // no texture - HWD.pfnSetTexture(NULL); - wallVerts[3].t = wallVerts[2].t = 0; - wallVerts[0].t = wallVerts[1].t = 0; - wallVerts[0].s = wallVerts[3].s = 0; - wallVerts[2].s = wallVerts[1].s = 0; - - //wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f; whatever this is i guess it cant be here - wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(INT32_MIN); - wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(INT32_MAX); - - // first - vs.x = FIXED_TO_FLOAT(line->v1->x); - vs.y = FIXED_TO_FLOAT(line->v1->y); - - angle -= ANGLE_180; - lineangle = (angle >> ANGLETOFINESHIFT); - temp = FixedMul(length, FINECOSINE(lineangle)); - ve.x = vs.x + FIXED_TO_FLOAT(temp); - temp = FixedMul(length, FINESINE(lineangle)); - ve.y = vs.y + FIXED_TO_FLOAT(temp); - - wallVerts[0].x = wallVerts[3].x = ve.x; - wallVerts[0].z = wallVerts[3].z = ve.y; - wallVerts[2].x = wallVerts[1].x = vs.x; - wallVerts[2].z = wallVerts[1].z = vs.y; - - HWR_ProjectWall(wallVerts, &Surf, PF_NoTexture, 255, NULL); - - // second - vs.x = FIXED_TO_FLOAT(line->v2->x); - vs.y = FIXED_TO_FLOAT(line->v2->y); - - angle += ANGLE_180; - lineangle = (angle >> ANGLETOFINESHIFT); - temp = FixedMul(length, FINECOSINE(lineangle)); - ve.x = vs.x + FIXED_TO_FLOAT(temp); - temp = FixedMul(length, FINESINE(lineangle)); - ve.y = vs.y + FIXED_TO_FLOAT(temp); - - wallVerts[0].x = wallVerts[3].x = ve.x; - wallVerts[0].z = wallVerts[3].z = ve.y; - wallVerts[2].x = wallVerts[1].x = vs.x; - wallVerts[2].z = wallVerts[1].z = vs.y; - - HWR_ProjectWall(wallVerts, &Surf, PF_NoTexture, 255, NULL); -} - // // HWR_ProcessSeg // A portion or all of a wall segment will be drawn, from startfrac to endfrac, @@ -2879,15 +2779,7 @@ static boolean CheckClip(sector_t * afrontsector, sector_t * abacksector) viewc1 = backc1; viewc2 = backc2; } -/* - // dont clip viewsector when rendering portal contents - if (portalclipline) - { - if (printportals) - CONS_Printf("Clipping skipped on portal viewsector\n"); - return false; - } -*/ + // check if camera is outside the bounds of the floor and the ceiling (noclipping) // either above the ceiling or below the floor if ((viewz > viewc1 && viewz > viewc2) || (viewz < viewf1 && viewz < viewf2)) @@ -3002,20 +2894,7 @@ void HWR_AddLine(seg_t *line) { vertex_t closest_point; boolean pass = false; - /* - if (P_PointOnLineSide(line->v1->x, line->v1->y, portalclipline) != portalviewside) - { - P_ClosestPointOnLine(line->v1->x, line->v1->y, portalclipline, &closest_point); - if (closest_point.x != line->v1->x || closest_point.y != line->v1->y) - pass = true; - } - if (!pass && P_PointOnLineSide(line->v2->x, line->v2->y, portalclipline) != portalviewside) - { - P_ClosestPointOnLine(line->v2->x, line->v2->y, portalclipline, &closest_point); - if (closest_point.x != line->v2->x || closest_point.y != line->v2->y) - pass = true; - } - */ + // similar idea than in PortalCheckBBox, but checking the line vertices instead // TODO could make the check more efficient and not check anything if pass==true from earlier or something P_ClosestPointOnLine(line->v1->x, line->v1->y, portalclipline, &closest_point); @@ -3029,19 +2908,7 @@ void HWR_AddLine(seg_t *line) { if (P_PointOnLineSide(line->v2->x, line->v2->y, portalclipline) != portalviewside) pass = true; - }/* - P_ClosestPointOnLine(v1x, v1y, portalclipline, &closest_point); - if (closest_point.x != v1x || closest_point.y != v1y) - { - if (P_PointOnLineSide(v1x, v1y, portalclipline) != portalviewside) - pass = true; } - P_ClosestPointOnLine(v2x, v2y, portalclipline, &closest_point); - if (closest_point.x != v2x || closest_point.y != v2y) - { - if (P_PointOnLineSide(v2x, v2y, portalclipline) != portalviewside) - pass = true; - }*/ if (!pass) return; } @@ -3064,83 +2931,6 @@ void HWR_AddLine(seg_t *line) gr_backsector = line->backsector; - // Portal line -/* - if (cv_grportals.value && line->linedef->special == 40 && line->side == 0) - { - if (portalrender < cv_maxportals.value) - { - // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); - if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); - if (line2 >= 0) // found it! - { - // oh no :DD - if (gr_portal == GRPORTAL_PROCESS) - { - gr_portal = GRPORTAL_FOUND; - return; - } - - // Portal processing - if ((gr_portal == GRPORTAL_MASKING) || (gr_portal == GRPORTAL_INSIDE)) - { - // masking the view 1 - if (gr_portal == GRPORTAL_MASKING) - { - size_t numportal = gr_numportalsegs; - if (numportal < MAX_GRPORTALS) - { - gr_portalsegs[numportal].seg = line; - gr_portalsegs[numportal].frontsector = gr_frontsector; - gr_portalsegs[numportal].backsector = gr_backsector; - gr_numportalsegs++; - } - } - - // Add the portal - HWR_Portal_Add2Lines(line->linedef-lines, line2); - - // masking the view 2 - if (gr_portal == GRPORTAL_MASKING) - { - // portal_cap_gl = last added portal - portal_t *lastportal = portal_cap_gl; - lastportal->drawcount = drawcount++; - - // extend clipping - HWR_DrawPortalClipWall(line->linedef); - - // add cull sector - if (gr_numportalcullsectors < MAX_GRPORTALS) - { - sector_t *cullsec = NULL; - if (lastportal->clipline != -1) - { - line_t *grclipline = &lines[lastportal->clipline]; - cullsec = grclipline->frontsector; - } - gr_portalcullsectors[gr_numportalcullsectors] = cullsec; - gr_numportalcullsectors++; - } - } - } - - gld_clipper_SafeAddClipRange(angle2, angle1); - - if (gr_portal != GRPORTAL_OUTSIDE) - return; - } - } - // Recursed TOO FAR (viewing a portal within a portal) - // So uhhh, render it as a normal wall instead or something ??? - } -#ifndef PORTALSORTING - else if (gr_portal == GRPORTAL_MASKING) - return; -#endif -*/ if (line->linedef->special == 40) { if (line->side == 0) @@ -3947,7 +3737,7 @@ skip_stuff_for_portals: // use returned value as multiplier for the added values from p_thrust thing // P_InterceptVector needs divlines which need dx and dy, dx=x2-x1 dy=y2-y1 -boolean HWR_PortalCheckBBox(fixed_t *bspcoord) +static boolean HWR_PortalCheckBBox(fixed_t *bspcoord) { vertex_t closest_point; if (!portalclipline) @@ -4020,10 +3810,6 @@ void HWR_RenderBSPNode(INT32 bspnum) return; } - // in portal checking phase we can stop after one is found - //if (gr_portal == GRPORTAL_FOUND) - // return; - // Decide which side the view point is on. side = R_PointOnSide(viewx, viewy, bsp); @@ -4031,10 +3817,6 @@ void HWR_RenderBSPNode(INT32 bspnum) if (HWR_PortalCheckBBox(bsp->bbox[side])) HWR_RenderBSPNode(bsp->children[side]); - // in portal checking phase we can stop after one is found - //if (gr_portal == GRPORTAL_FOUND) - // return; - // Possibly divide back space. if (HWR_CheckBBox(bsp->bbox[side^1]) && HWR_PortalCheckBBox(bsp->bbox[side^1])) HWR_RenderBSPNode(bsp->children[side^1]); @@ -5518,7 +5300,6 @@ void HWR_ProjectSprite(mobj_t *thing) angle_t ang; const boolean papersprite = (thing->frame & FF_PAPERSPRITE); INT32 heightsec, phs; - vector3_t pos; fixed_t spr_width, spr_height; fixed_t spr_offset, spr_topoffset; @@ -6142,7 +5923,7 @@ void HWR_ClearClipper(void) } // Adds an entry to the clipper for portal rendering -void HWR_PortalClipping(portal_t *portal) +static void HWR_PortalClipping(gl_portal_t *portal) { angle_t angle1, angle2; @@ -6158,11 +5939,11 @@ void HWR_PortalClipping(portal_t *portal) // // Render portals recursively depth first. With portals disabled only current scene is rendered. // -void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) +static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) { - portallist_t portallist; - portal_t *portal; - portal_t *portal_temp; + gl_portallist_t portallist; + gl_portal_t *portal; + gl_portal_t *gl_portal_temp; portallist.base = portallist.cap = NULL; const boolean skybox = (skyboxmo[0] && cv_skybox.value); @@ -6205,8 +5986,8 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * } // go to portal frame HWR_PortalFrame(portal); - // call RecursivePortalRendering - RecursivePortalRendering(portal, fpov, player, stencil_level + 1, true); + // call HWR_RenderViewpoint + HWR_RenderViewpoint(portal, fpov, player, stencil_level + 1, true); // return to current frame if (rootportal) HWR_PortalFrame(rootportal); @@ -6282,14 +6063,14 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * // HAYA: Save the old portal state, and turn portals off while normally rendering the BSP tree. // This fixes specific effects not working, such as horizon lines. - int oldportal_state = gr_portal; + int oldgl_portal_state = gr_portal; 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 = oldportal_state; + gr_portal = oldgl_portal_state; PS_STOP_TIMING(ps_bsptime); @@ -6330,12 +6111,12 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * HWR_RenderDrawNodes(); } // free memory from portal list allocated by calls to Add2Lines - portal_temp = portallist.base; - while (portal_temp) + gl_portal_temp = portallist.base; + while (gl_portal_temp) { - portal_t *nextportal = portal_temp->next; - Z_Free(portal_temp); - portal_temp = nextportal; + gl_portal_t *nextportal = gl_portal_temp->next; + Z_Free(gl_portal_temp); + gl_portal_temp = nextportal; } // TODO: batching at some point @@ -6348,7 +6129,6 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * // ========================================================================== void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) { - angle_t a1; const float fpov = FIXED_TO_FLOAT(cv_fov.value+player->fovadd); postimg_t *postprocessor = &postimgtype[0]; INT32 i; @@ -6466,7 +6246,7 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) validcount++; portalclipline = NULL; - RecursivePortalRendering(NULL, fpov, player, 0, !skybox); + HWR_RenderViewpoint(NULL, fpov, player, 0, !skybox); HWR_SetTransform(fpov, player);// not sure if needed // Unset transform and shader @@ -6485,26 +6265,6 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) HWD.pfnGClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); } -void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, player_t *player) -{ - portalrender = portal->pass; // Recursiveness depth. - - // Apply the viewpoint stored for the portal. - HWR_PortalFrame(portal); - HWR_ClearClipper(); - HWR_ClearSprites(); - HWR_SetTransform(fpov, player); - validcount++; - - // Render the BSP from the new viewpoint. - portalcullsector = gr_portalcullsectors[portalnum]; - HWR_RenderBSPNode((INT32)numnodes - 1); - - HWR_SortVisSprites(); - HWR_DrawSprites(); - HWR_RenderDrawNodes(); -} - // ========================================================================== // Render the player view. // ========================================================================== From c7c645de00a838c35798790f08c15193f77c91e6 Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Thu, 21 Dec 2023 14:52:12 +0800 Subject: [PATCH 02/11] Portal code cleanup --- src/hardware/hw_main.c | 149 +++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 71 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b760c2a6f..439d08b9c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5936,9 +5936,79 @@ static void HWR_PortalClipping(gl_portal_t *portal) gld_clipper_SafeAddClipRange(angle2, angle1); } -// -// Render portals recursively depth first. With portals disabled only current scene is rendered. -// +enum +{ + HWR_STENCIL_NORMAL, + HWR_STENCIL_BEGIN, + HWR_STENCIL_REVERSE, + HWR_STENCIL_DEPTH, + HWR_STENCIL_SKY +}; + +// Changes the current stencil state. +static void HWR_SetStencilState(int state, int level) +{ + if (!cv_nostencil.value && level > -1) + HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, level); + HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, state); +} + +// Renders a portal segment. +static void HWR_RenderPortalSeg(gl_portal_t* portal, int state) +{ + gl_drawing_stencil = true; // do not draw outside of the stencil buffer, idiot. + // set our portal state and prepare to render the seg + gr_portal = state; + gr_curline = portal->seg; + gr_frontsector = portal->seg->frontsector; + gr_backsector = portal->seg->backsector; + HWR_ProcessSeg(); + gl_drawing_stencil = false; + // need to work around the r_opengl PF_Invisible bug with this call + // similarly as in the linkdraw hack in HWR_DrawSprites + HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); +} + +// Renders the current viewpoint, though takes portal arguments for recursive portals. +static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals); + +// Renders a single portal from the current viewpoint. +static void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, player_t *player, int stencil_level) +{ + // draw portal seg to stencil buffer with increment + HWR_SetTransform(fpov, player); + HWR_ClearClipper(); + + HWR_SetStencilState(HWR_STENCIL_BEGIN, stencil_level); + HWR_RenderPortalSeg(portal, GRPORTAL_STENCIL); + + // go to portal frame lmao + HWR_PortalFrame(portal); + // call HWR_RenderViewpoint + HWR_RenderViewpoint(portal, fpov, player, stencil_level + 1, true); + // return to current frame + if (rootportal) + HWR_PortalFrame(rootportal); + else // current frame is not a portal frame but the main view! + { + R_SetupFrame(player, false); + portalclipline = NULL; + } + + // remove portal seg from stencil buffer + HWR_SetTransform(fpov, player); + HWR_ClearClipper(); + + HWR_SetStencilState(HWR_STENCIL_REVERSE, stencil_level); + HWR_RenderPortalSeg(portal, GRPORTAL_STENCIL); + + // draw portal seg to depth buffer + HWR_ClearClipper(); + HWR_SetStencilState(HWR_STENCIL_DEPTH, stencil_level); + HWR_RenderPortalSeg(portal, GRPORTAL_DEPTH); +} + +// Renders the current viewpoint, though takes portal arguments for recursive portals. static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *player, int stencil_level, boolean allow_portals) { gl_portallist_t portallist; @@ -5967,75 +6037,14 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe { if (cv_portalline.value && cv_portalline.value != portal->startline) continue; - if (!cv_nostencil.value) - { - // draw portal seg to stencil buffer with increment - HWR_SetTransform(fpov, player); - HWR_ClearClipper(); - gl_drawing_stencil = true; - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, stencil_level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_STENCIL_SEGS); - gr_portal = GRPORTAL_STENCIL; - gr_frontsector = portal->seg->frontsector; - validcount++; - HWR_AddLine(portal->seg); - gl_drawing_stencil = false; - // need to work around the r_opengl PF_Invisible bug with this call - // similarly as in the linkdraw hack in HWR_DrawSprites - HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); - } - // go to portal frame - HWR_PortalFrame(portal); - // call HWR_RenderViewpoint - HWR_RenderViewpoint(portal, fpov, player, stencil_level + 1, true); - // return to current frame - if (rootportal) - HWR_PortalFrame(rootportal); - else// current frame is not a portal frame but the main view! - { - R_SetupFrame(player, false); - portalclipline = NULL; - } - if (!cv_nostencil.value) - { - // remove portal seg from stencil buffer - HWR_SetTransform(fpov, player); - HWR_ClearClipper(); - gl_drawing_stencil = true; - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, stencil_level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_STENCIL_REVERSE_SEGS); - gr_portal = GRPORTAL_STENCIL; - gr_frontsector = portal->seg->frontsector; - validcount++; - HWR_AddLine(portal->seg); - gl_drawing_stencil = false; - // need to work around the r_opengl PF_Invisible bug with this call - // similarly as in the linkdraw hack in HWR_DrawSprites - HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); - } - // draw portal seg to depth buffer - HWR_ClearClipper(); - gl_drawing_stencil = true; - if (!cv_nostencil.value) - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, stencil_level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_DEPTH_SEGS); - gr_portal = GRPORTAL_DEPTH; - gr_frontsector = portal->seg->frontsector; - validcount++; - HWR_AddLine(portal->seg); - gl_drawing_stencil = false; - // need to work around the r_opengl PF_Invisible bug with this call - // similarly as in the linkdraw hack in HWR_DrawSprites - HWD.pfnSetBlend(PF_Translucent|PF_Occlude|PF_Masked); + HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); } gr_portal = GRPORTAL_INSIDE;// when portal walls are encountered in following bsp traversal, nothing should be drawn } else gr_portal = GRPORTAL_OFF;// there may be portals and they need to be drawn as regural walls // draw normal things in current frame in current incremented stencil buffer area - if (!cv_nostencil.value) - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, stencil_level); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_NORMAL); + HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); if (!cv_portalonly.value || rootportal) { HWR_ClearClipper(); @@ -6083,15 +6092,13 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe } if (skyWallVertexArraySize)// if there are skywalls to draw using the alternate method { - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_SKY_STENCIL_SEGS); + HWR_SetStencilState(HWR_STENCIL_SKY, -1); HWR_DrawSkyWallList(); HWR_SkyWallList_Clear(); - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, 1); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_NORMAL); + HWR_SetStencilState(HWR_STENCIL_NORMAL, 1); drewsky = false; HWR_DrawSkyBackground(fpov); - HWD.pfnSetSpecialState(HWD_SET_STENCIL_LEVEL, 0); - HWD.pfnSetSpecialState(HWD_SET_PORTAL_MODE, HWD_PORTAL_NORMAL); + HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); HWD.pfnClearBuffer(false, false, true, 0);// clear skywall markings from the stencil buffer HWR_SetTransform(fpov, player);// restore transform } From 8dcdbecf0c9937dc5e28935b25c84fbd599f07b6 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 09:01:27 +0100 Subject: [PATCH 03/11] fix may be unitialized warning --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 439d08b9c..d56bc94ac 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2314,7 +2314,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { ffloor_t * rover; fixed_t highcut = 0, lowcut = 0; - fixed_t lowcutslope, highcutslope; + fixed_t lowcutslope = 0, highcutslope = 0; // Used for height comparisons and etc across FOFs and slopes fixed_t high1, highslope1, low1, lowslope1; From d07e7ade4a6bf67e943378a57a2580c3e6e70c68 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 09:18:20 +0100 Subject: [PATCH 04/11] this does absolutely nothing leftover from porting musictest --- src/s_sound.c | 13 ------------- src/s_sound.h | 1 - 2 files changed, 14 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index ffe18d492..4be55a8a0 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1323,19 +1323,6 @@ static UINT32 queue_fadeinms; musicdef_t *musicdefstart = NULL; // First music definition struct cursongcredit cursongcredit; // Currently displayed song credit info -musicdef_t soundtestsfx = { - "_STSFX", // prevents exactly one valid track name from being used on the sound test - "Sound Effects", - "", - "SEGA, Sonic Team Jr, other sources", - 1, // show on soundtest page 1 - 0, // with no conditions - 0, - 0, - false, - NULL -}; - // // search for music definition in wad // diff --git a/src/s_sound.h b/src/s_sound.h index 5cfe937ea..72d4bd38d 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -172,7 +172,6 @@ typedef struct musicdef_s struct musicdef_s *next; } musicdef_t; -extern musicdef_t soundtestsfx; extern musicdef_t *musicdefstart; extern musicdef_t **soundtestdefs; extern INT32 numsoundtestdefs; From 0dca9f9537fb7d1ab049f5dc564ead88cda7d33e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 09:22:19 +0100 Subject: [PATCH 05/11] use the bool brap --- src/hardware/hw_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d56bc94ac..f749be289 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4113,7 +4113,7 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts // do interpolation if (R_UsingFrameInterpolation() && !paused) { - if (spr->precip) + if (precip) { R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, rendertimefrac, &interp); } @@ -4124,7 +4124,7 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts } else { - if (spr->precip) + if (precip) { R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, FRACUNIT, &interp); } From f7f3b6497b62701b1433592c2be5469d244b898d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 10:08:57 +0100 Subject: [PATCH 06/11] fix palshader compiler warning + other stuff asdfgfagregar set a gl special state instead of using the boolean in r_opengl also move hwr_ code out of setshaders --- src/hardware/hw_defs.h | 2 +- src/hardware/hw_drv.h | 2 ++ src/hardware/hw_main.c | 14 +++++++++++--- src/hardware/hw_main.h | 1 + src/hardware/r_opengl/r_opengl.c | 30 +++++++++++++++--------------- src/hardware/r_opengl/r_opengl.h | 1 - src/sdl/hwsym_sdl.c | 1 + src/sdl/i_video.c | 1 + src/v_video.c | 4 ++-- 9 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 4c682b2eb..0275f7c2c 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -232,7 +232,7 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { HWD_SET_SHADERS, - HWD_SET_PALETTE_SHADER_ENABLED, + HWD_PAL_SHADER, HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index 42183a015..b231e76c4 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -84,6 +84,7 @@ EXPORT boolean HWRAPI(InitCustomShaders) (void); EXPORT void HWRAPI(StartBatching) (void); EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors); +EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut); EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable); EXPORT void HWRAPI(ClearLightTableCache) (void); @@ -138,6 +139,7 @@ struct hwdriver_s StartBatching pfnStartBatching; RenderBatches pfnRenderBatches; + InitPalette pfnInitPalette; AddLightTable pfnAddLightTable; ClearLightTableCache pfnClearLightTableCache; }; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f749be289..bc5888b2e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -183,9 +183,9 @@ static void CV_grshaders_OnChange(void) if (rendermode == render_opengl) { if (HWR_ShouldUsePaletteRendering()) - { - InitPalette(0, false); - } + HWR_InitPalette(0, false); + + HWD.pfnSetSpecialState(HWD_PAL_SHADER, HWR_ShouldUsePaletteRendering()); V_SetPalette(0); } @@ -197,6 +197,9 @@ static void CV_useCustomShaders_ONChange(void) { if (HWR_UseShader()) HWD.pfnInitCustomShaders(); + + if (HWR_ShouldUsePaletteRendering()) + HWR_InitPalette(0, false); } } @@ -207,6 +210,11 @@ static void CV_Gammaxxx_ONChange(void) V_SetPalette(0); } +void HWR_InitPalette(int flashnum, boolean skiplut) +{ + HWD.pfnInitPalette(flashnum, skiplut); +} + // ========================================================================== // Globals diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 1b259e5e7..3dc18ccf8 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -114,6 +114,7 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum); void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); void HWR_MakeScreenFinalTexture(void); void HWR_DrawScreenFinalTexture(int width, int height); +void HWR_InitPalette(int flashnum, boolean skiplut); // hw_main.c: Planes 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); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index cf10c059f..d489306f9 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -638,6 +638,7 @@ static boolean gl_batching = false;// are we currently collecting batches? static GLint gl_palette[768]; boolean gl_palette_initialized = false; +static boolean gl_palshader = false; static INT32 gl_enable_screen_textures = 1; @@ -1286,11 +1287,6 @@ EXPORT boolean HWRAPI(InitCustomShaders) (void) #ifdef GL_SHADERS KillShaders(); return LoadShaders(); - - if (HWR_ShouldUsePaletteRendering()) - { - InitPalette(0, false); - } #endif } @@ -1340,7 +1336,7 @@ GLuint palette_tex_num; // the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! // the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! -void InitPalette(int flashnum, boolean skiplut) +EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut) { int i, r, g, b; @@ -1805,7 +1801,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too - if ((!gl_palette_initialized) && (HWR_ShouldUsePaletteRendering())) + if ((!gl_palette_initialized) && (gl_palshader)) InitPalette(0, false); // just gonna put this here for now } @@ -2428,7 +2424,7 @@ static int comparePolygons(const void *p1, const void *p2) diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { diff = poly1->surf.LightTableId - poly2->surf.LightTableId; if (diff != 0) return diff; @@ -2571,7 +2567,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i if (gl_allowshaders) { Shader_Load(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade); - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId); @@ -2688,7 +2684,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeState = true; changePolyFlags = true; } - if ((gl_allowshaders) && (HWR_ShouldUsePaletteRendering())) + if (gl_allowshaders && gl_palshader) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2702,7 +2698,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeSurfaceInfo = true; } } - else if ((gl_allowshaders) && (!HWR_ShouldUsePaletteRendering())) + else if ((gl_allowshaders) && (!gl_palshader)) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2833,7 +2829,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade); - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId); @@ -2944,7 +2940,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; } - if (HWR_ShouldUsePaletteRendering() && gl_allowshaders) + if (gl_palshader && gl_allowshaders) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); @@ -3292,6 +3288,10 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) break; } break; + + case HWD_PAL_SHADER: + gl_palshader = Value; + break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) @@ -4479,7 +4479,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) ClearBuffer(true, false, false, &clearColour); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { Shader_SetUniforms(NULL, NULL, NULL, NULL); // prepare shader, if it is enabled @@ -4495,7 +4495,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; - if (HWR_ShouldUsePaletteRendering()) + if (gl_palshader) { pglUseProgram(0); pglActiveTexture(GL_TEXTURE0); diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 8bce7d15b..a65c085a5 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -135,6 +135,5 @@ typedef enum // in order for custom playpals n shit to work properly extern boolean gl_palette_initialized; -void InitPalette(int flashnum, boolean skiplut); #endif diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index a64a11135..96b7b0679 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -118,6 +118,7 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(StartBatching); GETFUNC(RenderBatches); + GETFUNC(InitPalette); GETFUNC(AddLightTable); GETFUNC(ClearLightTableCache); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 5aa4b684c..33ca71e94 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2151,6 +2151,7 @@ void I_StartupGraphics(void) HWD.pfnStartBatching = hwSym("StartBatching",NULL); HWD.pfnRenderBatches = hwSym("RenderBatches",NULL); + HWD.pfnInitPalette = hwSym("InitPalette",NULL); HWD.pfnAddLightTable = hwSym("AddLightTable",NULL); HWD.pfnClearLightTableCache = hwSym("ClearLightTableCache",NULL); diff --git a/src/v_video.c b/src/v_video.c index 1fc9be187..6058d8ede 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -207,7 +207,7 @@ void V_SetPalette(INT32 palettenum) { // reset our palette lookups n shit gl_palette_initialized = false; - InitPalette(palettenum, true); + HWR_InitPalette(palettenum, true); } else HWR_SetPalette(&pLocalPalette[palettenum*256]); @@ -229,7 +229,7 @@ void V_SetPaletteLump(const char *pal) { // reset our palette lookups n shit gl_palette_initialized = false; - InitPalette(0, false); + HWR_InitPalette(0, false); } HWR_SetPalette(pLocalPalette); From 2a6f551f7aaa2639263d77773393d6f7b2e08f50 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 10:31:45 +0100 Subject: [PATCH 07/11] fix compact fps counter screwing up ping counter offsets in tab rankings AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA --- src/hu_stuff.c | 42 +++++++----------------------------------- src/screen.c | 5 +++-- 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index e63fceffb..53f3666a0 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2583,50 +2583,22 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags) gfxnum = Ping_gfx_num(lag); if (measureid == 1) - { - if (cv_ticrate.value == 2){ - V_DrawScaledPatch(x+12 - pingmeasure[measureid]->width, y+22, flags, pingmeasure[measureid]); - }else{ - V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - } - } - + V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); if (cv_pingicon.value) - { - if (cv_ticrate.value == 2){ - V_DrawScaledPatch(x+2, y+13, flags, pinggfx[gfxnum]); - }else{ - V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); - } - } - + V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); if (servermaxping && lag > servermaxping && hu_tick < 4) - { - // flash ping red if too high - colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); - } + colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); // flash ping red if too high if (cv_pingmeasurement.value) - { lag = (INT32)(lag * (1000.00f / TICRATE)); - } - - if (cv_ticrate.value == 2){ - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+22, flags, lag, colormap); - }else{ - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); - } - if (measureid == 0){ - if (cv_ticrate.value == 2){ - V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+22, flags, pingmeasure[measureid]); - }else{ + x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); + + + if (measureid == 0) V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - } - } - } // diff --git a/src/screen.c b/src/screen.c index ee0c76e82..bc787e4b2 100644 --- a/src/screen.c +++ b/src/screen.c @@ -476,7 +476,8 @@ void SCR_DisplayLocalPing(void) if (cv_showping.value == 1 || (cv_showping.value == 2 && ping > servermaxping)) // only show 2 (warning) if our ping is at a bad level { - INT32 dispy = cv_ticrate.value ? 160 : 181; - HU_drawPing(307, dispy, ping, fpsflags); + INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2) ? 172 : 181); + + HU_drawPing(308, dispy, ping, fpsflags); } } From bccc79fe4bd38cf6323fe22eaf88cace4954fb5d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 12:06:31 +0100 Subject: [PATCH 08/11] Kart v1.0/srb2 ping display option well i adjusted it a little and made it compatible with the frame ping stuff just hope the bar stuff is right but seemed so also changed it so the numbers are right alignent so they dont go out of screen aaaa --- src/d_netcmd.c | 6 ++++ src/d_netcmd.h | 1 + src/hu_stuff.c | 90 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 43d7377a7..b15b15526 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -484,6 +484,11 @@ consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0 static CV_PossibleValue_t pingmeasurement_cons_t[] = {{0, "Frames"}, {1, "Milliseconds"}, {0, NULL}}; consvar_t cv_pingmeasurement = {"pingmeasurement", "Frames", CV_SAVE, pingmeasurement_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t cv_pingstyle_cons_t[] = {{0, "New"}, {1, "Old"}, {0, NULL}}; +consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; + + consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -795,6 +800,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_showping); CV_RegisterVar(&cv_pingmeasurement); CV_RegisterVar(&cv_pingicon); + CV_RegisterVar(&cv_pingstyle); #ifdef SEENAMES CV_RegisterVar(&cv_allowseenames); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 0f44840d8..8fbdf1d5f 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -156,6 +156,7 @@ extern consvar_t cv_pingtimeout; extern consvar_t cv_showping; extern consvar_t cv_pingmeasurement; extern consvar_t cv_pingicon; +extern consvar_t cv_pingstyle; //extern consvar_t cv_smallpos; extern consvar_t cv_showminimapnames; diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 53f3666a0..08c2d7c33 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2579,26 +2579,92 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags) UINT8 *colormap = NULL; INT32 measureid = cv_pingmeasurement.value ? 1 : 0; INT32 gfxnum; // gfx to draw + + //SRB2/Kart v1.0 style + UINT8 numbars = 0; // how many ping bars do we draw? + UINT8 barcolor = 31; // color we use for the bars (green, yellow, red or black) + SINT8 i = 0; + SINT8 yoffset = 6; + INT32 dx; gfxnum = Ping_gfx_num(lag); - - if (measureid == 1) - V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - if (cv_pingicon.value) - V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); + if (!cv_pingstyle.value) + { + if (measureid == 1) + V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + + if (cv_pingicon.value) + V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); - if (servermaxping && lag > servermaxping && hu_tick < 4) - colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); // flash ping red if too high + if (servermaxping && lag > servermaxping && hu_tick < 4) + colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); // flash ping red if too high - if (cv_pingmeasurement.value) - lag = (INT32)(lag * (1000.00f / TICRATE)); + if (cv_pingmeasurement.value) + lag = (INT32)(lag * (1000.00f / TICRATE)); - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); + x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); + if (measureid == 0) + V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + } + else if (cv_pingstyle.value) // old style ping + { + if (cv_pingicon.value) + { + if (lag < 4) + { + numbars = 3; + barcolor = 184; + } + else if (lag < 7) + { + numbars = 2; // Apparently ternaries w/ multiple statements don't look good in C so I decided against it. + barcolor = 103; + } + else if (lag < 10) + { + numbars = 1; + barcolor = 155; // need a better red + } + else // brazil + { + numbars = 0; + barcolor = 31; + } + } - if (measureid == 0) - V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + if (cv_pingmeasurement.value) + lag = (INT32)(lag * (1000.00f / TICRATE)); + + if (vid.width >= 640) // how sad, we're using a shit resolution. + { + if (measureid == 1) + { + //dx = x+1 - (V_SmallStringWidth(va("%dms", lag), V_ALLOWLOWERCASE|flags)/2); + //V_DrawSmallString(dx, y+4, V_ALLOWLOWERCASE|flags, va("%dms", lag)); + V_DrawRightAlignedSmallString(x+12, y+13, V_ALLOWLOWERCASE|flags, va("%dms", lag)); + } + else if (measureid == 0) + { + //dx = x+1 - (V_SmallStringWidth(va("d%d", lag), flags)/2); + //V_DrawSmallString(dx, y+4, flags, va("d%d", lag)); + V_DrawRightAlignedSmallString(x+12, y+13, flags, va("d%d", lag)); + } + } + + if (cv_pingicon.value) + { + for (i=0; (i<3); i++) // Draw the ping bar + { + V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-4, 2, 8-yoffset, 31|flags); + if (i < numbars) + V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-3, 1, 8-yoffset-1, barcolor|flags); + + yoffset -= 2; + } + } + } } // From ea3fc8f526415d0bb624af6dcad23635225318f9 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 13:41:13 +0100 Subject: [PATCH 09/11] Kart v1.0/srb2 styled fps counter option this was so much pain for whatever reason lmao --- src/d_netcmd.c | 1 - src/m_menu.c | 2 +- src/screen.c | 76 +++++++++++++++++++++++++++++++++----------------- src/v_video.c | 2 +- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b15b15526..5cb77bf61 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -488,7 +488,6 @@ consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, static CV_PossibleValue_t cv_pingstyle_cons_t[] = {{0, "New"}, {1, "Old"}, {0, NULL}}; consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; - consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/m_menu.c b/src/m_menu.c index 1e0c28352..3e366df68 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1392,7 +1392,7 @@ static const char* OP_VideoTooltips[] = "How far away weather is drawn.", "Toggle being able to see the sky.", "Player field of view.", - "Show current game framerate.", + "Show current game framerate and select the style.", "Sync game framerate to refresh rate of monitor.", "Set manual framerate cap.", "Size of drift spark pulse.", diff --git a/src/screen.c b/src/screen.c index bc787e4b2..06be64abf 100644 --- a/src/screen.c +++ b/src/screen.c @@ -429,41 +429,65 @@ void SCR_DisplayTicRate(void) INT32 x = 318; double fps = round(averageFPS); INT32 fpsflags = SCR_FPSflags(); + const char *fps_string; + + INT32 ticcntcolor2 = 0; if (gamestate == GS_NULL) return; - // draw "FPS" - if (cv_ticrate.value == 1) - V_DrawFixedPatch(306< (benchmark - 5)) - ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); - else if (fps < 20) - ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); - - if (cap != 0) + // new kart counter + if ((cv_ticrate.value == 1) || (cv_ticrate.value == 2)) { - UINT32 digits = 1; - UINT32 c2 = cap; + // draw "FPS" + if (cv_ticrate.value == 1) + V_DrawFixedPatch(306< (benchmark - 5)) + ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); + else if (fps < 20) + ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); - while (c2 > 0) + if (cap != 0) { - c2 = c2 / 10; - digits++; + UINT32 digits = 1; + UINT32 c2 = cap; + + while (c2 > 0) + { + c2 = c2 / 10; + digits++; + } + + // draw total frame: + V_DrawPingNum(x, 190, fpsflags, cap, ticcntcolor); + + x -= digits * 4; + + // draw "/" + V_DrawFixedPatch(x< (benchmark - 5)) + ticcntcolor2 = V_GREENMAP; + else if (fps < 20) + ticcntcolor2 = V_REDMAP; - // draw our actual framerate - V_DrawPingNum(x, 190, fpsflags, fps, ticcntcolor); + if (cap != 0) + fps_string = va("%d/%d\x82", (INT32)fps, cap); + else + fps_string = va("%d\x82", (INT32)fps); + + if (cv_ticrate.value == 3) + V_DrawRightAlignedString(319, 181, V_YELLOWMAP|fpsflags, "FPS"); + + V_DrawRightAlignedString(319, 190, ticcntcolor2|fpsflags, fps_string); + } } // SCR_DisplayLocalPing @@ -476,8 +500,8 @@ void SCR_DisplayLocalPing(void) if (cv_showping.value == 1 || (cv_showping.value == 2 && ping > servermaxping)) // only show 2 (warning) if our ping is at a bad level { - INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2) ? 172 : 181); - + INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2 || cv_ticrate.value == 4) ? 172 : ((cv_ticrate.value == 3) ? 163 : 181)); // absolute buttpain + HU_drawPing(308, dispy, ping, fpsflags); } } diff --git a/src/v_video.c b/src/v_video.c index 6058d8ede..d6c8831bf 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -42,7 +42,7 @@ UINT8 *screens[5]; static CV_PossibleValue_t gamma_cons_t[] = {{0, "MIN"}, {4, "MAX"}, {0, NULL}}; static void CV_usegamma_OnChange(void); -static CV_PossibleValue_t fps_cons_t[] = {{0, "No"}, {1, "Normal"}, {2, "Compact"}, {0, NULL}}; +static CV_PossibleValue_t fps_cons_t[] = {{0, "No"}, {1, "Normal"}, {2, "Compact"}, {3, "Old"}, {4, "Old Compact"}, {0, NULL}}; consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, fps_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usegamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_usegamma_OnChange, 0, NULL, NULL, 0, 0, NULL}; From 0a38a2fd899d0cb87931679d376bf6af4437a3ab Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 13:41:52 +0100 Subject: [PATCH 10/11] forgor to add ping display stuff to menu someone pls make a better tooltip i bed ingles --- src/m_menu.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 3e366df68..3187d9219 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1762,23 +1762,24 @@ static menuitem_t OP_HUDOptionsMenu[] = static menuitem_t OP_ChatOptionsMenu[] = { // will ANYONE who doesn't know how to use the console want to touch this one? - {IT_STRING | IT_CVAR, NULL, "Chat Mode", &cv_consolechat, 10}, // nonetheless... + {IT_STRING | IT_CVAR, NULL, "Chat Mode", &cv_consolechat, 5}, // nonetheless... {IT_STRING | IT_CVAR | IT_CV_SLIDER, - NULL, "Chat Box Width", &cv_chatwidth, 25}, + NULL, "Chat Box Width", &cv_chatwidth, 20}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, - NULL, "Chat Box Height", &cv_chatheight, 35}, + NULL, "Chat Box Height", &cv_chatheight, 30}, - {IT_STRING | IT_CVAR, NULL, "Chat Background Tint", &cv_chatbacktint, 50}, - {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 60}, - {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 70}, - {IT_STRING | IT_CVAR, NULL, "Max Chat Messages", &cv_chatlogsize, 80}, + {IT_STRING | IT_CVAR, NULL, "Chat Background Tint", &cv_chatbacktint, 45}, + {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 55}, + {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 65}, + {IT_STRING | IT_CVAR, NULL, "Max Chat Messages", &cv_chatlogsize, 75}, - {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 100}, // shows ping next to framerate if we want to. - {IT_STRING | IT_CVAR, NULL, "Ping measurement", &cv_pingmeasurement, 110}, - {IT_STRING | IT_CVAR, NULL, "Ping icon", &cv_pingicon, 120}, - - {IT_STRING | IT_CVAR, NULL, "Show IP addresses in playerlist", &cv_shownodeip, 140}, + {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 95}, // shows ping above the framerate if we want to. + {IT_STRING | IT_CVAR, NULL, "Ping display style", &cv_pingstyle, 105}, + {IT_STRING | IT_CVAR, NULL, "Ping measurement", &cv_pingmeasurement, 115}, + {IT_STRING | IT_CVAR, NULL, "Ping icon", &cv_pingicon, 125}, + + {IT_STRING | IT_CVAR, NULL, "Show IP address in playerlist", &cv_shownodeip, 135}, }; static const char* OP_ChatOptionsTooltips[] = @@ -1791,6 +1792,7 @@ static const char* OP_ChatOptionsTooltips[] = "Spam protection for in-game chat.", "Maxiumum amount of chat messages to look back at.", "Show player ping.", + "Choose the looks of the ping display.", // this is ass idk english lmao "Measurement used for ping.", "Visibility of ping icon.", "Should Player IP addresses be printed when using\nthe nodes or listplayers command?", From b87b55ec453ea9cdddfef3b6b3caa4350b377097 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 21 Dec 2023 13:42:05 +0100 Subject: [PATCH 11/11] fix compiler warning --- src/v_video.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/v_video.c b/src/v_video.c index d6c8831bf..894037cab 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -20,6 +20,8 @@ #include "r_draw.h" #include "console.h" +#include "r_fps.h" //vhs effect stuff + #include "i_video.h" // rendermode #include "z_zone.h" #include "m_misc.h"