My bodies are orbiting Earth and moving at great speeds (above 7000 m/s). As the simulation runs, I insert new bodies and I attach (link) them to the existing structure. Then, I save this set up to a text file (the save process is instantaneous). The objects get saved with their positional and attitude data, and their linkage info.
Then, I want to load the file I just saved. The problem is, my game engine has to load the saved visual objects asynchronously (requests them from a server and waits for the reply). While this is happening, I have to suspend calls NewtonUpdate(), otherwise, the few frames the server waits for the requested object to load, the previously loaded objects "run away" ahead and appear at the wrong positions.
As the objects are loaded, I link them, but for that I found (by experimenting) that I need to call NewtonUpdate(0.0) (with zero time step) for the link to function. Once all the objects are loaded, I activate calls to NewtonUpdate() and the sim runs.
Now, I'm sure this is not the proper way of doing it, because I am getting inconsistent results. Sometimes the whole linked structure loads fine, sometimes it has a rotation, and sometimes it goes into a wild spin with all the objects being thrown away form each other, and sometimes the objects are not in the positions they were when I saved them.
My questions are:
- What's the proper way (sequence of calls) for Newton engine when I need to discard existing objects from a scene and load now objects into the scene? (Keeping in mind asynchronous nature of loader of my visual objects).
- How do I properly suspend Newton engine while my objects load?
- Do I need to destroy and re-create the world?
- Do I need to use NewtonInvalidateCache (m_world); ? (I tried but not much changed, not sure where exactly it goes)
Thanks in advance.