Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Changed the network object registration timing #270

Conversation

PyeonggukLee
Copy link
Contributor

@PyeonggukLee PyeonggukLee commented May 9, 2019

Why pushed this PR?
I had a problem that the client A doesn't get synced a network object of the client B sometimes when they try to connect to a server at the same time.

Sequences when new client connects to a server(AFAIK):

  1. A client connects to the server.
  2. The server sends the data containing currently existed 'NetworkObjects' to the client.
  3. A networkObject is created for the client and send the data to other players.
  4. On the main thread, the networkObject is initialized and added to 'NetworkObjects'.

In the case that two clients try to connect at the same time,
sometimes the client connected later than another doesn't get the networkObject data for another client.
There are two clients: A, B.
A3-B1-B2-A4 => a networkObject of the client A doesn't get synced on the client B side, because A4 happens later than B2.

so, to solve these problem, I merged the step 3 and 4 in to one step.

Merged Sequences:

  1. A client connects to the server. (same)
  2. The server sends the data containing currently existed 'NetworkObjects' to the client. (same)
  3. A networkObject is created and initialize & added to 'NetworkObjects'. for the client and send the data to other players.

so, A3-B1-B2 (NetworkObjects is updated at A3 timing, there's no omitted data at B2.)

Please, review this PR and give me any opinons to discuss or questions about this.

@phalasz
Copy link
Contributor

phalasz commented May 12, 2019

I assume CompleteInitialization then doesn't need to be called anywhere else right? Did you remove those calls as well if there were any?

@PyeonggukLee
Copy link
Contributor Author

PyeonggukLee commented May 13, 2019

@phalasz
The purpose of this PR is that the server should register the networkObject to NetworkObjects collection as soon as the networkObject is created.
so, I've added the CompleteInitialization in there(RegisterNetworkObject).
As you said, CompleteInitialization also gets called when NetworkStart is called for the first time, but it checks the networkObject is in the NetworkObjects collection or not. so it seems fine, doesn't it?

ref:

public void CompleteInitialization(NetworkObject networkObject)
{
    lock (NetworkObjects)
    {
        if (NetworkObjects.ContainsKey(networkObject.NetworkId))
            return;

        NetworkObjects.Add(networkObject.NetworkId, networkObject);
        NetworkObjectList.Add(networkObject);
    }
}

@PyeonggukLee
Copy link
Contributor Author

or... more clearly, I could do adding a networkObject to the NetworkObjects collection if the NetWorker is IServer.

@phalasz
Copy link
Contributor

phalasz commented May 15, 2019

Ah I see, makes sense. I think using CompleteInitialization is fine.

Copy link
Contributor

@phalasz phalasz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look fine to me.

@NFMynster NFMynster merged commit 7c544a4 into BeardedManStudios:develop Jun 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants