Ticket #1589: rms_interface.patch

File rms_interface.patch, 4.2 KB (added by Itms, 10 years ago)
  • source/graphics/MapGenerator.cpp

     
    1 /* Copyright (C) 2012 Wildfire Games.
     1/* Copyright (C) 2014 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    9191    m_ScriptInterface->RegisterFunction<void, int, CMapGeneratorWorker::SetProgress>("SetProgress");
    9292    m_ScriptInterface->RegisterFunction<void, CMapGeneratorWorker::MaybeGC>("MaybeGC");
    9393    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");
    9497
    9598    // TODO: This code is a bit ugly because we have to ensure that CScriptValRooted gets destroyed before the ScriptInterface.
    9699    // In the future we should work more with the standard JSAPI types for rooting on the stack, which should avoid such problems.
     
    220223
    221224}
    222225
     226CParamNode 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
     239std::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
     245std::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
    223251bool CMapGeneratorWorker::LoadScripts(const std::wstring& libraryName)
    224252{
    225253    // Ignore libraries that are already loaded
  • source/graphics/MapGenerator.h

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2014 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2020
    2121#include "ps/FileIo.h"
    2222#include "ps/ThreadUtil.h"
     23#include "ps/TemplateLoader.h"
    2324#include "scriptinterface/ScriptInterface.h"
    2425
    2526#include <boost/random/linear_congruential.hpp>
     
    125126    static void SetProgress(ScriptInterface::CxPrivate* pCxPrivate, int progress);
    126127    static void MaybeGC(ScriptInterface::CxPrivate* pCxPrivate);
    127128    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);
    128132
    129133    std::set<std::wstring> m_LoadedLibraries;
    130134    shared_ptr<ScriptInterface::StructuredClone> m_MapData;
     
    133137    ScriptInterface* m_ScriptInterface;
    134138    VfsPath m_ScriptPath;
    135139    std::string m_Settings;
     140    CTemplateLoader m_TemplateLoader;
    136141
    137142// Thread
    138143    static void* RunThread(void* data);