From 3ab9b7f2d32dc45684a5abe1fc6a08350796ad4e Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 1 Feb 2020 15:23:03 +0100 Subject: [PATCH] Inline rand --- CMakeLists.txt | 1 - Source/codec.cpp | 5 +++-- Source/diablo.cpp | 1 - SourceS/miniwin.h | 1 - SourceS/miniwin/rand.h | 8 -------- SourceX/miniwin/rand.cpp | 20 -------------------- 6 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 SourceS/miniwin/rand.h delete mode 100644 SourceX/miniwin/rand.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 794da9932..c6070553e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,7 +251,6 @@ set(devilutionx_SRCS SourceX/controls/touch.cpp SourceX/display.cpp SourceX/miniwin/misc_msg.cpp - SourceX/miniwin/rand.cpp SourceX/miniwin/thread.cpp SourceX/sound.cpp SourceX/soundsample.cpp diff --git a/Source/codec.cpp b/Source/codec.cpp index dcbb291c1..127af291c 100644 --- a/Source/codec.cpp +++ b/Source/codec.cpp @@ -61,11 +61,12 @@ void codec_init_key(int unused, char *pszPassword) char digest[SHA1HashSize]; char *keyInit; - srand(0x7058); + uint32_t rand_state = 0x7058; keyInit = key; for (i = 0; i < 136; i++) { - *keyInit = rand(); + rand_state = rand_state * 214013 + 2531011; + *keyInit = (rand_state >> 16) & 0x7FFF; keyInit++; } ch = 0; diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 09770ae02..a847e4331 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -266,7 +266,6 @@ void diablo_init() ReadOnlyTest(); - srand(SDL_GetTicks()); InitHash(); diablo_init_screen(); diff --git a/SourceS/miniwin.h b/SourceS/miniwin.h index 175fe53f4..4619e0962 100644 --- a/SourceS/miniwin.h +++ b/SourceS/miniwin.h @@ -23,7 +23,6 @@ #include "miniwin/misc.h" #include "miniwin/thread.h" -#include "miniwin/rand.h" #include "storm_full.h" #ifndef MAX_PATH diff --git a/SourceS/miniwin/rand.h b/SourceS/miniwin/rand.h deleted file mode 100644 index 4bd5a3bed..000000000 --- a/SourceS/miniwin/rand.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace dvl { - -int rand(void); -void srand(uint32_t seed); - -} // namespace dvl diff --git a/SourceX/miniwin/rand.cpp b/SourceX/miniwin/rand.cpp deleted file mode 100644 index f1e96d32e..000000000 --- a/SourceX/miniwin/rand.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#include "devilution.h" - -namespace dvl { - -static uint32_t rand_state = 0; - -int rand(void) -{ - rand_state = rand_state * 214013 + 2531011; - return (rand_state >> 16) & 0x7FFF; -} - -void srand(uint32_t seed) -{ - rand_state = seed; -} - -} // namespace dvl