Random map generator worker thread.
More...
#include <MapGenerator.h>
Random map generator worker thread.
(This is run in a thread so that the GUI remains responsive while loading)
Thread-safety:
- Initialize and constructor/destructor must be called from the main thread.
- ScriptInterface created and destroyed by thread
- StructuredClone used to return JS map data - JS:Values can't be used across threads/contexts.
◆ CMapGeneratorWorker()
CMapGeneratorWorker::CMapGeneratorWorker |
( |
ScriptInterface * |
scriptInterface | ) |
|
◆ ~CMapGeneratorWorker()
CMapGeneratorWorker::~CMapGeneratorWorker |
( |
| ) |
|
◆ ExportMap()
void CMapGeneratorWorker::ExportMap |
( |
JS::HandleValue |
data | ) |
|
|
private |
Finalize map generation and pass results from the script to the engine.
◆ FindActorTemplates()
std::vector< std::string > CMapGeneratorWorker::FindActorTemplates |
( |
const std::string & |
path, |
|
|
bool |
includeSubdirectories |
|
) |
| |
|
private |
Returns all template names of actors.
◆ FindTemplates()
std::vector< std::string > CMapGeneratorWorker::FindTemplates |
( |
const std::string & |
path, |
|
|
bool |
includeSubdirectories |
|
) |
| |
|
private |
Returns all template names of simulation entity templates.
◆ GetMicroseconds()
double CMapGeneratorWorker::GetMicroseconds |
( |
| ) |
|
|
private |
Microseconds since the epoch.
◆ GetProgress()
int CMapGeneratorWorker::GetProgress |
( |
| ) |
|
Get status of the map generator thread.
- Returns
- Progress percentage 1-100 if active, 0 when finished, or -1 on error
◆ GetResults()
◆ GetTemplate()
CParamNode CMapGeneratorWorker::GetTemplate |
( |
const std::string & |
templateName | ) |
|
|
private |
Return the template data of the given template name.
◆ Initialize()
void CMapGeneratorWorker::Initialize |
( |
const VfsPath & |
scriptFile, |
|
|
const std::string & |
settings |
|
) |
| |
Start the map generator thread.
- Parameters
-
scriptFile | The VFS path for the script, e.g. "maps/random/latium.js" |
settings | JSON string containing settings for the map generator |
◆ InitScriptInterface()
void CMapGeneratorWorker::InitScriptInterface |
( |
const u32 |
seed | ) |
|
Set initial seed, callback data.
Expose functions, globals and classes defined in this class relevant to the map and test scripts.
◆ LoadHeightmap()
JS::Value CMapGeneratorWorker::LoadHeightmap |
( |
const VfsPath & |
src | ) |
|
|
private |
Load an image file and return it as a height array.
◆ LoadMapTerrain()
JS::Value CMapGeneratorWorker::LoadMapTerrain |
( |
const VfsPath & |
filename | ) |
|
|
private |
Load an Atlas terrain file (PMP) returning textures and heightmap.
◆ LoadScripts()
bool CMapGeneratorWorker::LoadScripts |
( |
const VfsPath & |
libraryName | ) |
|
|
private |
Load all scripts of the given library.
- Parameters
-
libraryName | VfsPath specifying name of the library (subfolder of ../maps/random/) |
- Returns
- true if all scripts ran successfully, false if there's an error
◆ RegisterScriptFunctions_MapGenerator()
void CMapGeneratorWorker::RegisterScriptFunctions_MapGenerator |
( |
| ) |
|
|
private |
Expose functions defined in this class that are relevant to mapscripts but not the tests.
◆ Run()
bool CMapGeneratorWorker::Run |
( |
| ) |
|
|
private |
Perform the map generation.
◆ SetProgress()
void CMapGeneratorWorker::SetProgress |
( |
int |
progress | ) |
|
|
private |
Sets the map generation progress, which is one of multiple stages determining the loading screen progress.
◆ TemplateExists()
bool CMapGeneratorWorker::TemplateExists |
( |
const std::string & |
templateName | ) |
|
|
private |
Check whether the given template exists.
◆ m_LoadedLibraries
std::set<VfsPath> CMapGeneratorWorker::m_LoadedLibraries |
|
private |
Currently loaded script librarynames.
◆ m_MapData
Result of the mapscript generation including terrain, entities and environment settings.
◆ m_MapGenRNG
boost::rand48 CMapGeneratorWorker::m_MapGenRNG |
|
private |
Deterministic random number generator.
◆ m_Progress
int CMapGeneratorWorker::m_Progress |
|
private |
Current map generation progress.
◆ m_ScriptInterface
Provides the script context.
◆ m_ScriptPath
VfsPath CMapGeneratorWorker::m_ScriptPath |
|
private |
Map generation script to run.
◆ m_Settings
std::string CMapGeneratorWorker::m_Settings |
|
private |
Map and simulation settings chosen in the gamesetup stage.
◆ m_TemplateLoader
Backend to loading template data.
◆ m_WorkerMutex
std::mutex CMapGeneratorWorker::m_WorkerMutex |
|
private |
Avoids thread synchronization issues.
◆ m_WorkerThread
Future<void> CMapGeneratorWorker::m_WorkerThread |
|
private |
Holds the completion result of the asynchronous map generation.
TODO: this whole class could really be a future on its own.
The documentation for this class was generated from the following files: