Skip to content

Commit 833fb7c

Browse files
authored
refactor(heightmap): Simplify functions getXWithOrigin(), getYWithOrigin() of HeightMapRenderObjClass (#2103)
1 parent e989576 commit 833fb7c

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,12 @@ is confusing, but it makes sliding the map 10x faster. */
257257
//=============================================================================
258258
Int HeightMapRenderObjClass::getXWithOrigin(Int x)
259259
{
260+
const Int xMax = m_x-1;
260261
x -= m_originX;
261-
if (x<0) x+= m_x-1;
262-
if (x>= m_x-1) x-=m_x-1;
263-
#ifdef RTS_DEBUG
264-
DEBUG_ASSERTCRASH (x>=0, ("X out of range."));
265-
DEBUG_ASSERTCRASH (x<m_x-1, ("X out of range."));
266-
#endif
267-
if (x<0) x = 0;
268-
if (x>= m_x-1) x=m_x-1;
262+
if (x < 0) x += xMax;
263+
if (x >= xMax) x -= xMax;
264+
if (x < 0) { DEBUG_CRASH(("X out of range.")); x = 0; }
265+
if (x >= xMax) { DEBUG_CRASH(("X out of range.")); x = xMax; }
269266
return x;
270267
}
271268

@@ -278,15 +275,12 @@ is confusing, but it makes sliding the map 10x faster. */
278275
//=============================================================================
279276
Int HeightMapRenderObjClass::getYWithOrigin(Int y)
280277
{
278+
const Int yMax = m_y-1;
281279
y -= m_originY;
282-
if (y<0) y+= m_y-1;
283-
if (y>= m_y-1) y-=m_y-1;
284-
#ifdef RTS_DEBUG
285-
DEBUG_ASSERTCRASH (y>=0, ("Y out of range."));
286-
DEBUG_ASSERTCRASH (y<m_y-1, ("Y out of range."));
287-
#endif
288-
if (y<0) y = 0;
289-
if (y>= m_y-1) y=m_y-1;
280+
if (y < 0) y += yMax;
281+
if (y >= yMax) y -= yMax;
282+
if (y < 0) { DEBUG_CRASH(("Y out of range.")); y = 0; }
283+
if (y >= yMax) { DEBUG_CRASH(("Y out of range.")); y = yMax; }
290284
return y;
291285
}
292286

0 commit comments

Comments
 (0)