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.

fix(gameenginedevice): step light and tree animation on the logic frame

Olcay Seygan24ae239b73b5
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.h
index 2f9a680bf..d5669e7bf 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.h
@@ -63,6 +63,10 @@ protected:
Vector3 m_targetAmbient;
Vector3 m_targetDiffuse;
+ /// last client frame we stepped the fade counters on; these count LOGIC frames, and
+ /// On_Frame_Update is driven once per RENDER frame.
+ UnsignedInt m_lastFadeFrame;
+
public:
W3DDynamicLight();
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h
index 0da8aec84..0cecc724d 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DTreeBuffer.h
@@ -252,6 +252,7 @@ private:
Int m_curSwayVersion;
Real m_curSwayOffset[MAX_SWAY_TYPES];
+ UnsignedInt m_lastSwayFrame; ///< last logic frame the sway was stepped on (drawTrees runs per render frame)
Real m_curSwayStep[MAX_SWAY_TYPES];
Real m_curSwayFactor[MAX_SWAY_TYPES];
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDynamicLight.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDynamicLight.cpp
index ac672c39f..ba60c803d 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDynamicLight.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDynamicLight.cpp
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include "W3DDevice/GameClient/W3DDynamicLight.h"
+#include "GameClient/GameClient.h" // for the logic-frame gate in On_Frame_Update
W3DDynamicLight::W3DDynamicLight(void):
LightClass(LightClass::POINT)
@@ -35,6 +36,7 @@ LightClass(LightClass::POINT)
m_priorEnable = false;
m_enabled = true;
+ m_lastFadeFrame = 0xffffffff; // so the first On_Frame_Update always steps
}
@@ -47,6 +49,18 @@ void W3DDynamicLight::On_Frame_Update(void)
if (!m_enabled) {
return;
}
+
+ //
+ // m_curIncreaseFrameCount/m_curDecayFrameCount are LOGIC frame counts, but this is called
+ // once per RENDER frame from RTS3DScene::Customized_Render. With rendering uncapped that
+ // made muzzle flashes and explosion lights fade at (fps/30)x speed. Step once per logic frame.
+ //
+ UnsignedInt now = TheGameClient ? TheGameClient->getFrame() : 0;
+ if (now == m_lastFadeFrame) {
+ return;
+ }
+ m_lastFadeFrame = now;
+
Real factor = 1.0f;
if (m_curIncreaseFrameCount>0 && m_increaseFrameCount>0) {
// increasing
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
index 744bb5b1a..082f95da1 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
@@ -71,6 +71,7 @@ enum
#include "GameLogic/Object.h"
#include "GameLogic/PartitionManager.h"
#include "GameClient/ClientRandomValue.h"
+#include "GameClient/GameClient.h" // logic-frame gate for the sway phase
#include "GameClient/FXList.h"
#include "W3DDevice/GameClient/TerrainTex.h"
#include "W3DDevice/GameClient/HeightMap.h"
@@ -1121,6 +1122,7 @@ W3DTreeBuffer::W3DTreeBuffer(void)
allocateTreeBuffers();
m_initialized = true;
m_curSwayVersion = -1;
+ m_lastSwayFrame = 0xffffffff; // so the first drawTrees always steps
m_shadow = NULL;
@@ -1563,9 +1565,21 @@ void W3DTreeBuffer::drawTrees(CameraClass * camera, RefRenderObjListIterator *pD
updateSway(info);
}
}
+
+ //
+ // m_curSwayStep is a per-LOGIC-frame increment, but drawTrees runs once per RENDER frame, so
+ // with rendering uncapped the trees swayed at (fps/30)x speed. Advance the phase only when
+ // the logic frame changed; the interpolation below still runs every render frame.
+ //
+ UnsignedInt swayNow = TheGameClient ? TheGameClient->getFrame() : 0;
+ Bool stepSway = !pause && (swayNow != m_lastSwayFrame);
+ if (stepSway) {
+ m_lastSwayFrame = swayNow;
+ }
+
Vector3 swayFactor[MAX_SWAY_TYPES];
for (i=0; i<MAX_SWAY_TYPES; i++) {
- if (!pause) {
+ if (stepSway) {
m_curSwayOffset[i] += m_curSwayStep[i];
if (m_curSwayOffset[i] > NUM_SWAY_ENTRIES-1) {
m_curSwayOffset[i] -= NUM_SWAY_ENTRIES-1;