From 64940305099d18f0c6d7e3a2f4549a7992c9d9f1 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 22 Jun 2023 14:39:12 +0800 Subject: [PATCH] refactoring --- src/Debug/Attributes/DebugColorAttribute.cs | 2 +- src/Debug/EcsDebugUtility.cs | 8 +++----- src/EcsGroup.cs | 2 +- src/EcsWorld.cs | 5 ++--- src/Executors/EcsWhereExecutor.cs | 2 +- src/Pools/EcsPoolBase.cs | 1 - src/Utils/WorldMetaStorage.cs | 6 +++--- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Debug/Attributes/DebugColorAttribute.cs b/src/Debug/Attributes/DebugColorAttribute.cs index 75b8bc7..fe603dc 100644 --- a/src/Debug/Attributes/DebugColorAttribute.cs +++ b/src/Debug/Attributes/DebugColorAttribute.cs @@ -14,7 +14,7 @@ namespace DCFApixels.DragonECS public DebugColorAttribute(DebugColor color) => this.color = new Color((int)color); [StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)] - internal readonly struct Color + internal readonly struct Color { [FieldOffset(0)] public readonly int full; [FieldOffset(3)] public readonly byte r; diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index ce9cb89..7985286 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; namespace DCFApixels.DragonECS { @@ -105,7 +103,7 @@ namespace DCFApixels.DragonECS { foreach (var word in nameWords) { - if(!_words.TryGetValue(word, out WordColor color)) + if (!_words.TryGetValue(word, out WordColor color)) { color = new WordColor(); _words.Add(word, color); @@ -143,7 +141,7 @@ namespace DCFApixels.DragonECS private static DebugColorAttribute.Color CalcNameColorFor(Type type) { Type targetType = type.IsGenericType ? type.GetGenericTypeDefinition() : type; - if(!_names.TryGetValue(targetType, out NameColor nameColor)) + if (!_names.TryGetValue(targetType, out NameColor nameColor)) { nameColor = new NameColor(SplitString(targetType.Name)); _names.Add(targetType, nameColor); @@ -186,7 +184,7 @@ namespace DCFApixels.DragonECS public static bool TryGetColorRGB(Type type, out (byte, byte, byte) color) { var atr = type.GetCustomAttribute(); - if(atr != null) + if (atr != null) { color = (atr.r, atr.g, atr.b); return true; diff --git a/src/EcsGroup.cs b/src/EcsGroup.cs index 62b5140..7ec7c8c 100644 --- a/src/EcsGroup.cs +++ b/src/EcsGroup.cs @@ -272,7 +272,7 @@ namespace DCFApixels.DragonECS } public int Bake(ref int[] entities) { - if(entities.Length < _count) + if (entities.Length < _count) entities = new int[_count]; Array.Copy(_dense, 1, entities, 0, _count); return _count; diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index dcabfd7..4d3b758 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -2,7 +2,6 @@ using DCFApixels.DragonECS.Utils; using System; using System.Collections.Generic; -using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -67,7 +66,7 @@ namespace DCFApixels.DragonECS ref int itemIndex = ref _mapping[worldID]; if (itemIndex <= 0) { - if(_recycledItemsCount > 0) + if (_recycledItemsCount > 0) { _count++; itemIndex = _recycledItems[--_recycledItemsCount]; @@ -84,7 +83,7 @@ namespace DCFApixels.DragonECS private static void Release(int worldID) { ref int itemIndex = ref _mapping[worldID]; - if(itemIndex != 0) + if (itemIndex != 0) { _interface.OnDestroy(ref _items[itemIndex], Worlds[worldID]); _recycledItems[_recycledItemsCount++] = itemIndex; diff --git a/src/Executors/EcsWhereExecutor.cs b/src/Executors/EcsWhereExecutor.cs index 4ed4919..89a45ac 100644 --- a/src/Executors/EcsWhereExecutor.cs +++ b/src/Executors/EcsWhereExecutor.cs @@ -42,6 +42,6 @@ #endif return _filteredGroup.Readonly; } -#endregion + #endregion } } diff --git a/src/Pools/EcsPoolBase.cs b/src/Pools/EcsPoolBase.cs index ebfd812..bb4d4cd 100644 --- a/src/Pools/EcsPoolBase.cs +++ b/src/Pools/EcsPoolBase.cs @@ -1,7 +1,6 @@ using DCFApixels.DragonECS.Internal; using System; using System.Collections.Generic; -using System.Linq; using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS diff --git a/src/Utils/WorldMetaStorage.cs b/src/Utils/WorldMetaStorage.cs index 741a7f9..da3b563 100644 --- a/src/Utils/WorldMetaStorage.cs +++ b/src/Utils/WorldMetaStorage.cs @@ -6,7 +6,7 @@ using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS { //TODO этот класс требует переработки, изначально такая конструкция имела хорошую производительность, но сейчас он слишком раздулся - internal static class WorldMetaStorage + internal static class WorldMetaStorage { private static int _tokenCount = 0; private static List _resizers = new List(); @@ -81,7 +81,7 @@ namespace DCFApixels.DragonECS } else { - if(result.Length < targetSize) + if (result.Length < targetSize) { int oldSize = result.Length; Array.Resize(ref result, targetSize); @@ -290,7 +290,7 @@ namespace DCFApixels.DragonECS public bool IsDeclaredWorldComponentType(Type type) => _declaredWorldComponentTypes.ContainsKey(type); public int GetWorldComponentID(Type type) { - if(!_declaredWorldComponentTypes.TryGetValue(type, out int id)) + if (!_declaredWorldComponentTypes.TryGetValue(type, out int id)) id = DeclareWorldComponentType(type); return id; }