Pyrogenesis  trunk
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CMapGeneratorWorker Class Reference

Random map generator worker thread. More...

#include <MapGenerator.h>

Collaboration diagram for CMapGeneratorWorker:
Collaboration graph
[legend]

Public Member Functions

 CMapGeneratorWorker (ScriptInterface *scriptInterface)
 
 ~CMapGeneratorWorker ()
 
void Initialize (const VfsPath &scriptFile, const std::string &settings)
 Start the map generator thread. More...
 
int GetProgress ()
 Get status of the map generator thread. More...
 
Script::StructuredClone GetResults ()
 Get random map data, according to this format: http://trac.wildfiregames.com/wiki/Random_Map_Generator_Internals#Dataformat. More...
 
void InitScriptInterface (const u32 seed)
 Set initial seed, callback data. More...
 

Private Member Functions

void RegisterScriptFunctions_MapGenerator ()
 Expose functions defined in this class that are relevant to mapscripts but not the tests. More...
 
bool LoadScripts (const VfsPath &libraryName)
 Load all scripts of the given library. More...
 
void ExportMap (JS::HandleValue data)
 Finalize map generation and pass results from the script to the engine. More...
 
JS::Value LoadHeightmap (const VfsPath &src)
 Load an image file and return it as a height array. More...
 
JS::Value LoadMapTerrain (const VfsPath &filename)
 Load an Atlas terrain file (PMP) returning textures and heightmap. More...
 
void SetProgress (int progress)
 Sets the map generation progress, which is one of multiple stages determining the loading screen progress. More...
 
double GetMicroseconds ()
 Microseconds since the epoch. More...
 
CParamNode GetTemplate (const std::string &templateName)
 Return the template data of the given template name. More...
 
bool TemplateExists (const std::string &templateName)
 Check whether the given template exists. More...
 
std::vector< std::string > FindTemplates (const std::string &path, bool includeSubdirectories)
 Returns all template names of simulation entity templates. More...
 
std::vector< std::string > FindActorTemplates (const std::string &path, bool includeSubdirectories)
 Returns all template names of actors. More...
 
bool Run ()
 Perform the map generation. More...
 

Private Attributes

std::set< VfsPathm_LoadedLibraries
 Currently loaded script librarynames. More...
 
Script::StructuredClone m_MapData
 Result of the mapscript generation including terrain, entities and environment settings. More...
 
boost::rand48 m_MapGenRNG
 Deterministic random number generator. More...
 
int m_Progress
 Current map generation progress. More...
 
ScriptInterfacem_ScriptInterface
 Provides the script context. More...
 
VfsPath m_ScriptPath
 Map generation script to run. More...
 
std::string m_Settings
 Map and simulation settings chosen in the gamesetup stage. More...
 
CTemplateLoader m_TemplateLoader
 Backend to loading template data. More...
 
Future< void > m_WorkerThread
 Holds the completion result of the asynchronous map generation. More...
 
std::mutex m_WorkerMutex
 Avoids thread synchronization issues. More...
 

Detailed Description

Random map generator worker thread.

(This is run in a thread so that the GUI remains responsive while loading)

Thread-safety:

Constructor & Destructor Documentation

◆ CMapGeneratorWorker()

CMapGeneratorWorker::CMapGeneratorWorker ( ScriptInterface scriptInterface)

◆ ~CMapGeneratorWorker()

CMapGeneratorWorker::~CMapGeneratorWorker ( )

Member Function Documentation

◆ 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()

Script::StructuredClone CMapGeneratorWorker::GetResults ( )

Get random map data, according to this format: http://trac.wildfiregames.com/wiki/Random_Map_Generator_Internals#Dataformat.

Returns
StructuredClone containing map data

◆ 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
scriptFileThe VFS path for the script, e.g. "maps/random/latium.js"
settingsJSON 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
libraryNameVfsPath 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.

Member Data Documentation

◆ m_LoadedLibraries

std::set<VfsPath> CMapGeneratorWorker::m_LoadedLibraries
private

Currently loaded script librarynames.

◆ m_MapData

Script::StructuredClone CMapGeneratorWorker::m_MapData
private

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

ScriptInterface* CMapGeneratorWorker::m_ScriptInterface
private

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

CTemplateLoader CMapGeneratorWorker::m_TemplateLoader
private

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: