geckosio / snapshot-interpolation

A Snapshot Interpolation library for Real-Time Multiplayer Games.
BSD 3-Clause "New" or "Revised" License
277 stars 25 forks source link

Support nested objects for state #10

Closed silviuFlorin closed 2 years ago

silviuFlorin commented 3 years ago

I read that 'The World State has to be an Array with non nested Objects (expect for Quaternions)'

I have the following world state:

// the worldState on the server const worldState = [ { id: 'snake1', sections: [{x: 23, y: 14, rotation: 47}, {x: 23, y: 14, rotation: 47}]}, { id: 'snake2', sections: [{x: 23, y: 14, rotation: 47}, {x: 23, y: 14, rotation: 47}, {x: 23, y: 14, rotation: 47}]}, { id: 'snake3', sections: [{x: 23, y: 14, rotation: 47}]} ]

// calc interpolation on the client SI.calcInterpolation(???)

Is there a way to use this library for my use case? Is there a chance to add support for nested objects in case there is no way to do it at this point?

yandeu commented 3 years ago

I guess the easiest way would be to restructure your worldState before interpolating.

const worldState = [
  { id: 'snake1', section: 0, x: 23, y: 14, rotation: 47 },
  { id: 'snake1', section: 1, x: 23, y: 14, rotation: 47 },

  { id: 'snake2', section: 0, x: 23, y: 14, rotation: 47 },
  { id: 'snake2', section: 1, x: 23, y: 14, rotation: 47 },
  { id: 'snake2', section: 2, x: 23, y: 14, rotation: 47 },

  { id: 'snake3', section: 1, x: 23, y: 14, rotation: 47 }
]

Is there a chance to add support for nested objects

I don't know yet.

silviuFlorin commented 3 years ago

I followed your suggestion. It does work but adds a lot of complexity to the code. Anyways...great work with the libraries you built.