Skip to content

Draft: Complete rolling forward with events

BimDav requested to merge BimDav/godot-rollback-tutorial:events into main

This is a demo of how an event system could work so that rolling forward is still supported, while using faster rollback-only logic when the game is running. This is linked with the work in: godot-rollback-netcode!14 (closed)

  • Events are registered via SyncManager by special nodes (users can also define new event-using nodes if they want). Events are not used during normal gameplay, when only rolling back is possible. They are logged and are used for the cases when rolling forward is useful (replay, reconnecting,...).

  • SpawnManager uses events to initialize nodes with values that won't change for the node's entire lifetime. SyncManager.spawn() now returns a reference of type NetworkSpawnedNode, on which the callv, set and connect methods are overriden to register the corresponding events.

  • In the replay feature, when rolling forward to a frame, SpawnManager._prepare_events_up_to_tick() is first called to prepare the event data to be sent. Then on the receiver SpawnManager._load_events() is called to update the state with the permanent values.

  • This is illustrated in this example by the bombs and the explosions, which positions are not put into state but into events. The global state is nevertheless correctly loaded in the replay feature.

  • To further illustrate the concept of events, I added the NetworkArray node, which is basically an network synced array that takes advantage of events to have a memory consumption scaling linearly with its size, in comparison to an array using only state, which will scale quadratically.

  • This array registers append() and clear() as events, and is able to restore forward state by implementing _prepare_events_up_to_tick() and _load_events()

  • In the example the positions of the right side player are stored in such an array, and cleared when pressing "enter". They are displayed by a blue line

I thought that it was pretty cool, I hope that we can work something like this out!

Merge request reports