Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/graphics/MapGenerator.cpp
Show First 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
int CMapGeneratorWorker::GetProgress() | int CMapGeneratorWorker::GetProgress() | ||||
{ | { | ||||
std::lock_guard<std::mutex> lock(m_WorkerMutex); | std::lock_guard<std::mutex> lock(m_WorkerMutex); | ||||
return m_Progress; | return m_Progress; | ||||
} | } | ||||
double CMapGeneratorWorker::GetMicroseconds(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | double CMapGeneratorWorker::GetMicroseconds(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
return JS_Now(); | return JS_Now(); | ||||
} | } | ||||
shared_ptr<ScriptInterface::StructuredClone> CMapGeneratorWorker::GetResults() | shared_ptr<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::CxPrivate* pCxPrivate, const VfsPath& name) | bool CMapGeneratorWorker::LoadLibrary(ScriptInterface::CmptPrivate* pCmptPrivate, const VfsPath& name) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
return self->LoadScripts(name); | return self->LoadScripts(name); | ||||
} | } | ||||
void CMapGeneratorWorker::ExportMap(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data) | void CMapGeneratorWorker::ExportMap(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue data) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->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); | ||||
self->m_Progress = 0; | self->m_Progress = 0; | ||||
} | } | ||||
void CMapGeneratorWorker::SetProgress(ScriptInterface::CxPrivate* pCxPrivate, int progress) | void CMapGeneratorWorker::SetProgress(ScriptInterface::CmptPrivate* pCmptPrivate, int progress) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
// Copy data | // Copy data | ||||
std::lock_guard<std::mutex> lock(self->m_WorkerMutex); | std::lock_guard<std::mutex> lock(self->m_WorkerMutex); | ||||
if (progress >= self->m_Progress) | if (progress >= self->m_Progress) | ||||
self->m_Progress = progress; | self->m_Progress = progress; | ||||
else | else | ||||
LOGWARNING("The random map script tried to reduce the loading progress from %d to %d", self->m_Progress, progress); | LOGWARNING("The random map script tried to reduce the loading progress from %d to %d", self->m_Progress, progress); | ||||
} | } | ||||
CParamNode CMapGeneratorWorker::GetTemplate(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName) | CParamNode CMapGeneratorWorker::GetTemplate(ScriptInterface::CmptPrivate* pCmptPrivate, const std::string& templateName) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
const CParamNode& templateRoot = self->m_TemplateLoader.GetTemplateFileData(templateName).GetChild("Entity"); | const CParamNode& templateRoot = self->m_TemplateLoader.GetTemplateFileData(templateName).GetChild("Entity"); | ||||
if (!templateRoot.IsOk()) | if (!templateRoot.IsOk()) | ||||
LOGERROR("Invalid template found for '%s'", templateName.c_str()); | LOGERROR("Invalid template found for '%s'", templateName.c_str()); | ||||
return templateRoot; | return templateRoot; | ||||
} | } | ||||
bool CMapGeneratorWorker::TemplateExists(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName) | bool CMapGeneratorWorker::TemplateExists(ScriptInterface::CmptPrivate* pCmptPrivate, const std::string& templateName) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
return self->m_TemplateLoader.TemplateExists(templateName); | return self->m_TemplateLoader.TemplateExists(templateName); | ||||
} | } | ||||
std::vector<std::string> CMapGeneratorWorker::FindTemplates(ScriptInterface::CxPrivate* pCxPrivate, const std::string& path, bool includeSubdirectories) | std::vector<std::string> CMapGeneratorWorker::FindTemplates(ScriptInterface::CmptPrivate* pCmptPrivate, const std::string& path, bool includeSubdirectories) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
return self->m_TemplateLoader.FindTemplates(path, includeSubdirectories, SIMULATION_TEMPLATES); | return self->m_TemplateLoader.FindTemplates(path, includeSubdirectories, SIMULATION_TEMPLATES); | ||||
} | } | ||||
std::vector<std::string> CMapGeneratorWorker::FindActorTemplates(ScriptInterface::CxPrivate* pCxPrivate, const std::string& path, bool includeSubdirectories) | std::vector<std::string> CMapGeneratorWorker::FindActorTemplates(ScriptInterface::CmptPrivate* pCmptPrivate, const std::string& path, bool includeSubdirectories) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
return self->m_TemplateLoader.FindTemplates(path, includeSubdirectories, ACTOR_TEMPLATES); | return self->m_TemplateLoader.FindTemplates(path, includeSubdirectories, ACTOR_TEMPLATES); | ||||
} | } | ||||
bool CMapGeneratorWorker::LoadScripts(const VfsPath& libraryName) | bool CMapGeneratorWorker::LoadScripts(const VfsPath& libraryName) | ||||
{ | { | ||||
// Ignore libraries that are already loaded | // Ignore libraries that are already loaded | ||||
if (m_LoadedLibraries.find(libraryName) != m_LoadedLibraries.end()) | if (m_LoadedLibraries.find(libraryName) != m_LoadedLibraries.end()) | ||||
return true; | return true; | ||||
Show All 25 Lines | else | ||||
wchar_t error[200]; | wchar_t error[200]; | ||||
LOGERROR("CMapGeneratorWorker::LoadScripts: Error reading scripts in directory '%s': %s", path.string8(), utf8_from_wstring(StatusDescription(ret, error, ARRAY_SIZE(error)))); | LOGERROR("CMapGeneratorWorker::LoadScripts: Error reading scripts in directory '%s': %s", path.string8(), utf8_from_wstring(StatusDescription(ret, error, ARRAY_SIZE(error)))); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
JS::Value CMapGeneratorWorker::LoadHeightmap(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath& filename) | JS::Value CMapGeneratorWorker::LoadHeightmap(ScriptInterface::CmptPrivate* pCmptPrivate, const VfsPath& filename) | ||||
{ | { | ||||
std::vector<u16> heightmap; | std::vector<u16> heightmap; | ||||
if (LoadHeightmapImageVfs(filename, heightmap) != INFO::OK) | if (LoadHeightmapImageVfs(filename, heightmap) != INFO::OK) | ||||
{ | { | ||||
LOGERROR("Could not load heightmap file '%s'", filename.string8()); | LOGERROR("Could not load heightmap file '%s'", filename.string8()); | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
} | } | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
ScriptInterface::Request rq(self->m_ScriptInterface); | ScriptInterface::Request rq(self->m_ScriptInterface); | ||||
JS::RootedValue returnValue(rq.cx); | JS::RootedValue returnValue(rq.cx); | ||||
ToJSVal_vector(rq, &returnValue, heightmap); | ToJSVal_vector(rq, &returnValue, heightmap); | ||||
return returnValue; | return returnValue; | ||||
} | } | ||||
// See CMapReader::UnpackTerrain, CMapReader::ParseTerrain for the reordering | // See CMapReader::UnpackTerrain, CMapReader::ParseTerrain for the reordering | ||||
JS::Value CMapGeneratorWorker::LoadMapTerrain(ScriptInterface::CxPrivate* pCxPrivate, const VfsPath& filename) | JS::Value CMapGeneratorWorker::LoadMapTerrain(ScriptInterface::CmptPrivate* pCmptPrivate, const VfsPath& filename) | ||||
{ | { | ||||
CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCxPrivate->pCBData); | CMapGeneratorWorker* self = static_cast<CMapGeneratorWorker*>(pCmptPrivate->pCBData); | ||||
ScriptInterface::Request rq(self->m_ScriptInterface); | ScriptInterface::Request rq(self->m_ScriptInterface); | ||||
if (!VfsFileExists(filename)) | if (!VfsFileExists(filename)) | ||||
{ | { | ||||
self->m_ScriptInterface->ReportError( | self->m_ScriptInterface->ReportError( | ||||
("Terrain file \"" + filename.string8() + "\" does not exist!").c_str()); | ("Terrain file \"" + filename.string8() + "\" does not exist!").c_str()); | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator