mrvn wrote: Mon Oct 04, 2021 12:59 pm
Any case like that you don't calculate at all every tick. You simply record the start time and speed and if anything needs the current state it's calculated straight from that. And that remains frame accurate.
For machines this can be done, because you generaly only need the accurate state when you open its window. Outside of that it can just continue and wait for the frame.
mrvn wrote: Mon Oct 04, 2021 12:59 pm
Frame accuracy is actually rather important. Otherwise bots would jump whenever they switch back to accurate which would be horrible to the eye.
Im am aware that frame accuracy is important, but graphics wise it usualy isnt as much as players do rarely have such good eyes to notice it. And sure, some still might, but it at least shouldnt look ugly to them. And as long as you know the backend handles it frame perfectly, there is no issue anyway. Its like interpolation frames when you render a game at 120fps, while the server has 100fps, a good engine will render it at a very reliable way, and players then wont complain.
We can go even further with that, because if you are zoomed out heavily, you wont notice those things anyway. So these strict calculations are only needed when zoomed in anyway.
But anyway, if you want it more smooth... in that case the main thread should communicate with the secondary thread to provide a way to synchronize (probably communicate the frame number its processing.
The main thread only needs to communicate things for the secondary thread to calculate, and the frame number each frame that it is handling. This way you will only get a single frame off (depending on when the frame number gets sent), and 1 frame is not going to be noticed as easily, especialy if the animation remains that frame off until the end, while the item was transported at the intended frame.
The secondary thread can on that also communicate back that a certain object needs accurate calculations a few frames before they matter. If a bot is about to run out of power, you know that several frames before that. The main thread can then just read the state at whatever frame the bot was, and conitinue from that (either 1 or 2 frames). And if something has to change communicate it back to the secondary thread (the new path it will take and which frame this starts).
The threads in a CPU are normaly at the same clockspeed. So im not expecting a large gap of frames to appear. The main issues will start when the FPS starts to drop though, as that does slow down the game pace. And then the secondary threads get it a lot more difficult to synchronize as then the frames arent as smooth as they used to be, so predicting becomes harder. And caching such info ahead would consume quite a bit of RAM. But with that frame communication from the main thread (which should remain the heavier one anyway), you can mitigate issues here, as even at a slower framerate, the secondary thread will see it by getting the next frame call later.
Thats why i think that making the secondary threads only usable for things that do not realy require frame perfect accuracy is the better way (as to some degree they do, but thats mostly the deliver time itself, not the animation). Since the idea is that they arent going to be off like 10 frames anyway, its more like 1 or 2 frames at most. They will use info from the main thread to get a relatively accurate state.
And with it, the animation can just smooth itself to whatever state is needed. If its 3 frames ahead, you interpolate that by making the next 9 frames slower (each 3 frames you only make it move effectively worth 2 frames and just interpolate the locations to get a smooth animation). If you know how much FPS games use interpolation for animations, a 2d game like this isnt going to suffer a lot from that. There is a reason why in many games the models do not match the hitboxes, most players simply dont notice. And those that do, usualy know why, and do compensate in most cases (unless its bad netcode and positions are very unreliable).
But even then, i think keeping the animation slightly behind isnt realy going to be an issue if the items are still delivered in time. As thats the most important frame accuracy. However, in the end this isnt going to be suitable for GPU calculations, as its still going to remain rather strict.