Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/MapGenerator.cpp
Show All 25 Lines | |||||
#include "lib/status.h" | #include "lib/status.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/file/vfs/vfs_path.h" | #include "lib/file/vfs/vfs_path.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/FileIo.h" | #include "ps/FileIo.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/scripting/JSInterface_VFS.h" | #include "ps/scripting/JSInterface_VFS.h" | ||||
#include "scriptinterface/ScriptRuntime.h" | #include "scriptinterface/ScriptContext.h" | ||||
#include "scriptinterface/ScriptConversions.h" | #include "scriptinterface/ScriptConversions.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/helpers/MapEdgeTiles.h" | #include "simulation2/helpers/MapEdgeTiles.h" | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
// TODO: Maybe this should be optimized depending on the map size. | // TODO: Maybe this should be optimized depending on the map size. | ||||
constexpr int RMS_RUNTIME_SIZE = 96 * 1024 * 1024; | constexpr int RMS_CONTEXT_SIZE = 96 * 1024 * 1024; | ||||
extern bool IsQuitRequested(); | extern bool IsQuitRequested(); | ||||
static bool | static bool | ||||
MapGeneratorInterruptCallback(JSContext* UNUSED(cx)) | MapGeneratorInterruptCallback(JSContext* UNUSED(cx)) | ||||
{ | { | ||||
// This may not use SDL_IsQuitRequested(), because it runs in a thread separate to SDL, see SDL_PumpEvents | // This may not use SDL_IsQuitRequested(), because it runs in a thread separate to SDL, see SDL_PumpEvents | ||||
if (IsQuitRequested()) | if (IsQuitRequested()) | ||||
Show All 32 Lines | void CMapGeneratorWorker::Initialize(const VfsPath& scriptFile, const std::string& settings) | ||||
m_WorkerThread = std::thread(RunThread, this); | m_WorkerThread = std::thread(RunThread, this); | ||||
} | } | ||||
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<ScriptContext> mapgenContext = ScriptContext::CreateContext(RMS_CONTEXT_SIZE); | ||||
// Enable the script to be aborted | // Enable the script to be aborted | ||||
JS_SetInterruptCallback(mapgenRuntime->GetJSRuntime(), MapGeneratorInterruptCallback); | JS_SetInterruptCallback(mapgenContext->GetJSRuntime(), MapGeneratorInterruptCallback); | ||||
self->m_ScriptInterface = new ScriptInterface("Engine", "MapGenerator", mapgenRuntime); | 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); | ||||
self->m_Progress = -1; | self->m_Progress = -1; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 332 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator