Skip to content

feat: snapshot. ground work, preparing depedencies. No impact on code… #1012

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 2 commits into from
Aug 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -353,34 +353,34 @@ internal void SpawnNetworkObjectLocally(NetworkObject networkObject, ulong netwo

internal void SendSpawnCallForObject(ulong clientId, ulong ownerClientId, NetworkObject networkObject)
{
//Currently, if this is called and the clientId (destination) is the server's client Id, this case
//will be checked within the below Send function. To avoid unwarranted allocation of a PooledNetworkBuffer
//placing this check here. [NSS]
if (NetworkManager.IsServer && clientId == NetworkManager.ServerClientId)
if (true) // this is to keep the branch close to the snapshot branch. Merge planning
{
return;
}
//Currently, if this is called and the clientId (destination) is the server's client Id, this case
//will be checked within the below Send function. To avoid unwarranted allocation of a PooledNetworkBuffer
//placing this check here. [NSS]
if (NetworkManager.IsServer && clientId == NetworkManager.ServerClientId)
{
return;
}

var messageQueueContainer = NetworkManager.MessageQueueContainer;
var messageQueueContainer = NetworkManager.MessageQueueContainer;

var context = messageQueueContainer.EnterInternalCommandContext(
MessageQueueContainer.MessageType.CreateObject, NetworkChannel.Internal,
new ulong[] { clientId }, NetworkUpdateLoop.UpdateStage);
if (context != null)
{
using (var nonNullContext = (InternalCommandContext)context)
ulong[] clientIds = NetworkManager.ConnectedClientsIds;
var context = messageQueueContainer.EnterInternalCommandContext(
MessageQueueContainer.MessageType.CreateObject, NetworkChannel.Internal,
clientIds, NetworkUpdateLoop.UpdateStage);
if (context != null)
{
WriteSpawnCallForObject(nonNullContext.NetworkWriter, ownerClientId, networkObject);
using (var nonNullContext = (InternalCommandContext) context)
{
WriteSpawnCallForObject(nonNullContext.NetworkWriter, clientId, networkObject);
}
}
}
}

internal void WriteSpawnCallForObject(PooledNetworkWriter writer, ulong clientId, NetworkObject networkObject)
internal ulong? GetSpawnParentId(NetworkObject networkObject)
{
writer.WriteBool(networkObject.IsPlayerObject);
writer.WriteUInt64Packed(networkObject.NetworkObjectId);
writer.WriteUInt64Packed(networkObject.OwnerClientId);

NetworkObject parentNetworkObject = null;

if (!networkObject.AlwaysReplicateAsRoot && networkObject.transform.parent != null)
Expand All @@ -389,13 +389,28 @@ internal void WriteSpawnCallForObject(PooledNetworkWriter writer, ulong clientId
}

if (parentNetworkObject == null)
{
return null;
}

return parentNetworkObject.NetworkObjectId;
}

internal void WriteSpawnCallForObject(PooledNetworkWriter writer, ulong clientId, NetworkObject networkObject)
{
writer.WriteBool(networkObject.IsPlayerObject);
writer.WriteUInt64Packed(networkObject.NetworkObjectId);
writer.WriteUInt64Packed(networkObject.OwnerClientId);

var parent = GetSpawnParentId(networkObject);
if (parent == null)
{
writer.WriteBool(false);
}
else
{
writer.WriteBool(true);
writer.WriteUInt64Packed(parentNetworkObject.NetworkObjectId);
writer.WriteUInt64Packed(parent.Value);
}

writer.WriteBool(networkObject.IsSceneObject ?? true);
Expand Down