Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Networking and allegro timers

Credits go to Frank Drebin and Rob Fletcher for helping out!
This thread is locked; no one can reply to it. rss feed Print
Networking and allegro timers
anto80
Member #3,230
February 2003
avatar

When you do a client/server network based game, how do you declare you timers? (and where, that is : client-side? server-side? both?)
(TCP/IP, but i'm not sure that matters)

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.
But with network i have absolutely no idea of the result, because on the one hand, the server has to perform calculations on a regular basis (for example, every projectile move every frame) and on the other hand, the clients display have to be "brake" so as not to run too fast...

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.

??? any comment?

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Rob Fletcher
Member #2,830
October 2002
avatar

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. :P

Rob

Frank Drebin
Member #2,987
December 2002
avatar

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
avatar

:o 4 timers !!??

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

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Rob Fletcher
Member #2,830
October 2002
avatar

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
1 spaceship = 20 bytes of data (couple of floats, some ID bytes, meh)
1 second = 50 frames

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
avatar

as for me:
1 frame = location of (up to) 8 players
1 player = 6 bytes of data.

for 50 FPS, every client need : 48*50 = 2,4 k bps. maximum.
Is it reasonable or will i have to switch to something slower? (it would be nice if i can have more than one advice for this please)

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?
More specifically... i'm doing a tower-assault clone, network-based, and in this version each client can hit the other clients... 5 FPS refresh must stutter i fear...

Quote:

leave those games up to the server for important data. Particle effects, etc.. can stay on the client.

Of course.

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Rob Fletcher
Member #2,830
October 2002
avatar

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
avatar

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.

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Frank Drebin
Member #2,987
December 2002
avatar

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
avatar

That's definitely a good idea. thanks guys.
Anyway, it's clear that i must do that when the server send something to the client, but as far as the client is concerned too, will i have to limit the data sent from the client to the server?

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Frank Drebin
Member #2,987
December 2002
avatar

didn't get what you mean.
you have to do this "prediction" on both sides.

anto80
Member #3,230
February 2003
avatar

Yes, so from the client, i'll send positions packets to server only sometimes (instead of every frame)

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Frank Drebin
Member #2,987
December 2002
avatar

yes this goes for both server and client:
you only send packets at a specific rate (to keep your bandwith low) and between these times you predict what the other "part" is currently doing.

anto80
Member #3,230
February 2003
avatar

Thanks

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Go to: