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
feat(gameengine): the logic tick runs on its own thread on windows, always
Olcay Seyganf469a66f0847
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3a75d3fdc..a3bd1b479 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -236,8 +236,8 @@ 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 can run on a thread of its own, beside the drawing. The game works out a step and then draws, one after the other, so a heavy step stalls the picture; start it with `-logicthread 1` and 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. Network games keep each step in step with the other machines as before and do not overlap yet.-- That thread is off by default again. It was on from 3.2.0, and the crash reports from 3.3.0 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. The game works a step out between frames now, as it did before 3.2.0. Two of those collisions are fixed, one over the smoke and fire both sides create and one in the work a step leaves for the screen, which could run twice. The rest are still being hunted, so `-logicthread 1` is for whoever wants the smoother late game and accepts the risk.+- 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.+- 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.- 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.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.hindex 42c64ad7a..3d5b8ad5a 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/LogicThread.h@@ -39,10 +39,11 @@ class Drawable;class Player;/**- * `-logicthread 0`, the default since v3.3.0's crash reports, runs the tick on the main thread.- * `-logicthread 1` hands every tick to a dedicated thread; outside a network game the render draws- * beside it (phases 3 and 4), reading only the copies taken at the sync point, and in one the main- * thread waits for it (phase 5).+ * `-logicthread 1`, the default on Windows, hands every tick to a dedicated thread; outside a network+ * game the render draws beside it (phases 3 and 4), reading only the copies taken at the sync point,+ * and in one the main thread waits for it (phase 5). No option or saved setting reaches this.+ * `-logicthread 0`, the default off Windows and otherwise for a desync hunt, runs the tick on the main+ * thread.* `-logicthread 2` adds jitter to the tick to shake out races.** The census counts calls into the client made from the logic thread, one count per channeldiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cppindex 18de08f73..851f33e43 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/LogicThread.cpp@@ -492,9 +492,13 @@ void LogicThread::takeOverlapTimes( Real &tickMS, Real &waitMS )//-------------------------------------------------------------------------------------------------void LogicThread::init( void ){- // 0 unless the command line asks otherwise, since v3.3.0's crash reports showed the heap corrupted- // by the tick beside the render; -logicthread 1 hands it to its own thread+ // the command line has the last word. Off Windows the tick stays on the main thread: a macOS std::thread+ // has a 512 KB stack, and a tick needs more+#if defined(_WIN32)+ char value[ 32 ] = "1";+#elsechar value[ 32 ] = "0";+#endiffindEarlyCommandLineValue( L"-logicthread", value, sizeof(value) );if( atoi( value ) == 0 )return;diff --git a/README.md b/README.mdindex c273a2f07..77312967e 100644--- a/README.md+++ b/README.md@@ -98,7 +98,7 @@ yet. [CHANGELOG.md](CHANGELOG.md) has the measurements behind every line.| Veterancy is shared by everyone who hurt the target in the last ten seconds; healing earns too | 2.4.0 || The three sides mine a supply pile at the same pace, near the drop-off or far from it | 3.0.0 || The battle runs 60 steps a second, double the 30 of 2003; every speed, delay and reload was converted, so a Crusader still fires every two seconds | 3.0.0 |-| `-logicthread 1` works the battle out on its own thread beside the drawing; off by default again after 3.3.0's crashes | 3.2.0 |+| The battle is worked out on its own thread beside the drawing, by default on Windows; `-logicthread 0` puts it back between frames | 3.2.0 || Turbo mode replaces the speed dropdown: one lobby box, set by the host in a network game, two seconds of battle in every real one | 3.2.0 || Jets bank into turns, sweep wide at speed, take off down the runway, fly a landing circuit and taxi on their wheels | 3.2.0 || A jet shot down hits for 80 where it lands, 160 for a B-52 or a cargo plane, and leaves fire for about six seconds; its owner and allies are spared | 3.2.0 |@@ -267,7 +267,7 @@ Discs carry 1.00 and the engine is 1.04's, so files from a 1.04 install (Steam,| `-quickstart` | skips the intro movie, the shell map and the menu animations || `-nologo`, `-novideo` | skip the EA logo, or every movie || `-noaudio` | starts with every sound off |-| `-logicthread 1` | works the battle out on its own thread beside the drawing; the default 0 works it out between frames |+| `-logicthread 0` | for a desync hunt: works the battle out between frames, the default on Mac and Linux; Windows always runs it on its own thread otherwise, and no option turns that off |<details><summary>For testing: unattended computer matches</summary>