| 1383 | } |
| 1384 | |
| 1385 | bool NetworkReplicator::InvokeSerializer(const ScriptingTypeHandle& typeHandle, void* instance, NetworkStream* stream, bool serialize) |
| 1386 | { |
| 1387 | if (!typeHandle || !instance || !stream) |
| 1388 | return true; |
| 1389 | |
| 1390 | // Get serializers pair from table |
| 1391 | Serializer serializer; |
| 1392 | if (!SerializersTable.TryGet(typeHandle, serializer)) |
| 1393 | { |
| 1394 | // Fallback to INetworkSerializable interface (if type implements it) |
| 1395 | const ScriptingType& type = typeHandle.GetType(); |
| 1396 | const ScriptingType::InterfaceImplementation* interface = type.GetInterface(INetworkSerializable::TypeInitializer); |
| 1397 | if (interface) |
| 1398 | { |
| 1399 | if (interface->IsNative) |
| 1400 | { |
| 1401 | // Native interface (implemented in C++) |
| 1402 | serializer.Methods[0] = INetworkSerializable_Native_Serialize; |
| 1403 | serializer.Methods[1] = INetworkSerializable_Native_Deserialize; |
| 1404 | serializer.Tags[0] = serializer.Tags[1] = (void*)(intptr)interface->VTableOffset; // Pass VTableOffset to the callback |
| 1405 | } |
| 1406 | else |
| 1407 | { |
| 1408 | // Generic interface (implemented in C# or elsewhere) |
| 1409 | ASSERT(type.Type == ScriptingTypes::Script); |
| 1410 | serializer.Methods[0] = INetworkSerializable_Script_Serialize; |
| 1411 | serializer.Methods[1] = INetworkSerializable_Script_Deserialize; |
| 1412 | serializer.Tags[0] = serializer.Tags[1] = nullptr; |
| 1413 | } |
| 1414 | PROFILE_MEM(Networking); |
| 1415 | SerializersTable.Add(typeHandle, serializer); |
| 1416 | } |
| 1417 | else if (const ScriptingTypeHandle baseTypeHandle = typeHandle.GetType().GetBaseType()) |
| 1418 | { |
| 1419 | // Fallback to base type |
| 1420 | return InvokeSerializer(baseTypeHandle, instance, stream, serialize); |
| 1421 | } |
| 1422 | else |
| 1423 | return true; |
| 1424 | } |
| 1425 | |
| 1426 | // Invoke serializer |
| 1427 | const byte idx = serialize ? 0 : 1; |
| 1428 | serializer.Methods[idx](instance, stream, serializer.Tags[idx]); |
| 1429 | return false; |
| 1430 | } |
| 1431 | |
| 1432 | void NetworkReplicator::AddObject(ScriptingObject* obj, const ScriptingObject* parent) |
| 1433 | { |
nothing calls this directly
no test coverage detected