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(gameengine): the tick beside the render spends the catch-up budget

Olcay Seygan1e41dd2fc0d1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a0ee50ee..2f9fc7b51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -232,7 +232,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.
- On a screen faster than 60 Hz the armies glide. The battle moves in 60 steps a second, so a 144 or 240 Hz monitor showed every step two to four times over and a tank crossing the map moved in small hops. Now each picture draws every unit part of the way between its last two steps. The picture runs one step, 16.7 ms, behind the battle; the battle itself does not change, and a replay drawn with it, without it and with no picture at all ends on the same checksum. A 60 Hz screen gets nothing it did not have. `-nosmoothmotion` turns it off for a run, `-smoothmotion` turns it on whatever the screen.
-- The battle's arithmetic runs on a thread of its own, beside the drawing, on Windows. 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, which 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. A match too heavy to keep up with its clock goes the other way for now: eight Hard AIs on Twilight Flame at minute 16, 1370 objects, one frame in a thousand took 56.8 ms with the thread and 39.0 without. No menu or saved setting turns the thread off; `-logicthread 0` stays on the command line to chase a desync, and Mac and Linux keep the old order for now. Network games use the thread too, but the picture still waits for each step, so they do not overlap yet. Their machines compare checksums every 10 steps where they used to compare every step, so nine steps in ten skip a pass over the whole world, and a desync is caught at most 10 steps late.
+- The battle's arithmetic runs on a thread of its own, beside the drawing, on Windows. 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, which 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. A match too heavy for its clock used to pay for the thread: the catch-up steps after the picture ignored the step already run beside it, so each frame ran one step more than without the thread. Eight Hard AIs on Twilight Flame at minute 20, run at four times normal speed so they cannot keep up: one frame in a thousand took 26.8 ms with the thread and 24.0 without. Both now spend the same budget, and with the thread that frame is 21.5 ms and the average frame 11.9 ms against 13.9 without, at 12% more steps a second. No menu or saved setting turns the thread off; `-logicthread 0` stays on the command line to chase a desync, and Mac and Linux keep the old order for now. Network games use the thread too, but the picture still waits for each step, so they do not overlap yet. Their machines compare checksums every 10 steps where they used to compare every step, so nine steps in ten skip a pass over the whole world, and a desync is caught at most 10 steps late.
- That thread went off after 3.3.0, whose crash reports traced the random crashes in the middle of a match to the drawing and the battle writing to the same memory at the same moment. It is back because those collisions are closed. A model or animation the battle loads for the first time now waits for the picture to finish, the trees a unit pushes through move between frames, the team colours and the list of every object stay put while a picture is drawn, and the shadows thrown on units stop asking the battle where things stand while it is moving them. The test that decided it is a 4-against-4 match of 18000 steps, drawn with the thread on, drawn with it off and run with no picture at all, ending on the same checksum each time with the counter that flags the drawing reading the battle at zero.
- 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.
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 4c672826a..874fbb676 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -3198,6 +3198,12 @@ void GameEngine::update( void )
plus the render is a dropped frame nobody files a bug about. */
Int64 tCatchupStart, tCatchupNow;
tCatchupStart = Clock_Ticks();
+ /* The tick beside the render spends the budget like one run here. Left out, a match behind
+ its clock ran one more tick a pass at 1 than at 0, all of them in series after the picture:
+ 3.3 against 2.3 ticks, a frame 3 ms longer on average and 5 ms at p99.9. */
+ Real tickBesideRenderMS = 0.0f, waitForTickMS = 0.0f;
+ if (overlapped)
+ LogicThread::takeOverlapTimes( tickBesideRenderMS, waitForTickMS );
const UnsignedInt frameBeforeTicks = overlapped ? s_frameBeforeOverlap : TheGameLogic->getFrame();
for( ;; )
{
@@ -3221,7 +3227,7 @@ void GameEngine::update( void )
break;
tCatchupNow = Clock_Ticks();
if (!GameEngine_mayStartAnotherCatchupTick( logicTicksThisPass, maxTicksThisPass,
- engineElapsedMS( tCatchupStart, tCatchupNow ) ))
+ tickBesideRenderMS + engineElapsedMS( tCatchupStart, tCatchupNow ) ))
break;
if (networkPaced)
{
@@ -3268,11 +3274,8 @@ void GameEngine::update( void )
// One pass can pay off several ticks of debt; charge the histogram per tick, or a
// catch-up burst reads as one enormous logic frame that never actually happened. The tick
// beside the render is charged at its own length, the pass at the wait for it.
- Real overlapTickMS = 0.0f, overlapWaitMS = 0.0f;
- if (overlapped)
- LogicThread::takeOverlapTimes( overlapTickMS, overlapWaitMS );
- GameEngine_noteLogicTime( ( logicMS + overlapTickMS ) / (Real)logicTicksThisPass, TheGameLogic->getFrame() );
- logicMS += overlapWaitMS;
+ GameEngine_noteLogicTime( ( logicMS + tickBesideRenderMS ) / (Real)logicTicksThisPass, TheGameLogic->getFrame() );
+ logicMS += waitForTickMS;
#endif
}