Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to rollback game state if derialize the world won't delete new created entities? #70

Open
neroishero opened this issue Jan 11, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@neroishero
Copy link

I use bitEcs in my step-lock game as game states, somehow i let the client to predict next game frame state, if the predict state does not match the server's state, then I want to rollback the state to previous state. I tried to serialize the world every frame and save the packet, then derialize the world with certain frame if the predict is wrong. But the derialization won't delete the entitis created by the prediction. How can I achieve this idea? Any suggestion would be helpful. Or is there any way I can directly repace the world's state with the packet?
Many thanks!

@NateTheGreatt
Copy link
Owner

NateTheGreatt commented Jan 14, 2022

good question! i hadn't considered a situation like this. luckily i'm in the process of rewriting serialization, and i believe i have a solution for keeping everything in sync, component adds and removals. sit tight and i'll try my best to cater to your scenario :)

@NateTheGreatt NateTheGreatt added the enhancement New feature or request label Jan 14, 2022
@briancw
Copy link

briancw commented Jan 21, 2022

I am in a similar position. I am currently serializing the world on a server and deserializing it on a client and need to know when an entity has been removed by the server. I would like to be able to potentially miss an update from the server and still keep the client and server synced, so specifically sending a list of ents to remove is not preferable. Rather, I'd like to be able to just have the client determine when an entity has been removed because it is no longer being serialized.
My current approach to this in lieu of a method baked into bitECS is to set a UUID on each entity and then diff already known entities against ents from deserialization.
Here's a simplified version of how I'm going about this.

const knownEntities = new Map()
const renderSystem = (world) => {
  const now = Date.now()
  const ents = deserialize(world, serializedDataFromServer)
  for (let i = 0; i < ents.length; i += 1) {
    const entId = ents[i]
    const uuid = UUID.value[entId]
    if (!knownEntities.has(uuid)) {
      MyRenderLib.add(uuid)
      knownEntities.set(uuid, now)
    }
  }

  for (const [uuid, lastUpdate] of knownEntities) {
    if (lastUpdate !== now) {
      MyRenderLib.remove(uuid)
      knownEntities.delete(uuid)
    }
  }
}

It would make my setup much much simpler if bitECS's deserialization automatically removed entities from the world or returned a list of existing entities which are not present on the world.

@NateTheGreatt
Copy link
Owner

NateTheGreatt commented Jan 25, 2022

@briancw i can cater to removals being serialized, but i don't think i can generically cater to your specific scenario. it is not typical of networked games to serialize and send the state of all entities every single frame as that is highly inefficient, unless i'm misunderstanding something about your scenario. for example, in the networking system i have devised, i only serialize and send a value for an entity component when the value changes. i also have reliable messages separate from unreliable data updates, and i use a specific Removed message to reliably and explicitly let clients know what entities need removed, but will be attempting to make a generic serialization strategy for this concept.

@NateTheGreatt
Copy link
Owner

NateTheGreatt commented Jan 26, 2022

after pondering this for a bit longer, i think i see where you guys are coming from and what a generic solution might be: snapshots. these would entirely replace world state. however, i am not sure what the performance will be like for this concept just yet. stay tuned 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants