Sign in to follow this  

Moving to realtime?

This topic is 2392 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi
Ive done some turn-based games using raknet, but now i wanna do realtime (2D)! In turnbased i could just send a command to the server when moving a unit, clicking a button etc, and then server sends message to all clients to change their world, works fine.

But in realtime how do i achieve good results? I will have player controlled choppers firing bullets, units walking around that can also shoot and block tiles etc.
To send command all the time giving the exact correct position of projectiles and units seems unpractical.

As timing and lag will make bullets (for example) not be in exact same pos in the same time on different worlds, how do i ensure the bullet hits the same exact location?

Does it work to have each world handle its stuff for representation, but more important events like bullet collision (and damage dealing) is baby-sitted by the server alone?

Thanks for your help
Erik

Share this post


Link to post
Share on other sites
[quote name='suliman' timestamp='1306216875' post='4814905']
But in realtime how do i achieve good results? I will have player controlled choppers firing bullets, units walking around that can also shoot and block tiles etc.
To send command all the time giving the exact correct position of projectiles and units seems unpractical.
[/quote]

Generally, how this is done, is to build a command queue, and a deterministic simulation. (Beware of floating point: you have to set floating point precision registers and exception registers across CPUs for them to be deterministic).

Then, when a user gives a command (say, selects a bunch of units, and clicks somewhere to move them), that command is put into the queue for some time in the future (say, 300 milliseconds from now). The units will play a "yes sir!" animation, after which the command actually takes effect. The 300 millisecond delay allows the command to be distributed to all other players, and applied at the same time in their simulations. In this way, all simulations run in exact sync. This is known as the "lock-step" method, and generally used by RTS games like Starcraft, Warcraft, and Age of Empires.

In fact, the best write-up of this method that I know is written by the creators of Age of Empires, and called something like "1,500 archers on a 28.8 modem," and a link can be found in the FAQ.

The main thing, other from the mechanisms of creating deterministic simulators (including deterministic random number generators, etc), is to realize that real-time frame update (redraw) rate and unit animation rate is different from simulation rate. Most RTS games do fine with a 10 Hz command rate (every 100 milliseconds), but if running at 60 Hz, that means 6 frames of animation need to be displayed per command. For machines that lag, maybe only 1, 2 or 3 frames will be drawn per simulation tick. Your simulation/display separation needs to be robust enough to deal with this without affecting the sync of the simulation.

Share this post


Link to post
Share on other sites
does this mean that every command - like fire a bullet or create a unit, is accompanied with a timestamp (something that says: run this command on all machines at exact time [currentGameTime+0.3s])
So every client gets that command cued up and checks the command-cue constantly to see if a command has reached (or surpassed if something went wrong!) its exact timestamp?

Sounds cool, but as you said, if i run a match for 40 min and there is loads of decimal numbers around for positions (in 3d possibly) for projectiles and units , can i be sure they never go out of sync?

Thanks a lot
Erik

Share this post


Link to post
Share on other sites
[quote name='suliman' timestamp='1306345171' post='4815673']
Sounds cool, but as you said, if i run a match for 40 min and there is loads of decimal numbers around for positions (in 3d possibly) for projectiles and units , can i be sure they never go out of sync?
[/quote]

Yes. Read the 1,500 archers article for more.


Also, you may want to use fixed-point for game-based simulation, and only use float for display, if you want to avoid managing the CPU FPU state.

Share this post


Link to post
Share on other sites

This topic is 2392 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this