Rename globals

This commit is contained in:
Phillip Stephens 2016-02-07 08:15:43 -08:00
parent 8fbe6a953c
commit a96601f1b4
4 changed files with 15 additions and 17 deletions

View File

@ -3,7 +3,7 @@
namespace Retro namespace Retro
{ {
CRandom16* GLOBAL_RANDOM = nullptr; CRandom16* CRandom16::g_randomNumber = nullptr;
CGlobalRandom* GLOBAL_RANDOM_TOKEN = nullptr; CGlobalRandom* CGlobalRandom::g_currentGlobalRandom = nullptr;
} }

View File

@ -6,12 +6,11 @@
namespace Retro namespace Retro
{ {
extern class CRandom16* GLOBAL_RANDOM;
extern class CGlobalRandom* GLOBAL_RANDOM_TOKEN;
class CRandom16 class CRandom16
{ {
u32 m_seed; u32 m_seed;
static CRandom16* g_randomNumber;
public: public:
CRandom16(u32 p) : m_seed(p) {} CRandom16(u32 p) : m_seed(p) {}
@ -50,24 +49,25 @@ public:
return rand % diff + min; return rand % diff + min;
} }
static CRandom16* GetRandomNumber() {return GLOBAL_RANDOM;} static CRandom16* GetRandomNumber() {return g_randomNumber;}
static void SetRandomNumber(CRandom16* rnd) {GLOBAL_RANDOM = rnd;} static void SetRandomNumber(CRandom16* rnd) {g_randomNumber = rnd;}
}; };
class CGlobalRandom class CGlobalRandom
{ {
CRandom16& m_random; CRandom16& m_random;
CGlobalRandom* m_prev; CGlobalRandom* m_prev;
static CGlobalRandom* g_currentGlobalRandom;
public: public:
CGlobalRandom(CRandom16& rand) CGlobalRandom(CRandom16& rand)
: m_random(rand), m_prev(GLOBAL_RANDOM_TOKEN) : m_random(rand), m_prev(g_currentGlobalRandom)
{ {
GLOBAL_RANDOM_TOKEN = this; g_currentGlobalRandom = this;
CRandom16::SetRandomNumber(&m_random); CRandom16::SetRandomNumber(&m_random);
} }
~CGlobalRandom() ~CGlobalRandom()
{ {
GLOBAL_RANDOM_TOKEN = m_prev; g_currentGlobalRandom = m_prev;
if (m_prev) if (m_prev)
CRandom16::SetRandomNumber(&m_prev->m_random); CRandom16::SetRandomNumber(&m_prev->m_random);
else else

View File

@ -5,12 +5,10 @@
namespace Retro namespace Retro
{ {
CTimeProvider* g_TimeProvider = nullptr; CTimeProvider* CTimeProvider::g_currentTimeProvider = nullptr;
CTimeProvider::CTimeProvider(const float& time) CTimeProvider::CTimeProvider(const float& time)
: x0_currentTime(time) : x0_currentTime(time), x8_lastProvider(g_currentTimeProvider)
{ {
x8_lastProvider = g_TimeProvider;
if (x8_lastProvider != nullptr) if (x8_lastProvider != nullptr)
x8_lastProvider->x4_first = false; x8_lastProvider->x4_first = false;
@ -21,9 +19,9 @@ CTimeProvider::CTimeProvider(const float& time)
CTimeProvider::~CTimeProvider() CTimeProvider::~CTimeProvider()
{ {
g_TimeProvider = x8_lastProvider; g_currentTimeProvider = x8_lastProvider;
if (g_TimeProvider) if (g_currentTimeProvider)
g_TimeProvider->x4_first = true; g_currentTimeProvider->x4_first = true;
#if 0 #if 0
CGraphics::SetExternalTimeProvider(g_TimeProvider); CGraphics::SetExternalTimeProvider(g_TimeProvider);
#endif #endif

View File

@ -3,10 +3,10 @@
namespace Retro namespace Retro
{ {
class CTimeProvider; class CTimeProvider;
extern CTimeProvider* g_TimeProvider;
class CTimeProvider class CTimeProvider
{ {
public: public:
static CTimeProvider* g_currentTimeProvider;
const float& x0_currentTime; // in seconds const float& x0_currentTime; // in seconds
bool x4_first = true; bool x4_first = true;
CTimeProvider* x8_lastProvider = nullptr; CTimeProvider* x8_lastProvider = nullptr;