From c6fb4b3e7381e9ed7f18abb8d4d4f74f289e03a1 Mon Sep 17 00:00:00 2001 From: richdog Date: Tue, 16 Jan 2024 20:46:31 -0500 Subject: [PATCH] fixed issue with Unsafe.As not working in .Net 2.1 (#198) --- .../Dangerous/DangerousWorldExtensions.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs b/src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs index 1123f31..be2d4d2 100644 --- a/src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs +++ b/src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs @@ -105,20 +105,28 @@ public static void SetVersions(this World world, JaggedArray versions) /// /// The instance. /// Its array. - public static JaggedArray<(Archetype, (int,int))> GetSlots(this World world) + public static JaggedArray<(Archetype, (int, int))> GetSlots(this World world) { var array = world.EntityInfo.EntitySlots; - return Unsafe.As>(array); + return Unsafe.As>(array); } /// - /// Sets the of a . + /// Sets the of a . /// /// The instance. /// The new slots array. - public static void SetSlots(this World world, JaggedArray<(Archetype, (int,int))> slots) + public static void SetSlots(this World world, JaggedArray<(Archetype, (int, int))> slots) { - world.EntityInfo.EntitySlots = Unsafe.As>(slots); + var convertedSlots = new JaggedArray(slots.Buckets, slots.Capacity); + + for (int i = 0; i < slots.Capacity; i++) + { + var slot = slots[i]; + convertedSlots[i] = new EntitySlot(slot.Item1, new Slot(slot.Item2.Item1, slot.Item2.Item2)); + } + + world.EntityInfo.EntitySlots = convertedSlots; } ///