Skip to content

refactor: calling networkShow(NetworkObject) code in networkshow(List<NetworkObject>) #1028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 4 additions & 34 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,25 +278,9 @@ public static void NetworkShow(List<NetworkObject> networkObjects, ulong clientI
}
}


var context = networkManager.MessageQueueContainer.EnterInternalCommandContext(
MessageQueueContainer.MessageType.CreateObjects, NetworkChannel.Internal,
new[] { clientId }, NetworkUpdateLoop.UpdateStage);

if (context != null)
foreach (var networkObject in networkObjects)
{
using (var nonNullContext = (InternalCommandContext)context)
{
nonNullContext.NetworkWriter.WriteUInt16Packed((ushort)networkObjects.Count);

for (int i = 0; i < networkObjects.Count; i++)
{
networkObjects[i].Observers.Add(clientId);

networkManager.SpawnManager.WriteSpawnCallForObject(nonNullContext.NetworkWriter, clientId,
networkObjects[i]);
Comment on lines -296 to -297
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't this delete and the other below (nonNullContext.NetworkWriter.WriteUInt64Packed(networkObjects[i].NetworkObjectId);) break some stuff here? 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh.. right.. I had missed this and the subtle s in CreateObjects. I think this highlights the need for a test.
Thanks! Will rework.

Copy link
Contributor Author

@jeffreyrainy jeffreyrainy Aug 10, 2021

Choose a reason for hiding this comment

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

I take back my "ohh... right...".
This removes a WriteUInt64Packed and also removes a matching number of WriteSpawnCallForObject. The whole thing is done in a CreateObjects context. Removing them all is fine as it forms a consistent block.

It its place, we now call a given number of NetworkShow. But each will generate a consistent set of bytes. This then works.

I've updated the branch and checked the new test NetworkShowHideTest, which passes.

I've also checked on my not-yet-committed spawn branch. It works there too, with all the traffic going in Snapshot Messages.

Can you please re-check and potentially approve ? (but yeah, the test should have been there in the first place)

}
}
networkObject.NetworkShow(clientId);
}
}

Expand Down Expand Up @@ -385,23 +369,9 @@ public static void NetworkHide(List<NetworkObject> networkObjects, ulong clientI
}
}

var context = networkManager.MessageQueueContainer.EnterInternalCommandContext(
MessageQueueContainer.MessageType.DestroyObjects, NetworkChannel.Internal,
new[] { clientId }, NetworkUpdateStage.PostLateUpdate);
if (context != null)
foreach (var networkObject in networkObjects)
{
using (var nonNullContext = (InternalCommandContext)context)
{
nonNullContext.NetworkWriter.WriteUInt16Packed((ushort)networkObjects.Count);

for (int i = 0; i < networkObjects.Count; i++)
{
// Send destroy call
networkObjects[i].Observers.Remove(clientId);

nonNullContext.NetworkWriter.WriteUInt64Packed(networkObjects[i].NetworkObjectId);
}
}
networkObject.NetworkHide(clientId);
}
}

Expand Down