mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-28 09:50:28 +00:00
Cut worker→main bandwidth ~3.3× by switching PlayerUpdate to deltas (#3967)
## Description: Cut worker→main bandwidth ~3.3× by switching PlayerUpdate from a full per-tick snapshot to a field-level diff. PlayerImpl.toUpdate() now caches the last sent update and returns only changed fields, or null if nothing changed. The client-side applyStateUpdate() merges instead of overwriting. Per-tick total dropped from ~297 KB to ~89 KB; the Player bucket alone went from 258 KB/tick to 50 KB/tick. Diff/apply logic lives in a new GameUpdateUtils.ts module with unit tests. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
This commit is contained in:
@@ -80,7 +80,7 @@ describe("Disconnected", () => {
|
||||
test("should include disconnected state in player update", () => {
|
||||
player1.markDisconnected(true);
|
||||
const update = player1.toUpdate();
|
||||
expect(update.isDisconnected).toBe(true);
|
||||
expect(update?.isDisconnected).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -153,8 +153,9 @@ describe("Disconnected", () => {
|
||||
test("should maintain disconnected state in player updates across ticks", () => {
|
||||
player1.markDisconnected(true);
|
||||
executeTicks(game, 3);
|
||||
const update = player1.toUpdate();
|
||||
expect(update.isDisconnected).toBe(true);
|
||||
// toUpdate() returns diffs after the first call, so query engine state
|
||||
// directly rather than the wire payload (which only carries changed fields).
|
||||
expect(player1.isDisconnected()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user