Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpAIManager.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 615 Lines • ▼ Show 20 Lines | public: | ||||
void LoadEntityTemplates(const std::vector<std::pair<std::string, const CParamNode*> >& templates) | void LoadEntityTemplates(const std::vector<std::pair<std::string, const CParamNode*> >& templates) | ||||
{ | { | ||||
JSContext* cx = m_ScriptInterface->GetContext(); | JSContext* cx = m_ScriptInterface->GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
m_HasLoadedEntityTemplates = true; | m_HasLoadedEntityTemplates = true; | ||||
m_ScriptInterface->Eval("({})", &m_EntityTemplates); | m_ScriptInterface->CreateObject(&m_EntityTemplates); | ||||
JS::RootedValue val(cx); | JS::RootedValue val(cx); | ||||
for (size_t i = 0; i < templates.size(); ++i) | for (size_t i = 0; i < templates.size(); ++i) | ||||
{ | { | ||||
templates[i].second->ToJSVal(cx, false, &val); | templates[i].second->ToJSVal(cx, false, &val); | ||||
m_ScriptInterface->SetProperty(m_EntityTemplates, templates[i].first.c_str(), val, true); | m_ScriptInterface->SetProperty(m_EntityTemplates, templates[i].first.c_str(), val, true); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 536 Lines • ▼ Show 20 Lines | void LoadPathfinderClasses(JS::HandleValue state) | ||||
if (!cmpPathfinder) | if (!cmpPathfinder) | ||||
return; | return; | ||||
const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); | const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue classesVal(cx); | JS::RootedValue classesVal(cx); | ||||
scriptInterface.Eval("({})", &classesVal); | scriptInterface.CreateObject(&classesVal); | ||||
std::map<std::string, pass_class_t> classes; | std::map<std::string, pass_class_t> classes; | ||||
cmpPathfinder->GetPassabilityClasses(classes); | cmpPathfinder->GetPassabilityClasses(classes); | ||||
for (std::map<std::string, pass_class_t>::iterator it = classes.begin(); it != classes.end(); ++it) | for (std::map<std::string, pass_class_t>::iterator it = classes.begin(); it != classes.end(); ++it) | ||||
scriptInterface.SetProperty(classesVal, it->first.c_str(), it->second, true); | scriptInterface.SetProperty(classesVal, it->first.c_str(), it->second, true); | ||||
scriptInterface.SetProperty(state, "passabilityClasses", classesVal, true); | scriptInterface.SetProperty(state, "passabilityClasses", classesVal, true); | ||||
} | } | ||||
CAIWorker m_Worker; | CAIWorker m_Worker; | ||||
}; | }; | ||||
REGISTER_COMPONENT_TYPE(AIManager) | REGISTER_COMPONENT_TYPE(AIManager) |
Wildfire Games · Phabricator