Numerous postions and velocities over network
I have a question about the best way to implement a networked game where I have 200+ AI controlled entities, each with essentially a position and velocity (as well as a state). The game is something like Galaga or Asteroids (the enemy spaceships or asteroids would be the 200+ AI controlled entities). I'm thinking that each client could run their own version of the simulation. The AI behavior can be deterministic given the same set of initial starting conditions. Therefore all I would need to do is pass each client the same data, and they should be running identical simulations (just pass around each of the client's movement inputs, as well as other key events). This way I wouldn't have to send updates about every AI enemy from the server. However, would the server also have to keep track of its own version of the simulation (to check things such as making sure that a player really has killed an enemy, etc)? Wouldn't this be expensive for a person both running the server and playing on a client on the same machine? Is there anything wrong with this method, and is there a better way to do it? Could I set it up to where only the server runs the simulation and sends out information about the enemies to each client? This would put a major bandwidth strain on the person running the server for 200+ entities... I need some advice on how to go about doing something like this ^^ Any help would be greatly appreciated! P.S. I'm planning on using RakNet to do this :)
Hey,
That's the basic concept that many networkable games use. You've got some problems with your system though. Firstly, the games across the network are going to get out of sync. That's an unfortunate fact. PC A inputs a command. Maybe 25ms later, PC B gets it. PC A factors that command in at time 0, B at +25.
Similarly, the framerates will most probably differ, unless you lock the internal game logic rate. If you do this, make sure that it's decoupled from the graphics renderer though, because otherwise you'll be too slow on pcs that can't handle the graphics at that speed. Similarly, you'll be limiting the fast computers to the lowest computer's speed.
I remember a good article on this over at gamasutra, on one of the star wars games [x-wing? methinks]. You should probably check it out. They did basically what you're trying to do, and what they ended up having to do was resync each of the clients every second or so, and those changes were factored into the system.
Also, you'll have to be careful with random number generation [ie, write your own Pseudorandom number generator, with some quirky features (if you get this far down this path you'll probably see why these are nessecary)].
My approach would be to do simulation on each of the clients, but structure your AI so that you can step back any time up to 2 seconds ago, change some property in the game world, and recalculate what's going to happen from there. That way, each of the clients can receive packets saying 'at time X, client Y did Z.' and then every client can update the internal game state. Then you've got jittering concerns etc, so you'll probably need a system to interpolate between what has just happened on the clients system and what, retrospectively, should have happened.
Needless to say, it sounds pretty complicated to me, so I'd read the article. And as many other articles to do with this style of networking that you can find.
I wish you the best of luck, and I hope this helps point you in the right direction.
CJM
That's the basic concept that many networkable games use. You've got some problems with your system though. Firstly, the games across the network are going to get out of sync. That's an unfortunate fact. PC A inputs a command. Maybe 25ms later, PC B gets it. PC A factors that command in at time 0, B at +25.
Similarly, the framerates will most probably differ, unless you lock the internal game logic rate. If you do this, make sure that it's decoupled from the graphics renderer though, because otherwise you'll be too slow on pcs that can't handle the graphics at that speed. Similarly, you'll be limiting the fast computers to the lowest computer's speed.
I remember a good article on this over at gamasutra, on one of the star wars games [x-wing? methinks]. You should probably check it out. They did basically what you're trying to do, and what they ended up having to do was resync each of the clients every second or so, and those changes were factored into the system.
Also, you'll have to be careful with random number generation [ie, write your own Pseudorandom number generator, with some quirky features (if you get this far down this path you'll probably see why these are nessecary)].
My approach would be to do simulation on each of the clients, but structure your AI so that you can step back any time up to 2 seconds ago, change some property in the game world, and recalculate what's going to happen from there. That way, each of the clients can receive packets saying 'at time X, client Y did Z.' and then every client can update the internal game state. Then you've got jittering concerns etc, so you'll probably need a system to interpolate between what has just happened on the clients system and what, retrospectively, should have happened.
Needless to say, it sounds pretty complicated to me, so I'd read the article. And as many other articles to do with this style of networking that you can find.
I wish you the best of luck, and I hope this helps point you in the right direction.
CJM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement