Add objects ID inverse mapping from client to server for proper C# networking codegen

This commit is contained in:
Wojtek Figat
2023-06-18 19:27:46 +02:00
parent dd8817582a
commit 228ef4e130
4 changed files with 49 additions and 11 deletions

View File

@@ -279,6 +279,20 @@ namespace FlaxEngine
[LibraryImport("FlaxEngine", EntryPoint = "ObjectInternal_FromUnmanagedPtr", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(Interop.StringMarshaller))]
public static partial Object FromUnmanagedPtr(IntPtr ptr);
/// <summary>
/// Maps the object ID using the current Scripting::ObjectsLookupIdMapping (key to value). Used to map prefab object IDs into prefab instance object IDs, or when using network replication IDs table.
/// </summary>
/// <param name="id">Inout object identifier mapped as a result or unchanged if not mapped.</param>
[LibraryImport("FlaxEngine", EntryPoint = "ObjectInternal_MapObjectID")]
public static partial void MapObjectID(ref Guid id);
/// <summary>
/// Remaps the object ID using the current Scripting::ObjectsLookupIdMapping (value to key). Used to remap prefab instance IDs into prefab object IDs, or when using network replication IDs table.
/// </summary>
/// <param name="id">Inout object identifier mapped as a result or unchanged if not mapped.</param>
[LibraryImport("FlaxEngine", EntryPoint = "ObjectInternal_RemapObjectID")]
public static partial void RemapObjectID(ref Guid id);
/// <inheritdoc />
public override int GetHashCode()
{

View File

@@ -9,6 +9,7 @@
#include "Engine/Content/Asset.h"
#include "Engine/Content/Content.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Threading/ThreadLocal.h"
#include "ManagedCLR/MAssembly.h"
#include "ManagedCLR/MClass.h"
#include "ManagedCLR/MUtils.h"
@@ -750,6 +751,20 @@ DEFINE_INTERNAL_CALL(MObject*) ObjectInternal_FromUnmanagedPtr(ScriptingObject*
result = obj->GetOrCreateManagedInstance();
return result;
}
DEFINE_INTERNAL_CALL(void) ObjectInternal_MapObjectID(Guid* id)
{
const auto idsMapping = Scripting::ObjectsLookupIdMapping.Get();
if (idsMapping && id->IsValid())
idsMapping->TryGet(*id, *id);
}
DEFINE_INTERNAL_CALL(void) ObjectInternal_RemapObjectID(Guid* id)
{
const auto idsMapping = Scripting::ObjectsLookupIdMapping.Get();
if (idsMapping && id->IsValid())
idsMapping->KeyOf(*id, id);
}
#endif
class ScriptingObjectInternal
@@ -768,6 +783,8 @@ public:
ADD_INTERNAL_CALL("FlaxEngine.Object::Internal_ChangeID", &ObjectInternal_ChangeID);
ADD_INTERNAL_CALL("FlaxEngine.Object::Internal_GetUnmanagedInterface", &ObjectInternal_GetUnmanagedInterface);
ADD_INTERNAL_CALL("FlaxEngine.Object::FromUnmanagedPtr", &ObjectInternal_FromUnmanagedPtr);
ADD_INTERNAL_CALL("FlaxEngine.Object::MapObjectID", &ObjectInternal_MapObjectID);
ADD_INTERNAL_CALL("FlaxEngine.Object::RemapObjectID", &ObjectInternal_RemapObjectID);
}
static ScriptingObject* Spawn(const ScriptingObjectSpawnParams& params)