Im trying to make a multiplayer game with determinstic lockstep using the matterjs physics engine. For determinstic lockstep, I need to take frequent snapshots/copies of the world that I can rollback to at any time. The problem is copying the world efficiently.
(Also I mean determinstic lockstep as in each client running their own physics and the server exchanging the inputs among players. Everytime theres a phyiscs update, a tick variable goes up. When the client sends an input, they send { input, tick }. So when other client receive the input, they go back in time to the input tick and integrate the input into the game. Otherwise known as asynchronous determinstic lockstep [i think])
(Btw, I did this before without using a physics engine and just did a simple deepcopy function which was pretty fast). I've looked on the internet and couldn't find any efficient ways to clone the matterjs world. I did try to serialize the game and deserialize. However, when I did serialize, the string was so long even with just a few objects (around 40k chars) and took around 10ms to serialize/deserialize which was unacceptable. (serializing code from matterjs-tools serializer using resurrectjs). I tried to deepcopy engine.world or each body in engine.world.bodies but there were 3 circular properties in each of them. body.parts, body.vertices, body.parent!!
So how should I efficiently clone the world? If this is not possible, I will be very sad D:
Im trying to make a multiplayer game with determinstic lockstep using the matterjs physics engine. For determinstic lockstep, I need to take frequent snapshots/copies of the world that I can rollback to at any time. The problem is copying the world efficiently.
(Also I mean determinstic lockstep as in each client running their own physics and the server exchanging the inputs among players. Everytime theres a phyiscs update, a tick variable goes up. When the client sends an input, they send { input, tick }. So when other client receive the input, they go back in time to the input tick and integrate the input into the game. Otherwise known as asynchronous determinstic lockstep [i think])
(Btw, I did this before without using a physics engine and just did a simple deepcopy function which was pretty fast). I've looked on the internet and couldn't find any efficient ways to clone the matterjs world. I did try to serialize the game and deserialize. However, when I did serialize, the string was so long even with just a few objects (around 40k chars) and took around 10ms to serialize/deserialize which was unacceptable. (serializing code from matterjs-tools serializer using resurrectjs). I tried to deepcopy engine.world or each body in engine.world.bodies but there were 3 circular properties in each of them. body.parts, body.vertices, body.parent!! So how should I efficiently clone the world? If this is not possible, I will be very sad D: