Skip to content

Commit

Permalink
Reworked FRandom constructors
Browse files Browse the repository at this point in the history
Removes ambiguity while keeping old constructor syntax in check for better overall portability.
  • Loading branch information
Boondorl authored and RicardoLuis0 committed Nov 16, 2024
1 parent a1a4a97 commit 3ea5be1
Show file tree
Hide file tree
Showing 42 changed files with 130 additions and 119 deletions.
2 changes: 1 addition & 1 deletion src/bbannouncer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static const char *TelefragSounds[] =
#endif

static int LastAnnounceTime;
static FRandom pr_bbannounce ("BBAnnounce", true);
static FCRandom pr_bbannounce ("BBAnnounce");

// CODE --------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/common/audio/sound/s_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum
{
DEFAULT_PITCH = 128,
};
static FRandom pr_soundpitch ("SoundPitch", true);
static FCRandom pr_soundpitch ("SoundPitch");
SoundEngine* soundEngine;

//==========================================================================
Expand Down
8 changes: 4 additions & 4 deletions src/common/engine/m_random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@

// EXTERNAL DATA DECLARATIONS ----------------------------------------------

FRandom pr_exrandom("EX_Random", false);
FRandom pr_exrandom("EX_Random");

// PUBLIC DATA DEFINITIONS -------------------------------------------------

FRandom M_Random(true);
FCRandom M_Random;

