From 0e1bfbb0b5f97a9f1fc5d4e03cc4f5b4269b8568 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Dec 2024 23:23:27 +0100 Subject: [PATCH 1/3] clean up hw_cache stuff + fix accidental wrong cast --- src/hardware/hw_cache.c | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 652e1e903..b058bde99 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -54,10 +54,10 @@ static INT32 format2bpp(GLTextureFormat_t format) // It is now split from it for my sanity! (and the sanity of others) // -- Monster Iestyn (13/02/19) static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipmap_t *mipmap, - INT32 pblockheight, INT32 blockmodulo, - fixed_t yfracstep, fixed_t scale_y, - texpatch_t *originPatch, INT32 patchheight, - INT32 bpp, RGBA_t *palette) + INT32 pblockheight, INT32 blockmodulo, + fixed_t yfracstep, fixed_t scale_y, + texpatch_t *originPatch, INT32 patchheight, + INT32 bpp, RGBA_t *palette) { fixed_t yfrac, position, count; UINT8 *dest; @@ -73,9 +73,6 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm (void)patchheight; // This parameter is unused - if (!mipmap || mipmap == NULL) - return; - if (originPatch) // originPatch can be NULL here, unlike in the software version originy = originPatch->originy; @@ -111,10 +108,10 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm count--; texel = source[yfrac>>FRACBITS]; - alpha = 0xff; + alpha = 0xFF; - //Hurdler: not perfect, but better than holes - if (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX && (mipmap->flags & TF_CHROMAKEYED)) + // Make pixel transparent if chroma keyed + if ((mipmap->flags & TF_CHROMAKEYED) && (texel == HWR_PATCHES_CHROMAKEY_COLORINDEX)) alpha = 0x00; //Hurdler: 25/04/2000: now support colormap in hardware mode @@ -126,7 +123,8 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm // Alam: SRB2 uses Mingw, HUGS switch (bpp) { - case 2 : texelu16 = (UINT16)((alpha<<8) | texel); + case 2 : // uhhhhhhhh.......... + texelu16 = (UINT16)((alpha<<8) | texel); memcpy(dest, &texelu16, sizeof(UINT16)); break; case 3 : colortemp = palette[texel]; @@ -144,6 +142,7 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm dest += blockmodulo; yfrac += yfracstep; } + patchcol = (const column_t *)((const UINT8 *)patchcol + patchcol->length + 4); } } @@ -185,6 +184,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, if (bpp < 1 || bpp > 4) I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp); + // NOTE: should this actually be pblockwidth*bpp? blockmodulo = pblockwidth*bpp; // Draw each column to the block cache @@ -263,6 +263,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, if (bpp < 1 || bpp > 4) I_Error("HWR_DrawTexturePatchInCache: no drawer defined for this bpp (%d)\n",bpp); + // NOTE: should this actually be pblockwidth*bpp? blockmodulo = pblockwidth*bpp; // Draw each column to the block cache @@ -336,8 +337,8 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe else gltex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; - gltex->mipmap.width = SHORT(texture->width); - gltex->mipmap.height = SHORT(texture->height); + gltex->mipmap.width = (UINT16)(texture->width); + gltex->mipmap.height = (UINT16)(texture->height); if (skyspecial) gltex->mipmap.format = GL_TEXFMT_RGBA; // that skyspecial code below assumes this format ... @@ -362,14 +363,17 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe RGBA_t col; col = palette[HWR_CHROMAKEY_EQUIVALENTCOLORINDEX]; + for (j = 0; j < blockheight; j++) { for (i = 0; i < blockwidth; i++) { - block[4*(j*blockwidth+i)+0] = col.s.red; - block[4*(j*blockwidth+i)+1] = col.s.green; - block[4*(j*blockwidth+i)+2] = col.s.blue; - block[4*(j*blockwidth+i)+3] = 0xff; + int idx = (j*blockwidth+i); + + block[4*idx+0] = col.s.red; + block[4*idx+1] = col.s.green; + block[4*idx+2] = col.s.blue; + block[4*idx+3] = 0xff; } } } @@ -378,15 +382,12 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); - HWR_DrawTexturePatchInCache(&gltex->mipmap, - blockwidth, blockheight, - texture, patch, - realpatch); + HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); Z_ChangeTag(realpatch, PU_HWRCACHE_UNLOCKED); } //Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :( - if (format2bpp(gltex->mipmap.format)==4) + if (format2bpp(gltex->mipmap.format) == 4) { for (i = 3; i < blocksize*4; i += 4) // blocksize*4 because blocksize doesn't include the bpp { @@ -437,6 +438,7 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, bo if (makebitmap) { MakeBlock(glMipmap); + HWR_DrawPatchInCache(glMipmap, glMipmap->width, glMipmap->height, glPatch->width, glPatch->height, From 7ae361cb7c40d1a67ad3cb301fcb8c0d7f8938ad Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 12 Dec 2024 00:11:42 +0100 Subject: [PATCH 2/3] better cv_lessprecip handling idk what i was thinking lmao --- src/p_mobj.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 7bef4d727..b7c86cbd5 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10201,19 +10201,26 @@ void P_SpawnPrecipitation(void) if (dedicated || !cv_drawdist_precip.value || curWeather == PRECIP_NONE) // SRB2Kart return; + fixed_t density = (cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT); + + if (cv_lessprecip.value) + density *= 2; // just spawn half the precip + // Use the blockmap to narrow down our placing patterns for (i = 0; i < bmapwidth*bmapheight; ++i) { basex = bmaporgx + (i % bmapwidth) * MAPBLOCKSIZE; basey = bmaporgy + (i / bmapwidth) * MAPBLOCKSIZE; - for (j = 0; j < FRACUNIT; j += cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT) + // If mobjscale < FRACUNIT, each blockmap cell covers + // more area so spawn more precipitation in that area. + for (j = 0; j < FRACUNIT; j += density) { INT32 floorz; INT32 ceilingz; - x = ((cv_lessprecip.value ? basex*1.5 : basex) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); - y = ((cv_lessprecip.value ? basey*1.5 : basey) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); + x = basex + ((M_RandomKey(MAPBLOCKUNITS << 3) << FRACBITS) >> 3); + y = basey + ((M_RandomKey(MAPBLOCKUNITS << 3) << FRACBITS) >> 3); precipsector = R_IsPointInSubsector(x, y); From 13ad27bc9065a407642c6747d2a90e74b995fc26 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 12 Dec 2024 00:30:37 +0100 Subject: [PATCH 3/3] remove some precip code dupe --- src/p_spec.c | 89 ++++++++++++++++++---------------------------------- 1 file changed, 31 insertions(+), 58 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 2ab2c20df..2472c5dbf 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1807,27 +1807,23 @@ void P_SwitchWeather(INT32 weathernum) precipmobj = (precipmobj_t *)think; + mobjtype_t type = 0; + INT32 z = 0; + + if (swap == PRECIP_BLANK || swap == PRECIP_STORM_NORAIN) // Remove precip, but keep it around for reuse. + { + precipmobj->precipflags |= PCF_INVISIBLE; + continue; + } + if (swap == PRECIP_RAIN) // Snow To Rain { - precipmobj->type = MT_RAIN; // proper set the type - precipmobj->info = &mobjinfo[MT_RAIN]; - precipmobj->flags = mobjinfo[MT_RAIN].flags; - st = &states[mobjinfo[MT_RAIN].spawnstate]; - precipmobj->state = st; - precipmobj->tics = st->tics; - precipmobj->sprite = st->sprite; - precipmobj->frame = st->frame; - precipmobj->momz = cv_mobjscaleprecip.value ? FixedMul(mobjinfo[MT_RAIN].speed, mapobjectscale) : mobjinfo[MT_RAIN].speed; - - precipmobj->precipflags &= ~(PCF_INVISIBLE|PCF_SPLASH); // P_PrecipThinker will add this again if it needs to + type = MT_RAIN; } else if (swap == PRECIP_SNOW) // Rain To Snow { - INT32 z; + type = MT_SNOWFLAKE; - precipmobj->type = MT_SNOWFLAKE; // proper set the type - precipmobj->info = &mobjinfo[MT_SNOWFLAKE]; - precipmobj->flags = mobjinfo[MT_SNOWFLAKE].flags; z = M_RandomByte(); if (z < 64) @@ -1836,92 +1832,69 @@ void P_SwitchWeather(INT32 weathernum) z = 1; else z = 0; - - st = &states[mobjinfo[MT_SNOWFLAKE].spawnstate+z]; - precipmobj->state = st; - precipmobj->tics = st->tics; - precipmobj->sprite = st->sprite; - precipmobj->frame = st->frame; - precipmobj->momz = cv_mobjscaleprecip.value ? FixedMul(mobjinfo[MT_SNOWFLAKE].speed, mapobjectscale) : mobjinfo[MT_SNOWFLAKE].speed; - - precipmobj->precipflags &= ~(PCF_INVISIBLE|PCF_SPLASH); // P_PrecipThinker will add this again if it needs to - } - else if (swap == PRECIP_BLANK || swap == PRECIP_STORM_NORAIN) // Remove precip, but keep it around for reuse. - { - precipmobj->precipflags |= PCF_INVISIBLE; } + + precipmobj->type = type; // proper set the type + precipmobj->info = &mobjinfo[type]; + precipmobj->flags = mobjinfo[type].flags; + + st = &states[mobjinfo[type].spawnstate+z]; + + precipmobj->state = st; + precipmobj->tics = st->tics; + precipmobj->sprite = st->sprite; + precipmobj->frame = st->frame; + precipmobj->momz = (cv_mobjscaleprecip.value ? FixedMul(mobjinfo[type].speed, mapobjectscale) : mobjinfo[type].speed); + + precipmobj->precipflags &= ~(PCF_INVISIBLE|PCF_SPLASH); // P_PrecipThinker will add this again if it needs to } } + boolean dontspawn = false; + switch (weathernum) { case PRECIP_SNOW: // snow curWeather = PRECIP_SNOW; - - if (!swap) - P_SpawnPrecipitation(); - break; case PRECIP_RAIN: // rain { - boolean dontspawn = false; - if (curWeather == PRECIP_RAIN || curWeather == PRECIP_STORM || curWeather == PRECIP_STORM_NOSTRIKES) dontspawn = true; curWeather = PRECIP_RAIN; - - if (!dontspawn && !swap) - P_SpawnPrecipitation(); - break; } case PRECIP_STORM: // storm { - boolean dontspawn = false; - if (curWeather == PRECIP_RAIN || curWeather == PRECIP_STORM || curWeather == PRECIP_STORM_NOSTRIKES) dontspawn = true; curWeather = PRECIP_STORM; - - if (!dontspawn && !swap) - P_SpawnPrecipitation(); - break; } case PRECIP_STORM_NOSTRIKES: // storm w/o lightning { - boolean dontspawn = false; - if (curWeather == PRECIP_RAIN || curWeather == PRECIP_STORM || curWeather == PRECIP_STORM_NOSTRIKES) dontspawn = true; curWeather = PRECIP_STORM_NOSTRIKES; - - if (!dontspawn && !swap) - P_SpawnPrecipitation(); - break; } case PRECIP_STORM_NORAIN: // storm w/o rain curWeather = PRECIP_STORM_NORAIN; - - if (!swap) - P_SpawnPrecipitation(); - break; case PRECIP_BLANK: curWeather = PRECIP_BLANK; - - if (!swap) - P_SpawnPrecipitation(); - break; default: + dontspawn = true; curWeather = PRECIP_NONE; break; } + + if (!dontspawn && !swap) + P_SpawnPrecipitation(); } /** Gets an object.