From 35d71245bc1de44a694f385fda24f4bce60b45ec Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 27 Jun 2023 01:23:01 +0800 Subject: [PATCH] replace int with short for indexing world components --- src/EcsWorld.cs | 2 ++ src/EcsWorld.static.cs | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index dc9f5d6..6e8e334 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -142,6 +142,8 @@ namespace DCFApixels.DragonECS } return (TExecutor)result; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T Get() where T : struct => ref WorldComponentPool.GetForWorld(id); #endregion diff --git a/src/EcsWorld.static.cs b/src/EcsWorld.static.cs index cf61e9f..c131c80 100644 --- a/src/EcsWorld.static.cs +++ b/src/EcsWorld.static.cs @@ -47,10 +47,10 @@ namespace DCFApixels.DragonECS private static class WorldComponentPool { private static T[] _items = new T[4]; - private static int[] _mapping = new int[4]; - private static int _count; - private static int[] _recycledItems = new int[4]; - private static int _recycledItemsCount; + private static short[] _mapping = new short[4]; + private static short _count; + private static short[] _recycledItems = new short[4]; + private static short _recycledItemsCount; private static IEcsWorldComponent _interface = EcsWorldComponentHandler.instance; [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -62,7 +62,7 @@ namespace DCFApixels.DragonECS if (_mapping.Length < Worlds.Length) Array.Resize(ref _mapping, Worlds.Length); - ref int itemIndex = ref _mapping[worldID]; + ref short itemIndex = ref _mapping[worldID]; if (itemIndex <= 0) { if (_recycledItemsCount > 0) @@ -79,9 +79,10 @@ namespace DCFApixels.DragonECS } return itemIndex; } + private static void Release(int worldID) { - ref int itemIndex = ref _mapping[worldID]; + ref short itemIndex = ref _mapping[worldID]; if (itemIndex != 0) { _interface.OnDestroy(ref _items[itemIndex], Worlds[worldID]);