Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/Terrain.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* 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 103 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// | ||||
// CalcPosition: calculate the world space position of the vertex at (i,j) | // CalcPosition: calculate the world space position of the vertex at (i,j) | ||||
// If i,j is off the map, it acts as if the edges of the terrain are extended | // If i,j is off the map, it acts as if the edges of the terrain are extended | ||||
// outwards to infinity | // outwards to infinity | ||||
void CTerrain::CalcPosition(ssize_t i, ssize_t j, CVector3D& pos) const | 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 hi = Clamp(i, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
ssize_t hj = clamp(j, (ssize_t)0, m_MapSize-1); | ssize_t hj = Clamp(j, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
Stan: static_cast here and below | |||||
u16 height = m_Heightmap[hj*m_MapSize + hi]; | u16 height = m_Heightmap[hj*m_MapSize + hi]; | ||||
pos.X = float(i*TERRAIN_TILE_SIZE); | pos.X = float(i*TERRAIN_TILE_SIZE); | ||||
pos.Y = float(height*HEIGHT_SCALE); | pos.Y = float(height*HEIGHT_SCALE); | ||||
pos.Z = float(j*TERRAIN_TILE_SIZE); | pos.Z = float(j*TERRAIN_TILE_SIZE); | ||||
} | } | ||||
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// | ||||
// CalcPositionFixed: calculate the world space position of the vertex at (i,j) | // CalcPositionFixed: calculate the world space position of the vertex at (i,j) | ||||
void CTerrain::CalcPositionFixed(ssize_t i, ssize_t j, CFixedVector3D& pos) const | void CTerrain::CalcPositionFixed(ssize_t i, ssize_t j, CFixedVector3D& pos) const | ||||
{ | { | ||||
ssize_t hi = clamp(i, (ssize_t)0, m_MapSize-1); | ssize_t hi = Clamp(i, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
ssize_t hj = clamp(j, (ssize_t)0, m_MapSize-1); | ssize_t hj = Clamp(j, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
Not Done Inline Actionssame as above Stan: same as above | |||||
u16 height = m_Heightmap[hj*m_MapSize + hi]; | u16 height = m_Heightmap[hj*m_MapSize + hi]; | ||||
pos.X = fixed::FromInt(i) * (int)TERRAIN_TILE_SIZE; | pos.X = fixed::FromInt(i) * (int)TERRAIN_TILE_SIZE; | ||||
// fixed max value is 32767, but height is a u16, so divide by two to avoid overflow | // fixed max value is 32767, but height is a u16, so divide by two to avoid overflow | ||||
pos.Y = fixed::FromInt(height/ 2 ) / ((int)HEIGHT_UNITS_PER_METRE / 2); | pos.Y = fixed::FromInt(height/ 2 ) / ((int)HEIGHT_UNITS_PER_METRE / 2); | ||||
pos.Z = fixed::FromInt(j) * (int)TERRAIN_TILE_SIZE; | pos.Z = fixed::FromInt(j) * (int)TERRAIN_TILE_SIZE; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | void CTerrain::CalcNormalFixed(ssize_t i, ssize_t j, CFixedVector3D& normal) const | ||||
// Compute the mean of the normals | // Compute the mean of the normals | ||||
normal = n0 + n1 + n2 + n3; | normal = n0 + n1 + n2 + n3; | ||||
normal.Normalize(); | normal.Normalize(); | ||||
} | } | ||||
CVector3D CTerrain::CalcExactNormal(float x, float z) const | CVector3D CTerrain::CalcExactNormal(float x, float z) const | ||||
{ | { | ||||
// Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) | // 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/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); | const ssize_t xi = Clamp<ssize_t>(floor(x / TERRAIN_TILE_SIZE), 0, m_MapSize - 2); | ||||
const ssize_t zi = clamp((ssize_t)floor(z/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); | const ssize_t zi = Clamp<ssize_t>(floor(z / TERRAIN_TILE_SIZE), 0, m_MapSize - 2); | ||||
Not Done Inline Actionsstatic cast here and below Stan: static cast here and below | |||||
const float xf = clamp(x/TERRAIN_TILE_SIZE-xi, 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); | const float zf = Clamp(z / TERRAIN_TILE_SIZE - zi, 0.0f, 1.0f); | ||||
Not Done Inline Actionsspaces Stan: spaces | |||||
float h00 = m_Heightmap[zi*m_MapSize + xi]; | float h00 = m_Heightmap[zi*m_MapSize + xi]; | ||||
float h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; | float h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; | ||||
float h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; | float h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; | ||||
float h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; | float h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; | ||||
// Determine which terrain triangle this point is on, | // Determine which terrain triangle this point is on, | ||||
// then compute the normal of that triangle's plane | // then compute the normal of that triangle's plane | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | if( (size_t)i >= (size_t)(m_MapSize-1) || (size_t)j >= (size_t)(m_MapSize-1) ) | ||||
return 0; | return 0; | ||||
CPatch* patch=GetPatch(i/PATCH_SIZE, j/PATCH_SIZE); // can't fail (due to above check) | CPatch* patch=GetPatch(i/PATCH_SIZE, j/PATCH_SIZE); // can't fail (due to above check) | ||||
return &patch->m_MiniPatches[j%PATCH_SIZE][i%PATCH_SIZE]; | return &patch->m_MiniPatches[j%PATCH_SIZE][i%PATCH_SIZE]; | ||||
} | } | ||||
float CTerrain::GetVertexGroundLevel(ssize_t i, ssize_t j) const | float CTerrain::GetVertexGroundLevel(ssize_t i, ssize_t j) const | ||||
{ | { | ||||
i = clamp(i, (ssize_t)0, m_MapSize-1); | i = Clamp(i, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
j = clamp(j, (ssize_t)0, m_MapSize-1); | j = Clamp(j, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
return HEIGHT_SCALE * m_Heightmap[j*m_MapSize + i]; | return HEIGHT_SCALE * m_Heightmap[j*m_MapSize + i]; | ||||
} | } | ||||
fixed CTerrain::GetVertexGroundLevelFixed(ssize_t i, ssize_t j) const | fixed CTerrain::GetVertexGroundLevelFixed(ssize_t i, ssize_t j) const | ||||
{ | { | ||||
i = clamp(i, (ssize_t)0, m_MapSize-1); | i = Clamp(i, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
j = clamp(j, (ssize_t)0, m_MapSize-1); | j = Clamp(j, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
// Convert to fixed metres (being careful to avoid intermediate overflows) | // Convert to fixed metres (being careful to avoid intermediate overflows) | ||||
return fixed::FromInt(m_Heightmap[j*m_MapSize + i] / 2) / (int)(HEIGHT_UNITS_PER_METRE / 2); | return fixed::FromInt(m_Heightmap[j*m_MapSize + i] / 2) / (int)(HEIGHT_UNITS_PER_METRE / 2); | ||||
} | } | ||||
fixed CTerrain::GetSlopeFixed(ssize_t i, ssize_t j) const | fixed CTerrain::GetSlopeFixed(ssize_t i, ssize_t j) const | ||||
{ | { | ||||
// Clamp to size-2 so we can use the tiles (i,j)-(i+1,j+1) | // Clamp to size-2 so we can use the tiles (i,j)-(i+1,j+1) | ||||
i = clamp(i, (ssize_t)0, m_MapSize-2); | i = Clamp(i, static_cast<ssize_t>(0), m_MapSize - 2); | ||||
j = clamp(j, (ssize_t)0, m_MapSize-2); | j = Clamp(j, static_cast<ssize_t>(0), m_MapSize - 2); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
u16 h00 = m_Heightmap[j*m_MapSize + i]; | u16 h00 = m_Heightmap[j*m_MapSize + i]; | ||||
u16 h01 = m_Heightmap[(j+1)*m_MapSize + i]; | u16 h01 = m_Heightmap[(j+1)*m_MapSize + i]; | ||||
u16 h10 = m_Heightmap[j*m_MapSize + (i+1)]; | u16 h10 = m_Heightmap[j*m_MapSize + (i+1)]; | ||||
u16 h11 = m_Heightmap[(j+1)*m_MapSize + (i+1)]; | u16 h11 = m_Heightmap[(j+1)*m_MapSize + (i+1)]; | ||||
// Difference of highest point from lowest point | // Difference of highest point from lowest point | ||||
u16 delta = std::max(std::max(h00, h01), std::max(h10, h11)) - | u16 delta = std::max(std::max(h00, h01), std::max(h10, h11)) - | ||||
std::min(std::min(h00, h01), std::min(h10, h11)); | std::min(std::min(h00, h01), std::min(h10, h11)); | ||||
// Compute fractional slope (being careful to avoid intermediate overflows) | // Compute fractional slope (being careful to avoid intermediate overflows) | ||||
return fixed::FromInt(delta / TERRAIN_TILE_SIZE) / (int)HEIGHT_UNITS_PER_METRE; | return fixed::FromInt(delta / TERRAIN_TILE_SIZE) / (int)HEIGHT_UNITS_PER_METRE; | ||||
} | } | ||||
fixed CTerrain::GetExactSlopeFixed(fixed x, fixed z) const | fixed CTerrain::GetExactSlopeFixed(fixed x, fixed z) const | ||||
{ | { | ||||
// Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) | // 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)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); | const ssize_t xi = Clamp<ssize_t>((x / static_cast<int>(TERRAIN_TILE_SIZE)).ToInt_RoundToZero(), 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 ssize_t zi = Clamp<ssize_t>((z / static_cast<int>(TERRAIN_TILE_SIZE)).ToInt_RoundToZero(), 0, m_MapSize-2); | ||||
Not Done Inline Actionsstatic_cast int should probably be ssize_t Stan: static_cast
int should probably be ssize_t | |||||
Not Done Inline ActionsNot done :) Stan: Not done :) | |||||
const fixed one = fixed::FromInt(1); | const fixed one = fixed::FromInt(1); | ||||
const fixed xf = clamp((x / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(xi), fixed::Zero(), one); | const fixed xf = Clamp((x / static_cast<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); | const fixed zf = Clamp((z / static_cast<int>(TERRAIN_TILE_SIZE)) - fixed::FromInt(zi), fixed::Zero(), one); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
Not Done Inline ActionsHere too :D Stan: Here too :D | |||||
u16 h00 = m_Heightmap[zi*m_MapSize + xi]; | u16 h00 = m_Heightmap[zi*m_MapSize + xi]; | ||||
u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; | u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; | ||||
u16 h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; | u16 h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; | ||||
u16 h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; | u16 h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; | ||||
u16 delta; | u16 delta; | ||||
if (GetTriangulationDir(xi, zi)) | if (GetTriangulationDir(xi, zi)) | ||||
Show All 40 Lines | float CTerrain::GetFilteredGroundLevel(float x, float z, float radius) const | ||||
// get trilinear filtered mipmap height | // get trilinear filtered mipmap height | ||||
return HEIGHT_SCALE * m_HeightMipmap.GetTrilinearGroundLevel(nx, nz, nr); | return HEIGHT_SCALE * m_HeightMipmap.GetTrilinearGroundLevel(nx, nz, nr); | ||||
} | } | ||||
float CTerrain::GetExactGroundLevel(float x, float z) const | float CTerrain::GetExactGroundLevel(float x, float z) const | ||||
{ | { | ||||
// Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) | // 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/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); | const ssize_t xi = Clamp<ssize_t>(floor(x / TERRAIN_TILE_SIZE), 0, m_MapSize - 2); | ||||
const ssize_t zi = clamp((ssize_t)floor(z/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); | const ssize_t zi = Clamp<ssize_t>(floor(z / TERRAIN_TILE_SIZE), 0, m_MapSize - 2); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
const float xf = clamp(x/TERRAIN_TILE_SIZE-xi, 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); | const float zf = Clamp(z / TERRAIN_TILE_SIZE - zi, 0.0f, 1.0f); | ||||
Not Done Inline Actionsstatic_cast spaces Stan: static_cast spaces | |||||
Not Done Inline Actionsspaces Stan: spaces | |||||
float h00 = m_Heightmap[zi*m_MapSize + xi]; | float h00 = m_Heightmap[zi*m_MapSize + xi]; | ||||
float h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; | float h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; | ||||
float h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; | float h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; | ||||
float h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; | float h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; | ||||
// Determine which terrain triangle this point is on, | // Determine which terrain triangle this point is on, | ||||
// then compute the linearly-interpolated height on that triangle's plane | // then compute the linearly-interpolated height on that triangle's plane | ||||
Show All 24 Lines | else | ||||
return HEIGHT_SCALE * (h00 + (h10-h00)*xf + (h11-h10)*zf); | return HEIGHT_SCALE * (h00 + (h10-h00)*xf + (h11-h10)*zf); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
fixed CTerrain::GetExactGroundLevelFixed(fixed x, fixed 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) | // 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)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); | const ssize_t xi = Clamp<ssize_t>((x / static_cast<int>(TERRAIN_TILE_SIZE)).ToInt_RoundToZero(), 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 ssize_t zi = Clamp<ssize_t>((z / static_cast<int>(TERRAIN_TILE_SIZE)).ToInt_RoundToZero(), 0, m_MapSize - 2); | ||||
Done Inline Actionsstatic_cast int → ssize_t Stan: static_cast int → ssize_t | |||||
Done Inline ActionsMissed a static_cast. Stan: Missed a static_cast. | |||||
const fixed one = fixed::FromInt(1); | const fixed one = fixed::FromInt(1); | ||||
const fixed xf = clamp((x / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(xi), 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); | const fixed zf = Clamp((z / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(zi), fixed::Zero(), one); | ||||
Done Inline Actionsstatic_cast Stan: static_cast | |||||
Done Inline ActionsMissing static cast. Stan: Missing static cast. | |||||
u16 h00 = m_Heightmap[zi*m_MapSize + xi]; | u16 h00 = m_Heightmap[zi*m_MapSize + xi]; | ||||
u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; | u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; | ||||
u16 h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; | u16 h10 = m_Heightmap[zi*m_MapSize + (xi+1)]; | ||||
u16 h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; | u16 h11 = m_Heightmap[(zi+1)*m_MapSize + (xi+1)]; | ||||
// Intermediate scaling of xf, so we don't overflow in the multiplications below | // Intermediate scaling of xf, so we don't overflow in the multiplications below | ||||
// (h00 <= 65535, xf <= 1, max fixed is < 32768; divide by 2 here so xf1*h00 <= 32767.5) | // (h00 <= 65535, xf <= 1, max fixed is < 32768; divide by 2 here so xf1*h00 <= 32767.5) | ||||
const fixed xf0 = xf / 2; | const fixed xf0 = xf / 2; | ||||
const fixed xf1 = (one - xf) / 2; | const fixed xf1 = (one - xf) / 2; | ||||
// Linearly interpolate | // Linearly interpolate | ||||
return ((one - zf).Multiply(xf1 * h00 + xf0 * h10) | return ((one - zf).Multiply(xf1 * h00 + xf0 * h10) | ||||
+ zf.Multiply(xf1 * h01 + xf0 * h11)) / (int)(HEIGHT_UNITS_PER_METRE / 2); | + zf.Multiply(xf1 * h01 + xf0 * h11)) / (int)(HEIGHT_UNITS_PER_METRE / 2); | ||||
// TODO: This should probably be more like GetExactGroundLevel() | // TODO: This should probably be more like GetExactGroundLevel() | ||||
// in handling triangulation properly | // in handling triangulation properly | ||||
} | } | ||||
bool CTerrain::GetTriangulationDir(ssize_t i, ssize_t j) const | bool CTerrain::GetTriangulationDir(ssize_t i, ssize_t j) const | ||||
{ | { | ||||
// Clamp to size-2 so we can use the tiles (i,j)-(i+1,j+1) | // Clamp to size-2 so we can use the tiles (i,j)-(i+1,j+1) | ||||
i = clamp(i, (ssize_t)0, m_MapSize-2); | i = Clamp(i, static_cast<ssize_t>(0), m_MapSize - 2); | ||||
j = clamp(j, (ssize_t)0, m_MapSize-2); | j = Clamp(j, static_cast<ssize_t>(0), m_MapSize - 2); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
int h00 = m_Heightmap[j*m_MapSize + i]; | int h00 = m_Heightmap[j*m_MapSize + i]; | ||||
int h01 = m_Heightmap[(j+1)*m_MapSize + i]; | int h01 = m_Heightmap[(j+1)*m_MapSize + i]; | ||||
int h10 = m_Heightmap[j*m_MapSize + (i+1)]; | int h10 = m_Heightmap[j*m_MapSize + (i+1)]; | ||||
int h11 = m_Heightmap[(j+1)*m_MapSize + (i+1)]; | int h11 = m_Heightmap[(j+1)*m_MapSize + (i+1)]; | ||||
// Prefer triangulating in whichever direction means the midpoint of the diagonal | // Prefer triangulating in whichever direction means the midpoint of the diagonal | ||||
// will be the highest. (In particular this means a diagonal edge will be straight | // will be the highest. (In particular this means a diagonal edge will be straight | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// | ||||
void CTerrain::MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags) | void CTerrain::MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags) | ||||
{ | { | ||||
// Finds the inclusive limits of the patches that include the specified range of tiles | // Finds the inclusive limits of the patches that include the specified range of tiles | ||||
ssize_t pi0 = clamp( i0 /PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1); | ssize_t pi0 = Clamp(i0 / PATCH_SIZE, static_cast<ssize_t>(0), m_MapSizePatches - 1); | ||||
ssize_t pi1 = clamp((i1-1)/PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1); | ssize_t pi1 = Clamp((i1 - 1) / PATCH_SIZE, static_cast<ssize_t>(0), m_MapSizePatches - 1); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
ssize_t pj0 = clamp( j0 /PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1); | ssize_t pj0 = Clamp(j0 / PATCH_SIZE, static_cast<ssize_t>(0), m_MapSizePatches - 1); | ||||
ssize_t pj1 = clamp((j1-1)/PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1); | ssize_t pj1 = Clamp((j1 - 1) / PATCH_SIZE, static_cast<ssize_t>(0), m_MapSizePatches - 1); | ||||
for (ssize_t j = pj0; j <= pj1; j++) | for (ssize_t j = pj0; j <= pj1; j++) | ||||
{ | { | ||||
for (ssize_t i = pi0; i <= pi1; i++) | for (ssize_t i = pi0; i <= pi1; i++) | ||||
{ | { | ||||
CPatch* patch = GetPatch(i, j); // can't fail (i,j were clamped) | CPatch* patch = GetPatch(i, j); // can't fail (i,j were clamped) | ||||
if (dirtyFlags & RENDERDATA_UPDATE_VERTICES) | if (dirtyFlags & RENDERDATA_UPDATE_VERTICES) | ||||
patch->CalcBounds(); | patch->CalcBounds(); | ||||
patch->SetDirty(dirtyFlags); | patch->SetDirty(dirtyFlags); | ||||
} | } | ||||
} | } | ||||
if (m_Heightmap) | if (m_Heightmap) | ||||
{ | { | ||||
m_HeightMipmap.Update(m_Heightmap, | m_HeightMipmap.Update(m_Heightmap, | ||||
clamp(i0, (ssize_t)0, m_MapSize-1), | Clamp(i0, static_cast<ssize_t>(0), m_MapSize - 1), | ||||
clamp(j0, (ssize_t)0, m_MapSize-1), | Clamp(j0, static_cast<ssize_t>(0), m_MapSize - 1), | ||||
clamp(i1, (ssize_t)1, m_MapSize), | Clamp(i1, static_cast<ssize_t>(1), m_MapSize), | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
clamp(j1, (ssize_t)1, m_MapSize) | Clamp(j1, static_cast<ssize_t>(1), m_MapSize) | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
void CTerrain::MakeDirty(int dirtyFlags) | void CTerrain::MakeDirty(int dirtyFlags) | ||||
{ | { | ||||
for (ssize_t j = 0; j < m_MapSizePatches; j++) | for (ssize_t j = 0; j < m_MapSizePatches; j++) | ||||
{ | { | ||||
for (ssize_t i = 0; i < m_MapSizePatches; i++) | for (ssize_t i = 0; i < m_MapSizePatches; i++) | ||||
{ | { | ||||
CPatch* patch = GetPatch(i, j); // can't fail | CPatch* patch = GetPatch(i, j); // can't fail | ||||
if (dirtyFlags & RENDERDATA_UPDATE_VERTICES) | if (dirtyFlags & RENDERDATA_UPDATE_VERTICES) | ||||
patch->CalcBounds(); | patch->CalcBounds(); | ||||
patch->SetDirty(dirtyFlags); | patch->SetDirty(dirtyFlags); | ||||
} | } | ||||
} | } | ||||
if (m_Heightmap) | if (m_Heightmap) | ||||
m_HeightMipmap.Update(m_Heightmap); | m_HeightMipmap.Update(m_Heightmap); | ||||
} | } | ||||
CBoundingBoxAligned CTerrain::GetVertexesBound(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) | CBoundingBoxAligned CTerrain::GetVertexesBound(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) | ||||
{ | { | ||||
i0 = clamp(i0, (ssize_t)0, m_MapSize-1); | i0 = Clamp(i0, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
j0 = clamp(j0, (ssize_t)0, m_MapSize-1); | j0 = Clamp(j0, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
i1 = clamp(i1, (ssize_t)0, m_MapSize-1); | i1 = Clamp(i1, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
j1 = clamp(j1, (ssize_t)0, m_MapSize-1); | j1 = Clamp(j1, static_cast<ssize_t>(0), m_MapSize - 1); | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
u16 minH = 65535; | u16 minH = 65535; | ||||
u16 maxH = 0; | u16 maxH = 0; | ||||
for (ssize_t j = j0; j <= j1; ++j) | for (ssize_t j = j0; j <= j1; ++j) | ||||
{ | { | ||||
for (ssize_t i = i0; i <= i1; ++i) | for (ssize_t i = i0; i <= i1; ++i) | ||||
{ | { | ||||
Show All 14 Lines |
Wildfire Games · Phabricator
static_cast here and below