From 17ea4d827ad8fa1462447d59f490a007ba706d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Mon, 29 Nov 2021 23:23:26 +0700 Subject: Use more efficient PRNG --- src/GameInitDispose.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/GameInitDispose.cpp') diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index 50b848e..b95768e 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -20,15 +20,13 @@ // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see . -#include - -#include +#include #include #include #include "Game.h" -#include "Support.h" +#include "misc.h" extern unsigned int gSourceID[37]; extern unsigned int gSampleSet[37]; @@ -279,9 +277,6 @@ void initGame(Game* game) alSourcef(sound_source, AL_MAX_GAIN, 1); } - // Setup random seed - srand(time(NULL)); - // Setup block models if (!game->initialized) { game->blocks[0].load("blocks/0.off"); @@ -330,11 +325,11 @@ void initGame(Game* game) while (vip.pathnum < 0 || vip.pathnum == 1 || vip.pathnum >= game->path.vertexNum) - vip.pathnum = Random() % game->path.vertexNum; + vip.pathnum = randUint(game->path.vertexNum); vip.pathtarget.x = game->path.vertex[vip.pathnum].x; vip.pathtarget.z = game->path.vertex[vip.pathnum].z; - vip.pathsize = 0.98f + abs(Random() % 20) / 400.0f; + vip.pathsize = 0.98f + 0.04f * randFloat(); vip.pathtarget *= vip.pathsize; vip.pathtarget.x += vip.whichblockx * block_spacing; vip.pathtarget.z += vip.whichblocky * block_spacing; @@ -359,13 +354,13 @@ void initGame(Game* game) game->spawndelay = 0.1f; game->vipgoal = vip.playercoords - + DoRotation({10000000.0f, 0.0f, 0.0f}, 0, Random() % 360, 0); + + DoRotation({10000000.0f, 0.0f, 0.0f}, 0, randUint(360), 0); // Init city block rotations for (int i = 0; i < num_blocks; ++i) for (int j = 0; j < num_blocks; ++j) { - game->cityrotation[i][j] = Random() % 4; - game->citytype[i][j] = abs(Random()) % 4; + game->cityrotation[i][j] = randUint(4); + game->citytype[i][j] = randUint(4); game->citypeoplenum[i][j] = 0; } @@ -971,7 +966,7 @@ void initGame(Game* game) person.whichcostume = bodyguardcostume; else if (i > 1) person.whichcostume = casualcostumes - + abs(Random()) % numcasual; + + randUint(numcasual); // person.firstlongdead = 0; person.dead = 0; -- cgit v1.2.3