From d5a3437882f740cc7bcf04c069cda586d1411b9c Mon Sep 17 00:00:00 2001 From: elexis Date: Fri, 12 Jul 2019 16:38:51 +0000 Subject: [PATCH] Unify the magic number indicating the number of impassable tiles at the map edge redundant in the Pathfinder, RangeManager and MapGenerator. Refs #4034, #4636. Differential Revision: https://code.wildfiregames.com/D2061 Reviewed By: wraitii This was SVN commit r22459. --- .../mods/public/maps/random/rmgen/library.js | 5 ---- source/graphics/LOSTexture.cpp | 1 + source/graphics/MapGenerator.cpp | 2 ++ .../simulation2/components/CCmpPathfinder.cpp | 4 +-- .../components/CCmpRangeManager.cpp | 16 ++++++----- source/simulation2/helpers/MapEdgeTiles.h | 27 +++++++++++++++++++ 6 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 source/simulation2/helpers/MapEdgeTiles.h diff --git a/binaries/data/mods/public/maps/random/rmgen/library.js b/binaries/data/mods/public/maps/random/rmgen/library.js index 2256e707de..58bc325072 100644 --- a/binaries/data/mods/public/maps/random/rmgen/library.js +++ b/binaries/data/mods/public/maps/random/rmgen/library.js @@ -21,11 +21,6 @@ const TERRAIN_SEPARATOR = "|"; const SEA_LEVEL = 20.0; const HEIGHT_UNITS_PER_METRE = 92; -/** - * Number of impassable, unexplorable tiles at the map border. - */ -const MAP_BORDER_WIDTH = 3; - const g_DamageTypes = new DamageTypes(); /** diff --git a/source/graphics/LOSTexture.cpp b/source/graphics/LOSTexture.cpp index 5614a6b50f..60b1dd22eb 100644 --- a/source/graphics/LOSTexture.cpp +++ b/source/graphics/LOSTexture.cpp @@ -49,6 +49,7 @@ The blurred bitmap is then uploaded into a GL texture for use by the renderer. // Blur with a NxN filter, where N = g_BlurSize must be an odd number. +// Keep it in relation to the number of impassable tiles in MAP_EDGE_TILES. static const size_t g_BlurSize = 7; // Alignment (in bytes) of the pixel data passed into glTexSubImage2D. diff --git a/source/graphics/MapGenerator.cpp b/source/graphics/MapGenerator.cpp index 95a0cf7741..28d2004408 100644 --- a/source/graphics/MapGenerator.cpp +++ b/source/graphics/MapGenerator.cpp @@ -34,6 +34,7 @@ #include "scriptinterface/ScriptRuntime.h" #include "scriptinterface/ScriptConversions.h" #include "scriptinterface/ScriptInterface.h" +#include "simulation2/helpers/MapEdgeTiles.h" #include #include @@ -142,6 +143,7 @@ bool CMapGeneratorWorker::Run() m_ScriptInterface->RegisterFunction, std::string, bool, CMapGeneratorWorker::FindTemplates>("FindTemplates"); m_ScriptInterface->RegisterFunction, std::string, bool, CMapGeneratorWorker::FindActorTemplates>("FindActorTemplates"); m_ScriptInterface->RegisterFunction("GetTerrainTileSize"); + m_ScriptInterface->SetGlobal("MAP_BORDER_WIDTH", static_cast(MAP_EDGE_TILES)); // Globalscripts may use VFS script functions m_ScriptInterface->LoadGlobalScripts(); diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index 8cbd990579..9ee9a2627e 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -36,6 +36,7 @@ #include "simulation2/components/ICmpWaterManager.h" #include "simulation2/helpers/HierarchicalPathfinder.h" #include "simulation2/helpers/LongPathfinder.h" +#include "simulation2/helpers/MapEdgeTiles.h" #include "simulation2/helpers/Rasterize.h" #include "simulation2/helpers/VertexPathfinder.h" #include "simulation2/serialization/SerializeTemplates.h" @@ -637,8 +638,7 @@ void CCmpPathfinder::TerrainUpdateHelper(bool expandPassability/* = true */) } // Compute off-world passability - // WARNING: CCmpRangeManager::LosIsOffWorld needs to be kept in sync with this - const int edgeSize = 3 * Pathfinding::NAVCELLS_PER_TILE; // number of tiles around the edge that will be off-world + const int edgeSize = MAP_EDGE_TILES * Pathfinding::NAVCELLS_PER_TILE; NavcellData edgeMask = 0; for (PathfinderPassability& passability : m_PassClasses) diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 1cdc49f3af..238fdf3ea9 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -32,6 +32,7 @@ #include "simulation2/components/ICmpVisibility.h" #include "simulation2/components/ICmpVision.h" #include "simulation2/components/ICmpWaterManager.h" +#include "simulation2/helpers/MapEdgeTiles.h" #include "simulation2/helpers/Render.h" #include "simulation2/helpers/Spatial.h" @@ -2020,9 +2021,6 @@ public: */ inline bool LosIsOffWorld(ssize_t i, ssize_t j) const { - // WARNING: CCmpPathfinder::UpdateGrid needs to be kept in sync with this - const ssize_t edgeSize = 3; // number of vertexes around the edge that will be off-world - if (m_LosCircular) { // With a circular map, vertex is off-world if hypot(i - size/2, j - size/2) >= size/2: @@ -2030,7 +2028,7 @@ public: ssize_t dist2 = (i - m_TerrainVerticesPerSide/2)*(i - m_TerrainVerticesPerSide/2) + (j - m_TerrainVerticesPerSide/2)*(j - m_TerrainVerticesPerSide/2); - ssize_t r = m_TerrainVerticesPerSide/2 - edgeSize + 1; + ssize_t r = m_TerrainVerticesPerSide / 2 - MAP_EDGE_TILES + 1; // subtract a bit from the radius to ensure nice // SoD blurring around the edges of the map @@ -2040,8 +2038,9 @@ public: { // With a square map, the outermost edge of the map should be off-world, // so the SoD texture blends out nicely - - return (i < edgeSize || j < edgeSize || i >= m_TerrainVerticesPerSide-edgeSize || j >= m_TerrainVerticesPerSide-edgeSize); + return i < MAP_EDGE_TILES || j < MAP_EDGE_TILES || + i >= m_TerrainVerticesPerSide - MAP_EDGE_TILES || + j >= m_TerrainVerticesPerSide - MAP_EDGE_TILES; } } @@ -2439,3 +2438,6 @@ public: }; REGISTER_COMPONENT_TYPE(RangeManager) + +#undef LOS_TILES_RATIO +#undef DEBUG_RANGE_MANAGER_BOUNDS diff --git a/source/simulation2/helpers/MapEdgeTiles.h b/source/simulation2/helpers/MapEdgeTiles.h new file mode 100644 index 0000000000..ff7aafb582 --- /dev/null +++ b/source/simulation2/helpers/MapEdgeTiles.h @@ -0,0 +1,27 @@ +/* Copyright (C) 2019 Wildfire Games. + * This file is part of 0 A.D. + * + * 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 + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_MAP_EDGE_TILES +#define INCLUDED_MAP_EDGE_TILES + +/** + * Number of impassable, unexplorable tiles at the map border. + * Keep it in relation to the shadow blur size in CLOSTexture. + */ +static const ssize_t MAP_EDGE_TILES = 3; + +#endif // INCLUDED_MAP_EDGE_TILES