Search Unity

API to offset sequence of Entity index and version in context of determinism MP setup

Discussion in 'Entity Component System' started by Spy-Shifty, Jan 18, 2019.

  1. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Hi,

    short story: I'm on converting the FPS multiplayerstack to a full jobyfied version and generic component serialization...

    For that scenarios I use two worlds. The game world and a network world. Each reliable entity that lives in the game world (an entity that will be synchronized through the net) also has a representing entity + components in the network world.

    In the network world I've full control over all processes that happens (adding, removing entities in specific order,...) to provide a deterministic behaviour on each client. This will result in jobiefied componentwise de/serialization behaviour without referencing entities...(order of chunks and components of entities are the same on server and on all clients)

    The only problem is the Entity itself. So Entity.Index and Entity.Version defines whether an entity is equal or not.
    To transmit an entity reference to an other reliable entity would mean that thouse also have to be deterministic on all machines.

    The problem is: when a client joines the game at a later point in time. Then the sequence of index and version numbers of Entities won't be in synch!

    Is there any API to lets say offset those index and version numbers?

    An alternative would be to store an selfmanaged id on each entity. But this is an extra effort in de/serialization.
     
  2. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    I don't fully understand your use case but can you reserve n number of player entities at start and just hand them out and recycle them as players join/leave?

    -- Edit: Ah never mind, I think I just got what you meant. So you're effectively keeping all clients Worlds perfectly synchronised down to the Entity level? If a new player joins, you'd have to replicate that world on the client?
     
    Last edited: Jan 18, 2019
  3. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    I would simply have a mapping that consits of netid <> entity, can store that in a NativeHashMap so it can be accessed inside of jobs, etc. also, this is the classic way of doing it and it works well.

    Making sure that entity(index, version) never desynchronizes between any of the clients/server and dealing with potential packet losses, etc. at the same time seems like way to much of a headache
     
  4. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Yes, correct. Because of that I can just synchronize my data componentwise in a job (componentJob.ScheduleSingle(...))
    and I don't need a reference between entity and the data in the networkstream.

    Determinism of Entity index + vesion is just a usecase if you want to synch a reference between 2 reliable entities.

    E.g. Entity A controlse Entity B.
    Or Entity A is doing what ever with Entity B..

    That won't be the case. Just adding an offset at the beginning of the communication would be required. The last commited state of client is always known to the server. Therefore package loss is no deal.

    EDIT:
    Ok I think there could be no additional pay of by using a netId.
    Because of the fact that the game world doesn't know anything about its network world.
    I already need to hold a Entity to Entity mapping between those worlds.
    And instead of using network world entities I can use the netId in the hashmaps.

    That would might work!
     
    Last edited: Jan 18, 2019