Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpAIManager.cpp
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | bool Initialise() | ||||
LOGERROR("Failed to create AI player: can't find %s", path.string8()); | LOGERROR("Failed to create AI player: can't find %s", path.string8()); | ||||
return false; | return false; | ||||
} | } | ||||
// Get the constructor name from the metadata | // Get the constructor name from the metadata | ||||
std::string moduleName; | std::string moduleName; | ||||
std::string constructor; | std::string constructor; | ||||
JS::RootedValue objectWithConstructor(rq.cx); // object that should contain the constructor function | JS::RootedValue objectWithConstructor(rq.cx); // object that should contain the constructor function | ||||
JS::RootedValue global(rq.cx, m_ScriptInterface->GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
JS::RootedValue ctor(rq.cx); | JS::RootedValue ctor(rq.cx); | ||||
if (!m_ScriptInterface->HasProperty(metadata, "moduleName")) | if (!m_ScriptInterface->HasProperty(metadata, "moduleName")) | ||||
{ | { | ||||
LOGERROR("Failed to create AI player: %s: missing 'moduleName'", path.string8()); | LOGERROR("Failed to create AI player: %s: missing 'moduleName'", path.string8()); | ||||
return false; | return false; | ||||
} | } | ||||
m_ScriptInterface->GetProperty(metadata, "moduleName", moduleName); | m_ScriptInterface->GetProperty(metadata, "moduleName", moduleName); | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | public: | ||||
}; | }; | ||||
CAIWorker() : | CAIWorker() : | ||||
m_ScriptInterface(new ScriptInterface("Engine", "AI", g_ScriptRuntime)), | m_ScriptInterface(new ScriptInterface("Engine", "AI", g_ScriptRuntime)), | ||||
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->m_rt), | m_EntityTemplates(g_ScriptRuntime->GetJSRuntime()), | ||||
m_SharedAIObj(g_ScriptRuntime->m_rt), | m_SharedAIObj(g_ScriptRuntime->GetJSRuntime()), | ||||
m_PassabilityMapVal(g_ScriptRuntime->m_rt), | m_PassabilityMapVal(g_ScriptRuntime->GetJSRuntime()), | ||||
m_TerritoryMapVal(g_ScriptRuntime->m_rt) | m_TerritoryMapVal(g_ScriptRuntime->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 186 Lines • ▼ Show 20 Lines | else | ||||
return false; | return false; | ||||
// mainly here for the error messages | // mainly here for the error messages | ||||
OsPath path = L"simulation/ai/common-api/"; | OsPath path = L"simulation/ai/common-api/"; | ||||
// Constructor name is SharedScript, it's in the module API3 | // Constructor name is SharedScript, it's in the module API3 | ||||
// TODO: Hardcoding this is bad, we need a smarter way. | // TODO: Hardcoding this is bad, we need a smarter way. | ||||
JS::RootedValue AIModule(rq.cx); | JS::RootedValue AIModule(rq.cx); | ||||
JS::RootedValue global(rq.cx, m_ScriptInterface->GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
JS::RootedValue ctor(rq.cx); | JS::RootedValue ctor(rq.cx); | ||||
if (!m_ScriptInterface->GetProperty(global, "API3", &AIModule) || AIModule.isUndefined()) | if (!m_ScriptInterface->GetProperty(global, "API3", &AIModule) || AIModule.isUndefined()) | ||||
{ | { | ||||
LOGERROR("Failed to create shared AI component: %s: can't find module '%s'", path.string8(), "API3"); | LOGERROR("Failed to create shared AI component: %s: can't find module '%s'", path.string8(), "API3"); | ||||
return false; | return false; | ||||
} | } | ||||
if (!m_ScriptInterface->GetProperty(AIModule, "SharedScript", &ctor) | if (!m_ScriptInterface->GetProperty(AIModule, "SharedScript", &ctor) | ||||
▲ Show 20 Lines • Show All 725 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator