network game loop
I may be a little slow, but what is the difference between
time-based and frame-based? They both use time?
- Splat
So if that is correct what is generaly the best way to lock there logic loops but keep the fps open.
I suppose for reciving i would use another thread in the backround. And im planning on using directplay.
I think locking any loop is not the best of ideas. Why does the logic loop need to be locked at 40fps? Why not, if your frame rate is capable of 60, of updating the objects in your game at 60 frames per second.
Ideally, you want to pretend that you are playing single player (with a few noticeable changes). Just have a normal, unlocked game loop, ie:
Check input, update status of objects, display, repeat.
Now, you're network code is NOT going to always have new data, so you will have to use dead reckoning or statistical prediction. The idea is, while you are not receiving data from the other people, pick the least obtrusive, highest probability action and continue it.
Now, whenever you get data from the other connection, it will obviously have slightly lagged ACCURATE data. It will also have a timestamp that can tell you WHEN that accurate data was really accurate. You then take that data, run statistical prediction from its time to the current time, and update the position of that object.
Overall, that method should give you excellent results in the display of remote objects, keep them accurate, and all without using a constant logic code (which begins to fail if, for example, the machine runs a background process that sucks up CPU.) With this method, you replace a tick/logic frame delta timestamp in network messages with a real time timestamp:
This works very well because, if you wanted to, you could store the timestamp as absolute time since the game was started. A 4-byte timestamp gets you 1/10th of a millisecond resolution for a timeperiod of about 5 days long.
Realistically, you would restart the timestamp every 5 minutes (since a client that hasn't gotten data in 5 minutes is in deeper trouble anyway). Therefore, a 19-bit timestamp at millisecond resolution works in this scenario.
- Splat
[This message has been edited by Splat (edited October 23, 1999).]
When I receive a package saying Object A is at location P, moving with velocity V, and the package containing this info is T ms old, the predicted position of A will be P+V*T...
/Niels
Or do i need to cap framerates and such?