Commit e846be2c authored by NY00123's avatar NY00123 Committed by Richard Gobeille
Browse files

Ken-Build, Duke3D, SW, mmulti: Replace rand with wrand almost everywhere.

Outside of 3rd party libraries, remaining uses are the Polymer-specific
macro LIGHTRAD2 within Duke3D, system_15bit_rand and vox2poly.
Also use WRANDOM_MAX in SW.
parent fbf1c846
...@@ -256,7 +256,7 @@ int netread(int *other, char *dabuf, int bufsiz) //0:no packets in buffer ...@@ -256,7 +256,7 @@ int netread(int *other, char *dabuf, int bufsiz) //0:no packets in buffer
if (recvfrom(mysock,dabuf,bufsiz,0,(struct sockaddr *)&ip,(socklen_t *)&i) == -1) return(0); if (recvfrom(mysock,dabuf,bufsiz,0,(struct sockaddr *)&ip,(socklen_t *)&i) == -1) return(0);
#if (SIMMIS > 0) #if (SIMMIS > 0)
if ((rand()&255) < SIMMIS) return(0); if ((wrand()&255) < SIMMIS) return(0);
#endif #endif
snatchip = (int)ip.sin_addr.s_addr; snatchport = (int)ip.sin_port; snatchip = (int)ip.sin_addr.s_addr; snatchport = (int)ip.sin_port;
......
...@@ -3931,7 +3931,7 @@ void G_DoSpriteAnimations(int32_t ourx, int32_t oury, int32_t ourz, int32_t oura ...@@ -3931,7 +3931,7 @@ void G_DoSpriteAnimations(int32_t ourx, int32_t oury, int32_t ourz, int32_t oura
if (g_curViewscreen >= 0 && actor[OW(i)].t_data[0] == 1) if (g_curViewscreen >= 0 && actor[OW(i)].t_data[0] == 1)
{ {
t->picnum = STATIC; t->picnum = STATIC;
t->cstat |= (rand()&12); t->cstat |= (wrand()&12);
t->xrepeat += 10; t->xrepeat += 10;
t->yrepeat += 9; t->yrepeat += 9;
} }
......
...@@ -2493,7 +2493,7 @@ void P_DisplayWeapon(void) ...@@ -2493,7 +2493,7 @@ void P_DisplayWeapon(void)
weaponYOffset -= sintable[(*weaponFrame)<<7]>>12; weaponYOffset -= sintable[(*weaponFrame)<<7]>>12;
if (doAnim) if (doAnim)
weaponX += 1-(rand()&3); weaponX += 1-(wrand()&3);
} }
if (WW2GI) if (WW2GI)
...@@ -2585,12 +2585,12 @@ void P_DisplayWeapon(void) ...@@ -2585,12 +2585,12 @@ void P_DisplayWeapon(void)
default: default:
if (*weaponFrame > PWEAPON(screenpeek, CHAINGUN_WEAPON, FireDelay) && *weaponFrame < PWEAPON(screenpeek, CHAINGUN_WEAPON, TotalTime)) if (*weaponFrame > PWEAPON(screenpeek, CHAINGUN_WEAPON, FireDelay) && *weaponFrame < PWEAPON(screenpeek, CHAINGUN_WEAPON, TotalTime))
{ {
int randomOffset = doAnim ? rand() & 7 : 0; int randomOffset = doAnim ? wrand() & 7 : 0;
G_DrawWeaponTile(randomOffset + weaponX - 4 + 140 - (pPlayer->look_ang >> 1), G_DrawWeaponTile(randomOffset + weaponX - 4 + 140 - (pPlayer->look_ang >> 1),
randomOffset + weaponY - ((*weaponFrame) >> 1) + 208 - weaponYOffset, CHAINGUN + 5 + ((*weaponFrame - 4) / 5), randomOffset + weaponY - ((*weaponFrame) >> 1) + 208 - weaponYOffset, CHAINGUN + 5 + ((*weaponFrame - 4) / 5),
weaponShade, weaponBits, weaponPal); weaponShade, weaponBits, weaponPal);
if (doAnim) if (doAnim)
randomOffset = rand() & 7; randomOffset = wrand() & 7;
G_DrawWeaponTile(randomOffset + weaponX - 4 + 184 - (pPlayer->look_ang >> 1), G_DrawWeaponTile(randomOffset + weaponX - 4 + 184 - (pPlayer->look_ang >> 1),
randomOffset + weaponY - ((*weaponFrame) >> 1) + 208 - weaponYOffset, CHAINGUN + 5 + ((*weaponFrame - 4) / 5), randomOffset + weaponY - ((*weaponFrame) >> 1) + 208 - weaponYOffset, CHAINGUN + 5 + ((*weaponFrame - 4) / 5),
weaponShade, weaponBits, weaponPal); weaponShade, weaponBits, weaponPal);
...@@ -2598,7 +2598,7 @@ void P_DisplayWeapon(void) ...@@ -2598,7 +2598,7 @@ void P_DisplayWeapon(void)
if (*weaponFrame < PWEAPON(screenpeek, CHAINGUN_WEAPON, TotalTime) - 4) if (*weaponFrame < PWEAPON(screenpeek, CHAINGUN_WEAPON, TotalTime) - 4)
{ {
int const randomOffset = doAnim ? rand() & 7 : 0; int const randomOffset = doAnim ? wrand() & 7 : 0;
G_DrawWeaponTile(randomOffset + weaponX - 4 + 162 - (pPlayer->look_ang >> 1), G_DrawWeaponTile(randomOffset + weaponX - 4 + 162 - (pPlayer->look_ang >> 1),
randomOffset + weaponY - ((*weaponFrame) >> 1) + 208 - weaponYOffset, CHAINGUN + 5 + ((*weaponFrame - 2) / 5), randomOffset + weaponY - ((*weaponFrame) >> 1) + 208 - weaponYOffset, CHAINGUN + 5 + ((*weaponFrame - 2) / 5),
weaponShade, weaponBits, weaponPal); weaponShade, weaponBits, weaponPal);
...@@ -2827,8 +2827,8 @@ void P_DisplayWeapon(void) ...@@ -2827,8 +2827,8 @@ void P_DisplayWeapon(void)
if (doAnim) if (doAnim)
{ {
weaponX += rand() & 3; weaponX += wrand() & 3;
weaponY += rand() & 3; weaponY += wrand() & 3;
} }
weaponYOffset -= 16; weaponYOffset -= 16;
G_DrawWeaponTile(weaponX + 210 - (pPlayer->look_ang >> 1), weaponY + 261 - weaponYOffset, WORLDTOUR ? FREEZEFIREWIDE : FREEZE + 2, -32, G_DrawWeaponTile(weaponX + 210 - (pPlayer->look_ang >> 1), weaponY + 261 - weaponYOffset, WORLDTOUR ? FREEZEFIREWIDE : FREEZE + 2, -32,
...@@ -2848,8 +2848,8 @@ void P_DisplayWeapon(void) ...@@ -2848,8 +2848,8 @@ void P_DisplayWeapon(void)
if (doAnim) if (doAnim)
{ {
weaponX += rand() & 1; weaponX += wrand() & 1;
weaponY += rand() & 1; weaponY += wrand() & 1;
} }
weaponYOffset -= 16; weaponYOffset -= 16;
G_DrawWeaponTile(weaponX + 210 - (pPlayer->look_ang >> 1), weaponY + 261 - weaponYOffset, FLAMETHROWERFIRE, -32, weaponBits & ~RS_LERP, weaponPal, G_DrawWeaponTile(weaponX + 210 - (pPlayer->look_ang >> 1), weaponY + 261 - weaponYOffset, FLAMETHROWERFIRE, -32, weaponBits & ~RS_LERP, weaponPal,
...@@ -2899,8 +2899,8 @@ void P_DisplayWeapon(void) ...@@ -2899,8 +2899,8 @@ void P_DisplayWeapon(void)
// the 'active' display. // the 'active' display.
if (doAnim) if (doAnim)
{ {
weaponX += rand() & 3; weaponX += wrand() & 3;
weaponYOffset += rand() & 3; weaponYOffset += wrand() & 3;
} }
int const totalTime = PWEAPON(screenpeek, pPlayer->curr_weapon, TotalTime); int const totalTime = PWEAPON(screenpeek, pPlayer->curr_weapon, TotalTime);
...@@ -2937,8 +2937,8 @@ void P_DisplayWeapon(void) ...@@ -2937,8 +2937,8 @@ void P_DisplayWeapon(void)
{ {
if (doAnim) if (doAnim)
{ {
weaponX += rand() & 3; weaponX += wrand() & 3;
weaponYOffset += (rand() & 3); weaponYOffset += (wrand() & 3);
} }
G_DrawWeaponTileUnfaded(weaponX + 184 - halfLookAng, weaponY + 240 - weaponYOffset, SHRINKER + 3 + ((*weaponFrame) & 3), -32, G_DrawWeaponTileUnfaded(weaponX + 184 - halfLookAng, weaponY + 240 - weaponYOffset, SHRINKER + 3 + ((*weaponFrame) & 3), -32,
...@@ -3605,7 +3605,7 @@ access_incs: ...@@ -3605,7 +3605,7 @@ access_incs:
if (totalclock > 1024) if (totalclock > 1024)
if (playerNum == screenpeek || GTFLAGS(GAMETYPE_COOPSOUND)) if (playerNum == screenpeek || GTFLAGS(GAMETYPE_COOPSOUND))
{ {
if (rand()&1) if (wrand()&1)
A_PlaySound(DUKE_CRACK,pPlayer->i); A_PlaySound(DUKE_CRACK,pPlayer->i);
else A_PlaySound(DUKE_CRACK2,pPlayer->i); else A_PlaySound(DUKE_CRACK2,pPlayer->i);
} }
......
...@@ -2411,7 +2411,7 @@ void G_BonusScreen(int32_t bonusonly) ...@@ -2411,7 +2411,7 @@ void G_BonusScreen(int32_t bonusonly)
{ {
bonuscnt++; bonuscnt++;
S_PlaySound(SHOTGUN_COCK); S_PlaySound(SHOTGUN_COCK);
switch (rand()&3) switch (wrand()&3)
{ {
case 0: case 0:
S_PlaySound(BONUS_SPEECH1); S_PlaySound(BONUS_SPEECH1);
......
...@@ -581,7 +581,7 @@ static inline int S_GetPitch(int num) ...@@ -581,7 +581,7 @@ static inline int S_GetPitch(int num)
auto const &snd = g_sounds[num]; auto const &snd = g_sounds[num];
int const range = klabs(snd.pe - snd.ps); int const range = klabs(snd.pe - snd.ps);
return (range == 0) ? snd.ps : min(snd.ps, snd.pe) + rand() % range; return (range == 0) ? snd.ps : min(snd.ps, snd.pe) + wrand() % range;
} }
static int S_TakeSlot(int soundNum) static int S_TakeSlot(int soundNum)
......
...@@ -251,9 +251,9 @@ int32_t S_PlaySound3D(int32_t const num, int32_t i, const vec3_t *pos) ...@@ -251,9 +251,9 @@ int32_t S_PlaySound3D(int32_t const num, int32_t i, const vec3_t *pos)
if (cx) if (cx)
{ {
if (pitchs < pitche) if (pitchs < pitche)
pitch = pitchs + (rand()%cx); pitch = pitchs + (wrand()%cx);
else else
pitch = pitche + (rand()%cx); pitch = pitche + (wrand()%cx);
} }
else else
pitch = pitchs; pitch = pitchs;
...@@ -360,9 +360,9 @@ void S_PlaySound(int32_t const num) ...@@ -360,9 +360,9 @@ void S_PlaySound(int32_t const num)
if (cx) if (cx)
{ {
if (pitchs < pitche) if (pitchs < pitche)
pitch = pitchs + (rand()%cx); pitch = pitchs + (wrand()%cx);
else else
pitch = pitche + (rand()%cx); pitch = pitche + (wrand()%cx);
} }
else else
pitch = pitchs; pitch = pitchs;
......
...@@ -5094,8 +5094,8 @@ void movelava(char *dapic) ...@@ -5094,8 +5094,8 @@ void movelava(char *dapic)
for (z=min(LAVAMAXDROPS-lavanumdrops-1,3); z>=0; z--) for (z=min(LAVAMAXDROPS-lavanumdrops-1,3); z>=0; z--)
{ {
lavadropx[lavanumdrops] = (rand()&(LAVASIZ-1)); lavadropx[lavanumdrops] = (wrand()&(LAVASIZ-1));
lavadropy[lavanumdrops] = (rand()&(LAVASIZ-1)); lavadropy[lavanumdrops] = (wrand()&(LAVASIZ-1));
lavadropsiz[lavanumdrops] = 1; lavadropsiz[lavanumdrops] = 1;
lavanumdrops++; lavanumdrops++;
} }
...@@ -5919,7 +5919,7 @@ void getpackets(void) ...@@ -5919,7 +5919,7 @@ void getpackets(void)
} }
if ((networkmode == 0) && (myconnectindex != connecthead) && ((movecnt&1) == 0)) if ((networkmode == 0) && (myconnectindex != connecthead) && ((movecnt&1) == 0))
{ {
if (rand()&1) ototalclock += (TICSPERFRAME>>1); if (wrand()&1) ototalclock += (TICSPERFRAME>>1);
else ototalclock -= (TICSPERFRAME>>1); else ototalclock -= (TICSPERFRAME>>1);
} }
} }
......
...@@ -5957,14 +5957,14 @@ StdRandomRange(int range) ...@@ -5957,14 +5957,14 @@ StdRandomRange(int range)
rand_num = STD_RANDOM(); rand_num = STD_RANDOM();
if (rand_num == RAND_MAX) if (rand_num == WRAND_MAX)
rand_num--; rand_num--;
// shift values to give more precision // shift values to give more precision
#if (RAND_MAX > 0x7fff) #if (WRAND_MAX > 0x7fff)
value = rand_num / (((int)RAND_MAX) / range); value = rand_num / (((int)WRAND_MAX) / range);
#else #else
value = (rand_num << 14) / ((((int)RAND_MAX) << 14) / range); value = (rand_num << 14) / ((((int)WRAND_MAX) << 14) / range);
#endif #endif
if (value >= (uint32_t)range) if (value >= (uint32_t)range)
......
...@@ -397,9 +397,9 @@ static fix16_t FORCE_INLINE PedanticQ16AngleFloor(fix16_t ang) ...@@ -397,9 +397,9 @@ static fix16_t FORCE_INLINE PedanticQ16AngleFloor(fix16_t ang)
} }
int StdRandomRange(int range); int StdRandomRange(int range);
#define STD_RANDOM_P2(pwr_of_2) (MOD_P2(rand(),(pwr_of_2))) #define STD_RANDOM_P2(pwr_of_2) (MOD_P2(wrand(),(pwr_of_2)))
#define STD_RANDOM_RANGE(range) (StdRandomRange(range)) #define STD_RANDOM_RANGE(range) (StdRandomRange(range))
#define STD_RANDOM() (rand()) #define STD_RANDOM() (wrand())
#if 0 #if 0
// TODO: PedanticMode // TODO: PedanticMode
......
...@@ -792,7 +792,7 @@ void computergetinput(int snum, SW_PACKET *syn) ...@@ -792,7 +792,7 @@ void computergetinput(int snum, SW_PACKET *syn)
{ {
for (k=0; k<4; k++) for (k=0; k<4; k++)
{ {
i = (rand()%numsectors); i = (wrand()%numsectors);
for (j=headspritesect[i]; j>=0; j=nextspritesect[j]) for (j=headspritesect[i]; j>=0; j=nextspritesect[j])
{ {
if ((sprite[j].xrepeat <= 0) || (sprite[j].yrepeat <= 0)) continue; if ((sprite[j].xrepeat <= 0) || (sprite[j].yrepeat <= 0)) continue;
......
...@@ -3111,8 +3111,8 @@ void movelava(char *dapic) ...@@ -3111,8 +3111,8 @@ void movelava(char *dapic)
z = LAVAMAXDROPS - lavanumdrops - 1; z = LAVAMAXDROPS - lavanumdrops - 1;
while (z >= 0) while (z >= 0)
{ {
lavadropx[lavanumdrops] = (rand() & (LAVASIZ - 1)); lavadropx[lavanumdrops] = (wrand() & (LAVASIZ - 1));
lavadropy[lavanumdrops] = (rand() & (LAVASIZ - 1)); lavadropy[lavanumdrops] = (wrand() & (LAVASIZ - 1));
lavadropsiz[lavanumdrops] = 1; lavadropsiz[lavanumdrops] = 1;
lavanumdrops++; lavanumdrops++;
z--; z--;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment