Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpAIManager.cpp
Show All 26 Lines | |||||
#include "lib/tex/tex.h" | #include "lib/tex/tex.h" | ||||
#include "lib/allocators/shared_ptr.h" | #include "lib/allocators/shared_ptr.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/scripting/JSInterface_VFS.h" | #include "ps/scripting/JSInterface_VFS.h" | ||||
#include "ps/TemplateLoader.h" | #include "ps/TemplateLoader.h" | ||||
#include "ps/Util.h" | #include "ps/Util.h" | ||||
#include "scriptinterface/ScriptRuntime.h" | #include "scriptinterface/ScriptContext.h" | ||||
#include "simulation2/components/ICmpAIInterface.h" | #include "simulation2/components/ICmpAIInterface.h" | ||||
#include "simulation2/components/ICmpCommandQueue.h" | #include "simulation2/components/ICmpCommandQueue.h" | ||||
#include "simulation2/components/ICmpObstructionManager.h" | #include "simulation2/components/ICmpObstructionManager.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | #include "simulation2/components/ICmpRangeManager.h" | ||||
#include "simulation2/components/ICmpTemplateManager.h" | #include "simulation2/components/ICmpTemplateManager.h" | ||||
#include "simulation2/components/ICmpTerritoryManager.h" | #include "simulation2/components/ICmpTerritoryManager.h" | ||||
#include "simulation2/helpers/HierarchicalPathfinder.h" | #include "simulation2/helpers/HierarchicalPathfinder.h" | ||||
#include "simulation2/helpers/LongPathfinder.h" | #include "simulation2/helpers/LongPathfinder.h" | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | public: | ||||
CAIWorker& m_Worker; | CAIWorker& m_Worker; | ||||
std::wstring m_AIName; | std::wstring m_AIName; | ||||
player_id_t m_Player; | player_id_t m_Player; | ||||
u8 m_Difficulty; | u8 m_Difficulty; | ||||
std::wstring m_Behavior; | std::wstring m_Behavior; | ||||
bool m_UseSharedComponent; | bool m_UseSharedComponent; | ||||
// Take care to keep this declaration before heap rooted members. Destructors of heap rooted | // Take care to keep this declaration before heap rooted members. Destructors of heap rooted | ||||
// members have to be called before the runtime destructor. | // members have to be called before the context destructor. | ||||
shared_ptr<ScriptInterface> m_ScriptInterface; | shared_ptr<ScriptInterface> m_ScriptInterface; | ||||
JS::PersistentRootedValue m_Obj; | JS::PersistentRootedValue m_Obj; | ||||
std::vector<shared_ptr<ScriptInterface::StructuredClone> > m_Commands; | std::vector<shared_ptr<ScriptInterface::StructuredClone> > m_Commands; | ||||
}; | }; | ||||
public: | public: | ||||
struct SCommandSets | struct SCommandSets | ||||
{ | { | ||||
player_id_t player; | player_id_t player; | ||||
std::vector<shared_ptr<ScriptInterface::StructuredClone> > commands; | std::vector<shared_ptr<ScriptInterface::StructuredClone> > commands; | ||||
}; | }; | ||||
CAIWorker() : | CAIWorker() : | ||||
m_ScriptInterface(new ScriptInterface("Engine", "AI", g_ScriptRuntime)), | m_ScriptInterface(new ScriptInterface("Engine", "AI", g_ScriptContext)), | ||||
m_TurnNum(0), | m_TurnNum(0), | ||||
m_CommandsComputed(true), | m_CommandsComputed(true), | ||||
m_HasLoadedEntityTemplates(false), | m_HasLoadedEntityTemplates(false), | ||||
m_HasSharedComponent(false), | m_HasSharedComponent(false), | ||||
m_EntityTemplates(g_ScriptRuntime->GetJSRuntime()), | m_EntityTemplates(g_ScriptContext->GetJSRuntime()), | ||||
m_SharedAIObj(g_ScriptRuntime->GetJSRuntime()), | m_SharedAIObj(g_ScriptContext->GetJSRuntime()), | ||||
m_PassabilityMapVal(g_ScriptRuntime->GetJSRuntime()), | m_PassabilityMapVal(g_ScriptContext->GetJSRuntime()), | ||||
m_TerritoryMapVal(g_ScriptRuntime->GetJSRuntime()) | m_TerritoryMapVal(g_ScriptContext->GetJSRuntime()) | ||||
{ | { | ||||
m_ScriptInterface->ReplaceNondeterministicRNG(m_RNG); | m_ScriptInterface->ReplaceNondeterministicRNG(m_RNG); | ||||
m_ScriptInterface->SetCallbackData(static_cast<void*> (this)); | m_ScriptInterface->SetCallbackData(static_cast<void*> (this)); | ||||
JS_AddExtraGCRootsTracer(m_ScriptInterface->GetJSRuntime(), Trace, this); | JS_AddExtraGCRootsTracer(m_ScriptInterface->GetJSRuntime(), Trace, this); | ||||
▲ Show 20 Lines • Show All 633 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < m_Players.size(); ++i) | ||||
if (m_HasSharedComponent && m_Players[i]->m_UseSharedComponent) | if (m_HasSharedComponent && m_Players[i]->m_UseSharedComponent) | ||||
m_Players[i]->Run(state, m_Players[i]->m_Player, m_SharedAIObj); | m_Players[i]->Run(state, m_Players[i]->m_Player, m_SharedAIObj); | ||||
else | else | ||||
m_Players[i]->Run(state, m_Players[i]->m_Player); | m_Players[i]->Run(state, m_Players[i]->m_Player); | ||||
} | } | ||||
} | } | ||||
// Take care to keep this declaration before heap rooted members. Destructors of heap rooted | // Take care to keep this declaration before heap rooted members. Destructors of heap rooted | ||||
// members have to be called before the runtime destructor. | // members have to be called before the context destructor. | ||||
shared_ptr<ScriptRuntime> m_ScriptRuntime; | shared_ptr<ScriptContext> m_ScriptContext; | ||||
shared_ptr<ScriptInterface> m_ScriptInterface; | shared_ptr<ScriptInterface> m_ScriptInterface; | ||||
boost::rand48 m_RNG; | boost::rand48 m_RNG; | ||||
u32 m_TurnNum; | u32 m_TurnNum; | ||||
JS::PersistentRootedValue m_EntityTemplates; | JS::PersistentRootedValue m_EntityTemplates; | ||||
bool m_HasLoadedEntityTemplates; | bool m_HasLoadedEntityTemplates; | ||||
▲ Show 20 Lines • Show All 277 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator