Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/MapGenerator.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
// If something happens before we initialize, that's a failure | // If something happens before we initialize, that's a failure | ||||
m_Progress = -1; | m_Progress = -1; | ||||
} | } | ||||
CMapGeneratorWorker::~CMapGeneratorWorker() | CMapGeneratorWorker::~CMapGeneratorWorker() | ||||
{ | { | ||||
// Wait for thread to end | // Wait for thread to end | ||||
pthread_join(m_WorkerThread, NULL); | m_WorkerThread.join(); | ||||
} | } | ||||
void CMapGeneratorWorker::Initialize(const VfsPath& scriptFile, const std::string& settings) | void CMapGeneratorWorker::Initialize(const VfsPath& scriptFile, const std::string& settings) | ||||
{ | { | ||||
std::lock_guard<std::mutex> lock(m_WorkerMutex); | std::lock_guard<std::mutex> lock(m_WorkerMutex); | ||||
// Set progress to positive value | // Set progress to positive value | ||||
m_Progress = 1; | m_Progress = 1; | ||||
m_ScriptPath = scriptFile; | m_ScriptPath = scriptFile; | ||||
m_Settings = settings; | m_Settings = settings; | ||||
// Launch the worker thread | // Launch the worker thread | ||||
int ret = pthread_create(&m_WorkerThread, NULL, &RunThread, this); | m_WorkerThread = std::thread(RunThread, this); | ||||
ENSURE(ret == 0); | |||||
} | } | ||||
void* CMapGeneratorWorker::RunThread(void *data) | void* CMapGeneratorWorker::RunThread(CMapGeneratorWorker* self) | ||||
{ | { | ||||
debug_SetThreadName("MapGenerator"); | debug_SetThreadName("MapGenerator"); | ||||
g_Profiler2.RegisterCurrentThread("MapGenerator"); | g_Profiler2.RegisterCurrentThread("MapGenerator"); | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(data); | |||||
shared_ptr<ScriptRuntime> mapgenRuntime = ScriptInterface::CreateRuntime(g_ScriptRuntime, RMS_RUNTIME_SIZE); | shared_ptr<ScriptRuntime> mapgenRuntime = ScriptInterface::CreateRuntime(g_ScriptRuntime, RMS_RUNTIME_SIZE); | ||||
// Enable the script to be aborted | // Enable the script to be aborted | ||||
JS_SetInterruptCallback(mapgenRuntime->m_rt, MapGeneratorInterruptCallback); | JS_SetInterruptCallback(mapgenRuntime->m_rt, 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 | ||||
▲ Show 20 Lines • Show All 337 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator