Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/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<ScriptContext> mapgenContext = ScriptContext::CreateContext(RMS_CONTEXT_SIZE); | shared_ptr<ScriptContext> mapgenContext = ScriptContext::CreateContext(RMS_CONTEXT_SIZE); | ||||
// Enable the script to be aborted | // Enable the script to be aborted | ||||
JS_SetInterruptCallback(mapgenContext->GetJSRuntime(), MapGeneratorInterruptCallback); | JS_AddInterruptCallback(mapgenContext->GetGeneralJSContext(), MapGeneratorInterruptCallback); | ||||
self->m_ScriptInterface = new ScriptInterface("Engine", "MapGenerator", mapgenContext); | self->m_ScriptInterface = new ScriptInterface("Engine", "MapGenerator", mapgenContext); | ||||
// 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 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | int CMapGeneratorWorker::GetProgress() | ||||
return m_Progress; | return m_Progress; | ||||
} | } | ||||
double CMapGeneratorWorker::GetMicroseconds(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | double CMapGeneratorWorker::GetMicroseconds(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
return JS_Now(); | return JS_Now(); | ||||
} | } | ||||
shared_ptr<ScriptInterface::StructuredClone> CMapGeneratorWorker::GetResults() | ScriptInterface::StructuredClone CMapGeneratorWorker::GetResults() | ||||
{ | { | ||||
std::lock_guard<std::mutex> lock(m_WorkerMutex); | std::lock_guard<std::mutex> lock(m_WorkerMutex); | ||||
return m_MapData; | return m_MapData; | ||||
} | } | ||||
bool CMapGeneratorWorker::LoadLibrary(ScriptInterface::CmptPrivate* pCmptPrivate, const VfsPath& name) | bool CMapGeneratorWorker::LoadLibrary(ScriptInterface::CmptPrivate* pCmptPrivate, const VfsPath& name) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
return self->LoadScripts(name); | return self->LoadScripts(name); | ||||
} | } | ||||
void CMapGeneratorWorker::ExportMap(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue data) | void CMapGeneratorWorker::ExportMap(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue data) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
// Copy results | // Copy results | ||||
std::lock_guard<std::mutex> lock(self->m_WorkerMutex); | std::lock_guard<std::mutex> lock(self->m_WorkerMutex); | ||||
self->m_MapData = self->m_ScriptInterface->WriteStructuredClone(data); | self->m_MapData = self->m_ScriptInterface->WriteStructuredClone(data, false); | ||||
self->m_Progress = 0; | self->m_Progress = 0; | ||||
} | } | ||||
void CMapGeneratorWorker::SetProgress(ScriptInterface::CmptPrivate* pCmptPrivate, int progress) | void CMapGeneratorWorker::SetProgress(ScriptInterface::CmptPrivate* pCmptPrivate, int progress) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
// Copy data | // Copy data | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | void CMapGenerator::GenerateMap(const VfsPath& scriptFile, const std::string& settings) | ||||
m_Worker->Initialize(scriptFile, settings); | m_Worker->Initialize(scriptFile, settings); | ||||
} | } | ||||
int CMapGenerator::GetProgress() | int CMapGenerator::GetProgress() | ||||
{ | { | ||||
return m_Worker->GetProgress(); | return m_Worker->GetProgress(); | ||||
} | } | ||||
shared_ptr<ScriptInterface::StructuredClone> CMapGenerator::GetResults() | ScriptInterface::StructuredClone CMapGenerator::GetResults() | ||||
{ | { | ||||
return m_Worker->GetResults(); | return m_Worker->GetResults(); | ||||
} | } |
Wildfire Games · Phabricator