mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 21:34:08 -07:00
Initialize the AIManager AISeed immediately in C++ rather than too late and in JS.
Fixes #4907
Differential Revision: https://code.wildfiregames.com/D1178
Reviewed By: mimo
Refs D1159, f88ee2766e
This was SVN commit r20700.
This commit is contained in:
parent
a89918c952
commit
7e05d7edc9
3 changed files with 27 additions and 9 deletions
|
|
@ -72,8 +72,6 @@ function InitGame(settings)
|
|||
// Map or player data (handicap...) dependent initialisations of components (i.e. garrisoned units)
|
||||
Engine.BroadcastMessage(MT_InitGame, {});
|
||||
|
||||
let seed = settings.AISeed ? settings.AISeed : 0;
|
||||
cmpAIManager.SetRNGSeed(seed);
|
||||
cmpAIManager.TryLoadSharedComponent();
|
||||
cmpAIManager.RunGamestateInit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,6 +161,9 @@ public:
|
|||
SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter,
|
||||
SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter);
|
||||
|
||||
void InitRNGSeedSimulation();
|
||||
void InitRNGSeedAI();
|
||||
|
||||
static std::vector<SimulationCommand> CloneCommandsFromOtherContext(const ScriptInterface& oldScript, const ScriptInterface& newScript,
|
||||
const std::vector<SimulationCommand>& commands)
|
||||
{
|
||||
|
|
@ -334,6 +337,28 @@ void CSimulation2Impl::ReportSerializationFailure(
|
|||
debug_warn(L"Serialization test failure");
|
||||
}
|
||||
|
||||
void CSimulation2Impl::InitRNGSeedSimulation()
|
||||
{
|
||||
u32 seed = 0;
|
||||
if (!m_ComponentManager.GetScriptInterface().HasProperty(m_MapSettings, "Seed") ||
|
||||
!m_ComponentManager.GetScriptInterface().GetProperty(m_MapSettings, "Seed", seed))
|
||||
LOGWARNING("CSimulation2Impl::InitRNGSeedSimulation: No seed value specified - using %d", seed);
|
||||
|
||||
m_ComponentManager.SetRNGSeed(seed);
|
||||
}
|
||||
|
||||
void CSimulation2Impl::InitRNGSeedAI()
|
||||
{
|
||||
u32 seed = 0;
|
||||
if (!m_ComponentManager.GetScriptInterface().HasProperty(m_MapSettings, "AISeed") ||
|
||||
!m_ComponentManager.GetScriptInterface().GetProperty(m_MapSettings, "AISeed", seed))
|
||||
LOGWARNING("CSimulation2Impl::InitRNGSeedAI: No seed value specified - using %d", seed);
|
||||
|
||||
CmpPtr<ICmpAIManager> cmpAIManager(m_SimContext, SYSTEM_ENTITY);
|
||||
if (cmpAIManager)
|
||||
cmpAIManager->SetRNGSeed(seed);
|
||||
}
|
||||
|
||||
void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationCommand>& commands)
|
||||
{
|
||||
PROFILE3("sim update");
|
||||
|
|
@ -793,12 +818,8 @@ void CSimulation2::SetMapSettings(JS::HandleValue settings)
|
|||
{
|
||||
m->m_MapSettings = settings;
|
||||
|
||||
u32 seed = 0;
|
||||
if (!m->m_ComponentManager.GetScriptInterface().HasProperty(m->m_MapSettings, "Seed") ||
|
||||
!m->m_ComponentManager.GetScriptInterface().GetProperty(m->m_MapSettings, "Seed", seed))
|
||||
LOGWARNING("CSimulation2::SetInitAttributes: No seed value specified - using %d", seed);
|
||||
|
||||
m->m_ComponentManager.SetRNGSeed(seed);
|
||||
m->InitRNGSeedSimulation();
|
||||
m->InitRNGSeedAI();
|
||||
}
|
||||
|
||||
std::string CSimulation2::GetMapSettingsString()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
BEGIN_INTERFACE_WRAPPER(AIManager)
|
||||
DEFINE_INTERFACE_METHOD_4("AddPlayer", void, ICmpAIManager, AddPlayer, std::wstring, player_id_t, uint8_t, std::wstring)
|
||||
DEFINE_INTERFACE_METHOD_1("SetRNGSeed", void, ICmpAIManager, SetRNGSeed, uint32_t)
|
||||
DEFINE_INTERFACE_METHOD_0("TryLoadSharedComponent", void, ICmpAIManager, TryLoadSharedComponent)
|
||||
DEFINE_INTERFACE_METHOD_0("RunGamestateInit", void, ICmpAIManager, RunGamestateInit)
|
||||
END_INTERFACE_WRAPPER(AIManager)
|
||||
|
|
|
|||
Loading…
Reference in a new issue