// Global seed. This is modified predictably to initialize every RNG.
uint32_t rngseed;
Expand Down Expand Up @@ -145,7 +145,7 @@ FRandom::FRandom (bool client)
#ifndef NDEBUG
Name = NULL;
#endif
if (client)
if (bClient)
{
Next = CRNGList;
CRNGList = this;
Expand Down Expand Up @@ -178,7 +178,7 @@ FRandom::FRandom (const char *name, bool client) : bClient(client)
#endif

// Insert the RNG in the list, sorted by CRC
FRandom **prev = (client ? &CRNGList : &RNGList), * probe = (client ? CRNGList : RNGList);
FRandom **prev = (bClient ? &CRNGList : &RNGList), * probe = (bClient ? CRNGList : RNGList);

while (probe != NULL && probe->NameCRC < NameCRC)
{
Expand Down
19 changes: 15 additions & 4 deletions src/common/engine/m_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class FSerializer;
class FRandom : public SFMTObj
{
public:
FRandom (bool client);
FRandom (const char *name, bool client);
~FRandom ();
FRandom() : FRandom(false) {}
FRandom(const char* name) : FRandom(name, false) {}
~FRandom();

int Seed() const
{
Expand Down Expand Up @@ -178,6 +178,10 @@ class FRandom : public SFMTObj
static void StaticPrintSeeds ();
#endif

protected:
FRandom(bool client);
FRandom(const char* name, bool client);

private:
#ifndef NDEBUG
const char *Name;
Expand All @@ -189,13 +193,20 @@ class FRandom : public SFMTObj
static FRandom *RNGList, *CRNGList;
};

class FCRandom : public FRandom
{
public:
FCRandom() : FRandom(true) {}
FCRandom(const char* name) : FRandom(name, true) {}
};

extern uint32_t rngseed; // The starting seed (not part of state)

extern uint32_t staticrngseed; // Static rngseed that can be set by the user
extern bool use_staticrng;


// M_Random can be used for numbers that do not affect gameplay
extern FRandom M_Random;
extern FCRandom M_Random;

#endif
2 changes: 1 addition & 1 deletion src/d_netinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "gstrings.h"
#include "g_game.h"

static FRandom pr_pickteam ("PickRandomTeam", false);
static FRandom pr_pickteam ("PickRandomTeam");

CVAR (Float, autoaim, 35.f, CVAR_USERINFO | CVAR_ARCHIVE);
CVAR (String, name, "Player", CVAR_USERINFO | CVAR_ARCHIVE);
Expand Down
4 changes: 2 additions & 2 deletions src/g_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
#include "fs_findfile.h"


static FRandom pr_dmspawn ("DMSpawn", false);
static FRandom pr_pspawn ("PlayerSpawn", false);
static FRandom pr_dmspawn ("DMSpawn");
static FRandom pr_pspawn ("PlayerSpawn");

extern int startpos, laststartpos;

Expand Down
2 changes: 1 addition & 1 deletion src/g_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ ELightMode getRealLightmode(FLevelLocals* Level, bool for3d)

CVAR(Int, sv_alwaystally, 0, CVAR_SERVERINFO)

static FRandom pr_classchoice ("RandomPlayerClassChoice", false);
static FRandom pr_classchoice ("RandomPlayerClassChoice");

extern level_info_t TheDefaultLevelInfo;
extern bool timingdemo;
Expand Down
4 changes: 2 additions & 2 deletions src/g_statusbar/sbarinfo_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3225,9 +3225,9 @@ class CommandDrawGem : public SBarInfoCommand
int goalValue;
private:
int chainWiggle;
static FRandom pr_chainwiggle;
static FCRandom pr_chainwiggle;
};
FRandom CommandDrawGem::pr_chainwiggle(true); //use the same method of chain wiggling as heretic.
FCRandom CommandDrawGem::pr_chainwiggle; //use the same method of chain wiggling as heretic.

////////////////////////////////////////////////////////////////////////////////

Expand Down
4 changes: 2 additions & 2 deletions src/gamedata/decallib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ static TArray<uint8_t> DecalTranslations;
// Sometimes two machines in a game will disagree on the state of
// decals. I do not know why.

static FRandom pr_decalchoice ("DecalChoice", true);
static FRandom pr_decal ("Decal", true);
static FCRandom pr_decalchoice ("DecalChoice");
static FCRandom pr_decal ("Decal");

class FDecalGroup : public FDecalBase
{
Expand Down
2 changes: 1 addition & 1 deletion src/gamedata/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern void InitBotStuff();
extern void ClearStrifeTypes();

TArray<PClassActor *> PClassActor::AllActorClasses;
FRandom FState::pr_statetics("StateTics", false);
FRandom FState::pr_statetics("StateTics");

cycle_t ActionCycles;

Expand Down
2 changes: 1 addition & 1 deletion src/gamedata/textures/animations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ FTextureAnimator TexAnim;

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static FRandom pr_animatepictures ("AnimatePics", true);
static FCRandom pr_animatepictures ("AnimatePics");

// CODE --------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/p_conversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#include "doommenu.h"
#include "g_game.h"

static FRandom pr_randomspeech("RandomSpeech", true);
static FCRandom pr_randomspeech("RandomSpeech");

static int ConversationMenuY;

Expand Down
2 changes: 1 addition & 1 deletion src/playsim/a_dynlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

static FMemArena DynLightArena(sizeof(FDynamicLight) * 200);
static TArray<FDynamicLight*> FreeList;
static FRandom randLight(true);
static FCRandom randLight;

extern TArray<FLightDefaults *> StateLights;

Expand Down
2 changes: 1 addition & 1 deletion src/playsim/a_specialspot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "a_pickups.h"
#include "vm.h"

static FRandom pr_spot ("SpecialSpot", false);
static FRandom pr_spot ("SpecialSpot");

IMPLEMENT_CLASS(DSpotState, false, false)

Expand Down
2 changes: 1 addition & 1 deletion src/playsim/bots/b_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include "p_checkposition.h"
#include "actorinlines.h"

static FRandom pr_botdofire ("BotDoFire", false);
static FRandom pr_botdofire ("BotDoFire");


//Checks TRUE reachability from bot to a looker.
Expand Down
2 changes: 1 addition & 1 deletion src/playsim/bots/b_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Everything that is changed is marked (maybe commented) with "Added by MC"
#include "i_system.h" // for SHARE_DIR
#endif // !_WIN32 && !__APPLE__

static FRandom pr_botspawn ("BotSpawn", false);
static FRandom pr_botspawn ("BotSpawn");

cycle_t BotThinkCycles, BotSupportCycles;
int BotWTG;
Expand Down
6 changes: 3 additions & 3 deletions src/playsim/bots/b_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
#include "p_checkposition.h"
#include "actorinlines.h"

static FRandom pr_botopendoor ("BotOpenDoor", false);
static FRandom pr_bottrywalk ("BotTryWalk", false);
static FRandom pr_botnewchasedir ("BotNewChaseDir", false);
static FRandom pr_botopendoor ("BotOpenDoor");
static FRandom pr_bottrywalk ("BotTryWalk");
static FRandom pr_botnewchasedir ("BotNewChaseDir");

// borrow some tables from p_enemy.cpp
extern dirtype_t opposite[9];
Expand Down
2 changes: 1 addition & 1 deletion src/playsim/bots/b_think.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "d_player.h"
#include "actorinlines.h"

static FRandom pr_botmove ("BotMove", false);
static FRandom pr_botmove ("BotMove");

//This function is called each tic for each bot,
//so this is what the bot does.
Expand Down
2 changes: 1 addition & 1 deletion src/playsim/fragglescript/t_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

using namespace FileSys;

static FRandom pr_script("FScript", false);
static FRandom pr_script("FScript");

// functions. FParser::SF_ means Script Function not, well.. heh, me

Expand Down
2 changes: 1 addition & 1 deletion src/playsim/mapthinkers/a_lightning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "gi.h"
#include <vm.h>

static FRandom pr_lightning ("Lightning", false);
static FRandom pr_lightning ("Lightning");

IMPLEMENT_CLASS(DLightningThinker, false, false)

Expand Down
8 changes: 4 additions & 4 deletions src/playsim/mapthinkers/a_lights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
// State.
#include "serializer.h"

static FRandom pr_flicker ("Flicker", true);
static FRandom pr_lightflash ("LightFlash", true);
static FRandom pr_strobeflash ("StrobeFlash", true);
static FRandom pr_fireflicker ("FireFlicker", true);
static FCRandom pr_flicker ("Flicker");
static FCRandom pr_lightflash ("LightFlash");
static FCRandom pr_strobeflash ("StrobeFlash");
static FCRandom pr_fireflicker ("FireFlicker");


//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/playsim/mapthinkers/a_plats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "p_spec.h"
#include "g_levellocals.h"

static FRandom pr_doplat ("DoPlat", false);
static FRandom pr_doplat ("DoPlat");

IMPLEMENT_CLASS(DPlat, false, false)

Expand Down
2 changes: 1 addition & 1 deletion src/playsim/mapthinkers/a_quake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "actorinlines.h"
#include <p_maputl.h>

static FRandom pr_quake ("Quake", true);
static FCRandom pr_quake ("Quake");

IMPLEMENT_CLASS(DEarthquake, false, true)

Expand Down
2 changes: 1 addition & 1 deletion src/playsim/p_acs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@



FRandom pr_acs ("ACS", false);
FRandom pr_acs ("ACS");

// I imagine this much stack space is probably overkill, but it could
// potentially get used with recursive functions.
Expand Down
28 changes: 14 additions & 14 deletions src/playsim/p_actionfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@
#include "shadowinlines.h"
#include "i_time.h"

static FRandom pr_camissile ("CustomActorfire", false);
static FRandom pr_cabullet ("CustomBullet", false);
static FRandom pr_cwjump ("CustomWpJump", false);
static FRandom pr_cwpunch ("CustomWpPunch", false);
static FRandom pr_grenade ("ThrowGrenade", false);
FRandom pr_crailgun ("CustomRailgun", false);
static FRandom pr_spawndebris ("SpawnDebris", false);
static FRandom pr_spawnitemex ("SpawnItemEx", false);
static FRandom pr_burst ("Burst", false);
static FRandom pr_monsterrefire ("MonsterRefire", false);
static FRandom pr_teleport("A_Teleport", false);
static FRandom pr_bfgselfdamage("BFGSelfDamage", false);
FRandom pr_cajump("CustomJump", false);
static FRandom pr_camissile ("CustomActorfire");
static FRandom pr_cabullet ("CustomBullet");
static FRandom pr_cwjump ("CustomWpJump");
static FRandom pr_cwpunch ("CustomWpPunch");
static FRandom pr_grenade ("ThrowGrenade");
FRandom pr_crailgun ("CustomRailgun");
static FRandom pr_spawndebris ("SpawnDebris");
static FRandom pr_spawnitemex ("SpawnItemEx");
static FRandom pr_burst ("Burst");
static FRandom pr_monsterrefire ("MonsterRefire");
static FRandom pr_teleport("A_Teleport");
static FRandom pr_bfgselfdamage("BFGSelfDamage");
FRandom pr_cajump("CustomJump");

//==========================================================================
//
Expand Down Expand Up @@ -746,7 +746,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_StopSoundEx)
// Generic seeker missile function
//
//==========================================================================
static FRandom pr_seekermissile ("SeekerMissile", false);
static FRandom pr_seekermissile ("SeekerMissile");
enum
{
SMF_LOOK = 1,
Expand Down
2 changes: 1 addition & 1 deletion src/playsim/p_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ CVAR (Int, r_rail_trailsparsity, 1, CVAR_ARCHIVE);
CVAR (Bool, r_particles, true, 0);
EXTERN_CVAR(Int, r_maxparticles);

FRandom pr_railtrail("RailTrail", true);
FCRandom pr_railtrail("RailTrail");

#define FADEFROMTTL(a) (1.f/(a))

Expand Down
40 changes: 20 additions & 20 deletions src/playsim/p_enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@

#include "gi.h"

static FRandom pr_checkmissilerange ("CheckMissileRange", false);
static FRandom pr_opendoor ("OpenDoor", false);
static FRandom pr_trywalk ("TryWalk", false);
static FRandom pr_newchasedir ("NewChaseDir", false);
static FRandom pr_lookformonsters ("LookForMonsters", false);
static FRandom pr_lookforplayers ("LookForPlayers", false);
static FRandom pr_scaredycat ("Anubis", false);
FRandom pr_chase ("Chase", false);
FRandom pr_facetarget ("FaceTarget", false);
FRandom pr_railface ("RailFace", false);
static FRandom pr_look2 ("LookyLooky", false);
static FRandom pr_look3 ("IGotHooky", false);
static FRandom pr_slook ("SlooK", false);
static FRandom pr_dropoff ("Dropoff", false);
static FRandom pr_defect ("Defect", false);
static FRandom pr_avoidcrush("AvoidCrush", false);
static FRandom pr_stayonlift("StayOnLift", false);

static FRandom pr_skiptarget("SkipTarget", false);
static FRandom pr_enemystrafe("EnemyStrafe", false);
static FRandom pr_checkmissilerange ("CheckMissileRange");
static FRandom pr_opendoor ("OpenDoor");
static FRandom pr_trywalk ("TryWalk");
static FRandom pr_newchasedir ("NewChaseDir");
static FRandom pr_lookformonsters ("LookForMonsters");
static FRandom pr_lookforplayers ("LookForPlayers");
static FRandom pr_scaredycat ("Anubis");
FRandom pr_chase ("Chase");
FRandom pr_facetarget ("FaceTarget");
FRandom pr_railface ("RailFace");
static FRandom pr_look2 ("LookyLooky");
static FRandom pr_look3 ("IGotHooky");
static FRandom pr_slook ("SlooK");
static FRandom pr_dropoff ("Dropoff");
static FRandom pr_defect ("Defect");
static FRandom pr_avoidcrush("AvoidCrush");
static FRandom pr_stayonlift("StayOnLift");

static FRandom pr_skiptarget("SkipTarget");
static FRandom pr_enemystrafe("EnemyStrafe");

// movement interpolation is fine for objects that are moved by their own
// velocity. But for monsters it is problematic.
Expand Down
Loading

0 comments on commit 3ea5be1

Please sign in to comment.