Ticket #1589: rms_interface.patch
File rms_interface.patch, 4.2 KB (added by , 10 years ago) |
---|
-
source/graphics/MapGenerator.cpp
1 /* Copyright (C) 201 2Wildfire Games.1 /* Copyright (C) 2014 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 91 91 m_ScriptInterface->RegisterFunction<void, int, CMapGeneratorWorker::SetProgress>("SetProgress"); 92 92 m_ScriptInterface->RegisterFunction<void, CMapGeneratorWorker::MaybeGC>("MaybeGC"); 93 93 m_ScriptInterface->RegisterFunction<std::vector<std::string>, CMapGeneratorWorker::GetCivData>("GetCivData"); 94 m_ScriptInterface->RegisterFunction<CParamNode, std::string, CMapGeneratorWorker::GetTemplate>("GetTemplate"); 95 m_ScriptInterface->RegisterFunction<std::vector<std::string>, std::string, bool, CMapGeneratorWorker::FindTemplates>("FindTemplates"); 96 m_ScriptInterface->RegisterFunction<std::vector<std::string>, std::string, bool, CMapGeneratorWorker::FindActorTemplates>("FindActorTemplates"); 94 97 95 98 // TODO: This code is a bit ugly because we have to ensure that CScriptValRooted gets destroyed before the ScriptInterface. 96 99 // In the future we should work more with the standard JSAPI types for rooting on the stack, which should avoid such problems. … … 220 223 221 224 } 222 225 226 CParamNode CMapGeneratorWorker::GetTemplate(ScriptInterface::CxPrivate* pCxPrivate, std::string templateName) 227 { 228 // TODO: Find a way to validate templates outside of the simulation. 229 // This should be implemented in TemplateLoader though. 230 231 CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); 232 const CParamNode& templateRoot = self->m_TemplateLoader.GetTemplateFileData(templateName).GetChild("Entity"); 233 if (!templateRoot.IsOk()) 234 LOGERROR(L"Invalid template found for '%hs'", templateName.c_str()); 235 236 return templateRoot; 237 } 238 239 std::vector<std::string> CMapGeneratorWorker::FindTemplates(ScriptInterface::CxPrivate* pCxPrivate, std::string path, bool includeSubdirectories) 240 { 241 CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); 242 return self->m_TemplateLoader.FindTemplates(path, includeSubdirectories, SIMULATION_TEMPLATES); 243 } 244 245 std::vector<std::string> CMapGeneratorWorker::FindActorTemplates(ScriptInterface::CxPrivate* pCxPrivate, std::string path, bool includeSubdirectories) 246 { 247 CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); 248 return self->m_TemplateLoader.FindTemplates(path, includeSubdirectories, ACTOR_TEMPLATES); 249 } 250 223 251 bool CMapGeneratorWorker::LoadScripts(const std::wstring& libraryName) 224 252 { 225 253 // Ignore libraries that are already loaded -
source/graphics/MapGenerator.h
1 /* Copyright (C) 201 3Wildfire Games.1 /* Copyright (C) 2014 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 20 20 21 21 #include "ps/FileIo.h" 22 22 #include "ps/ThreadUtil.h" 23 #include "ps/TemplateLoader.h" 23 24 #include "scriptinterface/ScriptInterface.h" 24 25 25 26 #include <boost/random/linear_congruential.hpp> … … 125 126 static void SetProgress(ScriptInterface::CxPrivate* pCxPrivate, int progress); 126 127 static void MaybeGC(ScriptInterface::CxPrivate* pCxPrivate); 127 128 static std::vector<std::string> GetCivData(ScriptInterface::CxPrivate* pCxPrivate); 129 static CParamNode GetTemplate(ScriptInterface::CxPrivate* pCxPrivate, std::string templateName); 130 static std::vector<std::string> FindTemplates(ScriptInterface::CxPrivate* pCxPrivate, std::string path, bool includeSubdirectories); 131 static std::vector<std::string> FindActorTemplates(ScriptInterface::CxPrivate* pCxPrivate, std::string path, bool includeSubdirectories); 128 132 129 133 std::set<std::wstring> m_LoadedLibraries; 130 134 shared_ptr<ScriptInterface::StructuredClone> m_MapData; … … 133 137 ScriptInterface* m_ScriptInterface; 134 138 VfsPath m_ScriptPath; 135 139 std::string m_Settings; 140 CTemplateLoader m_TemplateLoader; 136 141 137 142 // Thread 138 143 static void* RunThread(void* data);