1500 Archers on a 28.8: Network Programming in Age of Empires and Beyond (2001)
As someone who fixes up old games in my spare time, and Age of Empires II being one of them, I&#x27;ll provide a bit of trivia about the game&#x27;s internals:<p>- The AI system is not part of the deterministic simulation. This was surprising to me, and after contacting one of the original programmers it was explained that it was due to a desynchronization bug that the &quot;AI and network programmers weren&#x27;t able to fix it in time&quot;.<p>A consequence of this design regression is that, due to the AI now being authoritatively run by the designated host player, network congestion issues arose which lead to a clear series of progressively more aggressive optimizations to reduce egress traffic. This primarily consisted of a very simple filter (mentioned in the article) which dropped duplicate commands in the common submission path, meaning it applied to both local user and AI commands, along with batching of AI-submitted commands which would be flushed at rather arbitrary times.<p>I&#x27;ll note that I&#x27;ve restored AI being deterministic in my project.<p>- A rather obscure determinism bug resulted from their compiler&#x27;s implementation of a few CRT routines, namely fsin&#x2F;fcos and a few others, which leveraged the specialized ISA instructions of the same name. The problem being that these transcendental functions are beyond the scope of the IEEE 754 spec. and ergo are hardware implementation-dependent. In practice, contemporary Intel&#x2F;AMD chip families produce bitwise the same result, however those around the time of AoE are known to diverge on results to some small margin (as confirmed by an Intel engineer on a thread I came across while researching).<p>- The game employs a dirty-update system for rendering, not only that it&#x27;s at a scanline granularity. This was something I was very pleased to see, as it&#x27;s a exceedingly rare to see such an important optimization in games of this era (although common in earlier eras)<p>- There&#x27;s some &quot;interesting&quot; naming conventions, one being prefixing member variables names with &quot;value&quot; -- there&#x27;s even a &quot;valueValue&quot;. Very little consistency in general in this regard, a reflection of independence between teams working on different components.<p>- While there are attempts at validation of input into the simulation (albeit woefully inadequate), it relies on ad hoc inclusion of PID (player ID) fields within commands. This is entirely useless, as this information is not authoritative and controlled by the players, permitting them to &quot;spoof&quot; the contextual information required for validation.<p>This is one of the more perplexing aspects of the engine, especially given the necessary information about the origin of a command is ofcourse available.<p>(As this information was later publicly published by other individuals I don&#x27;t see a problem with elaborating on it here as I have)<p>- An example of missing the wood for the trees: session information goes through an ad hoc compression for its wire form (just bitpacks fields) to conserve bandwidth, however the architectural choice is to synchronize this session state by just having the host broadcast the state --dirty or not-- every 200ms, flooding the network pointlessly (atleast in the 18.8k days)<p>- While Age of Empires is somewhat notorious for its poor multiplayer performance (notably when contrasted with say, the recent &quot;Definitive Edition&quot;), and while its implementation of this synchronization model is certainly rather juvenile, it should be understood that the final MP gameplay issues are primarily due to the choice of a peer-to-peer topology over the public internet, which at the time was the most reasonable.<p>While superficially P2P may seem like it should achieve the lowest latencies for instance, the reality is that the primary determinant is the characteristics --jitter, delays and packet-loss, reordering, ect-- of the path between two hosts and a P2P architecture means there&#x27;s n*n paths (network egress&#x2F;ingress paths are typically asymmetric). In contrast, a server&#x2F;client model you not only have far fewer routes, but datacenters are located at critical points in the network, roughly analogous to comparing travelling A-&gt;B along a freeway versus via the maze of residential streets.<p>- The state checksum &quot;algorithms&quot; involved are bordering on useless, atleast for state-tracing (such as when debugging desync. bugs.). They appear to have been devised by way of believing doing &quot;a bunch of random bitwise ops&quot; constitutes sufficient mixing -- a quick test demonstrated that csum collisions were not just possible, but occured sometimes for over 80% of inputs.<p>--<p>There&#x27;s a lot more that could be said but I feel that&#x27;s enough for now.