bevy_replicon icon indicating copy to clipboard operation
bevy_replicon copied to clipboard

Manually set global last-changed tick

Open UkoeHB opened this issue 2 years ago • 6 comments

There is a category of games that have limited conditions where the server world will be modified. For those games, it is feasible to manually track the last tick where something in the world was modified (or an event sent to clients). Once the last world-change-tick has been acked, it is a waste of CPU time to scan the ECS world for individual changes.

It would be nice if we could manually define/inject the last world-change-tick to the server replication loop, either on a global or per-client basis. We can then short-circuit replication if a client has acked that tick. Moreover, even if a client has not acked a tick, if we have cached replication buffers for the tick range (last acked, last world-change], then we don't need to scan the world (just send the buffers again).

UkoeHB avatar Nov 01 '23 16:11 UkoeHB

So it's basically pause replication after specific tick? Make sense to me. I think it should be done globally and once we will have rooms - per room.

Shatur avatar Nov 01 '23 18:11 Shatur

No longer relevant after #16.

Shatur avatar Dec 17 '23 13:12 Shatur

This is still relevant, #116 still scans the entire world every tick even if there is nothing to replicate.

UkoeHB avatar Dec 17 '23 16:12 UkoeHB

But there is not such thing as last changed tick. I feel like it's something that should be solved on Bevy side. They considering adding change detection on archetype and entity levels.

Shatur avatar Dec 17 '23 17:12 Shatur

Right, that's why I said "it is [sometimes] feasible to manually track the last tick where something in the world was modified".

UkoeHB avatar Dec 17 '23 18:12 UkoeHB

Instead of global last-change tick, we could do TickPolicy::Manual and add a system that can be manually scheduled which resends the last-buffered component updates that haven't been acked (EDIT: acks are tracked per-update message so this works out well).

Since renet uses Bytes, we can just store a copy per client. Very cheap, no need to allocate again.

UkoeHB avatar Dec 21 '23 19:12 UkoeHB