diff --git a/package.json b/package.json index e205bfc..e8fcc56 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "displayName": "LeoECS Lite", "description": "LeoECS Lite - легковесный ECS-фреймворк, основанный на структурах. Производительность, нулевые или минимальные аллокации, минимизация использования памяти, отсутствие зависимостей от любого игрового движка - это основные цели данного фреймворка.", "unity": "2020.3", - "version": "2023.9.22", + "version": "2023.11.22", "keywords": [ "leoecslite", "leoecs", diff --git a/src/entities.cs b/src/entities.cs index eac3216..fab17ca 100644 --- a/src/entities.cs +++ b/src/entities.cs @@ -11,14 +11,26 @@ namespace Leopotam.EcsLite { public struct EcsPackedEntity { - internal int Id; - internal int Gen; + public int Id; + public int Gen; + + public override int GetHashCode () { + unchecked { + return (23 * 31 + Id) * 31 + Gen; + } + } } public struct EcsPackedEntityWithWorld { - internal int Id; - internal int Gen; - internal EcsWorld World; + public int Id; + public int Gen; + public EcsWorld World; + + public override int GetHashCode () { + unchecked { + return ((23 * 31 + Id) * 31 + Gen) * 31 + (World?.GetHashCode () ?? 0); + } + } #if DEBUG // For using in IDE debugger. internal object[] DebugComponentsView { diff --git a/src/worlds.cs b/src/worlds.cs index 555e3db..b4f4c22 100644 --- a/src/worlds.cs +++ b/src/worlds.cs @@ -616,12 +616,14 @@ public EcsFilter End (int capacity = 512) { Array.Sort (Include, 0, IncludeCount); Array.Sort (Exclude, 0, ExcludeCount); // calculate hash. - Hash = IncludeCount + ExcludeCount; - for (int i = 0, iMax = IncludeCount; i < iMax; i++) { - Hash = unchecked (Hash * 314159 + Include[i]); - } - for (int i = 0, iMax = ExcludeCount; i < iMax; i++) { - Hash = unchecked (Hash * 314159 - Exclude[i]); + unchecked { + Hash = IncludeCount + ExcludeCount; + for (int i = 0, iMax = IncludeCount; i < iMax; i++) { + Hash = Hash * 314159 + Include[i]; + } + for (int i = 0, iMax = ExcludeCount; i < iMax; i++) { + Hash = Hash * 314159 - Exclude[i]; + } } var (filter, isNew) = _world.GetFilterInternal (this, capacity); if (!isNew) { Recycle (); }