Pyrogenesis  trunk
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>

Collaboration diagram for CMapGeneratorWorker:
Collaboration graph
[legend]

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::StructuredCloneGetResults ()
 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 (ScriptInterface::CxPrivate *pCxPrivate, const std::wstring &name)
 
static void ExportMap (ScriptInterface::CxPrivate *pCxPrivate, JS::HandleValue data)
 
static void SetProgress (ScriptInterface::CxPrivate *pCxPrivate, int progress)
 
static void MaybeGC (ScriptInterface::CxPrivate *pCxPrivate)
 
static std::vector< std::string > GetCivData (ScriptInterface::CxPrivate *pCxPrivate)
 
static CParamNode GetTemplate (ScriptInterface::CxPrivate *pCxPrivate, const std::string &templateName)
 
static bool TemplateExists (ScriptInterface::CxPrivate *pCxPrivate, const std::string &templateName)
 
static std::vector< std::string > FindTemplates (ScriptInterface::CxPrivate *pCxPrivate, const std::string &path, bool includeSubdirectories)
 
static std::vector< std::string > FindActorTemplates (ScriptInterface::CxPrivate *pCxPrivate, const std::string &path, bool includeSubdirectories)
 
static void * RunThread (void *data)
 

Private Attributes

std::set< std::wstring > m_LoadedLibraries
 
shared_ptr< ScriptInterface::StructuredClonem_MapData
 
boost::rand48 m_MapGenRNG
 
int m_Progress
 
ScriptInterfacem_ScriptInterface
 
VfsPath m_ScriptPath
 
std::string m_Settings
 
CTemplateLoader m_TemplateLoader
 
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:

Constructor & Destructor Documentation

CMapGeneratorWorker::CMapGeneratorWorker ( )
CMapGeneratorWorker::~CMapGeneratorWorker ( )

Member Function Documentation

void CMapGeneratorWorker::ExportMap ( ScriptInterface::CxPrivate pCxPrivate,
JS::HandleValue  data 
)
staticprivate
std::vector< std::string > CMapGeneratorWorker::FindActorTemplates ( ScriptInterface::CxPrivate pCxPrivate,
const std::string &  path,
bool  includeSubdirectories 
)
staticprivate
std::vector< std::string > CMapGeneratorWorker::FindTemplates ( ScriptInterface::CxPrivate pCxPrivate,
const std::string &  path,
bool  includeSubdirectories 
)
staticprivate
std::vector< std::string > CMapGeneratorWorker::GetCivData ( ScriptInterface::CxPrivate pCxPrivate)
staticprivate
int CMapGeneratorWorker::GetProgress ( )

Get status of the map generator thread.

Returns
Progress percentage 1-100 if active, 0 when finished, or -1 on error
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
CParamNode CMapGeneratorWorker::GetTemplate ( ScriptInterface::CxPrivate pCxPrivate,
const std::string &  templateName 
)
staticprivate
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
bool CMapGeneratorWorker::LoadLibrary ( ScriptInterface::CxPrivate pCxPrivate,
const std::wstring &  name 
)
staticprivate
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
void CMapGeneratorWorker::MaybeGC ( ScriptInterface::CxPrivate pCxPrivate)
staticprivate
bool CMapGeneratorWorker::Run ( )
private
void * CMapGeneratorWorker::RunThread ( void *  data)
staticprivate
void CMapGeneratorWorker::SetProgress ( ScriptInterface::CxPrivate pCxPrivate,
int  progress 
)
staticprivate
bool CMapGeneratorWorker::TemplateExists ( ScriptInterface::CxPrivate pCxPrivate,
const std::string &  templateName 
)
staticprivate

Member Data Documentation

std::set<std::wstring> CMapGeneratorWorker::m_LoadedLibraries
private
shared_ptr<ScriptInterface::StructuredClone> CMapGeneratorWorker::m_MapData
private
boost::rand48 CMapGeneratorWorker::m_MapGenRNG
private
int CMapGeneratorWorker::m_Progress
private
ScriptInterface* CMapGeneratorWorker::m_ScriptInterface
private
VfsPath CMapGeneratorWorker::m_ScriptPath
private
std::string CMapGeneratorWorker::m_Settings
private
CTemplateLoader CMapGeneratorWorker::m_TemplateLoader
private
CMutex CMapGeneratorWorker::m_WorkerMutex
private
pthread_t CMapGeneratorWorker::m_WorkerThread
private

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