From 864e3e34425e021393bc1d4586d72def7ac52657 Mon Sep 17 00:00:00 2001 From: Brad Harding Date: Sat, 12 Oct 2024 09:55:35 +1100 Subject: [PATCH] Use separate fuzztable, etc. for player weapon fuzz effect --- src/m_random.c | 3 ++- src/m_random.h | 25 ++++++++++++++++++------- src/p_setup.c | 3 ++- src/r_draw.c | 25 ++++++++++++++----------- src/r_draw.h | 9 ++++++--- src/r_main.c | 5 ++++- src/r_things.c | 6 +++--- src/v_video.c | 16 ++++++++-------- 8 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/m_random.c b/src/m_random.c index 06da440e4..14db79dff 100644 --- a/src/m_random.c +++ b/src/m_random.c @@ -39,7 +39,8 @@ unsigned int seed; unsigned int bigseed; -unsigned int fuzzseed; +unsigned int fuzz1seed; +unsigned int fuzz2seed; // MBF21: [XA] Common random formulas used by codepointers diff --git a/src/m_random.h b/src/m_random.h index 556bf6a3c..c6dd04f92 100644 --- a/src/m_random.h +++ b/src/m_random.h @@ -38,11 +38,11 @@ #include "m_fixed.h" #define BIGSEED 1 -#define FUZZSEED 1 #define RAND rndtable[(seed = (seed + 1) & 255)] #define BIGRAND ((bigseed = 214013 * bigseed + 2531011) >> 16) -#define FUZZRAND ((fuzzseed = 214013 * fuzzseed + 2531011) >> 16) +#define FUZZ1RAND ((fuzz1seed = 214013 * fuzz1seed + 2531011) >> 16) +#define FUZZ2RAND ((fuzz2seed = 214013 * fuzz2seed + 2531011) >> 16) static const unsigned char rndtable[] = { @@ -66,7 +66,8 @@ static const unsigned char rndtable[] = extern unsigned int seed; extern unsigned int bigseed; -extern unsigned int fuzzseed; +extern unsigned int fuzz1seed; +extern unsigned int fuzz2seed; int P_RandomHitscanAngle(const fixed_t spread); int P_RandomHitscanSlope(const fixed_t spread); @@ -131,12 +132,22 @@ static inline void M_BigSeed(const unsigned int value) bigseed = value; } -static inline int M_FuzzRandomInt(const int lower, const int upper) +static inline int M_Fuzz1RandomInt(const int lower, const int upper) { - return (FUZZRAND % (upper - lower + 1) + lower); + return (FUZZ1RAND % (upper - lower + 1) + lower); } -static inline void M_FuzzSeed(const unsigned int value) +static inline void M_Fuzz1Seed(const unsigned int value) { - fuzzseed = value; + fuzz1seed = value; +} + +static inline int M_Fuzz2RandomInt(const int lower, const int upper) +{ + return (FUZZ2RAND % (upper - lower + 1) + lower); +} + +static inline void M_Fuzz2Seed(const unsigned int value) +{ + fuzz2seed = value; } diff --git a/src/p_setup.c b/src/p_setup.c index 3bfed360b..9a32d637c 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2027,7 +2027,8 @@ static void P_LoadThings(int map, int lump) M_Seed((unsigned int)time(NULL)); M_BigSeed((unsigned int)time(NULL)); - M_FuzzSeed((unsigned int)time(NULL)); + M_Fuzz1Seed((unsigned int)time(NULL)); + M_Fuzz2Seed((unsigned int)time(NULL)); W_ReleaseLumpNum(lump); } diff --git a/src/r_draw.c b/src/r_draw.c index 2f305f066..fe9935ab1 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -54,8 +54,10 @@ int viewwindowx; int viewwindowy; int fuzzrange[3]; -int fuzzpos; -int fuzztable[MAXSCREENAREA]; +int fuzz1pos; +int fuzz2pos; +int fuzz1table[MAXSCREENAREA]; +int fuzz2table[MAXSCREENAREA]; static byte *ylookup0[MAXHEIGHT]; static byte *ylookup1[MAXHEIGHT]; @@ -1050,24 +1052,24 @@ void R_DrawFuzzColumn(void) // top if (dc_yl >= 2) - BIGFUZZYPIXEL(8, (fuzztable[fuzzpos++] = FUZZ(-1, 1))); + BIGFUZZYPIXEL(8, (fuzz1table[fuzz1pos++] = FUZZ1(-1, 1))); else - BIGFUZZYPIXEL(6, (fuzztable[fuzzpos++] = FUZZ(0, 1))); + BIGFUZZYPIXEL(6, (fuzz1table[fuzz1pos++] = FUZZ1(0, 1))); dest += SCREENWIDTH * 2; while (--count) { // middle - BIGFUZZYPIXEL(6, (fuzztable[fuzzpos++] = FUZZ(-1, 1))); + BIGFUZZYPIXEL(6, (fuzz1table[fuzz1pos++] = FUZZ1(-1, 1))); dest += SCREENWIDTH * 2; } // bottom if (dc_yl & 1) - HALFBIGFUZZYPIXEL(5, (fuzztable[fuzzpos++] = FUZZ(-1, 0))); + HALFBIGFUZZYPIXEL(5, (fuzz1table[fuzz1pos++] = FUZZ1(-1, 0))); else - BIGFUZZYPIXEL(5, (fuzztable[fuzzpos++] = FUZZ(-1, 0))); + BIGFUZZYPIXEL(5, (fuzz1table[fuzz1pos++] = FUZZ1(-1, 0))); } void R_DrawFuzzColumns(void) @@ -1085,11 +1087,11 @@ void R_DrawFuzzColumns(void) byte *dest = screens[0] + x; if (y == height - SCREENWIDTH * 2) - BIGFUZZYPIXEL(5, (fuzztable[fuzzpos++] = FUZZ(-1, 0))); + BIGFUZZYPIXEL(5, (fuzz2table[fuzz2pos++] = FUZZ2(-1, 0))); else if (y >= SCREENWIDTH * 2 && *(source - SCREENWIDTH * 2) == NOFUZZ) - BIGFUZZYPIXEL(8, (fuzztable[fuzzpos++] = FUZZ(-1, 1))); + BIGFUZZYPIXEL(8, (fuzz2table[fuzz2pos++] = FUZZ2(-1, 1))); else - BIGFUZZYPIXEL(6, (fuzztable[fuzzpos++] = FUZZ(-1, 1))); + BIGFUZZYPIXEL(6, (fuzz2table[fuzz2pos++] = FUZZ2(-1, 1))); } } } @@ -1304,7 +1306,8 @@ void R_InitBuffer(void) fuzzrange[1] = 0; fuzzrange[2] = SCREENWIDTH * 2; - memset(fuzztable, 0, MAXSCREENAREA); + memset(fuzz1table, 0, MAXSCREENAREA); + memset(fuzz2table, 0, MAXSCREENAREA); } void R_FillBezel(void) diff --git a/src/r_draw.h b/src/r_draw.h index 46a102e07..40ca8e521 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -37,7 +37,8 @@ #include "m_random.h" -#define FUZZ(a, b) fuzzrange[M_FuzzRandomInt(a, b) + 1] +#define FUZZ1(a, b) fuzzrange[M_Fuzz1RandomInt(a, b) + 1] +#define FUZZ2(a, b) fuzzrange[M_Fuzz2RandomInt(a, b) + 1] #define BIGFUZZYPIXEL(a, b) *dest = *(dest + 1) = *(dest + SCREENWIDTH) = *(dest + SCREENWIDTH + 1) = \ fullcolormap[(a) * 256 + dest[b]] #define HALFBIGFUZZYPIXEL(a, b) *dest = *(dest + 1) = fullcolormap[(a) * 256 + dest[b]] @@ -67,9 +68,11 @@ extern byte *dc_black40; // first pixel in a column extern byte *dc_source; -extern int fuzzpos; +extern int fuzz1pos; +extern int fuzz2pos; extern int fuzzrange[3]; -extern int fuzztable[MAXSCREENAREA]; +extern int fuzz1table[MAXSCREENAREA]; +extern int fuzz2table[MAXSCREENAREA]; // The span blitting interface. // Hook in assembler or system specific BLT here. diff --git a/src/r_main.c b/src/r_main.c index 1eb9566d8..91176dc9b 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1173,7 +1173,10 @@ void R_RenderPlayerView(void) R_DrawPlanes(); if (consoleactive || freeze) - M_FuzzSeed(0); + { + M_Fuzz1Seed(0); + M_Fuzz2Seed(0); + } R_DrawMasked(); diff --git a/src/r_things.c b/src/r_things.c index de0cd73eb..99a399107 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -484,7 +484,7 @@ static void R_DrawVisSprite(const vissprite_t *vis) sprtopscreen = (int64_t)centeryfrac - FixedMul(dc_texturemid, spryscale); baseclip = (vis->footclip ? (int)(sprtopscreen + vis->footclip) >> FRACBITS : viewheight); - fuzzpos = 0; + fuzz1pos = 0; for (dc_x = vis->x1; dc_x <= x2; dc_x++, frac += xiscale) { @@ -559,7 +559,7 @@ static void R_DrawVisSpriteWithShadow(const vissprite_t *vis) shadowcolfunc = mobj->shadowcolfunc; shadowtopscreen = centeryfrac - FixedMul(vis->shadowpos, spryscale); shadowshift = (shadowtopscreen * 9 / 10) >> FRACBITS; - fuzzpos = 0; + fuzz1pos = 0; for (dc_x = vis->x1; dc_x <= x2; dc_x++, frac += xiscale) { @@ -1206,7 +1206,7 @@ static void R_DrawPlayerSprites(void) // add all active psprites if (invisibility && (invisibility > STARTFLASHING || (invisibility & FLASHONTIC))) { - fuzzpos = 0; + fuzz2pos = 0; V_FillRect(1, viewwindowx, viewwindowy, viewwidth, viewheight, PINK, 0, false, false, NULL, NULL); R_DrawPlayerSprite(weapon, true, (weaponstate->dehacked || altered)); diff --git a/src/v_video.c b/src/v_video.c index 0f30949bf..41992d51e 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1511,7 +1511,7 @@ void V_DrawFuzzPatch(int x, int y, patch_t *patch) x -= SHORT(patch->leftoffset); x += WIDESCREENDELTA; - fuzzpos = 0; + fuzz1pos = 0; desttop = &screens[0][((y * DY) >> FRACBITS) * SCREENWIDTH + ((x * DX) >> FRACBITS)]; @@ -1529,13 +1529,13 @@ void V_DrawFuzzPatch(int x, int y, patch_t *patch) { if (count & 1) { - fuzzpos++; + fuzz1pos++; if (!menuactive && !consoleactive && !paused) - fuzztable[fuzzpos] = FUZZ(-1, 1); + fuzz1table[fuzz1pos] = FUZZ1(-1, 1); } - *dest = fullcolormap[6 * 256 + dest[fuzztable[fuzzpos]]]; + *dest = fullcolormap[6 * 256 + dest[fuzz1table[fuzz1pos]]]; dest += SCREENWIDTH; } @@ -1553,7 +1553,7 @@ void V_DrawFlippedFuzzPatch(int x, int y, patch_t *patch) x -= SHORT(patch->leftoffset); x += WIDESCREENDELTA; - fuzzpos = 0; + fuzz1pos = 0; desttop = &screens[0][((y * DY) >> FRACBITS) * SCREENWIDTH + ((x * DX) >> FRACBITS)]; @@ -1571,13 +1571,13 @@ void V_DrawFlippedFuzzPatch(int x, int y, patch_t *patch) { if (count & 1) { - fuzzpos++; + fuzz1pos++; if (!menuactive && !consoleactive && !paused) - fuzztable[fuzzpos] = FUZZ(-1, 1); + fuzz1table[fuzz1pos] = FUZZ1(-1, 1); } - *dest = fullcolormap[6 * 256 + dest[fuzztable[fuzzpos]]]; + *dest = fullcolormap[6 * 256 + dest[fuzz1table[fuzz1pos]]]; dest += SCREENWIDTH; }