1
0
forked from 0ad/0ad

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.
This commit is contained in:
elexis 2019-07-12 16:38:51 +00:00
parent dcf5bad7fd
commit d5a3437882
6 changed files with 41 additions and 14 deletions

View File

@ -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();
/**

View File

@ -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.

View File

@ -34,6 +34,7 @@
#include "scriptinterface/ScriptRuntime.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "simulation2/helpers/MapEdgeTiles.h"
#include <string>
#include <vector>
@ -142,6 +143,7 @@ bool CMapGeneratorWorker::Run()
m_ScriptInterface->RegisterFunction<std::vector<std::string>, std::string, bool, CMapGeneratorWorker::FindTemplates>("FindTemplates");
m_ScriptInterface->RegisterFunction<std::vector<std::string>, std::string, bool, CMapGeneratorWorker::FindActorTemplates>("FindActorTemplates");
m_ScriptInterface->RegisterFunction<int, CMapGeneratorWorker::GetTerrainTileSize>("GetTerrainTileSize");
m_ScriptInterface->SetGlobal("MAP_BORDER_WIDTH", static_cast<int>(MAP_EDGE_TILES));
// Globalscripts may use VFS script functions
m_ScriptInterface->LoadGlobalScripts();

View File

@ -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)

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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