MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / AddObject

Method AddObject

Source/Engine/Networking/NetworkReplicator.cpp:1432–1478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1430}
1431
1432void NetworkReplicator::AddObject(ScriptingObject* obj, const ScriptingObject* parent)
1433{
1434 if (!obj || NetworkManager::IsOffline())
1435 return;
1436 PROFILE_MEM(Networking);
1437 ScopeLock lock(ObjectsLock);
1438 if (Objects.Contains(obj))
1439 return;
1440
1441 // Automatic parenting for scene objects
1442 if (!parent)
1443 {
1444 auto sceneObject = ScriptingObject::Cast<SceneObject>(obj);
1445 if (sceneObject)
1446 parent = sceneObject->GetParent();
1447 }
1448
1449 // Ensure to register object in a scripting system (eg. lookup by ObjectId will work)
1450 if (!obj->IsRegistered())
1451 obj->RegisterObject();
1452
1453 // Add object to the list
1454 NetworkReplicatedObject item;
1455 item.Object = obj;
1456 item.AsNetworkObject = ScriptingObject::ToInterface<INetworkObject>(obj);
1457 item.ObjectId = obj->GetID();
1458 item.ParentId = parent ? parent->GetID() : Guid::Empty;
1459 item.OwnerClientId = NetworkManager::ServerClientId; // Server owns objects by default
1460 item.Role = NetworkManager::IsClient() ? NetworkObjectRole::Replicated : NetworkObjectRole::OwnedAuthoritative;
1461 NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Add new object {}:{}, parent {}:{}", item.ToString(), obj->GetType().ToString(), item.ParentId.ToString(), parent ? parent->GetType().ToString() : String::Empty);
1462 for (const SpawnItem& spawnItem : SpawnQueue)
1463 {
1464 if (spawnItem.HasOwnership && spawnItem.HierarchicalOwnership)
1465 {
1466 if (IsParentOf(obj, spawnItem.Object))
1467 {
1468 // Inherit ownership
1469 item.Role = spawnItem.Role;
1470 item.OwnerClientId = spawnItem.OwnerClientId;
1471 break;
1472 }
1473 }
1474 }
1475 Objects.Add(MoveTemp(item));
1476 if (Hierarchy && item.Role == NetworkObjectRole::OwnedAuthoritative)
1477 Hierarchy->AddObject(obj);
1478}
1479
1480void NetworkReplicator::RemoveObject(ScriptingObject* obj)
1481{

Callers 4

InvokeObjectSpawnFunction · 0.45
SetHierarchyMethod · 0.45

Calls 9

IsOfflineFunction · 0.85
IsParentOfFunction · 0.85
GetIDMethod · 0.80
ContainsMethod · 0.45
GetParentMethod · 0.45
RegisterObjectMethod · 0.45
ToStringMethod · 0.45
GetTypeMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected