Archived

This topic is now archived and is closed to further replies.

Zenroth

network game loop

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).]

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Exactly. Dead reckoning works perfectly fine for a whole hell of a lot of situations. You also might add a LITTLE physics code, because the following would be really funny:

Guy is heading towards edge of cliff. You now stop receiving packets from the server. Now, if you JUST use dead reckoning, this guy keeps running and running on thin air hehe If you also do calculations for gravity, then he falls to his doom just like you'd expect.

Zenroth: I imagine finding good source code to a network/prediction part of a game would be REAL hard to come by. This is the kind of thing that is generally too complex and specific to a given game to be real helpful.

- Splat

Share this post


Link to post
Share on other sites