|
|
| Networking and allegro timers |
|
anto80
Member #3,230
February 2003
|
When you do a client/server network based game, how do you declare you timers? (and where, that is : client-side? server-side? both?) I wondering because in a non-network game, i always put a timer so as to "brake" the display to a max of XXX FPS. I also thought about setting a server-side timer, that force the server to send packets on a regular basis, and refresh client display only when receiving these incoming packets.
___________ |
|
Rob Fletcher
Member #2,830
October 2002
|
In my first crack at a networked game, I'm using four total, two for the client, two for the server. I have an FPS for the game physics, which is done on the server. The server keeps track of all the objects in the world and iterates them 30 times per second. That FPS (lets call it 30) is also on my client. It also iterates all the objects it cares about (a subset of the universes objects, let the server worry about them). This is how it does the prediction, in a perfect world in a vacuum, since movement is deterministic, it should mirror whats going on on the server perfectly. Then I have a network FPS on the server. I'm trying to find a good value for this, but at the moment I find 5 is surprisingly good (10 could be good too, it can be balanced, though). And it will send update packets to all the clients 5 times a second and the clients will smooth out the in-between frames. Then, I have a client side network FPS that sends the rendered data about the client's input so-many-times per second. It seems to work, but the engine is young and naive, but that works for me and I'll know which numbers to jiggle to make a tighter network system. You can do the same and we'll both become network savvy like Gillius. Rob |
|
Frank Drebin
Member #2,987
December 2002
|
if you use the "standard timer layout" for your game (the one how to keep my game running the same speed on every pc) you don't need any additional timer i think. you update your network-stuff as often as you do your game-logic. |
|
anto80
Member #3,230
February 2003
|
[edit] as for my game logic, will i have to use 1 timer in the server and 1 for the client?? because i planned to set a timer in the server and perform moves on the server, and send back absolute positions to clients (say 50 times per second)... ___________ |
|
Rob Fletcher
Member #2,830
October 2002
|
If you're on a LAN, and your data is of a reasonable size, you could pull off 50 frames per second on the network. But, you really don't need that much. I mean, my 5 FPS is a bit clunky, but the fact that I could double it and polish (heh, I mean 'introduce') prediction algorithms makes it a bit smoother. 50FPS is a lot of network frames. Math time, I'll be conservative here. 1 frame = locations of 20 spaceships So... per second, that works out to be (20 * 20 * 50) ends up being 20 k/s per client. That's biggish (not for a download speed, but if you play for an hour, you'll have downloaded 72 megs of play data), But think of your poor server. It has 8 clients connected, then it will have to be pushing out 160kps, in an hour you'll have sent over half a gig of data! You could have sent an hour-long movie of decent quality. So, it's good to send as little as possible, and since games are deterministic, it's save to send 'keyframes' and let the client extrapolate the positions between them. For me, I send the x, y, direction, and velocity 5 times a second, and let my little sprites coast between frames on their own. If I turn sharply, it will jerk a bit, but otherwise, at 5 fps, it's totally fine. And there are mounds of algorithms out there to smooth out the jerks. It's worth it. Rob (edit) I should have said "games can be made to be deterministic" anybody can go crazy with random functions, in this case, leave those games up to the server for important data. Particle effects, etc.. can stay on the client. |
|
anto80
Member #3,230
February 2003
|
as for me: for 50 FPS, every client need : 48*50 = 2,4 k bps. maximum. Quote: So, it's good to send as little as possible
I agree with you but if if switch to 5 FPS, i cannot guess if each remote client is gonna move... right? Quote: leave those games up to the server for important data. Particle effects, etc.. can stay on the client. Of course. ___________ |
|
Rob Fletcher
Member #2,830
October 2002
|
Sorry if I came off as saying 5FPS is all you'll ever need, I mean 5 FPS is really not enough for most games that have any kind of twitch element to them. It was more of a test to show that 5 FPS could surprisingly hold it's own, and a 400% increase in frames could make it great. Quote: I agree with you but if if switch to 5 FPS, i cannot guess if each remote client is gonna move... right? Sorry, I didn't follow that. Why would you have to guess if each client would move? You'd find out what they would be up every n seconds, right? Rob |
|
anto80
Member #3,230
February 2003
|
to Rob: Quote: I agree with you but if if switch to 5 FPS, i cannot guess if each remote client is gonna move... right? Sorry, I didn't follow that. Why would you have to guess if each client would move? You'd find out what they would be up every n seconds, right? I meant i have to "guess" if the players are moving between 2 screen refreshes (ie 2 server incoming packets), if i want to have an "exact refresh", that is the exact position players are. [edit]I had an idea: to extrapolate remote player position between 2 refreshes, i can assume the player is not changing his direction. ___________ |
|
Frank Drebin
Member #2,987
December 2002
|
Quote: I had an idea: to extrapolate remote player position between 2 refreshes, i can assume the player is not changing his direction. yes that's the thing to do. it is called dead reckoning. so you can keep you network-traffic low ( 10-20 times per second ). |
|
anto80
Member #3,230
February 2003
|
That's definitely a good idea. thanks guys. ___________ |
|
Frank Drebin
Member #2,987
December 2002
|
didn't get what you mean. |
|
anto80
Member #3,230
February 2003
|
Yes, so from the client, i'll send positions packets to server only sometimes (instead of every frame) ___________ |
|
Frank Drebin
Member #2,987
December 2002
|
yes this goes for both server and client: |
|
anto80
Member #3,230
February 2003
|
Thanks ___________ |
|
|