Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapGenerator.cpp
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
void* CMapGeneratorWorker::RunThread(CMapGeneratorWorker* self) | void* CMapGeneratorWorker::RunThread(CMapGeneratorWorker* self) | ||||
{ | { | ||||
debug_SetThreadName("MapGenerator"); | debug_SetThreadName("MapGenerator"); | ||||
g_Profiler2.RegisterCurrentThread("MapGenerator"); | g_Profiler2.RegisterCurrentThread("MapGenerator"); | ||||
shared_ptr<ScriptRuntime> mapgenRuntime = ScriptRuntime::CreateRuntime(RMS_RUNTIME_SIZE); | shared_ptr<ScriptRuntime> mapgenRuntime = ScriptRuntime::CreateRuntime(RMS_RUNTIME_SIZE); | ||||
// Enable the script to be aborted | // Enable the script to be aborted | ||||
JS_SetInterruptCallback(mapgenRuntime->m_rt, MapGeneratorInterruptCallback); | JS_SetInterruptCallback(mapgenRuntime->GetJSRuntime(), MapGeneratorInterruptCallback); | ||||
self->m_ScriptInterface = new ScriptInterface("Engine", "MapGenerator", mapgenRuntime); | self->m_ScriptInterface = new ScriptInterface("Engine", "MapGenerator", mapgenRuntime); | ||||
// Run map generation scripts | // Run map generation scripts | ||||
if (!self->Run() || self->m_Progress > 0) | if (!self->Run() || self->m_Progress > 0) | ||||
{ | { | ||||
// Don't leave progress in an unknown state, if generator failed, set it to -1 | // Don't leave progress in an unknown state, if generator failed, set it to -1 | ||||
std::lock_guard<std::mutex> lock(self->m_WorkerMutex); | std::lock_guard<std::mutex> lock(self->m_WorkerMutex); | ||||
Show All 34 Lines | if (!m_ScriptInterface->HasProperty(settingsVal, "Seed") || | ||||
!m_ScriptInterface->GetProperty(settingsVal, "Seed", seed)) | !m_ScriptInterface->GetProperty(settingsVal, "Seed", seed)) | ||||
LOGWARNING("CMapGeneratorWorker::Run: No seed value specified - using 0"); | LOGWARNING("CMapGeneratorWorker::Run: No seed value specified - using 0"); | ||||
InitScriptInterface(seed); | InitScriptInterface(seed); | ||||
RegisterScriptFunctions_MapGenerator(); | RegisterScriptFunctions_MapGenerator(); | ||||
// Copy settings to global variable | // Copy settings to global variable | ||||
JS::RootedValue global(rq.cx, m_ScriptInterface->GetGlobalObject()); | JS::RootedValue global(rq.cx, rq.globalValue()); | ||||
if (!m_ScriptInterface->SetProperty(global, "g_MapSettings", settingsVal, true, true)) | if (!m_ScriptInterface->SetProperty(global, "g_MapSettings", settingsVal, true, true)) | ||||
{ | { | ||||
LOGERROR("CMapGeneratorWorker::Run: Failed to define g_MapSettings"); | LOGERROR("CMapGeneratorWorker::Run: Failed to define g_MapSettings"); | ||||
return false; | return false; | ||||
} | } | ||||
// Load RMS | // Load RMS | ||||
LOGMESSAGE("Loading RMS '%s'", m_ScriptPath.string8()); | LOGMESSAGE("Loading RMS '%s'", m_ScriptPath.string8()); | ||||
▲ Show 20 Lines • Show All 283 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator