Setting up for faster PRNG experimentation.

This commit is contained in:
Mari the Deer 2025-06-25 14:30:48 +02:00
commit 4374d54f27
11 changed files with 129 additions and 92 deletions

View file

@ -1,3 +1,3 @@
[default]
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r1226 \cu(jue 12 jun 2025 23:11:50 CEST)\c-";
SWWM_SHORTVER="\cw1.3pre r1226 \cu(2025-06-12 23:11:50)\c-";
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r1226 \cu(mié 25 jun 2025 14:30:48 CEST)\c-";
SWWM_SHORTVER="\cw1.3pre r1226 \cu(2025-06-25 14:30:48)\c-";

View file

@ -3,25 +3,15 @@
// enjoy getting bonked, you pervy perv
Class SWWMHDoomHandler : StaticEventHandler
{
Mixin SWWMUIRandom;
int callout_len;
ui int timer;
ui TextureID bonker, bonk, bonked;
bool detected;
ui int rss;
ui Font mBigFont;
private ui int GetUIRandom()
{
return (rss = (rss<<1)*35447+(rss/87));
}
private ui double RandomShiver()
{
int sd = GetUIRandom();
return ((abs(sd)%11)-5)*.1;
}
override void OnRegister()
{
if ( FindClass('HDoomPlayer','PlayerPawn') )
@ -104,7 +94,7 @@ Class SWWMHDoomHandler : StaticEventHandler
double oy = Screen.GetHeight()/2-4*scl;
String str = "HORNY";
double alf = clamp(16-((timer%16)+e.FracTic)*2,0,16)/16.;
rss = MSTime()/10;
SetUIRandom(MSTime()/10);
Vector2 ofs = (RandomShiver(),RandomShiver())*3.*scl*alf;
Screen.DrawText(mBigFont,Font.CR_SAPPHIRE,ox-(mBigFont.StringWidth(str)*scl*2)/2+ofs.x,oy+8*scl+ofs.y,str,DTA_ScaleX,scl*2,DTA_ScaleY,scl*2);
Screen.DrawText(mBigFont,Font.FindFontColor('MiniFlash'),ox-(mBigFont.StringWidth(str)*scl*2)/2+ofs.x,oy+8*scl+ofs.y,str,DTA_ScaleX,scl*2,DTA_ScaleY,scl*2,DTA_LegacyRenderStyle,STYLE_Add,DTA_Alpha,alf);

View file

@ -18,6 +18,8 @@
// (except Black Edition, that one is just embarrassing)
Class SWWMBrutalHandler : StaticEventHandler
{
Mixin SWWMUIRandom;
ui int timer;
ui Font fnt;
ui TextureID eztex[7];
@ -29,9 +31,6 @@ Class SWWMBrutalHandler : StaticEventHandler
ui double ezlinesw[5];
ui int ezcolor[5];
bool detected;
ui int rss;
const BOYTICRATE = 5;
override void OnRegister()
{
@ -150,23 +149,6 @@ Class SWWMBrutalHandler : StaticEventHandler
for ( int i=0; i<MAXPLAYERS; i++ ) if ( playeringame[i] ) players[i].cheats |= CF_TOTALLYFROZEN;
}
private ui int GetUIRandom()
{
return (rss = (rss<<1)*35447+(rss/87));
}
private ui double RandomShiver()
{
int sd = GetUIRandom();
return ((abs(sd)%11)-5)*.1;
}
private ui double RandomOffset()
{
int sd = GetUIRandom();
return (abs(sd)&65535)/65535.;
}
override void RenderOverlay( RenderEvent e )
{
if ( !detected ) return;
@ -178,13 +160,13 @@ Class SWWMBrutalHandler : StaticEventHandler
{
double fact = clamp(((timer+e.fractic)-300.)/100.,0.,1.);
Screen.Dim(0xFFFF0000,fact,0,0,Screen.GetWidth(),Screen.GetHeight(),STYLE_Add);
rss = MSTime()/10;
SetUIRandom(MSTime()/10);
pos.x += RandomShiver()*128.*hs*fact*fact;
pos.y += RandomShiver()*128.*hs*fact*fact;
}
Screen.SetClipRect(int(pos.x),int(pos.y),int(2800.*hs),int(2100.*hs));
Screen.Dim(0xFFFFFFFF,1.,int(pos.x),int(pos.y),int(2800.*hs),int(2100.*hs));
rss = MSTime()/40;
SetUIRandom(MSTime()/40);
for ( int i=0; i<6; i++ )
{
double ypos = RandomOffset()*2100.*hs;

View file

@ -3,6 +3,8 @@
Class SWWMHandler : EventHandler
{
Mixin SWWMUIRandom;
transient int lastlock;
transient int lastpickuptic[MAXPLAYERS]; // these two are mostly used
transient int lastnuggettic[MAXPLAYERS]; // to avoid deafening players

View file

@ -5,7 +5,6 @@ extend Class SWWMHandler
transient ui int kcode, klinger;
transient ui String kstr, klingerstr;
transient ui bool kfail;
transient ui int rss;
ui bool nostalgic;
ui Font CheatFont;
@ -456,23 +455,6 @@ extend Class SWWMHandler
return false;
}
private ui int GetUIRandom()
{
return (rss = (rss<<1)*35447+(rss/87));
}
private ui double RandomShiver()
{
int sd = GetUIRandom();
return ((abs(sd)%11)-5)*.1;
}
private ui int RandomFall()
{
int sd = GetUIRandom();
return ((abs(sd)%22)+10);
}
private ui void CheatOverlay( RenderEvent e )
{
// cheat input
@ -488,7 +470,7 @@ extend Class SWWMHandler
int width = (CheatFont.StringWidth(chstr)+3*(tlen-1));
double xx = int(Screen.GetWidth()-width*scl)/2;
double yy = int(Screen.GetHeight()-CheatFont.GetHeight()*scl)/2;
rss = (kcode>4)?gametic:klinger;
SetUIRandom((kcode>4)?gametic:klinger);
for ( int i=0, pos=0; i<tlen; i++ )
{
int ch;

View file

@ -86,6 +86,8 @@ Enum EMiniHUDFontColor
Class SWWMStatusBar : BaseStatusBar
{
Mixin SWWMUIRandom;
TextureID StatusTex, WeaponTex, ScoreTex, InventoryTex, ChatTex[6],
HealthTex[9], FuelTex[2], DashTex, EnemyBTex, EnemyHTex[7],
GenericAmmoTex[3], AmmoTex[3], MiniBox[2], bgtex, FaceTex[21];
@ -202,8 +204,6 @@ Class SWWMStatusBar : BaseStatusBar
int cummscoreup, cummspanup, cummflashup;
int cummscoredn, cummspandn, cummflashdn;
transient ui int rss;
// called by static handler when loading a game
// forcibly flushes our interpolators
void Flush()

View file

@ -64,17 +64,6 @@ extend Class SWWMStatusBar
}
}
private int GetRandom()
{
return (rss = (rss<<1)*35447+(rss/87));
}
private double RandomShiver()
{
int sd = GetRandom();
return ((abs(sd)%11)-5)*.1;
}
private int GetFaceTex( Demolitionist demo )
{
let facestate = demo.facestate;
@ -105,7 +94,7 @@ extend Class SWWMStatusBar
private void DrawMugshot()
{
rss = MSTime()*128;
SetUIRandom(MSTime()*128);
let demo = Demolitionist(CPlayer.mo);
if ( !demo ) return;
double paintime = clamp((demo.lastdamagetimer-(gametic+Fractic))/double(GameTicRate),0.,1.);

View file

@ -500,13 +500,14 @@ Class SWWMWeaponTooltip : HUDMessageBase
// Used sparingly for some events
Class SWWMDirectMessage : HUDMessageBase
{
Mixin SWWMUIRandom;
TextureID MessageBox, BG, Avatar, Blink[2], Talk[5], Noiz[4];
transient BrokenLines l;
String seqname, chrname, chrfullname;
bool znvspecial; // seqnum 2 string replacement
int seqnum, seqcnt, delay, charcnt, blinktics, talktics, talkframe;
int startdelay, enddelay, pausedelay, chardelay;
int rss;
int fadein, fadeout;
double hs;
Vector2 ss, origin;
@ -516,11 +517,6 @@ Class SWWMDirectMessage : HUDMessageBase
SWWMHandler hnd;
transient bool bDontResetMe; // savegame safeguard
private int GetRandom()
{
return (rss = (rss<<1)*35447+(rss/87));
}
virtual SWWMDirectMessage Init( String chrn, String chrfn, String texn )
{
MessageBox = TexMan.CheckForTexture("graphics/HUD/DM/DirectMessageBox.png");
@ -543,7 +539,7 @@ Class SWWMDirectMessage : HUDMessageBase
enddelay = 40;
pausedelay = 30;
chardelay = 1;
rss = 1232;
SetUIRandom(1232);
mSmallFont = Font.GetFont('TewiFont');
bDontResetMe = true;
return self;
@ -698,12 +694,12 @@ Class SWWMDirectMessage : HUDMessageBase
if ( blinktics <= 0 )
{
blinktics--;
if ( blinktics < -3 ) blinktics = (abs(GetRandom())%10)?(60+abs(GetRandom())%30):6;
if ( blinktics < -3 ) blinktics = (abs(GetUIRandom())%10)?(60+abs(GetUIRandom())%30):6;
}
else blinktics--;
if ( talktics > 0 )
{
if ( !(gametic%3) ) talkframe = (talkframe==-1)?(abs(GetRandom())%5):-1;
if ( !(gametic%3) ) talkframe = (talkframe==-1)?(abs(GetUIRandom())%5):-1;
talktics--;
}
else talkframe = -1;

View file

@ -12,6 +12,8 @@ Struct TitleExplosion
Class SWWMTitleStuff : EventHandler
{
Mixin SWWMUIRandom;
ui bool bInitialized;
ui TextureID tex[6];
ui TextureID letters[13];
@ -24,22 +26,10 @@ Class SWWMTitleStuff : EventHandler
ui TitleExplosion smk[64];
ui TextureID smk_frame[19];
ui int titletimer;
ui int rss;
ui int stopinit_t;
ui bool bFadeIn;
ui Font mSmallFont, mBigFont;
private ui int GetUIRandom()
{
return (rss = (rss<<1)*35447+(rss/87));
}
private ui double RandomShiver()
{
int sd = GetUIRandom();
return ((abs(sd)%11)-5)*.1;
}
private ui void TickExplosions()
{
if ( stopinit_t > 0 ) stopinit_t--;
@ -166,7 +156,7 @@ Class SWWMTitleStuff : EventHandler
Screen.Dim(0xFF000000,1.,0,0,Screen.GetWidth(),Screen.GetHeight());
if ( titletimer < -20 )
{
rss = int(MSTime()*(GameTicRate/1000.));
SetUIRandom(int(MSTime()*(GameTicRate/1000.)));
Vector2 ofs = (RandomShiver(),RandomShiver())*clamp((80+titletimer+e.FracTic)/50.,0.,1.);
tsize = TexMan.GetScaledSize(tex[3]);
ofs *= tsize.y/10.;

View file

@ -1,6 +1,9 @@
// facial animation and cosmetics
extend Class Demolitionist
{
// dirt-cheap PRNG
// (make sure to keep algo in sync w/ swwm_utility_math.zsc ver if it
// ever changes)
private int GetRandom()
{
return (rss = (rss<<1)*35447+(rss/87));

View file

@ -7,6 +7,12 @@ Struct SWWMProjectionData
int viewx, viewy, vieww, viewh;
}
Struct SWWMFRNGState
{
bool init;
uint x, y, z, w, v, d;
}
extend Class SWWMUtility
{
// cache some data that requires trig and quat math
@ -444,4 +450,101 @@ extend Class SWWMUtility
double yscale = dist*len;
return angle, pitch, yscale;
}
// XORWOW-based PRNG, the best and fastest we can really use in ZScript due to lack of 64-bit integers
private static uint XORWOW( SWWMFRNGState &rss )
{
if ( !rss.init )
{
rss.x = 123456789;
rss.y = 362436069;
rss.z = 521288629;
rss.w = 88675123;
rss.v = 5783321;
rss.d = 6615241;
rss.init = true;
}
uint t = rss.v;
uint s = rss.x;
rss.v = rss.w;
rss.w = rss.z;
rss.z = rss.y;
rss.y = s;
t ^= t>>2;
t ^= t<<1;
t ^= s^(s<<4);
rss.x = t;
rss.d += 362437;
return t+rss.d;
}
// the public-callable functions
static uint FastRand( SWWMFRNGState &rss, uint mod = 0 )
{
uint rslt = XORWOW(rss);
if ( mod ) return rslt%mod;
return rslt;
}
static int FastRandRange( SWWMFRNGState &rss, int low, int high )
{
if ( low >= high ) ThrowAbortException("FastRandomRange called with low >= high");
uint range = uint(high-low);
int rslt = int(FastRand(rss,range));
return low+rslt;
}
static double FastFRand( SWWMFRNGState &rss )
{
uint rslt = XORWOW(rss);
return rslt/double(uint.max);
}
static Vector3 FastVRand( SWWMFRNGState &rss )
{
double ang = FastFRand(rss)*360;
double pt = 90-FastFRand(rss)*180;
return (cos(ang)*cos(pt),sin(ang)*cos(pt),-sin(pt));
}
static Vector2 FastVRand2D( SWWMFRNGState &rss )
{
double ang = FastFRand(rss)*360;
return (cos(ang),sin(ang));
}
}
// ultrafast PRNG for a bunch of UI stuff
// kept here to reduce duplication and to tweak the (very cheap) algo if needed
Mixin Class SWWMUIRandom
{
private ui int rss;
private ui void SetUIRandom( int seed )
{
rss = seed;
}
private ui int GetUIRandom()
{
return (rss = (rss<<1)*35447+(rss/87));
}
private ui double RandomShiver()
{
int sd = GetUIRandom();
return ((abs(sd)%11)-5)*.1;
}
private ui int RandomFall()
{
int sd = GetUIRandom();
return ((abs(sd)%22)+10);
}
private ui double RandomOffset()
{
int sd = GetUIRandom();
return (abs(sd)&65535)/65535.;
}
}