Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapGenerator.cpp
Show All 25 Lines | |||||
#include "lib/status.h" | #include "lib/status.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/file/vfs/vfs_path.h" | #include "lib/file/vfs/vfs_path.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/FileIo.h" | #include "ps/FileIo.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/scripting/JSInterface_VFS.h" | #include "ps/scripting/JSInterface_VFS.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | |||||
#include "scriptinterface/ScriptRuntime.h" | #include "scriptinterface/ScriptRuntime.h" | ||||
#include "scriptinterface/ScriptConversions.h" | #include "scriptinterface/ScriptConversions.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/helpers/MapEdgeTiles.h" | #include "simulation2/helpers/MapEdgeTiles.h" | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | bool CMapGeneratorWorker::Run() | ||||
{ | { | ||||
LOGERROR("CMapGeneratorWorker::Run: Failed to load RMS '%s'", m_ScriptPath.string8()); | LOGERROR("CMapGeneratorWorker::Run: Failed to load RMS '%s'", m_ScriptPath.string8()); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void CMapGeneratorWorker::InitScriptInterface(const u32 seed) | void CMapGeneratorWorker::InitScriptInterface(const u32 seed) | ||||
Stan: RegisterFunctionMaybe? Can this be something else than a macro? | |||||
{ | { | ||||
m_ScriptInterface->SetCallbackData(static_cast<void*>(this)); | m_ScriptInterface->SetCallbackData(static_cast<void*>(this)); | ||||
m_ScriptInterface->ReplaceNondeterministicRNG(m_MapGenRNG); | m_ScriptInterface->ReplaceNondeterministicRNG(m_MapGenRNG); | ||||
m_MapGenRNG.seed(seed); | m_MapGenRNG.seed(seed); | ||||
// VFS | // VFS | ||||
JSI_VFS::RegisterScriptFunctions_Maps(*m_ScriptInterface); | JSI_VFS::RegisterScriptFunctions_Maps(*m_ScriptInterface); | ||||
// Globalscripts may use VFS script functions | // Globalscripts may use VFS script functions | ||||
m_ScriptInterface->LoadGlobalScripts(); | m_ScriptInterface->LoadGlobalScripts(); | ||||
// File loading | // File loading | ||||
m_ScriptInterface->RegisterFunction<bool, VfsPath, CMapGeneratorWorker::LoadLibrary>("LoadLibrary"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::LoadLibrary), &CMapGeneratorWorker::LoadLibrary>(*m_ScriptInterface, "LoadLibrary"); | ||||
m_ScriptInterface->RegisterFunction<JS::Value, VfsPath, CMapGeneratorWorker::LoadHeightmap>("LoadHeightmapImage"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::LoadHeightmap), &CMapGeneratorWorker::LoadHeightmap>(*m_ScriptInterface, "LoadHeightmapImage"); | ||||
m_ScriptInterface->RegisterFunction<JS::Value, VfsPath, CMapGeneratorWorker::LoadMapTerrain>("LoadMapTerrain"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::LoadMapTerrain), &CMapGeneratorWorker::LoadMapTerrain>(*m_ScriptInterface, "LoadMapTerrain"); | ||||
// Engine constants | // Engine constants | ||||
// Length of one tile of the terrain grid in metres. | // Length of one tile of the terrain grid in metres. | ||||
// Useful to transform footprint sizes to the tilegrid coordinate system. | // Useful to transform footprint sizes to the tilegrid coordinate system. | ||||
m_ScriptInterface->SetGlobal("TERRAIN_TILE_SIZE", static_cast<int>(TERRAIN_TILE_SIZE)); | m_ScriptInterface->SetGlobal("TERRAIN_TILE_SIZE", static_cast<int>(TERRAIN_TILE_SIZE)); | ||||
// Number of impassable tiles at the map border | // Number of impassable tiles at the map border | ||||
m_ScriptInterface->SetGlobal("MAP_BORDER_WIDTH", static_cast<int>(MAP_EDGE_TILES)); | m_ScriptInterface->SetGlobal("MAP_BORDER_WIDTH", static_cast<int>(MAP_EDGE_TILES)); | ||||
} | } | ||||
void CMapGeneratorWorker::RegisterScriptFunctions_MapGenerator() | void CMapGeneratorWorker::RegisterScriptFunctions_MapGenerator() | ||||
{ | { | ||||
// Template functions | // Template functions | ||||
m_ScriptInterface->RegisterFunction<CParamNode, std::string, CMapGeneratorWorker::GetTemplate>("GetTemplate"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::GetTemplate), &CMapGeneratorWorker::GetTemplate>(*m_ScriptInterface, "GetTemplate"); | ||||
m_ScriptInterface->RegisterFunction<bool, std::string, CMapGeneratorWorker::TemplateExists>("TemplateExists"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::TemplateExists), &CMapGeneratorWorker::TemplateExists>(*m_ScriptInterface, "TemplateExists"); | ||||
m_ScriptInterface->RegisterFunction<std::vector<std::string>, std::string, bool, CMapGeneratorWorker::FindTemplates>("FindTemplates"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::FindTemplates), &CMapGeneratorWorker::FindTemplates>(*m_ScriptInterface, "FindTemplates"); | ||||
m_ScriptInterface->RegisterFunction<std::vector<std::string>, std::string, bool, CMapGeneratorWorker::FindActorTemplates>("FindActorTemplates"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::FindActorTemplates), &CMapGeneratorWorker::FindActorTemplates>(*m_ScriptInterface, "FindActorTemplates"); | ||||
// Progression and profiling | // Progression and profiling | ||||
m_ScriptInterface->RegisterFunction<void, int, CMapGeneratorWorker::SetProgress>("SetProgress"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::SetProgress), &CMapGeneratorWorker::SetProgress>(*m_ScriptInterface, "SetProgress"); | ||||
m_ScriptInterface->RegisterFunction<double, CMapGeneratorWorker::GetMicroseconds>("GetMicroseconds"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::GetMicroseconds), &CMapGeneratorWorker::GetMicroseconds>(*m_ScriptInterface, "GetMicroseconds"); | ||||
m_ScriptInterface->RegisterFunction<void, JS::HandleValue, CMapGeneratorWorker::ExportMap>("ExportMap"); | ScriptWrapper::WrapAndRegister<decltype(&CMapGeneratorWorker::ExportMap), &CMapGeneratorWorker::ExportMap>(*m_ScriptInterface, "ExportMap"); | ||||
} | } | ||||
int CMapGeneratorWorker::GetProgress() | int CMapGeneratorWorker::GetProgress() | ||||
{ | { | ||||
std::lock_guard<std::mutex> lock(m_WorkerMutex); | std::lock_guard<std::mutex> lock(m_WorkerMutex); | ||||
return m_Progress; | return m_Progress; | ||||
} | } | ||||
double CMapGeneratorWorker::GetMicroseconds(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | double CMapGeneratorWorker::GetMicroseconds() | ||||
{ | { | ||||
return JS_Now(); | return JS_Now(); | ||||
} | } | ||||
shared_ptr<ScriptInterface::StructuredClone> CMapGeneratorWorker::GetResults() | shared_ptr<ScriptInterface::StructuredClone> CMapGeneratorWorker::GetResults() | ||||
{ | { | ||||
std::lock_guard<std::mutex> lock(m_WorkerMutex); | std::lock_guard<std::mutex> lock(m_WorkerMutex); | ||||
return m_MapData; | return m_MapData; | ||||
▲ Show 20 Lines • Show All 219 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
RegisterFunctionMaybe? Can this be something else than a macro?