Archived

This topic is now archived and is closed to further replies.

SkatMan

Command-Based Simulation

Recommended Posts

SkatMan    122
Hello. I want to make a simulation demo. It will run over a network and the communication between machines should be in the form of commands (not sending entire position and state). As a start, I want to make it a 2-player demo. The simulation will be of 2D Rigid Body Dynamics. The problem is that the machines can have different clock-rates. Therefore, when a comamnd is sent from one machine to another, the other machine might be calculating a frame and therefore will applicate the command only in the next frame and eventually create a different "world" on each machine. (if the input-communication thread is handled separately, the local machine might also need to finish calculating a frame before it applicates the input and therefore the remote machine might applicate this input even before the local one does). Does anyone have a solution for this? Please don''t give me the "full synchronization" solution because the purpose of this demo is to see to what extent synchronization can be avoided. Regards, Oren Becker. p.s: I know that due to the different clock-rates, I need to handle the simulation in a special way to maintain the same "world" on both stations (especially regarding collisions), but I think I''ve already got a solution for this, my question is about the cooperation of frame calculations and input communication.

Share this post


Link to post
Share on other sites
rileyriley    235
You could avoid some of the error by using a fixed time interval to update the worlds, that is independent of frame rate. That is, each "command" would be known to be referring to exactly 1/10th of a second of world time, or some other arbitrary, but constant, value.

If you really wanted to, you could do a similar thing with varying time intervals, but you''d have to send the time to apply each command along with the packet for each command, and the math in other areas would start to get tricky..

However, errors will accumulate. There is no way that you can guarantee synchronization because time delays for packet delivery will vary, some packets might be lost, the computer might hang for a bit and throw everything off, etc. If you are reluctant to send absolute positions and velocities instead of "commands," you might just consider sending positions and velocities once every one or two seconds to correct errors that have accumulated from the commands you send maybe 10 times a second.

Why are you trying to avoid "synchronization?" Sending the information "turn to direction <5, 5, 5> accelerate in direction <1, 2, 3>" is not much better than sending "I am currently at <0, 0, 0> with velocity <9, 8, 7>," and the errors in synch are much much worse.

Share this post


Link to post
Share on other sites