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(gameengine): stop the terrain flatten scanning from the map edge up

Olcay Seygan27526c54e275
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33fdb4625..a0e6edc28 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -379,6 +379,8 @@ found and fixed — EA's own, not port damage.**
- A replay that never recorded which seat was yours plays instead of crashing before the map loads.
- Alt-tabbing away with an arrow key held no longer leaves the camera sliding that way when you come back. The key release goes to whatever you switched to, so the game never heard it; losing focus now ends the scroll, the middle-button pan and the ALT pitch drag along with it.
- Locking Windows mid-battle no longer eats the game. Nothing that renders runs while the screen is locked, and the particle bookkeeping had been filed under rendering, so every explosion while you were away was created and never cleared up. A hundred rocket buggies firing at the ground for a minute is enough to come back to a game that has run out of memory or simply stopped responding.
+- Laying a foundation costs less the further up the map you build. Flattening the ground under a new building scanned every row of the map from the bottom edge up to the building, threw all of them away bar the ones actually under it, and did that once per column. It works out the rows it needs now. The ground comes out identical, down to the last unit of height.
+- EVA announcements that were queued behind another one no longer go quiet. A request waits its turn and expires if its turn never comes, and the sum that worked out when that was could wrap round to zero, retiring the announcement on the frame it was asked for.
- Tank tracks no longer crash the game. The renderer has to borrow the buffer it writes them into, and when that request failed, which is what a graphics device pulled out from under the game does, the tracks were written to address zero anyway. Two more of the same shape went with it: the screenshot path and the texture size lookup both used a pointer that the failing call had never filled in. Three of those texture lookups also leaked the surface they asked about, once per procedural texture, for the life of the process.
- Double-clicking a menu button opens the screen once. The button stays live while the old screen animates out, so the second click started the same transition again and the screen opened twice, one copy left drawn over whatever came next and doing nothing sensible when clicked.
- Double-tapping 0 jumps the camera to that group.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp
index 4721b0e34..3494fbb14 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Eva.cpp
@@ -484,8 +484,16 @@ void Eva::processPlayingMessages(UnsignedInt currentFrame)
continue;
}
- // These are requests that never got a chance to play and have since expired.
- if (it->m_triggeredOnFrame + it->m_evaInfo->m_framesToExpire <= currentFrame && !it->m_alreadyPlayed) {
+ //
+ // These are requests that never got a chance to play and have since expired. Both terms of
+ // that sum are unsigned, and ExpirationTimeMS comes straight out of an INI file with no
+ // range on it, so a large or negative entry wraps the addition round to a small number and
+ // the request expires the moment it is made - the announcement it was waiting to play never
+ // happens at all. Ask how long ago it was triggered instead: that cannot overflow.
+ //
+ const UnsignedInt framesWaiting = (currentFrame >= it->m_triggeredOnFrame)
+ ? (currentFrame - it->m_triggeredOnFrame) : 0;
+ if (framesWaiting >= it->m_evaInfo->m_framesToExpire && !it->m_alreadyPlayed) {
it = m_checks.erase(it);
continue;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
index de7f0572d..e5cc6541e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp
@@ -2686,7 +2686,18 @@ void TerrainLogic::setActiveBoundary(Int newActiveBoundary)
// ------------------------------------------------------------------------------------------------
/** Flatten the terrain beneath a struture. */
// ------------------------------------------------------------------------------------------------
-void TerrainLogic::flattenTerrain(Object *obj)
+//
+// Every row scan in here, and the one in createCraterInTerrain below, computes iMin.y and then
+// starts at row zero anyway. The shape test inside throws those rows away, so the terrain that
+// comes out is the same either way - what changes is how much work it took, and that grows with how
+// far up the map the building is. A base at the top edge of a large map paid for the whole column
+// on every foundation it laid.
+//
+// The clamp is not decoration: iMin.y goes negative for a footprint that hangs off the bottom edge,
+// and starting there would sample and stamp map cells that do not exist. Row zero was doing that
+// job by accident.
+//
+void TerrainLogic::flattenTerrain(Object *obj)
{
if (obj->getGeometryInfo().getIsSmall()) {
return;
@@ -2739,7 +2750,7 @@ void TerrainLogic::flattenTerrain(Object *obj)
Real totalHeight = 0;
Int numSamples = 0;
for (i=iMin.x; i<=iMax.x; i++) {
- for (j=0; j<=iMax.y; j++) {
+ for (j=(iMin.y>0?iMin.y:0); j<=iMax.y; j++) {
Vector3 testPt(i*MAP_XY_FACTOR, j*MAP_XY_FACTOR, 0);
Bool match = false;
unsigned char flags;
@@ -2765,7 +2776,7 @@ void TerrainLogic::flattenTerrain(Object *obj)
if (rawDataHeight>centerHeight) rawDataHeight = centerHeight;
for (i=iMin.x; i<=iMax.x; i++) {
- for (j=0; j<=iMax.y; j++) {
+ for (j=(iMin.y>0?iMin.y:0); j<=iMax.y; j++) {
Vector3 testPt(i*MAP_XY_FACTOR, j*MAP_XY_FACTOR, 0);
Bool match = false;
unsigned char flags;
@@ -2830,7 +2841,7 @@ void TerrainLogic::flattenTerrain(Object *obj)
Real totalHeight = 0;
Int numSamples = 0;
for (i=iMin.x; i<=iMax.x; i++) {
- for (j=0; j<=iMax.y; j++) {
+ for (j=(iMin.y>0?iMin.y:0); j<=iMax.y; j++) {
Vector3 testPt(i*MAP_XY_FACTOR, j*MAP_XY_FACTOR, 0);
Bool match = false;
Real dx = testPt.X - pos->x;
@@ -2848,7 +2859,7 @@ void TerrainLogic::flattenTerrain(Object *obj)
Real avgHeight = totalHeight/numSamples;
Int rawDataHeight = REAL_TO_INT_FLOOR(0.5f + avgHeight/MAP_HEIGHT_SCALE);
for (i=iMin.x; i<=iMax.x; i++) {
- for (j=0; j<=iMax.y; j++) {
+ for (j=(iMin.y>0?iMin.y:0); j<=iMax.y; j++) {
Vector3 testPt(i*MAP_XY_FACTOR, j*MAP_XY_FACTOR, 0);
Bool match = false;
Real dx = testPt.X - pos->x;
@@ -2925,7 +2936,7 @@ void TerrainLogic::createCraterInTerrain(Object *obj)
for (Int i = iMin.x; i <= iMax.x; i++ )
{
- for ( Int j=0; j <= iMax.y; j++ )
+ for ( Int j=(iMin.y>0?iMin.y:0); j <= iMax.y; j++ ) // see flattenTerrain: iMin.y was computed and then ignored
{
deltaX = ( i * MAP_XY_FACTOR ) - pos->x;
deltaY = ( j * MAP_XY_FACTOR ) - pos->y;