Skip to content

Commit

Permalink
[MP] seed RNG in modules (#1125)
Browse files Browse the repository at this point in the history
* [MP] seed RNG in modules

* [MP] use the same randomSeed for stdlib+vendored PRNG, and seed it a little earlier
  • Loading branch information
Razish committed Sep 29, 2023
1 parent f3e8614 commit 5f86d1a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions codemp/cgame/cg_main.c
Expand Up @@ -2403,6 +2403,8 @@ void CG_Init( int serverMessageNum, int serverCommandSequence, int clientNum )
const char *s;
int i = 0;

Rand_Init( trap->Milliseconds() );

BG_InitAnimsets(); //clear it out

trap->RegisterSharedMemory( cg.sharedBuffer.raw );
Expand Down
5 changes: 3 additions & 2 deletions codemp/game/g_main.c
Expand Up @@ -179,6 +179,9 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) {
vmCvar_t ckSum;
char serverinfo[MAX_INFO_STRING] = {0};

Rand_Init( randomSeed );
srand( randomSeed );

//Init RMG to 0, it will be autoset to 1 if there is terrain on the level.
trap->Cvar_Set("RMG", "0");
RMG.integer = 0;
Expand All @@ -199,8 +202,6 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) {
trap->Print ("gamename: %s\n", GAMEVERSION);
trap->Print ("gamedate: %s\n", SOURCE_DATE);

srand( randomSeed );

G_RegisterCvars();

G_ProcessIPBans();
Expand Down
2 changes: 2 additions & 0 deletions codemp/ui/ui_main.c
Expand Up @@ -9838,6 +9838,8 @@ UI_Init
void UI_Init( qboolean inGameLoad ) {
const char *menuSet;

Rand_Init( trap->Milliseconds() );

// Get the list of possible languages
uiInfo.languageCount = trap->SE_GetNumLanguages(); // this does a dir scan, so use carefully

Expand Down

0 comments on commit 5f86d1a

Please sign in to comment.