Bug fixes and requests
* Moved to CRandom to Common lib * Initialized CRandom with a time seed in CN64System constructor * Added CRandom::state getters and setters to support saved states
This commit is contained in:
parent
23c1007aa0
commit
1b8d032417
|
@ -43,6 +43,7 @@
|
|||
<ClCompile Include="MemTest.cpp" />
|
||||
<ClCompile Include="path.cpp" />
|
||||
<ClCompile Include="Platform.cpp" />
|
||||
<ClCompile Include="Random.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
|
@ -64,6 +65,7 @@
|
|||
<ClInclude Include="MemTest.h" />
|
||||
<ClInclude Include="path.h" />
|
||||
<ClInclude Include="Platform.h" />
|
||||
<ClInclude Include="Random.h" />
|
||||
<ClInclude Include="SmartPointer.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="StdString.h" />
|
||||
|
|
|
@ -62,6 +62,9 @@
|
|||
<ClCompile Include="DateTimeClass.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Random.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
|
@ -124,5 +127,8 @@
|
|||
<ClInclude Include="DateTimeClass.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Random.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -15,6 +15,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Random.h"
|
||||
#include <time.h>
|
||||
|
||||
|
@ -23,12 +24,12 @@ CRandom::CRandom()
|
|||
state = (uint32_t)time(NULL);
|
||||
}
|
||||
|
||||
CRandom::CRandom(uint32_t seed_value)
|
||||
CRandom::CRandom(uint32_t state_value)
|
||||
{
|
||||
state = seed_value;
|
||||
state = state_value;
|
||||
}
|
||||
|
||||
uint32_t randomizer(uint32_t val)
|
||||
uint32_t CRandom::randomizer(uint32_t val)
|
||||
{
|
||||
return ((uint64_t)val * 279470273UL) % 4294967291UL;
|
||||
}
|
||||
|
@ -39,10 +40,15 @@ uint32_t CRandom::next()
|
|||
return state;
|
||||
}
|
||||
|
||||
void CRandom::seed(uint32_t seed_value)
|
||||
void CRandom::set_state(uint32_t state_value)
|
||||
{
|
||||
if (seed_value == 0)
|
||||
state == 1;
|
||||
if (state_value == 0)
|
||||
state = 1;
|
||||
else
|
||||
state = seed_value;
|
||||
state = state_value;
|
||||
}
|
||||
|
||||
uint32_t CRandom::get_state()
|
||||
{
|
||||
return state;
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
* This class implements the Lehmer Random Number Generator.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <Common/stdtypes.h>
|
||||
|
||||
class CRandom
|
||||
|
@ -23,7 +23,8 @@ public:
|
|||
CRandom();
|
||||
CRandom(uint32_t seed_value);
|
||||
uint32_t next();
|
||||
void seed(uint32_t seed_value);
|
||||
uint32_t get_state();
|
||||
void set_state(uint32_t state_value);
|
||||
|
||||
protected:
|
||||
uint32_t randomizer(uint32_t val);
|
|
@ -57,7 +57,8 @@ CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem)
|
|||
m_thread(NULL),
|
||||
m_hPauseEvent(true),
|
||||
m_CheatsSlectionChanged(false),
|
||||
m_SyncCpu(SyncSystem)
|
||||
m_SyncCpu(SyncSystem),
|
||||
m_Random((uint32_t)time(NULL))
|
||||
{
|
||||
WriteTrace(TraceN64System, TraceDebug, "Start");
|
||||
memset(m_LastSuccessSyncPC, 0, sizeof(m_LastSuccessSyncPC));
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <Common/Random.h>
|
||||
#include <Common/SyncEvent.h>
|
||||
#include <Common/Thread.h>
|
||||
#include <Project64-core/Settings/N64SystemSettings.h>
|
||||
|
@ -23,7 +24,6 @@
|
|||
#include <Project64-core/Settings/DebugSettings.h>
|
||||
#include <Project64-core/Plugin.h>
|
||||
#include <Project64-core/Logging.h>
|
||||
#include <Project64-core/3rdParty/Random.h>
|
||||
|
||||
#include "Mips/TLBClass.h"
|
||||
#include "CheatClass.h"
|
||||
|
|
|
@ -32,5 +32,6 @@ uint32_t * g_TLBStoreAddress = NULL;
|
|||
CDebugger * g_Debugger = NULL;
|
||||
uint8_t ** g_RecompPos = NULL;
|
||||
CMempak * g_Mempak = NULL;
|
||||
CRandom * g_Random = NULL;
|
||||
|
||||
int * g_NextTimer;
|
|
@ -35,7 +35,6 @@
|
|||
<ClCompile Include="3rdParty\7zip.cpp">
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="3rdParty\Random.cpp" />
|
||||
<ClCompile Include="AppInit.cpp" />
|
||||
<ClCompile Include="Logging.cpp" />
|
||||
<ClCompile Include="MemoryExceptionFilter.cpp" />
|
||||
|
@ -127,7 +126,6 @@
|
|||
<ClInclude Include="..\3rdParty\zlib\zconf.h" />
|
||||
<ClInclude Include="..\3rdParty\zlib\zlib.h" />
|
||||
<ClInclude Include="3rdParty\7zip.h" />
|
||||
<ClInclude Include="3rdParty\Random.h" />
|
||||
<ClInclude Include="3rdParty\zip.h" />
|
||||
<ClInclude Include="AppInit.h" />
|
||||
<ClInclude Include="Debugger.h" />
|
||||
|
|
|
@ -339,9 +339,6 @@
|
|||
<ClCompile Include="N64System\Recompiler\Arm\ArmRegInfo.cpp">
|
||||
<Filter>Source Files\N64 System\Recompiler\Arm</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="3rdParty\Random.cpp">
|
||||
<Filter>Source Files\3rd Party</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
|
@ -662,9 +659,6 @@
|
|||
<ClInclude Include="Debugger.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="3rdParty\Random.h">
|
||||
<Filter>Header Files\3rd Party</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ClassDiagram.cd" />
|
||||
|
|
Loading…
Reference in New Issue