diff --git a/source/graphics/Camera.cpp b/source/graphics/Camera.cpp index 974983060b..9d75a8f1f4 100644 --- a/source/graphics/Camera.cpp +++ b/source/graphics/Camera.cpp @@ -233,8 +233,8 @@ CVector3D CCamera::GetWorldCoordinates(int px, int py, bool aboveWater) const ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); if (gotWater) { - waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*CELL_SIZE)); - waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*CELL_SIZE)); + waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); + waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); } if (gotTerrain) @@ -311,8 +311,8 @@ CVector3D CCamera::GetFocus() const ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); if (gotWater) { - waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*CELL_SIZE)); - waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*CELL_SIZE)); + waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); + waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); } if (gotTerrain) diff --git a/source/graphics/Decal.cpp b/source/graphics/Decal.cpp index 06258ebd69..8f4600f9b2 100644 --- a/source/graphics/Decal.cpp +++ b/source/graphics/Decal.cpp @@ -40,10 +40,10 @@ void CModelDecal::CalcVertexExtents(ssize_t& i0, ssize_t& j0, ssize_t& i1, ssize corner2 = GetTransform().Transform(corner2); corner3 = GetTransform().Transform(corner3); - i0 = floor(std::min(std::min(corner0.X, corner1.X), std::min(corner2.X, corner3.X)) / CELL_SIZE); - j0 = floor(std::min(std::min(corner0.Z, corner1.Z), std::min(corner2.Z, corner3.Z)) / CELL_SIZE); - i1 = ceil(std::max(std::max(corner0.X, corner1.X), std::max(corner2.X, corner3.X)) / CELL_SIZE); - j1 = ceil(std::max(std::max(corner0.Z, corner1.Z), std::max(corner2.Z, corner3.Z)) / CELL_SIZE); + i0 = floor(std::min(std::min(corner0.X, corner1.X), std::min(corner2.X, corner3.X)) / TERRAIN_TILE_SIZE); + j0 = floor(std::min(std::min(corner0.Z, corner1.Z), std::min(corner2.Z, corner3.Z)) / TERRAIN_TILE_SIZE); + i1 = ceil(std::max(std::max(corner0.X, corner1.X), std::max(corner2.X, corner3.X)) / TERRAIN_TILE_SIZE); + j1 = ceil(std::max(std::max(corner0.Z, corner1.Z), std::max(corner2.Z, corner3.Z)) / TERRAIN_TILE_SIZE); i0 = clamp(i0, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1); j0 = clamp(j0, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1); diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index 674b54d5e9..a58bb06759 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -61,7 +61,7 @@ extern int g_xres, g_yres; // Maximum distance outside the edge of the map that the camera's // focus point can be moved -static const float CAMERA_EDGE_MARGIN = 2.0f*CELL_SIZE; +static const float CAMERA_EDGE_MARGIN = 2.0f*TERRAIN_TILE_SIZE; /** * A value with exponential decay towards the target value. diff --git a/source/graphics/HFTracer.cpp b/source/graphics/HFTracer.cpp index 2f580195de..3b277d8769 100644 --- a/source/graphics/HFTracer.cpp +++ b/source/graphics/HFTracer.cpp @@ -40,7 +40,7 @@ CHFTracer::CHFTracer(CTerrain *pTerrain): m_pTerrain(pTerrain), m_Heightfield(m_pTerrain->GetHeightMap()), m_MapSize(m_pTerrain->GetVerticesPerSide()), - m_CellSize((float)CELL_SIZE), + m_CellSize((float)TERRAIN_TILE_SIZE), m_HeightScale(HEIGHT_SCALE) { } diff --git a/source/graphics/LOSTexture.cpp b/source/graphics/LOSTexture.cpp index 7eff017640..3e553cb4e3 100644 --- a/source/graphics/LOSTexture.cpp +++ b/source/graphics/LOSTexture.cpp @@ -135,7 +135,7 @@ void CLOSTexture::ConstructTexture(int unit) // world pos ((mapsize-1)*cellsize, y, (mapsize-1)*cellsize) (i.e. last vertex) // onto texcoord ((mapsize-0.5) / texsize, (mapsize-0.5) / texsize) (i.e. middle of last texel) - float s = (m_MapSize-1) / (float)(m_TextureSize * (m_MapSize-1) * CELL_SIZE); + float s = (m_MapSize-1) / (float)(m_TextureSize * (m_MapSize-1) * TERRAIN_TILE_SIZE); float t = 0.5f / m_TextureSize; m_TextureMatrix.SetZero(); m_TextureMatrix._11 = s; diff --git a/source/graphics/Terrain.cpp b/source/graphics/Terrain.cpp index c2ceebc200..e38d2a6b34 100644 --- a/source/graphics/Terrain.cpp +++ b/source/graphics/Terrain.cpp @@ -112,9 +112,9 @@ void CTerrain::CalcPosition(ssize_t i, ssize_t j, CVector3D& pos) const ssize_t hi = clamp(i, (ssize_t)0, m_MapSize-1); ssize_t hj = clamp(j, (ssize_t)0, m_MapSize-1); u16 height = m_Heightmap[hj*m_MapSize + hi]; - pos.X = float(i*CELL_SIZE); + pos.X = float(i*TERRAIN_TILE_SIZE); pos.Y = float(height*HEIGHT_SCALE); - pos.Z = float(j*CELL_SIZE); + pos.Z = float(j*TERRAIN_TILE_SIZE); } /////////////////////////////////////////////////////////////////////////////// @@ -124,9 +124,9 @@ void CTerrain::CalcPositionFixed(ssize_t i, ssize_t j, CFixedVector3D& pos) cons ssize_t hi = clamp(i, (ssize_t)0, m_MapSize-1); ssize_t hj = clamp(j, (ssize_t)0, m_MapSize-1); u16 height = m_Heightmap[hj*m_MapSize + hi]; - pos.X = fixed::FromInt(i) * (int)CELL_SIZE; + pos.X = fixed::FromInt(i) * (int)TERRAIN_TILE_SIZE; pos.Y = fixed::FromInt(height) / (int)HEIGHT_UNITS_PER_METRE; - pos.Z = fixed::FromInt(j) * (int)CELL_SIZE; + pos.Z = fixed::FromInt(j) * (int)TERRAIN_TILE_SIZE; } @@ -226,11 +226,11 @@ void CTerrain::CalcNormalFixed(ssize_t i, ssize_t j, CFixedVector3D& normal) con CVector3D CTerrain::CalcExactNormal(float x, float z) const { // Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) - const ssize_t xi = clamp((ssize_t)floor(x/CELL_SIZE), (ssize_t)0, m_MapSize-2); - const ssize_t zi = clamp((ssize_t)floor(z/CELL_SIZE), (ssize_t)0, m_MapSize-2); + const ssize_t xi = clamp((ssize_t)floor(x/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); + const ssize_t zi = clamp((ssize_t)floor(z/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); - const float xf = clamp(x/CELL_SIZE-xi, 0.0f, 1.0f); - const float zf = clamp(z/CELL_SIZE-zi, 0.0f, 1.0f); + const float xf = clamp(x/TERRAIN_TILE_SIZE-xi, 0.0f, 1.0f); + const float zf = clamp(z/TERRAIN_TILE_SIZE-zi, 0.0f, 1.0f); float h00 = m_Heightmap[zi*m_MapSize + xi]; float h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; @@ -245,12 +245,12 @@ CVector3D CTerrain::CalcExactNormal(float x, float z) const if (xf + zf <= 1.f) { // Lower-left triangle (don't use h11) - return -CVector3D(CELL_SIZE, (h10-h00)*HEIGHT_SCALE, 0).Cross(CVector3D(0, (h01-h00)*HEIGHT_SCALE, CELL_SIZE)).Normalized(); + return -CVector3D(TERRAIN_TILE_SIZE, (h10-h00)*HEIGHT_SCALE, 0).Cross(CVector3D(0, (h01-h00)*HEIGHT_SCALE, TERRAIN_TILE_SIZE)).Normalized(); } else { // Upper-right triangle (don't use h00) - return -CVector3D(CELL_SIZE, (h11-h01)*HEIGHT_SCALE, 0).Cross(CVector3D(0, (h11-h10)*HEIGHT_SCALE, CELL_SIZE)).Normalized(); + return -CVector3D(TERRAIN_TILE_SIZE, (h11-h01)*HEIGHT_SCALE, 0).Cross(CVector3D(0, (h11-h10)*HEIGHT_SCALE, TERRAIN_TILE_SIZE)).Normalized(); } } else @@ -258,12 +258,12 @@ CVector3D CTerrain::CalcExactNormal(float x, float z) const if (xf <= zf) { // Upper-left triangle (don't use h10) - return -CVector3D(CELL_SIZE, (h11-h01)*HEIGHT_SCALE, 0).Cross(CVector3D(0, (h01-h00)*HEIGHT_SCALE, CELL_SIZE)).Normalized(); + return -CVector3D(TERRAIN_TILE_SIZE, (h11-h01)*HEIGHT_SCALE, 0).Cross(CVector3D(0, (h01-h00)*HEIGHT_SCALE, TERRAIN_TILE_SIZE)).Normalized(); } else { // Lower-right triangle (don't use h01) - return -CVector3D(CELL_SIZE, (h10-h00)*HEIGHT_SCALE, 0).Cross(CVector3D(0, (h11-h10)*HEIGHT_SCALE, CELL_SIZE)).Normalized(); + return -CVector3D(TERRAIN_TILE_SIZE, (h10-h00)*HEIGHT_SCALE, 0).Cross(CVector3D(0, (h11-h10)*HEIGHT_SCALE, TERRAIN_TILE_SIZE)).Normalized(); } } } @@ -327,17 +327,17 @@ fixed CTerrain::GetSlopeFixed(ssize_t i, ssize_t j) const std::min(std::min(h00, h01), std::min(h10, h11)); // Compute fractional slope (being careful to avoid intermediate overflows) - return fixed::FromInt(delta / CELL_SIZE) / (int)HEIGHT_UNITS_PER_METRE; + return fixed::FromInt(delta / TERRAIN_TILE_SIZE) / (int)HEIGHT_UNITS_PER_METRE; } float CTerrain::GetExactGroundLevel(float x, float z) const { // Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) - const ssize_t xi = clamp((ssize_t)floor(x/CELL_SIZE), (ssize_t)0, m_MapSize-2); - const ssize_t zi = clamp((ssize_t)floor(z/CELL_SIZE), (ssize_t)0, m_MapSize-2); + const ssize_t xi = clamp((ssize_t)floor(x/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); + const ssize_t zi = clamp((ssize_t)floor(z/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); - const float xf = clamp(x/CELL_SIZE-xi, 0.0f, 1.0f); - const float zf = clamp(z/CELL_SIZE-zi, 0.0f, 1.0f); + const float xf = clamp(x/TERRAIN_TILE_SIZE-xi, 0.0f, 1.0f); + const float zf = clamp(z/TERRAIN_TILE_SIZE-zi, 0.0f, 1.0f); float h00 = m_Heightmap[zi*m_MapSize + xi]; float h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; @@ -378,13 +378,13 @@ float CTerrain::GetExactGroundLevel(float x, float z) const fixed CTerrain::GetExactGroundLevelFixed(fixed x, fixed z) const { // Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) - const ssize_t xi = clamp((ssize_t)(x / (int)CELL_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); - const ssize_t zi = clamp((ssize_t)(z / (int)CELL_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); + const ssize_t xi = clamp((ssize_t)(x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); + const ssize_t zi = clamp((ssize_t)(z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); const fixed one = fixed::FromInt(1); - const fixed xf = clamp((x / (int)CELL_SIZE) - fixed::FromInt(xi), fixed::Zero(), one); - const fixed zf = clamp((z / (int)CELL_SIZE) - fixed::FromInt(zi), fixed::Zero(), one); + const fixed xf = clamp((x / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(xi), fixed::Zero(), one); + const fixed zf = clamp((z / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(zi), fixed::Zero(), one); u16 h00 = m_Heightmap[zi*m_MapSize + xi]; u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; @@ -568,10 +568,10 @@ void CTerrain::SetHeightMap(u16* heightmap) // coords); return the average height of the flattened area float CTerrain::FlattenArea(float x0, float x1, float z0, float z1) { - const ssize_t tx0 = clamp(ssize_t(x0/CELL_SIZE), (ssize_t)0, m_MapSize-1); - const ssize_t tx1 = clamp(ssize_t(x1/CELL_SIZE)+1, (ssize_t)0, m_MapSize-1); - const ssize_t tz0 = clamp(ssize_t(z0/CELL_SIZE), (ssize_t)0, m_MapSize-1); - const ssize_t tz1 = clamp(ssize_t(z1/CELL_SIZE)+1, (ssize_t)0, m_MapSize-1); + const ssize_t tx0 = clamp(ssize_t(x0/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-1); + const ssize_t tx1 = clamp(ssize_t(x1/TERRAIN_TILE_SIZE)+1, (ssize_t)0, m_MapSize-1); + const ssize_t tz0 = clamp(ssize_t(z0/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-1); + const ssize_t tz1 = clamp(ssize_t(z1/TERRAIN_TILE_SIZE)+1, (ssize_t)0, m_MapSize-1); size_t count=0; double sum=0.0f; @@ -645,11 +645,11 @@ CBoundingBoxAligned CTerrain::GetVertexesBound(ssize_t i0, ssize_t j0, ssize_t i } CBoundingBoxAligned bound; - bound[0].X = (float)(i0*CELL_SIZE); + bound[0].X = (float)(i0*TERRAIN_TILE_SIZE); bound[0].Y = (float)(minH*HEIGHT_SCALE); - bound[0].Z = (float)(j0*CELL_SIZE); - bound[1].X = (float)(i1*CELL_SIZE); + bound[0].Z = (float)(j0*TERRAIN_TILE_SIZE); + bound[1].X = (float)(i1*TERRAIN_TILE_SIZE); bound[1].Y = (float)(maxH*HEIGHT_SCALE); - bound[1].Z = (float)(j1*CELL_SIZE); + bound[1].Z = (float)(j1*TERRAIN_TILE_SIZE); return bound; } diff --git a/source/graphics/Terrain.h b/source/graphics/Terrain.h index 2d44cd24ea..4002eb5f9a 100644 --- a/source/graphics/Terrain.h +++ b/source/graphics/Terrain.h @@ -36,7 +36,7 @@ class CBoundingBoxAligned; // Terrain Constants: /// metres [world space units] per tile in x and z -const ssize_t CELL_SIZE = 4; +const ssize_t TERRAIN_TILE_SIZE = 4; /// number of u16 height units per metre const ssize_t HEIGHT_UNITS_PER_METRE = 732; // == approx int(256.0f/0.35f) @@ -69,8 +69,8 @@ public: float GetMinX() const { return 0.0f; } float GetMinZ() const { return 0.0f; } - float GetMaxX() const { return (float)((m_MapSize-1) * CELL_SIZE); } - float GetMaxZ() const { return (float)((m_MapSize-1) * CELL_SIZE); } + float GetMaxX() const { return (float)((m_MapSize-1) * TERRAIN_TILE_SIZE); } + float GetMaxZ() const { return (float)((m_MapSize-1) * TERRAIN_TILE_SIZE); } bool IsOnMap(float x, float z) const { @@ -113,14 +113,14 @@ public: // calculate the vertex under a given position (rounding down coordinates) static void CalcFromPosition(const CVector3D& pos, ssize_t& i, ssize_t& j) { - i = (ssize_t)(pos.X/CELL_SIZE); - j = (ssize_t)(pos.Z/CELL_SIZE); + i = (ssize_t)(pos.X/TERRAIN_TILE_SIZE); + j = (ssize_t)(pos.Z/TERRAIN_TILE_SIZE); } // calculate the vertex under a given position (rounding down coordinates) static void CalcFromPosition(float x, float z, ssize_t& i, ssize_t& j) { - i = (ssize_t)(x/CELL_SIZE); - j = (ssize_t)(z/CELL_SIZE); + i = (ssize_t)(x/TERRAIN_TILE_SIZE); + j = (ssize_t)(z/TERRAIN_TILE_SIZE); } // calculate the normal at a given vertex void CalcNormal(ssize_t i, ssize_t j, CVector3D& normal) const; diff --git a/source/graphics/TerritoryTexture.cpp b/source/graphics/TerritoryTexture.cpp index f3b2b418b0..f445f4a3a0 100644 --- a/source/graphics/TerritoryTexture.cpp +++ b/source/graphics/TerritoryTexture.cpp @@ -118,7 +118,7 @@ void CTerritoryTexture::ConstructTexture(int unit) // world pos (mapsize*cellsize, y, mapsize*cellsize) (i.e. top-right of last tile) // onto texcoord (mapsize / texsize, mapsize / texsize) (i.e. top-right of last texel) - float s = 1.f / (float)(m_TextureSize * CELL_SIZE); + float s = 1.f / (float)(m_TextureSize * TERRAIN_TILE_SIZE); float t = 0.f; m_TextureMatrix.SetZero(); m_TextureMatrix._11 = s; diff --git a/source/graphics/tests/test_Terrain.h b/source/graphics/tests/test_Terrain.h index 9247e4d09f..c3bee6487d 100644 --- a/source/graphics/tests/test_Terrain.h +++ b/source/graphics/tests/test_Terrain.h @@ -42,26 +42,26 @@ class TestTerrain : public CxxTest::TestSuite SetVertex(terrain, 0, 0, 100); SetVertex(terrain, 0, 1, 100); SetVertex(terrain, 0, 2, 100); - SetVertex(terrain, 1, 0, 100 + CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 1, 1, 100 + CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 1, 2, 100 + CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 2, 0, 100 + 2*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 2, 1, 100 + 2*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 2, 2, 100 + 2*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 3, 0, 100 + 2*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 3, 1, 100 + 2*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 3, 2, 100 + 2*CELL_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 1, 0, 100 + TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 1, 1, 100 + TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 1, 2, 100 + TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 2, 0, 100 + 2*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 2, 1, 100 + 2*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 2, 2, 100 + 2*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 3, 0, 100 + 2*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 3, 1, 100 + 2*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 3, 2, 100 + 2*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); } void SetHighPlateau(CTerrain& terrain, int height) { - SetVertex(terrain, 4, 0, 100 + height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 4, 1, 100 + height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 4, 2, 100 + height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 5, 0, 100 + height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 5, 1, 100 + height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); - SetVertex(terrain, 5, 2, 100 + height*CELL_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 4, 0, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 4, 1, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 4, 2, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 5, 0, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 5, 1, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); + SetVertex(terrain, 5, 2, 100 + height*TERRAIN_TILE_SIZE*HEIGHT_UNITS_PER_METRE); } public: @@ -74,23 +74,23 @@ public: float ground; - ground = terrain.GetExactGroundLevel(0.f, 1.5f*CELL_SIZE); + ground = terrain.GetExactGroundLevel(0.f, 1.5f*TERRAIN_TILE_SIZE); TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE, 0.01f); - ground = terrain.GetExactGroundLevel(0.5f*CELL_SIZE, 1.5f*CELL_SIZE); - TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+0.5f*CELL_SIZE, 0.01f); + ground = terrain.GetExactGroundLevel(0.5f*TERRAIN_TILE_SIZE, 1.5f*TERRAIN_TILE_SIZE); + TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+0.5f*TERRAIN_TILE_SIZE, 0.01f); - ground = terrain.GetExactGroundLevel(1.5f*CELL_SIZE, 1.5f*CELL_SIZE); - TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+1.5f*CELL_SIZE, 0.01f); + ground = terrain.GetExactGroundLevel(1.5f*TERRAIN_TILE_SIZE, 1.5f*TERRAIN_TILE_SIZE); + TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+1.5f*TERRAIN_TILE_SIZE, 0.01f); - ground = terrain.GetExactGroundLevel(2.5f*CELL_SIZE, 1.5f*CELL_SIZE); - TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+2.f*CELL_SIZE, 0.01f); + ground = terrain.GetExactGroundLevel(2.5f*TERRAIN_TILE_SIZE, 1.5f*TERRAIN_TILE_SIZE); + TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+2.f*TERRAIN_TILE_SIZE, 0.01f); - ground = terrain.GetExactGroundLevel(3.5f*CELL_SIZE, 1.5f*CELL_SIZE); - TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+11.f*CELL_SIZE, 0.01f); + ground = terrain.GetExactGroundLevel(3.5f*TERRAIN_TILE_SIZE, 1.5f*TERRAIN_TILE_SIZE); + TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+11.f*TERRAIN_TILE_SIZE, 0.01f); - ground = terrain.GetExactGroundLevel(4.5f*CELL_SIZE, 1.5f*CELL_SIZE); - TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+20.f*CELL_SIZE, 0.01f); + ground = terrain.GetExactGroundLevel(4.5f*TERRAIN_TILE_SIZE, 1.5f*TERRAIN_TILE_SIZE); + TS_ASSERT_DELTA(ground, 100.f/HEIGHT_UNITS_PER_METRE+20.f*TERRAIN_TILE_SIZE, 0.01f); } void test_GetExactGroundLevelFixed() @@ -104,23 +104,23 @@ public: fixed ground; - ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(0.f), fixed::FromFloat(1.5f*CELL_SIZE)); + ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(0.f), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE, maxDelta); - ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(0.5f*CELL_SIZE), fixed::FromFloat(1.5f*CELL_SIZE)); - TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+0.5*CELL_SIZE, maxDelta); + ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(0.5f*TERRAIN_TILE_SIZE), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); + TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+0.5*TERRAIN_TILE_SIZE, maxDelta); - ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(1.5f*CELL_SIZE), fixed::FromFloat(1.5f*CELL_SIZE)); - TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+1.5*CELL_SIZE, maxDelta); + ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); + TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+1.5*TERRAIN_TILE_SIZE, maxDelta); - ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(2.5f*CELL_SIZE), fixed::FromFloat(1.5f*CELL_SIZE)); - TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+2.0*CELL_SIZE, maxDelta); + ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(2.5f*TERRAIN_TILE_SIZE), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); + TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+2.0*TERRAIN_TILE_SIZE, maxDelta); - ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(3.5f*CELL_SIZE), fixed::FromFloat(1.5f*CELL_SIZE)); - TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+11.0*CELL_SIZE, maxDelta); + ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(3.5f*TERRAIN_TILE_SIZE), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); + TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+11.0*TERRAIN_TILE_SIZE, maxDelta); - ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(4.5f*CELL_SIZE), fixed::FromFloat(1.5f*CELL_SIZE)); - TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+20.0*CELL_SIZE, maxDelta); + ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(4.5f*TERRAIN_TILE_SIZE), fixed::FromFloat(1.5f*TERRAIN_TILE_SIZE)); + TS_ASSERT_DELTA(ground.ToDouble(), 100.0/HEIGHT_UNITS_PER_METRE+20.0*TERRAIN_TILE_SIZE, maxDelta); } void test_GetExactGroundLevelFixed_max() @@ -139,7 +139,7 @@ public: { for (int xi = 0; xi < p; ++xi) { - fixed ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(xi/(float)p*CELL_SIZE), fixed::FromFloat(zi/(float)p*CELL_SIZE)); + fixed ground = terrain.GetExactGroundLevelFixed(fixed::FromFloat(xi/(float)p*TERRAIN_TILE_SIZE), fixed::FromFloat(zi/(float)p*TERRAIN_TILE_SIZE)); TS_ASSERT_DELTA(ground.ToDouble(), 65535.0/HEIGHT_UNITS_PER_METRE, maxDelta); } } @@ -231,7 +231,7 @@ public: EXPECT_DIRTY(false, 1, 2); EXPECT_DIRTY(false, 2, 2); - terrain.FlattenArea(PATCH_SIZE*CELL_SIZE, 2*PATCH_SIZE*CELL_SIZE, PATCH_SIZE*CELL_SIZE+1, 2*PATCH_SIZE*CELL_SIZE-1); + terrain.FlattenArea(PATCH_SIZE*TERRAIN_TILE_SIZE, 2*PATCH_SIZE*TERRAIN_TILE_SIZE, PATCH_SIZE*TERRAIN_TILE_SIZE+1, 2*PATCH_SIZE*TERRAIN_TILE_SIZE-1); EXPECT_DIRTY(true, 0, 0); EXPECT_DIRTY(true, 1, 0); diff --git a/source/gui/MiniMap.cpp b/source/gui/MiniMap.cpp index 97f05cc034..4d8ff0b9c0 100644 --- a/source/gui/MiniMap.cpp +++ b/source/gui/MiniMap.cpp @@ -149,8 +149,8 @@ void CMiniMap::GetMouseWorldCoordinates(float& x, float& z) float angle = GetAngle(); // Scale world coordinates for shrunken square map - x = CELL_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5); - z = CELL_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(py-0.5) + sin(angle)*(px-0.5)) + 0.5); + x = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5); + z = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(py-0.5) + sin(angle)*(px-0.5)) + 0.5); } void CMiniMap::SetCameraPos() @@ -206,8 +206,8 @@ void CMiniMap::DrawViewRect() // convert to minimap space float px=hitPt[i].X; float pz=hitPt[i].Z; - ViewRect[i][0]=(m_CachedActualSize.GetWidth()*px/float(CELL_SIZE*m_MapSize)); - ViewRect[i][1]=(m_CachedActualSize.GetHeight()*pz/float(CELL_SIZE*m_MapSize)); + ViewRect[i][0]=(m_CachedActualSize.GetWidth()*px/float(TERRAIN_TILE_SIZE*m_MapSize)); + ViewRect[i][1]=(m_CachedActualSize.GetHeight()*pz/float(TERRAIN_TILE_SIZE*m_MapSize)); } // Enable Scissoring as to restrict the rectangle @@ -372,8 +372,8 @@ void CMiniMap::Draw() // (~70msec/frame on a GF4 rendering a thousand points) glPointSize(3.f); - float sx = (float)m_Width / ((m_MapSize - 1) * CELL_SIZE); - float sy = (float)m_Height / ((m_MapSize - 1) * CELL_SIZE); + float sx = (float)m_Width / ((m_MapSize - 1) * TERRAIN_TILE_SIZE); + float sy = (float)m_Height / ((m_MapSize - 1) * TERRAIN_TILE_SIZE); CSimulation2::InterfaceList ents = sim->GetEntitiesWithInterface(IID_Minimap); diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 2354816b57..94bc573610 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -1124,8 +1124,8 @@ void CPatchRData::RenderPriorities() terrain->CalcPosition(gx, gz, pos); // Move a bit towards the center of the tile - pos.X += CELL_SIZE/4.f; - pos.Z += CELL_SIZE/4.f; + pos.X += TERRAIN_TILE_SIZE/4.f; + pos.Z += TERRAIN_TILE_SIZE/4.f; float x, y; camera->GetScreenCoordinates(pos, x, y); diff --git a/source/simulation2/components/CCmpFootprint.cpp b/source/simulation2/components/CCmpFootprint.cpp index 789172b288..ffc5c1854f 100644 --- a/source/simulation2/components/CCmpFootprint.cpp +++ b/source/simulation2/components/CCmpFootprint.cpp @@ -26,7 +26,7 @@ #include "simulation2/components/ICmpPosition.h" #include "simulation2/components/ICmpUnitMotion.h" #include "simulation2/MessageTypes.h" -#include "graphics/Terrain.h" // For CELL_SIZE +#include "graphics/Terrain.h" // For TERRAIN_TILE_SIZE #include "maths/FixedVector2D.h" class CCmpFootprint : public ICmpFootprint @@ -171,7 +171,7 @@ public: for (i32 dist = 0; dist <= maxSpawningDistance; ++dist) { // The spawn point should be far enough from this footprint to fit the unit, plus a little gap - entity_pos_t clearance = spawnedRadius + entity_pos_t::FromInt(2 + (int)CELL_SIZE*dist); + entity_pos_t clearance = spawnedRadius + entity_pos_t::FromInt(2 + (int)TERRAIN_TILE_SIZE*dist); entity_pos_t radius = m_Size0 + clearance; // Try equally-spaced points around the circle in alternating directions, starting from the front @@ -200,7 +200,7 @@ public: for (i32 dist = 0; dist <= maxSpawningDistance; ++dist) { // The spawn point should be far enough from this footprint to fit the unit, plus a little gap - entity_pos_t clearance = spawnedRadius + entity_pos_t::FromInt(2 + (int)CELL_SIZE*dist); + entity_pos_t clearance = spawnedRadius + entity_pos_t::FromInt(2 + (int)TERRAIN_TILE_SIZE*dist); for (i32 edge = 0; edge < 4; ++edge) { diff --git a/source/simulation2/components/CCmpObstructionManager.cpp b/source/simulation2/components/CCmpObstructionManager.cpp index 2c2cd5bad9..e1a8d6af6d 100644 --- a/source/simulation2/components/CCmpObstructionManager.cpp +++ b/source/simulation2/components/CCmpObstructionManager.cpp @@ -227,8 +227,8 @@ public: { // Use 8x8 tile subdivisions // (TODO: find the optimal number instead of blindly guessing) - m_UnitSubdivision.Reset(x1, z1, entity_pos_t::FromInt(8*CELL_SIZE)); - m_StaticSubdivision.Reset(x1, z1, entity_pos_t::FromInt(8*CELL_SIZE)); + m_UnitSubdivision.Reset(x1, z1, entity_pos_t::FromInt(8*TERRAIN_TILE_SIZE)); + m_StaticSubdivision.Reset(x1, z1, entity_pos_t::FromInt(8*TERRAIN_TILE_SIZE)); for (std::map::iterator it = m_UnitShapes.begin(); it != m_UnitShapes.end(); ++it) { @@ -690,8 +690,8 @@ bool CCmpObstructionManager::TestUnitShape(const IObstructionTestFilter& filter, */ static void NearestTile(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u16 h) { - i = (u16)clamp((x / (int)CELL_SIZE).ToInt_RoundToZero(), 0, w-1); - j = (u16)clamp((z / (int)CELL_SIZE).ToInt_RoundToZero(), 0, h-1); + i = (u16)clamp((x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), 0, w-1); + j = (u16)clamp((z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), 0, h-1); } /** @@ -699,8 +699,8 @@ static void NearestTile(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u */ static void TileCenter(u16 i, u16 j, entity_pos_t& x, entity_pos_t& z) { - x = entity_pos_t::FromInt(i*(int)CELL_SIZE + (int)CELL_SIZE/2); - z = entity_pos_t::FromInt(j*(int)CELL_SIZE + (int)CELL_SIZE/2); + x = entity_pos_t::FromInt(i*(int)TERRAIN_TILE_SIZE + (int)TERRAIN_TILE_SIZE/2); + z = entity_pos_t::FromInt(j*(int)TERRAIN_TILE_SIZE + (int)TERRAIN_TILE_SIZE/2); } bool CCmpObstructionManager::Rasterise(Grid& grid) @@ -723,7 +723,7 @@ bool CCmpObstructionManager::Rasterise(Grid& grid) // we maybe want to expand the square a bit so we're less likely to think there's // free space between buildings when there isn't. But this is just a random guess // and needs to be tweaked until everything works nicely. - //entity_pos_t expandPathfinding = entity_pos_t::FromInt(CELL_SIZE / 2); + //entity_pos_t expandPathfinding = entity_pos_t::FromInt(TERRAIN_TILE_SIZE / 2); // Actually that's bad because units get stuck when the A* pathfinder thinks they're // blocked on all sides, so it's better to underestimate entity_pos_t expandPathfinding = entity_pos_t::FromInt(0); @@ -731,7 +731,7 @@ bool CCmpObstructionManager::Rasterise(Grid& grid) // For AI building foundation planning, we want to definitely block all // potentially-obstructed tiles (so we don't blindly build on top of an obstruction), // so we need to expand by at least 1/sqrt(2) of a tile - entity_pos_t expandFoundation = (entity_pos_t::FromInt(CELL_SIZE) * 3) / 4; + entity_pos_t expandFoundation = (entity_pos_t::FromInt(TERRAIN_TILE_SIZE) * 3) / 4; for (std::map::iterator it = m_StaticShapes.begin(); it != m_StaticShapes.end(); ++it) { diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index 7f30a62e73..4ebdf08c9f 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -711,8 +711,8 @@ bool CCmpPathfinder::CheckBuildingPlacement(const IObstructionTestFilter& filter if (!cmpObstruction->GetObstructionSquare(square)) return false; - // Expand bounds by 1/sqrt(2) tile (multiply by CELL_SIZE since we want world coordinates) - entity_pos_t expand = entity_pos_t::FromInt(2).Sqrt().Multiply(entity_pos_t::FromInt(CELL_SIZE / 2)); + // Expand bounds by 1/sqrt(2) tile (multiply by TERRAIN_TILE_SIZE since we want world coordinates) + entity_pos_t expand = entity_pos_t::FromInt(2).Sqrt().Multiply(entity_pos_t::FromInt(TERRAIN_TILE_SIZE / 2)); CFixedVector2D halfSize(square.hw + expand, square.hh + expand); CFixedVector2D halfBound = Geometry::GetHalfBoundingBox(square.u, square.v, halfSize); diff --git a/source/simulation2/components/CCmpPathfinder_Common.h b/source/simulation2/components/CCmpPathfinder_Common.h index 207720a5a1..f025ab963d 100644 --- a/source/simulation2/components/CCmpPathfinder_Common.h +++ b/source/simulation2/components/CCmpPathfinder_Common.h @@ -277,8 +277,8 @@ public: */ void NearestTile(entity_pos_t x, entity_pos_t z, u16& i, u16& j) { - i = (u16)clamp((x / (int)CELL_SIZE).ToInt_RoundToZero(), 0, m_MapSize-1); - j = (u16)clamp((z / (int)CELL_SIZE).ToInt_RoundToZero(), 0, m_MapSize-1); + i = (u16)clamp((x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), 0, m_MapSize-1); + j = (u16)clamp((z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), 0, m_MapSize-1); } /** @@ -286,8 +286,8 @@ public: */ static void TileCenter(u16 i, u16 j, entity_pos_t& x, entity_pos_t& z) { - x = entity_pos_t::FromInt(i*(int)CELL_SIZE + (int)CELL_SIZE/2); - z = entity_pos_t::FromInt(j*(int)CELL_SIZE + (int)CELL_SIZE/2); + x = entity_pos_t::FromInt(i*(int)TERRAIN_TILE_SIZE + (int)TERRAIN_TILE_SIZE/2); + z = entity_pos_t::FromInt(j*(int)TERRAIN_TILE_SIZE + (int)TERRAIN_TILE_SIZE/2); } static fixed DistanceToGoal(CFixedVector2D pos, const CCmpPathfinder::Goal& goal); diff --git a/source/simulation2/components/CCmpPathfinder_Tile.cpp b/source/simulation2/components/CCmpPathfinder_Tile.cpp index f54a19a870..286e33b41a 100644 --- a/source/simulation2/components/CCmpPathfinder_Tile.cpp +++ b/source/simulation2/components/CCmpPathfinder_Tile.cpp @@ -218,7 +218,7 @@ static bool AtGoal(u16 i, u16 j, const ICmpPathfinder::Goal& goal) { // Allow tiles slightly more than sqrt(2) from the actual goal, // i.e. adjacent diagonally to the target tile - fixed tolerance = entity_pos_t::FromInt(CELL_SIZE*3/2); + fixed tolerance = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*3/2); entity_pos_t x, z; CCmpPathfinder::TileCenter(i, j, x, z); @@ -387,7 +387,7 @@ void CCmpPathfinder::ComputePath(entity_pos_t x0, entity_pos_t z0, const Goal& g // a large circle then the heuristics will aim us directly outwards); // otherwise just aim at the center point. (We'll never try moving outwards to a square shape.) if (goal.type == Goal::CIRCLE) - state.rGoal = (u16)(goal.hw / (int)CELL_SIZE).ToInt_RoundToZero(); + state.rGoal = (u16)(goal.hw / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(); else state.rGoal = 0; diff --git a/source/simulation2/components/CCmpPathfinder_Vertex.cpp b/source/simulation2/components/CCmpPathfinder_Vertex.cpp index e35c4b8367..89d7622f4c 100644 --- a/source/simulation2/components/CCmpPathfinder_Vertex.cpp +++ b/source/simulation2/components/CCmpPathfinder_Vertex.cpp @@ -382,8 +382,8 @@ static void AddTerrainEdges(std::vector& edgesAA, std::vector& ver // (The inner edges are redundant but it's easier than trying to split the squares apart.) if (any) { - CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i * (int)CELL_SIZE) - r, fixed::FromInt(j * (int)CELL_SIZE) - r); - CFixedVector2D v1 = CFixedVector2D(fixed::FromInt((i+1) * (int)CELL_SIZE) + r, fixed::FromInt((j+1) * (int)CELL_SIZE) + r); + CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i * (int)TERRAIN_TILE_SIZE) - r, fixed::FromInt(j * (int)TERRAIN_TILE_SIZE) - r); + CFixedVector2D v1 = CFixedVector2D(fixed::FromInt((i+1) * (int)TERRAIN_TILE_SIZE) + r, fixed::FromInt((j+1) * (int)TERRAIN_TILE_SIZE) + r); Edge e = { v0, v1 }; edgesAA.push_back(e); } @@ -409,32 +409,32 @@ static void AddTerrainEdges(std::vector& edgesAA, std::vector& ver { case TileEdge::BOTTOM: { - v0 = CFixedVector2D(fixed::FromInt(i * (int)CELL_SIZE) - r, fixed::FromInt(j * (int)CELL_SIZE) - r); - v1 = CFixedVector2D(fixed::FromInt((i+1) * (int)CELL_SIZE) + r, fixed::FromInt(j * (int)CELL_SIZE) - r); + v0 = CFixedVector2D(fixed::FromInt(i * (int)TERRAIN_TILE_SIZE) - r, fixed::FromInt(j * (int)TERRAIN_TILE_SIZE) - r); + v1 = CFixedVector2D(fixed::FromInt((i+1) * (int)TERRAIN_TILE_SIZE) + r, fixed::FromInt(j * (int)TERRAIN_TILE_SIZE) - r); vert.p.X = v0.X - EDGE_EXPAND_DELTA; vert.p.Y = v0.Y - EDGE_EXPAND_DELTA; vert.quadInward = QUADRANT_TR; vertexes.push_back(vert); vert.p.X = v1.X + EDGE_EXPAND_DELTA; vert.p.Y = v1.Y - EDGE_EXPAND_DELTA; vert.quadInward = QUADRANT_TL; vertexes.push_back(vert); break; } case TileEdge::TOP: { - v0 = CFixedVector2D(fixed::FromInt((i+1) * (int)CELL_SIZE) + r, fixed::FromInt((j+1) * (int)CELL_SIZE) + r); - v1 = CFixedVector2D(fixed::FromInt(i * (int)CELL_SIZE) - r, fixed::FromInt((j+1) * (int)CELL_SIZE) + r); + v0 = CFixedVector2D(fixed::FromInt((i+1) * (int)TERRAIN_TILE_SIZE) + r, fixed::FromInt((j+1) * (int)TERRAIN_TILE_SIZE) + r); + v1 = CFixedVector2D(fixed::FromInt(i * (int)TERRAIN_TILE_SIZE) - r, fixed::FromInt((j+1) * (int)TERRAIN_TILE_SIZE) + r); vert.p.X = v0.X + EDGE_EXPAND_DELTA; vert.p.Y = v0.Y + EDGE_EXPAND_DELTA; vert.quadInward = QUADRANT_BL; vertexes.push_back(vert); vert.p.X = v1.X - EDGE_EXPAND_DELTA; vert.p.Y = v1.Y + EDGE_EXPAND_DELTA; vert.quadInward = QUADRANT_BR; vertexes.push_back(vert); break; } case TileEdge::LEFT: { - v0 = CFixedVector2D(fixed::FromInt(i * (int)CELL_SIZE) - r, fixed::FromInt((j+1) * (int)CELL_SIZE) + r); - v1 = CFixedVector2D(fixed::FromInt(i * (int)CELL_SIZE) - r, fixed::FromInt(j * (int)CELL_SIZE) - r); + v0 = CFixedVector2D(fixed::FromInt(i * (int)TERRAIN_TILE_SIZE) - r, fixed::FromInt((j+1) * (int)TERRAIN_TILE_SIZE) + r); + v1 = CFixedVector2D(fixed::FromInt(i * (int)TERRAIN_TILE_SIZE) - r, fixed::FromInt(j * (int)TERRAIN_TILE_SIZE) - r); vert.p.X = v0.X - EDGE_EXPAND_DELTA; vert.p.Y = v0.Y + EDGE_EXPAND_DELTA; vert.quadInward = QUADRANT_BR; vertexes.push_back(vert); vert.p.X = v1.X - EDGE_EXPAND_DELTA; vert.p.Y = v1.Y - EDGE_EXPAND_DELTA; vert.quadInward = QUADRANT_TR; vertexes.push_back(vert); break; } case TileEdge::RIGHT: { - v0 = CFixedVector2D(fixed::FromInt((i+1) * (int)CELL_SIZE) + r, fixed::FromInt(j * (int)CELL_SIZE) - r); - v1 = CFixedVector2D(fixed::FromInt((i+1) * (int)CELL_SIZE) + r, fixed::FromInt((j+1) * (int)CELL_SIZE) + r); + v0 = CFixedVector2D(fixed::FromInt((i+1) * (int)TERRAIN_TILE_SIZE) + r, fixed::FromInt(j * (int)TERRAIN_TILE_SIZE) - r); + v1 = CFixedVector2D(fixed::FromInt((i+1) * (int)TERRAIN_TILE_SIZE) + r, fixed::FromInt((j+1) * (int)TERRAIN_TILE_SIZE) + r); vert.p.X = v0.X + EDGE_EXPAND_DELTA; vert.p.Y = v0.Y - EDGE_EXPAND_DELTA; vert.quadInward = QUADRANT_TL; vertexes.push_back(vert); vert.p.X = v1.X + EDGE_EXPAND_DELTA; vert.p.Y = v1.Y + EDGE_EXPAND_DELTA; vert.quadInward = QUADRANT_BL; vertexes.push_back(vert); break; diff --git a/source/simulation2/components/CCmpProjectileManager.cpp b/source/simulation2/components/CCmpProjectileManager.cpp index e4c988bbdc..df413301b4 100644 --- a/source/simulation2/components/CCmpProjectileManager.cpp +++ b/source/simulation2/components/CCmpProjectileManager.cpp @@ -338,8 +338,8 @@ void CCmpProjectileManager::RenderSubmit(SceneCollector& collector, const CFrust for (size_t i = 0; i < m_Projectiles.size(); ++i) { // Don't display projectiles outside the visible area - ssize_t posi = (ssize_t)(0.5f + m_Projectiles[i].pos.X / CELL_SIZE); - ssize_t posj = (ssize_t)(0.5f + m_Projectiles[i].pos.Z / CELL_SIZE); + ssize_t posi = (ssize_t)(0.5f + m_Projectiles[i].pos.X / TERRAIN_TILE_SIZE); + ssize_t posj = (ssize_t)(0.5f + m_Projectiles[i].pos.Z / TERRAIN_TILE_SIZE); if (!losRevealAll && !los.IsVisible(posi, posj)) continue; diff --git a/source/simulation2/components/CCmpRallyPointRenderer.cpp b/source/simulation2/components/CCmpRallyPointRenderer.cpp index ca47de0c4c..7e5a8c9ced 100644 --- a/source/simulation2/components/CCmpRallyPointRenderer.cpp +++ b/source/simulation2/components/CCmpRallyPointRenderer.cpp @@ -831,8 +831,8 @@ void CCmpRallyPointRenderer::FixInvisibleWaypoints(std::vector& coord //for (std::vector::iterator it = waypoints.begin(); it != waypoints.end();) for(std::vector::iterator it = coords.begin(); it != coords.end();) { - int i = (fixed::FromFloat(it->X) / (int)CELL_SIZE).ToInt_RoundToNearest(); - int j = (fixed::FromFloat(it->Y) / (int)CELL_SIZE).ToInt_RoundToNearest(); + int i = (fixed::FromFloat(it->X) / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest(); + int j = (fixed::FromFloat(it->Y) / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest(); bool explored = losQuerier.IsExplored(i, j); if (!explored) @@ -956,16 +956,16 @@ void CCmpRallyPointRenderer::GetVisibilitySegments(std::deque::const_iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it) { @@ -883,8 +883,8 @@ public: CFixedVector2D pos = cmpPosition->GetPosition2D(); - int i = (pos.X / (int)CELL_SIZE).ToInt_RoundToNearest(); - int j = (pos.Y / (int)CELL_SIZE).ToInt_RoundToNearest(); + int i = (pos.X / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest(); + int j = (pos.Y / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest(); // Reveal flag makes all positioned entities visible if (GetLosRevealAll(player)) @@ -1090,15 +1090,15 @@ public: // Compute top/bottom coordinates, and clamp to exclude the 1-tile border around the map // (so that we never render the sharp edge of the map) - i32 j0 = ((pos.Y - visionRange)/(int)CELL_SIZE).ToInt_RoundToInfinity(); - i32 j1 = ((pos.Y + visionRange)/(int)CELL_SIZE).ToInt_RoundToNegInfinity(); + i32 j0 = ((pos.Y - visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToInfinity(); + i32 j1 = ((pos.Y + visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(); i32 j0clamp = std::max(j0, 1); i32 j1clamp = std::min(j1, m_TerrainVerticesPerSide-2); // Translate world coordinates into fractional tile-space coordinates - entity_pos_t x = pos.X / (int)CELL_SIZE; - entity_pos_t y = pos.Y / (int)CELL_SIZE; - entity_pos_t r = visionRange / (int)CELL_SIZE; + entity_pos_t x = pos.X / (int)TERRAIN_TILE_SIZE; + entity_pos_t y = pos.Y / (int)TERRAIN_TILE_SIZE; + entity_pos_t r = visionRange / (int)TERRAIN_TILE_SIZE; entity_pos_t r2 = r.Square(); // Compute the integers on either side of x @@ -1175,18 +1175,18 @@ public: // so we can compute the difference between the removed/added strips // and only have to touch tiles that have a net change.) - i32 j0_from = ((from.Y - visionRange)/(int)CELL_SIZE).ToInt_RoundToInfinity(); - i32 j1_from = ((from.Y + visionRange)/(int)CELL_SIZE).ToInt_RoundToNegInfinity(); - i32 j0_to = ((to.Y - visionRange)/(int)CELL_SIZE).ToInt_RoundToInfinity(); - i32 j1_to = ((to.Y + visionRange)/(int)CELL_SIZE).ToInt_RoundToNegInfinity(); + i32 j0_from = ((from.Y - visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToInfinity(); + i32 j1_from = ((from.Y + visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(); + i32 j0_to = ((to.Y - visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToInfinity(); + i32 j1_to = ((to.Y + visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(); i32 j0clamp = std::max(std::min(j0_from, j0_to), 1); i32 j1clamp = std::min(std::max(j1_from, j1_to), m_TerrainVerticesPerSide-2); - entity_pos_t x_from = from.X / (int)CELL_SIZE; - entity_pos_t y_from = from.Y / (int)CELL_SIZE; - entity_pos_t x_to = to.X / (int)CELL_SIZE; - entity_pos_t y_to = to.Y / (int)CELL_SIZE; - entity_pos_t r = visionRange / (int)CELL_SIZE; + entity_pos_t x_from = from.X / (int)TERRAIN_TILE_SIZE; + entity_pos_t y_from = from.Y / (int)TERRAIN_TILE_SIZE; + entity_pos_t x_to = to.X / (int)TERRAIN_TILE_SIZE; + entity_pos_t y_to = to.Y / (int)TERRAIN_TILE_SIZE; + entity_pos_t r = visionRange / (int)TERRAIN_TILE_SIZE; entity_pos_t r2 = r.Square(); i32 xfloor_from = (x_from - entity_pos_t::Epsilon()).ToInt_RoundToNegInfinity(); diff --git a/source/simulation2/components/CCmpTerrain.cpp b/source/simulation2/components/CCmpTerrain.cpp index 65ec29bb67..1a1c4f83d6 100644 --- a/source/simulation2/components/CCmpTerrain.cpp +++ b/source/simulation2/components/CCmpTerrain.cpp @@ -68,7 +68,7 @@ public: virtual CFixedVector3D CalcNormal(entity_pos_t x, entity_pos_t z) { CFixedVector3D normal; - m_Terrain->CalcNormalFixed((x / (int)CELL_SIZE).ToInt_RoundToZero(), (z / (int)CELL_SIZE).ToInt_RoundToZero(), normal); + m_Terrain->CalcNormalFixed((x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), normal); return normal; } @@ -114,16 +114,16 @@ public: if (!cmpObstructionManager.null()) { cmpObstructionManager->SetBounds(entity_pos_t::Zero(), entity_pos_t::Zero(), - entity_pos_t::FromInt(tiles*(int)CELL_SIZE), - entity_pos_t::FromInt(tiles*(int)CELL_SIZE)); + entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE), + entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE)); } CmpPtr cmpRangeManager(GetSimContext(), SYSTEM_ENTITY); if (!cmpRangeManager.null()) { cmpRangeManager->SetBounds(entity_pos_t::Zero(), entity_pos_t::Zero(), - entity_pos_t::FromInt(tiles*(int)CELL_SIZE), - entity_pos_t::FromInt(tiles*(int)CELL_SIZE), + entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE), + entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE), vertices); } diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index 2bbae5544d..7b0f80a77a 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/source/simulation2/components/CCmpTerritoryManager.cpp @@ -426,12 +426,12 @@ void CCmpTerritoryManager::CalculateTerritories() CmpPtr cmpPosition(GetSimContext(), *eit); CFixedVector2D pos = cmpPosition->GetPosition2D(); - u16 i = (u16)clamp((pos.X / (int)CELL_SIZE).ToInt_RoundToNegInfinity(), 0, tilesW-1); - u16 j = (u16)clamp((pos.Y / (int)CELL_SIZE).ToInt_RoundToNegInfinity(), 0, tilesH-1); + u16 i = (u16)clamp((pos.X / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(), 0, tilesW-1); + u16 j = (u16)clamp((pos.Y / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(), 0, tilesH-1); CmpPtr cmpTerritoryInfluence(GetSimContext(), *eit); u32 weight = cmpTerritoryInfluence->GetWeight(); - u32 radius = cmpTerritoryInfluence->GetRadius() / CELL_SIZE; + u32 radius = cmpTerritoryInfluence->GetRadius() / TERRAIN_TILE_SIZE; u32 falloff = weight / radius; // earlier check for GetRadius() == 0 prevents divide-by-zero // TODO: we should have some maximum value on weight, to avoid overflow @@ -483,8 +483,8 @@ void CCmpTerritoryManager::CalculateTerritories() CmpPtr cmpPosition(GetSimContext(), *it); CFixedVector2D pos = cmpPosition->GetPosition2D(); - u16 i = (u16)clamp((pos.X / (int)CELL_SIZE).ToInt_RoundToNegInfinity(), 0, tilesW-1); - u16 j = (u16)clamp((pos.Y / (int)CELL_SIZE).ToInt_RoundToNegInfinity(), 0, tilesH-1); + u16 i = (u16)clamp((pos.X / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(), 0, tilesW-1); + u16 j = (u16)clamp((pos.Y / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity(), 0, tilesH-1); u8 owner = (u8)cmpOwnership->GetOwner(); @@ -538,8 +538,8 @@ void CCmpTerritoryManager::CalculateTerritories() */ static void NearestTile(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u16 h) { - i = (u16)clamp((x / (int)CELL_SIZE).ToInt_RoundToZero(), 0, w-1); - j = (u16)clamp((z / (int)CELL_SIZE).ToInt_RoundToZero(), 0, h-1); + i = (u16)clamp((x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), 0, w-1); + j = (u16)clamp((z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), 0, h-1); } /** @@ -547,8 +547,8 @@ static void NearestTile(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u */ static void TileCenter(u16 i, u16 j, entity_pos_t& x, entity_pos_t& z) { - x = entity_pos_t::FromInt(i*(int)CELL_SIZE + (int)CELL_SIZE/2); - z = entity_pos_t::FromInt(j*(int)CELL_SIZE + (int)CELL_SIZE/2); + x = entity_pos_t::FromInt(i*(int)TERRAIN_TILE_SIZE + (int)TERRAIN_TILE_SIZE/2); + z = entity_pos_t::FromInt(j*(int)TERRAIN_TILE_SIZE + (int)TERRAIN_TILE_SIZE/2); } // TODO: would be nice not to duplicate those two functions from CCmpObstructionManager.cpp @@ -639,7 +639,7 @@ std::vector CCmpTerritoryManager::Compu while (true) { - points.push_back((CVector2D(ci, cj) + edgeOffsets[cdir]) * CELL_SIZE); + points.push_back((CVector2D(ci, cj) + edgeOffsets[cdir]) * TERRAIN_TILE_SIZE); // Given that we're on an edge on a continuous boundary and aiming anticlockwise, // we can either carry on straight or turn left or turn right, so examine each diff --git a/source/simulation2/components/CCmpUnitMotion.cpp b/source/simulation2/components/CCmpUnitMotion.cpp index 23fcb40e4e..9309b3e93b 100644 --- a/source/simulation2/components/CCmpUnitMotion.cpp +++ b/source/simulation2/components/CCmpUnitMotion.cpp @@ -43,7 +43,7 @@ * towards, we'll pick one that's up to this far from the unit's current * position (to minimise the effects of grid-constrained movement) */ -static const entity_pos_t WAYPOINT_ADVANCE_MAX = entity_pos_t::FromInt(CELL_SIZE*8); +static const entity_pos_t WAYPOINT_ADVANCE_MAX = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*8); /** * When advancing along the long path, we'll pick a new waypoint to move @@ -58,27 +58,27 @@ static const int WAYPOINT_ADVANCE_LOOKAHEAD_TURNS = 4; * Maximum range to restrict short path queries to. (Larger ranges are slower, * smaller ranges might miss some legitimate routes around large obstacles.) */ -static const entity_pos_t SHORT_PATH_SEARCH_RANGE = entity_pos_t::FromInt(CELL_SIZE*10); +static const entity_pos_t SHORT_PATH_SEARCH_RANGE = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*10); /** * When short-pathing to an intermediate waypoint, we aim for a circle of this radius * around the waypoint rather than expecting to reach precisely the waypoint itself * (since it might be inside an obstacle). */ -static const entity_pos_t SHORT_PATH_GOAL_RADIUS = entity_pos_t::FromInt(CELL_SIZE*3/2); +static const entity_pos_t SHORT_PATH_GOAL_RADIUS = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*3/2); /** * If we are this close to our target entity/point, then think about heading * for it in a straight line instead of pathfinding. */ -static const entity_pos_t DIRECT_PATH_RANGE = entity_pos_t::FromInt(CELL_SIZE*4); +static const entity_pos_t DIRECT_PATH_RANGE = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*4); /** * If we're following a target entity, * we will recompute our path if the target has moved * more than this distance from where we last pathed to. */ -static const entity_pos_t CHECK_TARGET_MOVEMENT_MIN_DELTA = entity_pos_t::FromInt(CELL_SIZE*4); +static const entity_pos_t CHECK_TARGET_MOVEMENT_MIN_DELTA = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*4); /** * If we're following as part of a formation, @@ -86,19 +86,19 @@ static const entity_pos_t CHECK_TARGET_MOVEMENT_MIN_DELTA = entity_pos_t::FromIn * we will recompute our path if the target has moved * more than this distance from where we last pathed to. */ -static const entity_pos_t CHECK_TARGET_MOVEMENT_MIN_DELTA_FORMATION = entity_pos_t::FromInt(CELL_SIZE*1); +static const entity_pos_t CHECK_TARGET_MOVEMENT_MIN_DELTA_FORMATION = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*1); /** * If we're following something but it's more than this distance away along * our path, then don't bother trying to repath regardless of how much it has * moved, until we get this close to the end of our old path. */ -static const entity_pos_t CHECK_TARGET_MOVEMENT_AT_MAX_DIST = entity_pos_t::FromInt(CELL_SIZE*16); +static const entity_pos_t CHECK_TARGET_MOVEMENT_AT_MAX_DIST = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*16); static const CColor OVERLAY_COLOUR_LONG_PATH(1, 1, 1, 1); static const CColor OVERLAY_COLOUR_SHORT_PATH(1, 0, 0, 1); -static const entity_pos_t g_GoalDelta = entity_pos_t::FromInt(CELL_SIZE)/4; // for extending the goal outwards/inwards a little bit +static const entity_pos_t g_GoalDelta = entity_pos_t::FromInt(TERRAIN_TILE_SIZE)/4; // for extending the goal outwards/inwards a little bit class CCmpUnitMotion : public ICmpUnitMotion { @@ -1363,7 +1363,7 @@ bool CCmpUnitMotion::MoveToTargetRange(entity_id_t target, entity_pos_t minRange goal.type = ICmpPathfinder::Goal::SQUARE; goal.u = obstruction.u; goal.v = obstruction.v; - entity_pos_t delta = std::max(goalDistance, m_Radius + entity_pos_t::FromInt(CELL_SIZE)/16); // ensure it's far enough to not intersect the building itself + entity_pos_t delta = std::max(goalDistance, m_Radius + entity_pos_t::FromInt(TERRAIN_TILE_SIZE)/16); // ensure it's far enough to not intersect the building itself goal.hw = obstruction.hw + delta; goal.hh = obstruction.hh + delta; } @@ -1411,7 +1411,7 @@ bool CCmpUnitMotion::MoveToTargetRange(entity_id_t target, entity_pos_t minRange goal.type = ICmpPathfinder::Goal::SQUARE; goal.u = obstruction.u; goal.v = obstruction.v; - entity_pos_t delta = std::max(goalDistance, m_Radius + entity_pos_t::FromInt(CELL_SIZE)/16); // ensure it's far enough to not intersect the building itself + entity_pos_t delta = std::max(goalDistance, m_Radius + entity_pos_t::FromInt(TERRAIN_TILE_SIZE)/16); // ensure it's far enough to not intersect the building itself goal.hw = obstruction.hw + delta; goal.hh = obstruction.hh + delta; } diff --git a/source/simulation2/components/ICmpRangeManager.h b/source/simulation2/components/ICmpRangeManager.h index c001400565..2f77c7ec2e 100644 --- a/source/simulation2/components/ICmpRangeManager.h +++ b/source/simulation2/components/ICmpRangeManager.h @@ -22,7 +22,7 @@ #include "simulation2/helpers/Position.h" #include "simulation2/helpers/Player.h" -#include "graphics/Terrain.h" // for CELL_SIZE +#include "graphics/Terrain.h" // for TERRAIN_TILE_SIZE /** * Provides efficient range-based queries of the game world, diff --git a/source/simulation2/components/tests/test_Pathfinder.h b/source/simulation2/components/tests/test_Pathfinder.h index eb63801244..4a6c7aa089 100644 --- a/source/simulation2/components/tests/test_Pathfinder.h +++ b/source/simulation2/components/tests/test_Pathfinder.h @@ -118,7 +118,7 @@ public: sim2.LoadDefaultScripts(); sim2.ResetState(); - const entity_pos_t range = entity_pos_t::FromInt(CELL_SIZE*12); + const entity_pos_t range = entity_pos_t::FromInt(TERRAIN_TILE_SIZE*12); CmpPtr cmpObstructionMan(sim2, SYSTEM_ENTITY); CmpPtr cmpPathfinder(sim2, SYSTEM_ENTITY); diff --git a/source/simulation2/components/tests/test_RangeManager.h b/source/simulation2/components/tests/test_RangeManager.h index 77b88799c5..e965ff0091 100644 --- a/source/simulation2/components/tests/test_RangeManager.h +++ b/source/simulation2/components/tests/test_RangeManager.h @@ -87,7 +87,7 @@ public: // This tests that the incremental computation produces the correct result // in various edge cases - cmp->SetBounds(entity_pos_t::FromInt(0), entity_pos_t::FromInt(0), entity_pos_t::FromInt(512), entity_pos_t::FromInt(512), 512/CELL_SIZE + 1); + cmp->SetBounds(entity_pos_t::FromInt(0), entity_pos_t::FromInt(0), entity_pos_t::FromInt(512), entity_pos_t::FromInt(512), 512/TERRAIN_TILE_SIZE + 1); cmp->Verify(); { CMessageCreate msg(100); cmp->HandleMessage(msg, false); } cmp->Verify(); diff --git a/source/simulation2/helpers/Position.h b/source/simulation2/helpers/Position.h index 0f58af762d..8800f2516c 100644 --- a/source/simulation2/helpers/Position.h +++ b/source/simulation2/helpers/Position.h @@ -24,7 +24,7 @@ * @file * Entity coordinate types * - * The basic unit is the "meter". Terrain tiles are CELL_SIZE (=4) meters square. + * The basic unit is the "meter". Terrain tiles are TERRAIN_TILE_SIZE (=4) meters square. * To support deterministic computation across CPU architectures and compilers and * optimisation settings, the C++ simulation code must not use floating-point arithmetic. * We therefore use a fixed-point datatype for representing world positions. diff --git a/source/simulation2/helpers/Render.cpp b/source/simulation2/helpers/Render.cpp index 89e382e067..a8d9b3431d 100644 --- a/source/simulation2/helpers/Render.cpp +++ b/source/simulation2/helpers/Render.cpp @@ -100,11 +100,11 @@ void SimRender::ConstructCircleOnGround(const CSimContext& context, float x, flo } } -// This method splits up a straight line into a number of line segments each having a length ~= CELL_SIZE +// This method splits up a straight line into a number of line segments each having a length ~= TERRAIN_TILE_SIZE static void SplitLine(std::vector >& coords, float x1, float y1, float x2, float y2) { float length = sqrtf(SQR(x1 - x2) + SQR(y1 - y2)); - size_t pieces = ((int)length) / CELL_SIZE; + size_t pieces = ((int)length) / TERRAIN_TILE_SIZE; if (pieces > 0) { float xPieceLength = (x1 - x2) / (float)pieces; diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index 2d4f2739fc..188d6af8d7 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -344,7 +344,7 @@ void ActorViewer::SetActor(const CStrW& name, const CStrW& animation) CmpPtr cmpPosition(m.Simulation2, m.Entity); if (!cmpPosition.null()) { - ssize_t c = CELL_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2; + ssize_t c = TERRAIN_TILE_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2; cmpPosition->JumpTo(entity_pos_t::FromInt(c), entity_pos_t::FromInt(c)); cmpPosition->SetYRotation(entity_angle_t::Pi()); } @@ -478,7 +478,7 @@ void ActorViewer::Render() cmpVisual->GetBounds().GetCentre(centre); else centre.Y = 0.f; - centre.X = centre.Z = CELL_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2; + centre.X = centre.Z = TERRAIN_TILE_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2; CCamera camera = View::GetView_Actor()->GetCamera(); camera.m_Orientation.Translate(centre.X, centre.Y, centre.Z); @@ -541,9 +541,9 @@ void ActorViewer::Update(float dt) float z = cmpPosition->GetPosition().Z.ToFloat(); z -= m.CurrentSpeed*dt; // Wrap at the edges, so it doesn't run off into the horizon - ssize_t c = CELL_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2; - if (z < c - CELL_SIZE*PATCH_SIZE * 0.1f) - z = c + CELL_SIZE*PATCH_SIZE * 0.1f; + ssize_t c = TERRAIN_TILE_SIZE * m.Terrain.GetPatchesPerSide()*PATCH_SIZE/2; + if (z < c - TERRAIN_TILE_SIZE*PATCH_SIZE * 0.1f) + z = c + TERRAIN_TILE_SIZE*PATCH_SIZE * 0.1f; cmpPosition->JumpTo(cmpPosition->GetPosition().X, entity_pos_t::FromFloat(z)); } } diff --git a/source/tools/atlas/GameInterface/Brushes.cpp b/source/tools/atlas/GameInterface/Brushes.cpp index 2f057305a0..5b5bd1c10f 100644 --- a/source/tools/atlas/GameInterface/Brushes.cpp +++ b/source/tools/atlas/GameInterface/Brushes.cpp @@ -90,8 +90,8 @@ void Brush::SetData(ssize_t w, ssize_t h, const std::vector& data) void Brush::GetCentre(ssize_t& x, ssize_t& y) const { CVector3D c = m_Centre; - if (m_W % 2) c.X += CELL_SIZE/2.f; - if (m_H % 2) c.Z += CELL_SIZE/2.f; + if (m_W % 2) c.X += TERRAIN_TILE_SIZE/2.f; + if (m_H % 2) c.Z += TERRAIN_TILE_SIZE/2.f; ssize_t cx, cy; CTerrain::CalcFromPosition(c, cx, cy); diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index 4ef2cf6ab9..f9a4ac3c7e 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -265,7 +265,7 @@ static CVector3D GetUnitPos(const Position& pos, bool floating) // Use 'clamp' with a value slightly less than the width, so that converting // to integer (rounding towards zero) will put it on the tile inside the edge // instead of just outside - float mapWidth = (g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*CELL_SIZE; + float mapWidth = (g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; float delta = 1e-6f; // fraction of map width - must be > FLT_EPSILON float xOnMap = clamp(vec.X, 0.f, mapWidth * (1.f - delta));