Sign in to follow this  

Object synchronization.

This topic is 4039 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 all! I'm looking for some hints on how to implement some sort of object synchronization over an existing network connection. Another way of putting it is that I need a shared object amongst two or more computers. I.e if one client changes the object the change needs to be propagated to the other local copies, something like this: Sample setup With object I really doesn't mean any CPP class instance, I can live with a few hardcoded types. If we for instance assume that the shared object above is a std::map<std::string, float>, we can have any number of floating point "variables" referenced by a string. For instance if the client inserts a few strings like: "A", 10.0 "B", 2.0 "C", 12.0 The "system" should send these new additions to the server. If then the server changes some of the above the change would be sent to the client, i.e: "B" = 7.0 Am I making any sense at all? ;) What I'm after is not source or tools that let me do that, also I'm not looking for the answer "Use a database". All data communcation must be handled by my connection. I'm looking for a nice clean way to handle these sort of things, addressing problems like these: * What if the server and client changes the same variable at about the same time? * Handles huge objects but just sends the updates necessary? * Explicit synchronization points, i.e doesn't send any data before needed? * What if we have more than two parties involved? (Not really needed right now, but if there is a known methodology that is commonly used that can handle this, it's a bonus). If thinking about using a time stamp system and keeping a local copy of what the other computer(s) has, something like this (not working code):

struct SharedObject
{
  T m_localObject;
  T m_remoteObject;
  std::map<int, T> m_sentObjects;
  int m_remoteTimeStamp;
  int m_localTimeStamp;
};

doSync()
{
  ++ m_localTimeStamp;
  m_sentObjects.insert(std::make_pair(m_localTimeStamp, m_localObject));
  sendToRemote(m_localTimeStamp, Diff(m_remoteObject, m_localObject));
}

recieveFromRemote()
{
  while (m_remoteTimeStamp < Packet.m_timeStamp){
    m_sentObjects.erase(m_remoteTimeStamp);
    ++ m_remoteTimeStamp;
  }
  if (!Packet.m_diff)
    return;
  m_remoteObject = AddDiff(Packet.m_diff, m_sentObjects.find(Packet.m_timeStamp));
  sendToRemote(m_remoteTimeStamp, 0);
}




Edit: I could simplify the requirements slighly by disallowing different computer to modify the same variable. I.e all computers can read all variables, but only one computer may change it (the one that created it). I'm still looking for some good links to papers and or people who haved worked with this sort of things.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi eq!

So you're basically looking for some kind of "Property Replication" mechanism, right? If so, you may have a look at the UnrealEngine which does this sort of thing. I don't have any links here, sorry but googling for "Unreal Replication" may help you.

>>
* What if the server and client changes the same variable at about the same time?
>
* Handles huge objects but just sends the updates necessary?
>
* Explicit synchronization points, i.e doesn't send any data before needed?
>
* What if we have more than two parties involved?
<

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
EDIT: Sorry for the post above! There was some problem with quoting, so here again.

Hi eq!

So you're basically looking for some kind of "Property Replication" mechanism, right? If so, you may have a look at the UnrealEngine which does this sort of thing. I don't have any links here, sorry but googling for "Unreal Replication" may help you.


* What if the server and client changes the same variable at about the same time?

That must not happen! Exactly one host either one of the clients or the server must have authoritative access to a variable. And only that host is responsible for sending changes of that variable to other hosts. If another host wants to change a variable it has to send a "ChangeRequest" or something like that to the authoritative connection side.


* Handles huge objects but just sends the updates necessary?

That's a must! One easy way to do this, is that the authoritative host caches all his *owning* variables/objects with their initial values. You then check periodically (once per frame or so) whether a variable has changed and send it.
You may attach to each variable/object some kind of "UpdateFrequency" and/or "UpdatePriority", whether to send this variable reliably or unreliably, ordered/unordered etc.


* Explicit synchronization points, i.e doesn't send any data before needed?

You can attach to each variable a *condition*! Think of it as a script-function or so. And only if this condition evaluates to true, you send it.


* What if we have more than two parties involved?

I assume that party is a synonym for client!
Well, as I sad before only one host is *authoritative*!

cu,
Chris

Share this post


Link to post
Share on other sites
Two things pop into my mind, remembering courses and the Quake series (although, as the AP mentioned, Unreal has a nifty system as well):

1) on the client, keep bitfields indicating which variables have changed over the course of several frames. For example, you could store an integer that encodes the indices of each element of your map container that has changed, sending the respective changes later on. Quake for example, uses a boolean to update latched console variables between client and server.

2) send delta packets instead of the information in its entirety. This of course has to be applicable to your particular case. I'm sorry, but I can't seem to find a good general example of this. Anyone?

Share this post


Link to post
Share on other sites

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