18 #include "precompiled.h"
27 #define RMS_RUNTIME_SIZE 96 * 1024 * 1024
73 if ((!self->Run()) || (self->m_Progress > 0))
77 self->m_Progress = -1;
104 if (settingsVal.undefined())
106 LOGERROR(L
"CMapGeneratorWorker::Run: Failed to parse settings");
114 LOGWARNING(L
"CMapGeneratorWorker::Run: No seed value specified - using 0");
123 LOGERROR(L
"CMapGeneratorWorker::Run: Failed to define g_MapSettings");
163 self->m_MapData =
self->m_ScriptInterface->WriteStructuredClone(data.
get());
164 self->m_Progress = 0;
173 self->m_Progress = progress;
187 std::vector<std::string> data;
193 for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
230 VfsPath path = L
"maps/random/" + libraryName + L
"/";
237 for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
239 LOGMESSAGE(L
"Loading map generator script '%ls'", it->string().c_str());
243 LOGERROR(L
"CMapGeneratorWorker::LoadScripts: Failed to load script '%ls'", it->string().c_str());
int GetProgress()
Get status of the map generator thread.
CStr DecodeUTF8() const
Returns contents of a UTF-8 encoded file as a string with optional BOM removed.
bool ReplaceNondeterministicRNG(boost::rand48 &rng)
Replace the default JS random number geenrator with a seeded, network-sync'd one. ...
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
void SetCallbackData(void *cbdata)
const PSRETURN PSRETURN_OK
Reads a file, then gives read-only access to the contents.
static void SetProgress(void *cbdata, int progress)
CMapGeneratorWorker * m_Worker
shared_ptr< ScriptInterface::StructuredClone > GetResults()
Get random map data, according to this format: http://trac.wildfiregames.com/wiki/Random_Map_Generato...
static void MaybeGC(void *cbdata)
static std::vector< std::string > GetCivData(void *cbdata)
Locks a CMutex over this object's lifetime.
boost::rand48 m_MapGenRNG
bool LoadGlobalScripts()
Load global scripts that most script contexts need, located in the /globalscripts directory...
CScriptValRooted ParseJSON(const std::string &string_utf8)
Parse a UTF-8-encoded JSON string.
static void * RunThread(void *data)
LIB_API void debug_SetThreadName(const char *name)
inform the debugger of the current thread's name.
shared_ptr< ScriptInterface::StructuredClone > m_MapData
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
static void ExportMap(void *cbdata, CScriptValRooted data)
int pthread_create(pthread_t *thread_id, const void *attr, void *(*func)(void *), void *arg)
void RegisterCurrentThread(const std::string &name)
Call in any thread to enable the profiler in that thread.
const String & string() const
bool LoadGlobalScriptFile(const VfsPath &path)
Load and execute the given script in the global scope.
ScriptInterface * m_ScriptInterface
std::set< std::wstring > m_LoadedLibraries
int GetProgress()
Get status of the map generator thread.
static bool LoadLibrary(void *cbdata, std::wstring name)
i64 Status
Error handling system.
Random map generator worker thread.
const char * GetErrorString(PSRETURN code)
bool GetProperty(jsval obj, const char *name, T &out)
Get the named property on the given object.
void GenerateMap(const VfsPath &scriptFile, const std::string &settings)
Start the map generator thread.
PSRETURN Load(const PIVFS &vfs, const VfsPath &filename)
Returns either PSRETURN_OK or PSRETURN_CVFSFile_LoadFailed.
wchar_t * StatusDescription(Status status, wchar_t *buf, size_t max_chars)
generate textual description of a Status.
std::vector< VfsPath > VfsPaths
JSBool error(JSContext *cx, uintN argc, jsval *vp)
shared_ptr< ScriptInterface::StructuredClone > GetResults()
Get random map data, according to this format: http://trac.wildfiregames.com/wiki/Random_Map_Generato...
jsval get() const
Returns the current value (or JSVAL_VOID if uninitialised).
Abstraction around a SpiderMonkey JSContext.
int pthread_join(pthread_t thread, void **value_ptr)
bool SetProperty(jsval obj, const char *name, const T &value, bool constant=false, bool enumerate=true)
Set the named property on the given object.
bool LoadScripts(const std::wstring &libraryName)
Load all scripts of the given library.
void Initialize(const VfsPath &scriptFile, const std::string &settings)
Start the map generator thread.
static shared_ptr< ScriptRuntime > CreateRuntime(int runtimeSize=DEFAULT_RUNTIME_SIZE)
Returns a runtime, which can used to initialise any number of ScriptInterfaces contexts.
Status GetPathnames(const PIVFS &fs, const VfsPath &path, const wchar_t *filter, VfsPaths &pathnames)
void MaybeGC()
MaybeGC tries to determine whether garbage collection in cx's runtime would free up enough memory to ...