Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapGenerator.cpp
Show First 20 Lines • Show All 59 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); | pthread_join(m_WorkerThread, nullptr); | ||||
} | } | ||||
void CMapGeneratorWorker::Initialize(const VfsPath& scriptFile, const std::string& settings) | void CMapGeneratorWorker::Initialize(const VfsPath& scriptFile, const std::string& settings) | ||||
{ | { | ||||
CScopeLock lock(m_WorkerMutex); | CScopeLock 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); | int ret = pthread_create(&m_WorkerThread, nullptr, &RunThread, this); | ||||
ENSURE(ret == 0); | ENSURE(ret == 0); | ||||
} | } | ||||
void* CMapGeneratorWorker::RunThread(void *data) | void* CMapGeneratorWorker::RunThread(void *data) | ||||
{ | { | ||||
debug_SetThreadName("MapGenerator"); | debug_SetThreadName("MapGenerator"); | ||||
g_Profiler2.RegisterCurrentThread("MapGenerator"); | g_Profiler2.RegisterCurrentThread("MapGenerator"); | ||||
Show All 13 Lines | if (!self->Run() || self->m_Progress > 0) | ||||
CScopeLock lock(self->m_WorkerMutex); | CScopeLock lock(self->m_WorkerMutex); | ||||
self->m_Progress = -1; | self->m_Progress = -1; | ||||
} | } | ||||
// At this point the random map scripts are done running, so the thread has no further purpose | // At this point the random map scripts are done running, so the thread has no further purpose | ||||
// and can die. The data will be stored in m_MapData already if successful, or m_Progress | // and can die. The data will be stored in m_MapData already if successful, or m_Progress | ||||
// will contain an error value on failure. | // will contain an error value on failure. | ||||
return NULL; | return nullptr; | ||||
} | } | ||||
bool CMapGeneratorWorker::Run() | bool CMapGeneratorWorker::Run() | ||||
{ | { | ||||
// We must destroy the ScriptInterface in the same thread because the JSAPI requires that! | // We must destroy the ScriptInterface in the same thread because the JSAPI requires that! | ||||
// Also we must not be in a request when calling the ScriptInterface destructor, so the autoFree object | // Also we must not be in a request when calling the ScriptInterface destructor, so the autoFree object | ||||
// must be instantiated before the request (destructors are called in reverse order of instantiation) | // must be instantiated before the request (destructors are called in reverse order of instantiation) | ||||
struct AutoFree { | struct AutoFree { | ||||
▲ Show 20 Lines • Show All 291 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator