Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapGenerator.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
Lint: Inaccurate Copyright Year: Inaccurate Copyright Year | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | void CMapGeneratorWorker::InitScriptInterface(const u32 seed) | ||||
m_ScriptInterface->LoadGlobalScripts(); | m_ScriptInterface->LoadGlobalScripts(); | ||||
// File loading | // File loading | ||||
ScriptRequest rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
REGISTER_MAPGEN_FUNC_NAME(LoadScripts, "LoadLibrary"); | REGISTER_MAPGEN_FUNC_NAME(LoadScripts, "LoadLibrary"); | ||||
REGISTER_MAPGEN_FUNC_NAME(LoadHeightmap, "LoadHeightmapImage"); | REGISTER_MAPGEN_FUNC_NAME(LoadHeightmap, "LoadHeightmapImage"); | ||||
REGISTER_MAPGEN_FUNC(LoadMapTerrain); | REGISTER_MAPGEN_FUNC(LoadMapTerrain); | ||||
// Template loading interface | |||||
m_TemplateLoader.RegisterScriptFunctions<CMapGeneratorWorker>(rq); | |||||
// Engine constants | // Engine constants | ||||
// Length of one tile of the terrain grid in metres. | // Length of one tile of the terrain grid in metres. | ||||
// Useful to transform footprint sizes to the tilegrid coordinate system. | // Useful to transform footprint sizes to the tilegrid coordinate system. | ||||
m_ScriptInterface->SetGlobal("TERRAIN_TILE_SIZE", static_cast<int>(TERRAIN_TILE_SIZE)); | m_ScriptInterface->SetGlobal("TERRAIN_TILE_SIZE", static_cast<int>(TERRAIN_TILE_SIZE)); | ||||
// Number of impassable tiles at the map border | // Number of impassable tiles at the map border | ||||
m_ScriptInterface->SetGlobal("MAP_BORDER_WIDTH", static_cast<int>(MAP_EDGE_TILES)); | m_ScriptInterface->SetGlobal("MAP_BORDER_WIDTH", static_cast<int>(MAP_EDGE_TILES)); | ||||
} | } | ||||
void CMapGeneratorWorker::RegisterScriptFunctions_MapGenerator() | void CMapGeneratorWorker::RegisterScriptFunctions_MapGenerator() | ||||
{ | { | ||||
ScriptRequest rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
// Template functions | |||||
REGISTER_MAPGEN_FUNC(GetTemplate); | |||||
REGISTER_MAPGEN_FUNC(TemplateExists); | |||||
REGISTER_MAPGEN_FUNC(FindTemplates); | |||||
REGISTER_MAPGEN_FUNC(FindActorTemplates); | |||||
// Progression and profiling | // Progression and profiling | ||||
REGISTER_MAPGEN_FUNC(SetProgress); | REGISTER_MAPGEN_FUNC(SetProgress); | ||||
REGISTER_MAPGEN_FUNC(GetMicroseconds); | REGISTER_MAPGEN_FUNC(GetMicroseconds); | ||||
REGISTER_MAPGEN_FUNC(ExportMap); | REGISTER_MAPGEN_FUNC(ExportMap); | ||||
} | } | ||||
#undef REGISTER_MAPGEN_FUNC | #undef REGISTER_MAPGEN_FUNC | ||||
#undef REGISTER_MAPGEN_FUNC_NAME | #undef REGISTER_MAPGEN_FUNC_NAME | ||||
Show All 29 Lines | void CMapGeneratorWorker::SetProgress(int progress) | ||||
std::lock_guard<std::mutex> lock(m_WorkerMutex); | std::lock_guard<std::mutex> lock(m_WorkerMutex); | ||||
if (progress >= m_Progress) | if (progress >= m_Progress) | ||||
m_Progress = progress; | m_Progress = progress; | ||||
else | else | ||||
LOGWARNING("The random map script tried to reduce the loading progress from %d to %d", m_Progress, progress); | LOGWARNING("The random map script tried to reduce the loading progress from %d to %d", m_Progress, progress); | ||||
} | } | ||||
CParamNode CMapGeneratorWorker::GetTemplate(const std::string& templateName) | |||||
{ | |||||
const CParamNode& templateRoot = m_TemplateLoader.GetTemplateFileData(templateName).GetChild("Entity"); | |||||
if (!templateRoot.IsOk()) | |||||
LOGERROR("Invalid template found for '%s'", templateName.c_str()); | |||||
return templateRoot; | |||||
} | |||||
bool CMapGeneratorWorker::TemplateExists(const std::string& templateName) | |||||
{ | |||||
return m_TemplateLoader.TemplateExists(templateName); | |||||
} | |||||
std::vector<std::string> CMapGeneratorWorker::FindTemplates(const std::string& path, bool includeSubdirectories) | |||||
{ | |||||
return m_TemplateLoader.FindTemplates(path, includeSubdirectories, SIMULATION_TEMPLATES); | |||||
} | |||||
std::vector<std::string> CMapGeneratorWorker::FindActorTemplates(const std::string& path, bool includeSubdirectories) | |||||
{ | |||||
return 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; | ||||
// Mark this as loaded, to prevent it recursively loading itself | // Mark this as loaded, to prevent it recursively loading itself | ||||
m_LoadedLibraries.insert(libraryName); | m_LoadedLibraries.insert(libraryName); | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Inaccurate Copyright Year