Jump to content

  • Log In with Google      Sign In   
  • Create Account


network game loop


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 24 October 1999 - 03:04 PM

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?


Sponsor:

#2 Zer   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 October 1999 - 07:46 AM

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.

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 23 October 1999 - 08:02 AM


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



#4 Splat   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 October 1999 - 12:12 PM

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

- Splat


#5 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 23 October 1999 - 12:22 PM

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.


#6 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 23 October 1999 - 12:43 PM

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?

#7 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 23 October 1999 - 01:39 PM

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.


#8 Splat   Members   -  Reputation: 122

Like
Likes
Like

Posted 23 October 1999 - 04:50 PM

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


#9 Zenroth   Members   -  Reputation: 127

Like
Likes
Like

Posted 24 October 1999 - 07:57 AM

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)

#10 Niels   Members   -  Reputation: 122

Like
Likes
Like

Posted 24 October 1999 - 10:39 AM

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


#11 Splat   Members   -  Reputation: 122

Like
Likes
Like

Posted 24 October 1999 - 03:04 PM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS