From 3e9f9129d85ce8fbc5bb6757c1bf323e3cccdfaa Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 27 Sep 2024 05:00:01 +0200 Subject: [PATCH] cleanup + reformatting --- src/hardware/hw_main.c | 129 ++++++++++++++++++++--------------------- src/r_bsp.c | 3 +- src/v_video.c | 26 ++++----- 3 files changed, 75 insertions(+), 83 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d4c304790..107417005 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -194,7 +194,7 @@ static void CV_grshaders_OnChange(void) { ONLY_IF_GL_LOADED HWR_SetShaderState(); - if ((cv_grpaletterendering.value)) + if (cv_grpaletterendering.value) { // can't do palette rendering without shaders, so update the state if needed HWR_TogglePaletteRendering(); @@ -204,7 +204,6 @@ static void CV_grshaders_OnChange(void) static void CV_grpaletterendering_OnChange(void) { ONLY_IF_GL_LOADED - if (cv_grscreentextures.value != 2) // can't do palette rendering without screen textures CV_Set(&cv_grpaletterendering, "Off"); @@ -614,11 +613,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col Surface->LightInfo.fade_start = (colormap != NULL) ? colormap->fadestart : 0; Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31; Surface->LightInfo.directional = (maplighting.directional == true && directional == true); - - if (HWR_ShouldUsePaletteRendering()) - Surface->LightTableId = HWR_GetLightTableID(colormap); - else - Surface->LightTableId = 0; + Surface->LightTableId = HWR_ShouldUsePaletteRendering() ? HWR_GetLightTableID(colormap) : 0; } UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if this can work @@ -3401,13 +3396,13 @@ static gr_vissprite_t gr_overflowsprite; static gr_vissprite_t *HWR_GetVisSprite(UINT32 num) { - UINT32 chunk = num >> VISSPRITECHUNKBITS; + UINT32 chunk = num >> VISSPRITECHUNKBITS; - // Allocate chunk if necessary - if (!gr_visspritechunks[chunk]) - Z_Malloc(sizeof(gr_vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &gr_visspritechunks[chunk]); + // Allocate chunk if necessary + if (!gr_visspritechunks[chunk]) + Z_Malloc(sizeof(gr_vissprite_t) * VISSPRITESPERCHUNK, PU_LEVEL, &gr_visspritechunks[chunk]); - return gr_visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); + return gr_visspritechunks[chunk] + (num & VISSPRITEINDEXMASK); } static gr_vissprite_t *HWR_NewVisSprite(void) @@ -3783,15 +3778,13 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) HWR_RotateSpritePolyToAim(spr, baseWallVerts, false); // push it toward the camera to mitigate floor-clipping sprites + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); + float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + for (i = 0; i < 4; i++) { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); - float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; - for (i = 0; i < 4; i++) - { - baseWallVerts[i].x += (gr_viewx - baseWallVerts[i].x)*distfact; - baseWallVerts[i].z += (gr_viewy - baseWallVerts[i].z)*distfact; - baseWallVerts[i].y += (gr_viewz - baseWallVerts[i].y)*distfact; - } + baseWallVerts[i].x += (gr_viewx - baseWallVerts[i].x)*distfact; + baseWallVerts[i].z += (gr_viewy - baseWallVerts[i].z)*distfact; + baseWallVerts[i].y += (gr_viewz - baseWallVerts[i].y)*distfact; } realtop = top = baseWallVerts[3].y; @@ -3980,6 +3973,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) FOutVector wallVerts[4]; GLPatch_t *gpatch; // sprite patch converted to hardware FSurfaceInfo Surf; + FBITFIELD blend = 0; INT32 shader = SHADER_NONE; @@ -4062,16 +4056,14 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) HWR_RotateSpritePolyToAim(spr, wallVerts, false); // push it toward the camera to mitigate floor-clipping sprites + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); + float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + size_t i; + for (i = 0; i < 4; i++) { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->gzt - gr_viewz)*(spr->gzt - gr_viewz)); - float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; - size_t i; - for (i = 0; i < 4; i++) - { - wallVerts[i].x += (gr_viewx - wallVerts[i].x)*distfact; - wallVerts[i].z += (gr_viewy - wallVerts[i].z)*distfact; - wallVerts[i].y += (gr_viewz - wallVerts[i].y)*distfact; - } + wallVerts[i].x += (gr_viewx - wallVerts[i].x)*distfact; + wallVerts[i].z += (gr_viewy - wallVerts[i].z)*distfact; + wallVerts[i].y += (gr_viewz - wallVerts[i].y)*distfact; } // This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black. @@ -4090,38 +4082,35 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector) && !(spr->mobj->frame & FF_FULLBRIGHT)); + if (!cv_translucency.value) // translucency disabled { - FBITFIELD blend = 0; - if (!cv_translucency.value) // translucency disabled - { - Surf.PolyColor.s.alpha = 0xFF; - blend = PF_Translucent|PF_Occlude; - } - else if (spr->mobj->flags2 & MF2_SHADOW) - { - Surf.PolyColor.s.alpha = 0x40; - blend = PF_Translucent; - } - else if (spr->mobj->frame & FF_TRANSMASK) - blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); - else - { - // BP: i agree that is little better in environement but it don't - // work properly under glide nor with fogcolor to ffffff :( - // Hurdler: PF_Environement would be cool, but we need to fix - // the issue with the fog before - Surf.PolyColor.s.alpha = 0xFF; - blend = PF_Translucent|PF_Occlude; - } - - if (HWR_UseShader()) - { - shader = SHADER_SPRITE; - blend |= PF_ColorMapped; - } - - HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false); + Surf.PolyColor.s.alpha = 0xFF; + blend = PF_Translucent|PF_Occlude; } + else if (spr->mobj->flags2 & MF2_SHADOW) + { + Surf.PolyColor.s.alpha = 0x40; + blend = PF_Translucent; + } + else if (spr->mobj->frame & FF_TRANSMASK) + blend = HWR_TranstableToAlpha((spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); + else + { + // BP: i agree that is little better in environement but it don't + // work properly under glide nor with fogcolor to ffffff :( + // Hurdler: PF_Environement would be cool, but we need to fix + // the issue with the fog before + Surf.PolyColor.s.alpha = 0xFF; + blend = PF_Translucent|PF_Occlude; + } + + if (HWR_UseShader()) + { + shader = SHADER_SPRITE; + blend |= PF_ColorMapped; + } + + HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false); } // Sprite drawer for precipitation @@ -4492,8 +4481,9 @@ static void HWR_RenderDrawNodes(void) if (!(plane->blend & PF_NoTexture)) HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, plane->isceiling)); + HWR_RenderPlane(NULL, plane->xsub, plane->isceiling, plane->fixedheight, plane->blend, plane->lightlevel, - plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap); + plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap); } else if (drawnode->type == DRAWNODE_POLYOBJECT_PLANE) { @@ -4504,8 +4494,9 @@ static void HWR_RenderDrawNodes(void) if (!(polyplane->blend & PF_NoTexture)) HWR_GetFlat(polyplane->lumpnum, R_NoEncore(polyplane->FOFSector, polyplane->isceiling)); + HWR_RenderPolyObjectPlane(polyplane->polysector, polyplane->isceiling, polyplane->fixedheight, polyplane->blend, polyplane->lightlevel, - polyplane->lumpnum, polyplane->FOFSector, polyplane->alpha, polyplane->planecolormap); + polyplane->lumpnum, polyplane->FOFSector, polyplane->alpha, polyplane->planecolormap); } else if (drawnode->type == DRAWNODE_WALL) { @@ -4513,8 +4504,9 @@ static void HWR_RenderDrawNodes(void) if (!(wall->blend & PF_NoTexture)) HWR_GetTexture(wall->texnum, wall->noencore); + HWR_RenderWall(wall->wallVerts, &wall->Surf, wall->blend, wall->fogwall, - wall->lightlevel, wall->wallcolormap); + wall->lightlevel, wall->wallcolormap); } } @@ -4824,8 +4816,8 @@ void HWR_ProjectSprite(mobj_t *thing) flip ^= (1<skin && ((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->flags & SF_HIRES) - this_scale *= FIXED_TO_FLOAT(((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->highresscale); + if (thing->skin && ((skin_t *)(thing->localskin ? thing->localskin : thing->skin))->flags & SF_HIRES) + this_scale *= FIXED_TO_FLOAT(((skin_t *)(thing->localskin ? thing->localskin : thing->skin))->highresscale); spr_width = spritecachedinfo[lumpoff].width; spr_height = spritecachedinfo[lumpoff].height; @@ -4946,6 +4938,7 @@ void HWR_ProjectSprite(mobj_t *thing) FIXED_TO_FLOAT(interp.z) >= FIXED_TO_FLOAT(sectors[heightsec].floorheight) : gzt < FIXED_TO_FLOAT(sectors[heightsec].floorheight)) return; + if (gr_viewz > FIXED_TO_FLOAT(sectors[phs].ceilingheight) ? gzt < FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) && gr_viewz >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight) : FIXED_TO_FLOAT(interp.z) >= FIXED_TO_FLOAT(sectors[heightsec].ceilingheight)) @@ -5402,9 +5395,10 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe 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); - boolean useportals = gr_maphasportals && cv_grportals.value && allow_portals; + const boolean useportals = cv_grportals.value && gr_maphasportals && allow_portals; + + portallist.base = portallist.cap = NULL; if (useportals && stencil_level < cv_maxportals.value) // if recursion limit is not reached { @@ -5413,6 +5407,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe gr_portal = GRPORTAL_SEARCH; HWR_ClearClipper(); + if (!rootportal) portalclipline = NULL; else @@ -5877,7 +5872,7 @@ void HWR_DoPostProcessor(player_t *player) // Armageddon Blast Flash! // Could this even be considered postprocessor? - if ((player->flashcount) && (!HWR_PalRenderFlashpal())) + if (!HWR_PalRenderFlashpal() && player->flashcount) { FOutVector v[4]; FSurfaceInfo Surf; diff --git a/src/r_bsp.c b/src/r_bsp.c index a2f5a1cb2..d49da62cb 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -1348,8 +1348,7 @@ void R_RenderBSPNode(INT32 bspnum) // PORTAL CULLING if (portalcullsector) { - sector_t *sect = subsectors[bspnum & ~NF_SUBSECTOR].sector; - if (sect != portalcullsector) + if (subsectors[bspnum & ~NF_SUBSECTOR].sector != portalcullsector) return; portalcullsector = NULL; } diff --git a/src/v_video.c b/src/v_video.c index f41934752..b234161c8 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1615,21 +1615,19 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength) } #endif - { - const UINT8 *fadetable = - (color > 0xFFF0) // Grab a specific colormap palette? - ? R_GetTranslationColormap(color | 0xFFFF0000, strength, GTC_CACHE) - : ((color & 0xFF00) // Color is not palette index? - ? ((UINT8 *)colormaps + strength*256) // Do COLORMAP fade. - : ((UINT8 *)transtables + ((9-strength)< 0xFFF0) // Grab a specific colormap palette? + ? R_GetTranslationColormap(color | 0xFFFF0000, strength, GTC_CACHE) + : ((color & 0xFF00) // Color is not palette index? + ? ((UINT8 *)colormaps + strength*256) // Do COLORMAP fade. + : ((UINT8 *)transtables + ((9-strength)<