Improve network replication debug log usage
This commit is contained in:
@@ -27,6 +27,12 @@
|
|||||||
// Enables verbose logging for Network Replicator actions (dev-only)
|
// Enables verbose logging for Network Replicator actions (dev-only)
|
||||||
#define NETWORK_REPLICATOR_DEBUG_LOG 1
|
#define NETWORK_REPLICATOR_DEBUG_LOG 1
|
||||||
|
|
||||||
|
#if NETWORK_REPLICATOR_DEBUG_LOG
|
||||||
|
#define NETWORK_REPLICATOR_LOG(messageType, format, ...) LOG(messageType, format, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define NETWORK_REPLICATOR_LOG(messageType, format, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
PACK_STRUCT(struct NetworkMessageObjectReplicate
|
PACK_STRUCT(struct NetworkMessageObjectReplicate
|
||||||
{
|
{
|
||||||
NetworkMessageIDs ID = NetworkMessageIDs::ObjectReplicate;
|
NetworkMessageIDs ID = NetworkMessageIDs::ObjectReplicate;
|
||||||
@@ -178,9 +184,7 @@ NetworkReplicatedObject* ResolveObject(Guid objectId, Guid parentId, char object
|
|||||||
obj->GetTypeHandle() == objectType)
|
obj->GetTypeHandle() == objectType)
|
||||||
{
|
{
|
||||||
// Boost future lookups by using indirection
|
// Boost future lookups by using indirection
|
||||||
#if NETWORK_REPLICATOR_DEBUG_LOG
|
NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Remap object ID={} into object {}:{}", objectId, item.ToString(), obj->GetType().ToString());
|
||||||
LOG(Info, "[NetworkReplicator] Remap object ID={} into object {}:{}", objectId, item.ToString(), obj->GetType().ToString());
|
|
||||||
#endif
|
|
||||||
IdsRemappingTable.Add(objectId, item.ObjectId);
|
IdsRemappingTable.Add(objectId, item.ObjectId);
|
||||||
|
|
||||||
return &item;
|
return &item;
|
||||||
@@ -299,9 +303,7 @@ void NetworkReplicator::AddObject(ScriptingObject* obj, ScriptingObject* parent)
|
|||||||
item.ParentId = parent ? parent->GetID() : Guid::Empty;
|
item.ParentId = parent ? parent->GetID() : Guid::Empty;
|
||||||
item.OwnerClientId = NetworkManager::ServerClientId; // Server owns objects by default
|
item.OwnerClientId = NetworkManager::ServerClientId; // Server owns objects by default
|
||||||
item.Role = NetworkManager::IsClient() ? NetworkObjectRole::Replicated : NetworkObjectRole::OwnedAuthoritative;
|
item.Role = NetworkManager::IsClient() ? NetworkObjectRole::Replicated : NetworkObjectRole::OwnedAuthoritative;
|
||||||
#if NETWORK_REPLICATOR_DEBUG_LOG
|
NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Add new object {}:{}, parent {}:{}", item.ToString(), obj->GetType().ToString(), item.ParentId.ToString(), parent ? parent->GetType().ToString() : String::Empty);
|
||||||
LOG(Info, "[NetworkReplicator] Add new object {}:{}, parent {}:{}", item.ToString(), obj->GetType().ToString(), item.ParentId.ToString(), parent ? parent->GetType().ToString() : String::Empty);
|
|
||||||
#endif
|
|
||||||
Objects.Add(MoveTemp(item));
|
Objects.Add(MoveTemp(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,9 +426,7 @@ void NetworkInternal::NetworkReplicatorClear()
|
|||||||
ScopeLock lock(ObjectsLock);
|
ScopeLock lock(ObjectsLock);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
#if NETWORK_REPLICATOR_DEBUG_LOG
|
NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Shutdown");
|
||||||
LOG(Info, "[NetworkReplicator] Shutdown");
|
|
||||||
#endif
|
|
||||||
for (auto it = Objects.Begin(); it.IsNotEnd(); ++it)
|
for (auto it = Objects.Begin(); it.IsNotEnd(); ++it)
|
||||||
{
|
{
|
||||||
auto& item = it->Item;
|
auto& item = it->Item;
|
||||||
@@ -597,9 +597,7 @@ void NetworkInternal::NetworkReplicatorUpdate()
|
|||||||
if (!obj)
|
if (!obj)
|
||||||
{
|
{
|
||||||
// Object got deleted
|
// Object got deleted
|
||||||
#if NETWORK_REPLICATOR_DEBUG_LOG
|
NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Remove object {}, owned by {}", item.ToString(), item.ParentId.ToString());
|
||||||
LOG(Info, "[NetworkReplicator] Remove object {}, owned by {}", item.ToString(), item.ParentId.ToString());
|
|
||||||
#endif
|
|
||||||
Objects.Remove(it);
|
Objects.Remove(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -613,7 +611,7 @@ void NetworkInternal::NetworkReplicatorUpdate()
|
|||||||
if (!item.InvalidTypeWarn)
|
if (!item.InvalidTypeWarn)
|
||||||
{
|
{
|
||||||
item.InvalidTypeWarn = true;
|
item.InvalidTypeWarn = true;
|
||||||
LOG(Error, "[NetworkReplicator] Cannot serialize object {} of type {} (missing serialization logic)", item.ToString(), obj->GetType().ToString());
|
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Cannot serialize object {} of type {} (missing serialization logic)", item.ToString(), obj->GetType().ToString());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
continue;
|
continue;
|
||||||
@@ -687,7 +685,7 @@ void NetworkInternal::OnNetworkMessageObjectReplicate(NetworkEvent& event, Netwo
|
|||||||
if (failed && !item.InvalidTypeWarn)
|
if (failed && !item.InvalidTypeWarn)
|
||||||
{
|
{
|
||||||
item.InvalidTypeWarn = true;
|
item.InvalidTypeWarn = true;
|
||||||
LOG(Error, "[NetworkReplicator] Cannot serialize object {} of type {} (missing serialization logic)", item.ToString(), obj->GetType().ToString());
|
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Cannot serialize object {} of type {} (missing serialization logic)", item.ToString(), obj->GetType().ToString());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -747,15 +745,11 @@ void NetworkInternal::OnNetworkMessageObjectSpawn(NetworkEvent& event, NetworkCl
|
|||||||
item.OwnerClientId = client ? client->ClientId : NetworkManager::ServerClientId;
|
item.OwnerClientId = client ? client->ClientId : NetworkManager::ServerClientId;
|
||||||
item.Role = NetworkObjectRole::Replicated;
|
item.Role = NetworkObjectRole::Replicated;
|
||||||
item.Spawned = true;
|
item.Spawned = true;
|
||||||
#if NETWORK_REPLICATOR_DEBUG_LOG
|
NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Add new object {}:{}, parent {}:{}", item.ToString(), obj->GetType().ToString(), item.ParentId.ToString(), parent ? parent->Object->GetType().ToString() : String::Empty);
|
||||||
LOG(Info, "[NetworkReplicator] Add new object {}:{}, parent {}:{}", item.ToString(), obj->GetType().ToString(), item.ParentId.ToString(), parent ? parent->Object->GetType().ToString() : String::Empty);
|
|
||||||
#endif
|
|
||||||
Objects.Add(MoveTemp(item));
|
Objects.Add(MoveTemp(item));
|
||||||
|
|
||||||
// Boost future lookups by using indirection
|
// Boost future lookups by using indirection
|
||||||
#if NETWORK_REPLICATOR_DEBUG_LOG
|
NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Remap object ID={} into object {}:{}", msgData.ObjectId, item.ToString(), obj->GetType().ToString());
|
||||||
LOG(Info, "[NetworkReplicator] Remap object ID={} into object {}:{}", msgData.ObjectId, item.ToString(), obj->GetType().ToString());
|
|
||||||
#endif
|
|
||||||
IdsRemappingTable.Add(msgData.ObjectId, item.ObjectId);
|
IdsRemappingTable.Add(msgData.ObjectId, item.ObjectId);
|
||||||
|
|
||||||
// Automatic parenting for scene objects
|
// Automatic parenting for scene objects
|
||||||
@@ -795,9 +789,7 @@ void NetworkInternal::OnNetworkMessageObjectDespawn(NetworkEvent& event, Network
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if NETWORK_REPLICATOR_DEBUG_LOG
|
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Failed to despawn object {}", msgData.ObjectId);
|
||||||
LOG(Error, "[NetworkReplicator] Failed to despawn object {}", msgData.ObjectId);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -840,8 +832,6 @@ void NetworkInternal::OnNetworkMessageObjectRole(NetworkEvent& event, NetworkCli
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if NETWORK_REPLICATOR_DEBUG_LOG
|
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Unknown object role update {}", msgData.ObjectId);
|
||||||
LOG(Error, "[NetworkReplicator] Unknown object role update {}", msgData.ObjectId);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user