Advertisement

network game loop

Started by October 24, 1999 09:04 PM
9 comments, last by Zenroth 25 years, 1 month ago
Typically in a 8 player environment you generally do not want to have everyone have to synchronize -- except in the case of RTS. If you DO synchronize, have it done on time not frames and have the clients simulate eachother between syncs.

I may be a little slow, but what is the difference between
time-based and frame-based? They both use time?

Advertisement
Time-based is not fixed to any given frame rate. That way you don't have to cap everyone's frame rate.

- Splat

Ahh so like i was saying lock their logic loops(keys,communication,ect),but leave there fps open. And use dead reckoning.

So if that is correct what is generaly the best way to lock there logic loops but keep the fps open.

If you are doing a completely deterministic game, like StarCraft, where every computer has to show exactly the same thing you will have to sync your logic loops. I do believe that some action games, like Quake 3, are not perfectly deterministic though. In other words, if the local machine doesn't know the answer it guesses. I would be VERY interested to know the details of the algorithm that is used by games like that. It's my understanding that not even time is syncronized exactly except on the server. Hence, the client game loop must be able to adjust it's game clock based on data recieved remotely. Anyone have any ideas?
Well what im working on is more like quake than starcraft,but its peer to peer, not 3d and really shouldnt have that much info it would need to pass back and forth. Basicly just x,y the dir and when an event happens like if the ship(im not using ships but it works) fires,is hit,dies,ect. I fiqure collision detection well be off of the viewers screen. Thue im not sure bout that.

I suppose for reciving i would use another thread in the backround. And im planning on using directplay.

Advertisement
Well, I have been known to be wrong, but listen to my suggestion for a minute:

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).]

I could see that working. Just wish i could find some examples on doing something like that. Closest i can thing of sadly is duel(uses dead reckoning and some prediction i belive)
I do pretty much that - and it works OK! Only, the prediction is nothing fancy (or even intelligent ). It's simple physics:

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

<b>/NJ</b>
What is the best way to generaly structure the game loop for a peer to peer type action game with up to about 8 players. it well be realtime to. I mean is it best to have the logic loop run on all machines at a constant 40fps per second no matter what and the graphics run as fast as they can(faster machine get smoother graphics,slower get choppy ect,but all the input ect isnt effected by this.)

Or do i need to cap framerates and such?

This topic is closed to new replies.

Advertisement