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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(w3ddevice): retain composed model poses when pausing
Richard Louie Orilla4a9018df89bf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2eae19e8e..248b9c9ca 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -117,6 +117,7 @@ found and fixed — EA's own, not port damage.**- Mission timers keep EA's clock. A map's countdown still ticks 30 times a second, because the missions read a running timer's number and act on it: the second American mission declares victory when its "Win" timer drops below 1700, and on the first 60-step builds that came after 38 seconds instead of 10. The cutscene cues, the random music pick in the campaigns and the generals' challenges, the shell map's camera loop and the lightning on Eastern Everglades and Rocky Rampage were off the same way, 30 maps in all, and run on their original timing again. Custom maps get the same.- Normal speed is 60 steps a second. Turbo mode, the one other speed a match can have, runs 120 of the same steps a second (see Turbo mode above). Replays still play as fast as you ask.- The battle's arithmetic now runs on a thread of its own, beside the drawing. The game used to work out a step and then draw, one after the other, so a heavy step stalled the picture. Now the screen keeps drawing while the next step is worked out, and it pays most in the late game, where the steps are heaviest. In a late 4-player match, uncapped, frames slower than 16.7 ms (one 60 Hz refresh) fell from 23% to 0.8%, the slowest one frame in a hundred fell from 24.0 to 16.5 ms live and from 16.0-16.5 to 10.6-12.5 ms in a replay, and the average frame went from 15.2 to 11.8 ms. The battle still takes 60 steps a second, no more and no fewer. Network games keep each step in step with the other machines as before and do not overlap yet. If you want the old one-after-the-other loop back, start the game with `-logicthread 0`.+- Opening the pause menu no longer makes boats snap to a different angle or parked aircraft sink into the carrier deck. Boats keep their rocking angle and aircraft remain above the deck while the game is paused.- Replays and games saved in the middle of a match from earlier versions will not load in this one. The "Mission Start" saves a campaign makes between missions do, and every campaign mission can be picked from the campaign menu. A player on an earlier version cannot join a match with a player on this version, whichever of them hosts, so a LAN party needs everyone on the same build.- Guns fire at their 2003 rate again. After a shot the game goes back to aiming for a step before it can fire again, which at 30 steps put a 100 millisecond Quad Cannon on a shot every 0.133 seconds; at 60 the same loop fired it every 0.100, a third faster. Shot delays and reloads are rounded to the old step and a gun's next shot is held to the old rhythm, so every weapon fires on the frames it did in 2003. A turret with no turning speed in its data rose twice as fast as it should, aircraft weighed their thrust against gravity at half strength, and a unit hit on the step before still counted as untouched for stealth. All three keep EA's timing now.- Mod guns shoot straight again. Shockwave Chaos and other mods give their machine guns and autocannons a shell that arcs 300 high but flies so fast that the 30-step game only ever put it at the muzzle and on the target. At 60 steps the shell stopped partway up that arc, so in Chaos a Humvee's autocannon round went 200 into the air before coming down on a tank 100 away. A shell now passes through the points it passed through in 2003 and flies straight between them, so mod rounds hit straight and the original game's shells fly the same arcs. A shell fired point blank, close enough to arrive in one step, used to fly to the corner of the map and explode there, a bug since 2003; it hits its target now.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 4545efdba..38032e1de 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -1674,6 +1674,7 @@ GameEngineDevice/Include/W3DDevice/GameClient/W3DDebugIcons.hGameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.hGameEngineDevice/Include/W3DDevice/GameClient/W3DDisplayString.hGameEngineDevice/Include/W3DDevice/GameClient/W3DDisplayStringManager.h+GameEngineDevice/Include/W3DDevice/GameClient/W3DDrawableUpdate.hGameEngineDevice/Include/W3DDevice/GameClient/W3DDynamicLight.hGameEngineDevice/Include/W3DDevice/GameClient/W3DFileSystem.hGameEngineDevice/Include/W3DDevice/GameClient/W3DGUICallbacks.hdiff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDrawableUpdate.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDrawableUpdate.hnew file mode 100644index 000000000..dfafb9761--- /dev/null+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDrawableUpdate.h@@ -0,0 +1,37 @@+/* Per-view cadence for composing drawable render poses. */+#pragma once++#ifndef __W3DDRAWABLEUPDATE_H_+#define __W3DDRAWABLEUPDATE_H_++class W3DDrawableUpdate+{+public:+ W3DDrawableUpdate() : m_haveFrame(false), m_lastFrame(0) {}++ bool needsUpdate(unsigned clientFrame, bool animationAdvanced, unsigned videoPicture)+ {+ // Extra capture pictures use the first picture's pose and must not consume a new frame.+ if (videoPicture != 0)+ return false;+ // A flushed client frame can replace a render pose with its raw transform even when+ // pause has stopped W3D's animation clock. Compose that frame once for each view.+ if (!animationAdvanced && m_haveFrame && clientFrame == m_lastFrame)+ return false;+ m_haveFrame = true;+ m_lastFrame = clientFrame;+ return true;+ }++ void reset()+ {+ m_haveFrame = false;+ m_lastFrame = 0;+ }++private:+ bool m_haveFrame;+ unsigned m_lastFrame;+};++#endif // __W3DDRAWABLEUPDATE_H_diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.hindex 9d1eb74a8..0f6c920b5 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h@@ -48,6 +48,7 @@#include "GameClient/ParabolicEase.h"#include "GameClient/View.h"#include "GameClient/CameraScrollClock.h"+#include "W3DDevice/GameClient/W3DDrawableUpdate.h"#include "WW3D2/camera.h"// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////@@ -264,6 +265,8 @@ public:private:+ W3DDrawableUpdate m_drawableUpdate;+ Bool drawsDrawables( void );Bool m_freeCamera; ///< the console's freecam has the viewVector3 m_freeCameraEye;diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cppindex fbab987a0..388c64937 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp@@ -132,12 +132,13 @@ static const Int CAMERA_STEP_MSEC = 1000/RETAIL_LOGICFRAMES_PER_SECOND;static const Int MAX_REQUEST_CACHE_SIZE = 40; // Any size larger than 10, or examine code below for changes. jkmcd.static const Real DRAWABLE_OVERSCAN = 75.0f; ///< 3D world coords of how much to overscan in the 3D screen region-/* The drawables are drawn when W3D's clock has moved, which is once a logic frame: the clock stands still- between ticks. -recordfps moves it on every picture of a recorded frame, and a picture after the- first has nothing new to draw them with; smooth motion moves the models for it. */-static Bool drawsDrawables( void )+/* A tick flushed after rendering can replace model poses with raw logic transforms. Recompose that+ new client state even when pause has frozen W3D's animation clock, retaining instance rocking and+ aircraft physics. Later -recordfps pictures still leave the models to smooth motion. */+Bool W3DView::drawsDrawables( void ){- return WW3D::Get_Frame_Time() != 0 && GameEngine_videoPicture() == 0;+ return m_drawableUpdate.needsUpdate(TheGameClient->getFrame(), WW3D::Get_Frame_Time() != 0,+ GameEngine_videoPicture());}/* The camera's own clock: the wall clock, and while a -video range records the time of the picture@@ -1262,6 +1263,7 @@ const Coord3D& W3DView::get3DCameraPosition() constvoid W3DView::reset( void ){View::reset();+ m_drawableUpdate.reset();// the recording outlives its replays now (Display::replay); its strings go with Display::resetm_postDraw.clear();@@ -2179,7 +2181,7 @@ void W3DView::update(void)// render all of the visible Drawables/// @todo this needs to use a real region partition or something- if (drawsDrawables()) //make sure some time actually elapsed+ if (drawsDrawables())TheGameClient->iterateDrawablesInRegion( &axisAlignedRegion, drawDrawable, this );}diff --git a/GeneralsMD/Code/Tests/test_smooth_motion.cpp b/GeneralsMD/Code/Tests/test_smooth_motion.cppindex 71ee88439..3b5ff58ba 100644--- a/GeneralsMD/Code/Tests/test_smooth_motion.cpp+++ b/GeneralsMD/Code/Tests/test_smooth_motion.cpp@@ -22,6 +22,7 @@#include "test_harness.h"#include "W3DDevice/GameClient/W3DSmoothMotion.h"+#include "W3DDevice/GameClient/W3DDrawableUpdate.h"#include <math.h>@@ -132,3 +133,55 @@ TEST(smooth_motion_track_verdicts_per_tick)CHECK_EQ((int)(counts[SMOOTH_BLENDED] - before[SMOOTH_BLENDED]), 1);CHECK_EQ((int)(counts[SMOOTH_SNAP_HIDDEN] - before[SMOOTH_SNAP_HIDDEN]), 2);}++TEST(drawable_update_composes_flushed_client_frame_when_pause_stops_animation)+{+ W3DDrawableUpdate update;+ CHECK(update.needsUpdate(42, true, 0));+ CHECK(!update.needsUpdate(42, false, 0));+ // The overlapping tick flushes frame 43 after the render, replacing client poses with+ // raw transforms. Opening the pause menu freezes animation before the next view update.+ CHECK(update.needsUpdate(43, false, 0));+ for (int picture = 0; picture < 8; ++picture)+ CHECK(!update.needsUpdate(43, false, 0));+ // On resume an advancing animation clock still requests an update within the same frame.+ CHECK(update.needsUpdate(43, true, 0));+ CHECK(update.needsUpdate(44, true, 0));+}++TEST(drawable_update_first_view_and_reset_do_not_require_animation_time)+{+ W3DDrawableUpdate update;+ CHECK(update.needsUpdate(0, false, 0));+ CHECK(!update.needsUpdate(0, false, 0));+ // A new map can start at the same frame as the previous view's last picture.+ update.reset();+ CHECK(update.needsUpdate(0, false, 0));+ CHECK(update.needsUpdate(90, false, 0));+ update.reset();+ CHECK(update.needsUpdate(0, false, 0));+ CHECK(!update.needsUpdate(0, false, 0));+}++TEST(drawable_update_views_consume_client_frames_independently)+{+ W3DDrawableUpdate primary, observer;+ CHECK(primary.needsUpdate(25, false, 0));+ CHECK(observer.needsUpdate(25, false, 0));+ CHECK(!primary.needsUpdate(25, false, 0));+ CHECK(!observer.needsUpdate(25, false, 0));+ CHECK(primary.needsUpdate(26, false, 0));+ CHECK(!primary.needsUpdate(26, false, 0));+ CHECK(observer.needsUpdate(26, false, 0));+}++TEST(drawable_update_capture_pictures_skip_without_consuming_client_frame)+{+ W3DDrawableUpdate update;+ CHECK(!update.needsUpdate(0, true, 1));+ CHECK(update.needsUpdate(0, false, 0));+ CHECK(!update.needsUpdate(1, true, 1));+ CHECK(!update.needsUpdate(1, false, 2));+ CHECK(update.needsUpdate(1, false, 0));+ CHECK(!update.needsUpdate(1, false, 0));+}