Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

perf(w3ddevice): sweep the height map along its rows, not down its columns

Olcay Seygan9168c72ca65f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6d515505..14a1c1b0f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1008,6 +1008,11 @@ the entire map that way, one dot after another. The picture is now kept in ordin
dot costs nothing, and handed over once a frame — only the rectangle that actually changed, and
nothing at all on a frame where nothing moved.
+**And scrolling across a big map.** Every frame the camera moves, the game sweeps the whole terrain
+looking for its lowest point. It was reading that grid across the grain — every step landing in a
+different part of memory — and it is read along the grain now. Same answer, a fraction of the work,
+on exactly the maps where scrolling used to feel heaviest.
+
## Sound, video, and getting it to start at all
- **Audio is real**, through the game's own audio library. The sound SDK was stripped from the source
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp
index fd52ee707..4aed7d541 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp
@@ -1733,8 +1733,10 @@ void HeightMapRenderObjClass::updateCenter(CameraClass *camera , RefRenderObjLis
Real intersectionZ;
minHt = m_map->getMaxHeightValue();
- for (i=0; i<m_x; i++) {
- for (j=0; j<m_y; j++) {
+ // row major: getDisplayHeight indexes x + width*y, so y belongs on the outside. The answer is
+ // a minimum and does not care about the order; the cache does.
+ for (j=0; j<m_y; j++) {
+ for (i=0; i<m_x; i++) {
Short cur = m_map->getDisplayHeight(i,j);
if (cur<minHt) minHt = cur;
}