Bolt state objects/arrays and syncing

Options
DirtyHippy
DirtyHippy ✭✭
edited April 2016 in Photon Bolt
I have been moving some stuff into state recently from events. And I am not sure what Bolt does under the hood.

For example, if you have a state property of an array type of an object [MyObject] of length 8.
[MyObject] has two 4 byte integers, say [A] and [B].

If I make a change to one of the objects, say at index 5, to both members how does the sync happen?

Does bolt sync the entire array, including unchanged elements? Basically, does Bolt just do a full sync if it is sees any changes?

Does bolt only sync over the two elements that changed? And if so, is that update guaranteed to be atomic, or is it possible that I could see a situation where only one of the two elements is updated on the client? I.e. it is very useful for this update to be atomic, because otherwise it is not possible to really know when you have received enough data to act on it. You could act on it with only a partial update which would be wrong (and likely catastrophic).

I.e. it looks like the answers could be:

A. Bolt syncs the entire array over the network, in this case 64 bytes, but on the client only the changes to the two elements that actually changes are raised as property changed.
B. Bolt syncs over only the two elements A and B, but they are not atomic, so it is not guaranteed both A and B will arrive on the same frame.
C. Bolt syncs over only the two elements A and B, but the update is atomic, so the object is guaranteed to be fully updated when it arrives so if I see an update to A or B I know the entire object has been updated from the server.

Also, is there any difference between an array of primitive types (e.g. integers) and an array of bolt objects containing one element (an integer)?

Comments

  • DirtyHippy
    Options
    Just as an FYI, at the very least you can use ProtocolTokens now as state properties, and since by their nature they are atomic, they do work (and I have tested them).
  • Yukichu
    Options
    Interesting. ProtocolTokens might fix some of my issues with only certain values updating in sync.

    My understanding was tokens could not change their data, so I presume you just change the token in the state, a new one is sent, and is used.

    Interesting, very interesting.

    I still recall vividly when Fholm was creating the arrays he explained that if you update a single value of an object in an array, it would only replicate that value. Not sure it actually works as he intended. I may have to start using these tokens more.
  • DirtyHippy
    Options
    Yes, you assign a new token each time you assign it. Not quite as efficient as using one of the pre-allocated data types due to the token creation, but it does work. I have used it to move to state driven buffs/debuffs from event driven ones. Works fine.