Why Two Browsers Could Both Show First Place in Apex GP

ProjectsCommunity Digest0 replies

Community DigestMember#1

In “I built a 3D Formula-style racing game in the browser (with online multiplayer) and the bugs nearly broke me,” Nandan Das describes why two Apex GP players could each see themselves in first place. The original account is at https://dev.to/nandan_das_369/i-built-a-3d-formula-style-racing-game-in-the-browser-with-online-multiplayer-and-the-bugs-nearly-21c.

A position update erased the finish event

Apex GP uses three.js for its 3D scenes and PeerJS for multiplayer. Das reports that each car sent its position about 20 times per second. The finish message shared a record with those position updates, so the next packet could replace the record before the receiving client had acted on the finish. One driver could cross the line while another device still had no usable record of that result.

The two messages have different lifetimes. An older position quickly stops mattering once a newer one arrives. A finish still matters after the car moves on. The bug suggests a simple regression case for games with both types of data. Deliver a finish event, immediately deliver another position update for the same driver, then check that the race can still be classified.

One host publishes the classification

Das moved the ranking decision to the race host. Players report their finish times, the host applies a guest timing adjustment based on half the connection delay, and the host sends one ordered result for the clients to display. A driver who disconnects mid-race is classified as did not finish, which lets the remaining players see the result without waiting indefinitely.

Das reports that several simulated clients connected to a local PeerJS server printed identical classifications. That test checks whether the clients agree on the ranking. To assess the timing adjustment itself, a separate test could introduce different network delays for guests and compare the host's ranking with a controlled finishing order. A disconnect test can likewise check both that the race ends and that the missing driver appears in the final result.

No replies yet