AmbientRun / Ambient

The multiplayer game engine
https://ambient.run
Apache License 2.0
3.79k stars 122 forks source link

ECS diff recording/playback #769

Open philpax opened 1 year ago

philpax commented 1 year ago

Given that we store the majority/all of game state in the ECS, an interesting opportunity arises where we can record each tick's diff and save them to a file, and then play them back later.

This could be used for timelapses, demonstrations, video recording, debugging, and more. I'm especially interested in it for "time travel debugging", where you can record a play session, rewind to any point in the session, and play it back with new logic.

This is a popular feature in Quake-engine derivatives - especially in the Valve games, where you can record demos and then play them back from different angles. It's also available for Minecraft as a mod.

@pierd I heard you might be interested in this as a solution to world persistence?

pierd commented 1 year ago

There seems to be quite of an overlap between world persistence and replays.

In both cases I'm worried about client side scripts. There can be a lot of custom logic and out of bound (outside of the diff sync) networking that we wouldn't capture.

@pierd I heard you might be interested in this as a solution to world persistence?

I was thinking about using a diff stream alike protocol to have live replication of the world.

philpax commented 1 year ago

In both cases I'm worried about client side scripts. There can be a lot of custom logic and out of bound (outside of the diff sync) networking that we wouldn't capture.

Yeah, this is always a concern. My hope is that we get this in early enough that people try to use the ECS as much as possible so that they know their logic will be compatible with it. We should also encourage people to make their logic reentrant, so that a new server can be launched with a new instance of the logic, but using a persisted ECS.

I was thinking about using a diff stream alike protocol to have live replication of the world.

Live replication in what sense?

pierd commented 1 year ago

Live replication in what sense?

Like a database replication. Game server would have a connection with persistence server and they would use a diff stream to make sure that what's persisted is as up to date as possible. As opposite to game server doing data dumps periodically.

droqen commented 1 year ago

We should also encourage people to make their logic reentrant, so that a new server can be launched with a new instance of the logic, but using a persisted ECS.

@philpax Encouraging reentrancy will be easier if users have the ability to, or are even forced to, test it out and see the consequences of non-reentrant logic first-hand -- I assume that the package manager stuff will sort of test this? (i.e. if I check and uncheck things in the process of testing my game, that will test reentrancy to some degree?) -- Then we will start to get people (also me lol) confused about why certain things are acting weird, and see clearly what errors and messaging we need to clarify the situation