I've seen a few threads about this topic already, but no one seems to have really nailed serialization yet. I'm trying to serialize my scenes for demo playback in my game. I really just want a sort of arcade "attract mode" playing back gameplay on the main menu so total fidelity isn't really necessary.
First off, I just record the initial state of the world, and then the user input each frame. To get the state of the world, I save the velocity and position (linear and angular) for all of my bodies. I also save whatever unique properties each entity instance has, health, etc. When I want to reload that state, I spawn each type of entity like normal, then write the velocities and positions directly back to the newly spawned bodies that comprise these newly spawned entities.
Also, some of these entities have 2 bodies connected by a revolute joint. If I set these bodies up the same with every spawning, and then when I serialize them, I save GetJointSpeed and m_referenceAngle (then setting SetMotorSpeed() and m_referenceAngle back when reloading) along with all the body positions and velocities, then shouldn't I have the same entity state when I reload them? Is there something I'm missing here?
Furthermore, when I start to record, I first save the current state, then immediately reload it. The state load destroys all active entity bodies before loading a new state. I would assume this would mean that upon the start of the recording of the demo and the start of any future playback of this demo, I should have the same initial state. I've also turned off warm starting.
This works to a degree, but something is still different between state loads, as whenever I try to play back the demo player input will eventually get out of sync with what's going on in the world. Is there something else about the world that I'm not maintaining between state loads?
First off, I just record the initial state of the world, and then the user input each frame. To get the state of the world, I save the velocity and position (linear and angular) for all of my bodies. I also save whatever unique properties each entity instance has, health, etc. When I want to reload that state, I spawn each type of entity like normal, then write the velocities and positions directly back to the newly spawned bodies that comprise these newly spawned entities.
Also, some of these entities have 2 bodies connected by a revolute joint. If I set these bodies up the same with every spawning, and then when I serialize them, I save GetJointSpeed and m_referenceAngle (then setting SetMotorSpeed() and m_referenceAngle back when reloading) along with all the body positions and velocities, then shouldn't I have the same entity state when I reload them? Is there something I'm missing here?
Furthermore, when I start to record, I first save the current state, then immediately reload it. The state load destroys all active entity bodies before loading a new state. I would assume this would mean that upon the start of the recording of the demo and the start of any future playback of this demo, I should have the same initial state. I've also turned off warm starting.
This works to a degree, but something is still different between state loads, as whenever I try to play back the demo player input will eventually get out of sync with what's going on in the world. Is there something else about the world that I'm not maintaining between state loads?