Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
CMapGeneratorWorker Class Reference

Random map generator worker thread. More...

#include <MapGenerator.h>

Public Member Functions

 CMapGeneratorWorker ()
 
 ~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...
 
shared_ptr
< ScriptInterface::StructuredClone
GetResults ()
 Get random map data, according to this format: http://trac.wildfiregames.com/wiki/Random_Map_Generator_Internals#Dataformat. More...
 

Private Member Functions

bool LoadScripts (const std::wstring &libraryName)
 Load all scripts of the given library. More...
 
bool Run ()
 

Static Private Member Functions

static bool LoadLibrary (void *cbdata, std::wstring name)
 
static void ExportMap (void *cbdata, CScriptValRooted data)
 
static void SetProgress (void *cbdata, int progress)
 
static void MaybeGC (void *cbdata)
 
static std::vector< std::string > GetCivData (void *cbdata)
 
static void * RunThread (void *data)
 

Private Attributes

std::set< std::wstring > m_LoadedLibraries
 
shared_ptr
< ScriptInterface::StructuredClone
m_MapData
 
boost::rand48 m_MapGenRNG
 
int m_Progress
 
ScriptInterfacem_ScriptInterface
 
VfsPath m_ScriptPath
 
std::string m_Settings
 
pthread_t m_WorkerThread
 
CMutex m_WorkerMutex
 

Detailed Description

Random map generator worker thread.

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

Thread-safety:

Definition at line 82 of file MapGenerator.h.

Constructor & Destructor Documentation

CMapGeneratorWorker::CMapGeneratorWorker ( )

Definition at line 30 of file MapGenerator.cpp.

CMapGeneratorWorker::~CMapGeneratorWorker ( )

Definition at line 36 of file MapGenerator.cpp.

Member Function Documentation

void CMapGeneratorWorker::ExportMap ( void *  cbdata,
CScriptValRooted  data 
)
staticprivate

Definition at line 157 of file MapGenerator.cpp.

std::vector< std::string > CMapGeneratorWorker::GetCivData ( void *  cbdata)
staticprivate

Definition at line 182 of file MapGenerator.cpp.

int CMapGeneratorWorker::GetProgress ( )

Get status of the map generator thread.

Returns
Progress percentage 1-100 if active, 0 when finished, or -1 on error

Definition at line 138 of file MapGenerator.cpp.

shared_ptr< ScriptInterface::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

Definition at line 144 of file MapGenerator.cpp.

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

Definition at line 49 of file MapGenerator.cpp.

bool CMapGeneratorWorker::LoadLibrary ( void *  cbdata,
std::wstring  name 
)
staticprivate

Definition at line 150 of file MapGenerator.cpp.

bool CMapGeneratorWorker::LoadScripts ( const std::wstring &  libraryName)
private

Load all scripts of the given library.

Parameters
libraryNameString specifying name of the library (subfolder of ../maps/random/)
Returns
true if all scripts ran successfully, false if there's an error

Definition at line 219 of file MapGenerator.cpp.

void CMapGeneratorWorker::MaybeGC ( void *  cbdata)
staticprivate

Definition at line 176 of file MapGenerator.cpp.

bool CMapGeneratorWorker::Run ( )
private

Definition at line 87 of file MapGenerator.cpp.

void * CMapGeneratorWorker::RunThread ( void *  data)
staticprivate

Definition at line 63 of file MapGenerator.cpp.

void CMapGeneratorWorker::SetProgress ( void *  cbdata,
int  progress 
)
staticprivate

Definition at line 167 of file MapGenerator.cpp.

Member Data Documentation

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

Definition at line 129 of file MapGenerator.h.

shared_ptr<ScriptInterface::StructuredClone> CMapGeneratorWorker::m_MapData
private

Definition at line 130 of file MapGenerator.h.

boost::rand48 CMapGeneratorWorker::m_MapGenRNG
private

Definition at line 131 of file MapGenerator.h.

int CMapGeneratorWorker::m_Progress
private

Definition at line 132 of file MapGenerator.h.

ScriptInterface* CMapGeneratorWorker::m_ScriptInterface
private

Definition at line 133 of file MapGenerator.h.

VfsPath CMapGeneratorWorker::m_ScriptPath
private

Definition at line 134 of file MapGenerator.h.

std::string CMapGeneratorWorker::m_Settings
private

Definition at line 135 of file MapGenerator.h.

CMutex CMapGeneratorWorker::m_WorkerMutex
private

Definition at line 142 of file MapGenerator.h.

pthread_t CMapGeneratorWorker::m_WorkerThread
private

Definition at line 141 of file MapGenerator.h.


The documentation for this class was generated from the following files: