Sign in to follow this  

syncronising data over a network

This topic is 4661 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

ok this is a long shot but im trying to develop an app where a user will be able to have a series of lights running at a random speed / sequence displayed on screen (easy enough) but would like it to work across a network in the way that the sequence and speed on the first machine will be broadcasted to every other machine running the app on that network in real time so each computer will display exactly what is on the first computers screen at any given time im not asking any one to write this for me, but i really have no idea what i am supposed to be researching (i.e names of techniques and theorys behind it etc) thanks alot

Share this post


Link to post
Share on other sites
Well, there's a couple of things that will aid you on your quest:

1) Time based movement, which one can consider the opposite of frame based movement. You base movement on time, either by forcing a fixed "logic framerate" (which may or may not correspond to actual framerate) or by calculating time deltas (time since the last frame) and update positions as a factor of this delta.

2) The question: what does the client need to know in order to stay the same?

Lets say you have a light class:

struct light
{
double on_length;
double off_length;
double position;
bool on;

void update( double time_delta )
{
position += time_delta;
while ( true )
{
if ( on && (position > on_length) )
{
position -= on_length;
on = false;
}
else if ( off && (position > off_length) )
{
position -= off_length;
on = true;
}
else
{
return;
}
}
}
};


We have the boolean on, which tracks our current state, and position, which tracks our transition through the current cycle. In this method, in theory all we'd need to do in order for both clients to see the light correctly is to send the appropriate starting data - on , position, and *_length.

In reality, position will suffer from rounding errors because the time_delta s generated on each computer will differ depending on framerate. As such, an update by the "authority" would need to be sent every now and then to keep things up to date.


Now, as for a second method, it depends on everything staying the same:

struct light
{
unsigned int on_length;
unsigned intoff_length;
unsigned intposition;
bool on;

void update( unsigned int time_delta )
{
position += time_delta;
while ( true )
{
if ( on && (position > on_length) )
{
position -= on_length;
on = false;
}
else if ( off && (position > off_length) )
{
position -= off_length;
on = true;
}
else
{
return;
}
}
}
};


This time we use unsigned ints. Since our code does not depend on a fraction of the time_delta, as long as the timers are kept in sync everything WILL continue to work, as we will have no rounding errors. All that needs to be sent is the starting values and the time at which they are the starting values.

Since nothing can quite perfectly keep time in our universe, it may be wise to have the authority in this case send the "official" time every now and then.

The first method depends on approximation, the second depends on making sure your code will preform exactly the same on multiple systems. Usually this involves more than my example implies, because removing rounding errors can be quite tricky.

Share this post


Link to post
Share on other sites

This topic is 4661 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