Skip to content

Commit

Permalink
fixed issue with Unsafe.As not working in .Net 2.1 (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
richdog committed Jan 17, 2024
1 parent dc49bc1 commit c6fb4b3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,28 @@ public static void SetVersions(this World world, JaggedArray<int> versions)
/// </summary>
/// <param name="world">The <see cref="World"/> instance.</param>
/// <returns>Its <see cref="EntityInfoStorage.EntitySlots"/> array.</returns>
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<JaggedArray<(Archetype, (int,int))>>(array);
return Unsafe.As<JaggedArray<(Archetype, (int, int))>>(array);
}

/// <summary>
/// Sets the <see cref="EntityInfoStorage.Slots"/> of a <see cref="World"/>.
/// Sets the <see cref="EntityInfoStorage.EntitySlots"/> of a <see cref="World"/>.
/// </summary>
/// <param name="world">The <see cref="World"/> instance.</param>
/// <param name="slots">The new slots array.</param>
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<JaggedArray<EntitySlot>>(slots);
var convertedSlots = new JaggedArray<EntitySlot>(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;
}

/// <summary>
Expand Down

0 comments on commit c6fb4b3

Please sign in to comment.