From 7f89e9b4a043ff8d7a0d48a31deb9bf2ea424945 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Fri, 20 Mar 2020 00:09:57 -0700 Subject: [PATCH] fix style issues --- .../Attributes/DefaultWritePriority.cs | 4 +- encompass-cs/Attributes/QueryWith.cs | 4 +- encompass-cs/Attributes/QueryWithout.cs | 4 +- encompass-cs/Attributes/Reads.cs | 4 +- encompass-cs/Attributes/ReadsImmediate.cs | 4 +- encompass-cs/Attributes/Receives.cs | 4 +- encompass-cs/Attributes/Sends.cs | 4 +- encompass-cs/Attributes/Writes.cs | 10 +- encompass-cs/Attributes/WritesImmediate.cs | 4 +- encompass-cs/Collections/ComponentBitSet.cs | 24 +- encompass-cs/Collections/ComponentStore.cs | 27 +- encompass-cs/Collections/MessageStore.cs | 12 +- .../Collections/TypedComponentStore.cs | 52 ++-- encompass-cs/Collections/TypedMessageStore.cs | 48 ++-- encompass-cs/ComponentManager.cs | 138 +++++----- encompass-cs/DrawLayerManager.cs | 62 ++--- encompass-cs/Engine.cs | 260 +++++++++--------- encompass-cs/Engines/Spawner.cs | 4 +- encompass-cs/Entity.cs | 2 +- encompass-cs/EntityManager.cs | 40 +-- encompass-cs/IDManager.cs | 14 +- encompass-cs/MessageManager.cs | 28 +- encompass-cs/RenderManager.cs | 28 +- encompass-cs/Renderer.cs | 20 +- encompass-cs/TimeDilationData.cs | 51 +++- encompass-cs/TimeManager.cs | 41 ++- encompass-cs/TrackingManager.cs | 10 +- encompass-cs/UberEngine.cs | 14 +- encompass-cs/UberRenderer.cs | 2 +- encompass-cs/World.cs | 52 ++-- encompass-cs/WorldBuilder.cs | 194 ++++++------- 31 files changed, 591 insertions(+), 574 deletions(-) diff --git a/encompass-cs/Attributes/DefaultWritePriority.cs b/encompass-cs/Attributes/DefaultWritePriority.cs index cf0c065..65500c7 100644 --- a/encompass-cs/Attributes/DefaultWritePriority.cs +++ b/encompass-cs/Attributes/DefaultWritePriority.cs @@ -5,11 +5,11 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class)] public class DefaultWritePriority : Attribute { - public int writePriority; + public int WritePriority { get; } public DefaultWritePriority(int writePriority) { - this.writePriority = writePriority; + WritePriority = writePriority; } } } diff --git a/encompass-cs/Attributes/QueryWith.cs b/encompass-cs/Attributes/QueryWith.cs index 3ae11a6..5574c5b 100644 --- a/encompass-cs/Attributes/QueryWith.cs +++ b/encompass-cs/Attributes/QueryWith.cs @@ -8,7 +8,7 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class)] public class QueryWith : Attribute { - public readonly HashSet queryWithTypes = new HashSet(); + public readonly HashSet QueryWithTypes = new HashSet(); public QueryWith(params Type[] queryWithTypes) { @@ -21,7 +21,7 @@ namespace Encompass throw new IllegalReadTypeException("{0} must be a Component", queryWithType.Name); } - this.queryWithTypes.Add(queryWithType); + QueryWithTypes.Add(queryWithType); } } } diff --git a/encompass-cs/Attributes/QueryWithout.cs b/encompass-cs/Attributes/QueryWithout.cs index 77f1e9f..3588285 100644 --- a/encompass-cs/Attributes/QueryWithout.cs +++ b/encompass-cs/Attributes/QueryWithout.cs @@ -8,7 +8,7 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class)] public class QueryWithout : Attribute { - public readonly HashSet queryWithoutTypes = new HashSet(); + public readonly HashSet QueryWithoutTypes = new HashSet(); public QueryWithout(params Type[] queryWithoutTypes) { @@ -21,7 +21,7 @@ namespace Encompass throw new IllegalReadTypeException("{0} must be a Component", type.Name); } - this.queryWithoutTypes.Add(type); + this.QueryWithoutTypes.Add(type); } } } diff --git a/encompass-cs/Attributes/Reads.cs b/encompass-cs/Attributes/Reads.cs index b35e81f..b958a26 100644 --- a/encompass-cs/Attributes/Reads.cs +++ b/encompass-cs/Attributes/Reads.cs @@ -8,7 +8,7 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class)] public class Reads : Attribute { - public readonly HashSet readTypes = new HashSet(); + public readonly HashSet ReadTypes = new HashSet(); public Reads(params Type[] readTypes) { @@ -21,7 +21,7 @@ namespace Encompass throw new IllegalReadTypeException("{0} must be a Component", readType.Name); } - this.readTypes.Add(readType); + this.ReadTypes.Add(readType); } } } diff --git a/encompass-cs/Attributes/ReadsImmediate.cs b/encompass-cs/Attributes/ReadsImmediate.cs index e47d4ba..5d4b0ff 100644 --- a/encompass-cs/Attributes/ReadsImmediate.cs +++ b/encompass-cs/Attributes/ReadsImmediate.cs @@ -8,7 +8,7 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class)] public class ReadsImmediate : Attribute { - public readonly HashSet readImmediateTypes = new HashSet(); + public readonly HashSet ReadImmediateTypes = new HashSet(); public ReadsImmediate(params Type[] readImmediateTypes) { @@ -21,7 +21,7 @@ namespace Encompass throw new IllegalReadTypeException("{0} must be a Component", readImmediateType.Name); } - this.readImmediateTypes.Add(readImmediateType); + this.ReadImmediateTypes.Add(readImmediateType); } } } diff --git a/encompass-cs/Attributes/Receives.cs b/encompass-cs/Attributes/Receives.cs index e8d0542..79d4b66 100644 --- a/encompass-cs/Attributes/Receives.cs +++ b/encompass-cs/Attributes/Receives.cs @@ -8,7 +8,7 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class)] public class Receives : Attribute { - public readonly HashSet receiveTypes; + public readonly HashSet ReceiveTypes; public Receives(params Type[] receiveTypes) { @@ -21,7 +21,7 @@ namespace Encompass } } - this.receiveTypes = new HashSet(receiveTypes); + ReceiveTypes = new HashSet(receiveTypes); } } } diff --git a/encompass-cs/Attributes/Sends.cs b/encompass-cs/Attributes/Sends.cs index 7bb1a0e..8fbacd3 100644 --- a/encompass-cs/Attributes/Sends.cs +++ b/encompass-cs/Attributes/Sends.cs @@ -8,7 +8,7 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class)] public class Sends : Attribute { - public readonly HashSet sendTypes; + public readonly HashSet SendTypes; public Sends(params Type[] sendTypes) { @@ -21,7 +21,7 @@ namespace Encompass } } - this.sendTypes = new HashSet(sendTypes); + this.SendTypes = new HashSet(sendTypes); } } } diff --git a/encompass-cs/Attributes/Writes.cs b/encompass-cs/Attributes/Writes.cs index ee73ded..8eec04a 100644 --- a/encompass-cs/Attributes/Writes.cs +++ b/encompass-cs/Attributes/Writes.cs @@ -8,8 +8,8 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class Writes : Attribute { - public readonly HashSet writeTypes = new HashSet(); - public Dictionary priorities = new Dictionary(); + public readonly HashSet WriteTypes = new HashSet(); + public readonly Dictionary Priorities = new Dictionary(); public Writes(params Type[] writeTypes) { @@ -21,7 +21,7 @@ namespace Encompass throw new IllegalWriteTypeException("{0} must be a Component", writeType.Name); } - this.writeTypes.Add(writeType); + this.WriteTypes.Add(writeType); } } @@ -33,8 +33,8 @@ namespace Encompass throw new IllegalWriteTypeException("{0} must be a Component", writeType.Name); } - writeTypes.Add(writeType); - priorities.Add(writeType, priority); + WriteTypes.Add(writeType); + Priorities.Add(writeType, priority); } } } diff --git a/encompass-cs/Attributes/WritesImmediate.cs b/encompass-cs/Attributes/WritesImmediate.cs index 66a46a6..0b5db7c 100644 --- a/encompass-cs/Attributes/WritesImmediate.cs +++ b/encompass-cs/Attributes/WritesImmediate.cs @@ -8,7 +8,7 @@ namespace Encompass [AttributeUsage(AttributeTargets.Class)] public class WritesImmediate : Attribute { - public readonly HashSet writeImmediateTypes = new HashSet(); + public readonly HashSet WriteImmediateTypes = new HashSet(); public WritesImmediate(params Type[] writeImmediateTypes) { @@ -20,7 +20,7 @@ namespace Encompass throw new IllegalWriteImmediateTypeException("{0} must be a Component", writeImmediateType.Name); } - this.writeImmediateTypes.Add(writeImmediateType); + this.WriteImmediateTypes.Add(writeImmediateType); } } } diff --git a/encompass-cs/Collections/ComponentBitSet.cs b/encompass-cs/Collections/ComponentBitSet.cs index 1d0c39d..8c90cf5 100644 --- a/encompass-cs/Collections/ComponentBitSet.cs +++ b/encompass-cs/Collections/ComponentBitSet.cs @@ -6,49 +6,49 @@ namespace Encompass { internal class ComponentBitSet { - Dictionary entities = new Dictionary(); - Dictionary TypeToIndex { get; } + private readonly Dictionary _entities = new Dictionary(); + private readonly Dictionary _typeToIndex; public ComponentBitSet(Dictionary typeToIndex) { - TypeToIndex = typeToIndex; + _typeToIndex = typeToIndex; } public void Clear() { - entities.Clear(); + _entities.Clear(); } public void AddEntity(int entityID) { - entities.Add(entityID, BitSet512.Zero); + _entities.Add(entityID, BitSet512.Zero); } public void Set(int entityID) where TComponent : struct, IComponent { - if (!entities.ContainsKey(entityID)) { AddEntity(entityID); } - entities[entityID] = entities[entityID].Set(TypeToIndex[typeof(TComponent)]); + if (!_entities.ContainsKey(entityID)) { AddEntity(entityID); } + _entities[entityID] = _entities[entityID].Set(_typeToIndex[typeof(TComponent)]); } public void RemoveComponent(int entityID) where TComponent : struct, IComponent { - if (entities.ContainsKey(entityID)) + if (_entities.ContainsKey(entityID)) { - entities[entityID] = entities[entityID].UnSet(TypeToIndex[typeof(TComponent)]); + _entities[entityID] = _entities[entityID].UnSet(_typeToIndex[typeof(TComponent)]); } } public void RemoveEntity(int entityID) { - if (entities.ContainsKey(entityID)) + if (_entities.ContainsKey(entityID)) { - entities.Remove(entityID); + _entities.Remove(entityID); } } public BitSet512 EntityBitArray(int entityID) { - return entities.ContainsKey(entityID) ? entities[entityID] : BitSet512.Zero; + return _entities.ContainsKey(entityID) ? _entities[entityID] : BitSet512.Zero; } } } diff --git a/encompass-cs/Collections/ComponentStore.cs b/encompass-cs/Collections/ComponentStore.cs index fd0965d..3a65abe 100644 --- a/encompass-cs/Collections/ComponentStore.cs +++ b/encompass-cs/Collections/ComponentStore.cs @@ -4,14 +4,9 @@ using System.Collections.Generic; namespace Encompass { - public struct MutableComponentEntityPair where TComponent : struct, IComponent - { - public TComponent component; - } - internal class ComponentStore { - private Dictionary Stores = new Dictionary(512); + private Dictionary _stores = new Dictionary(512); public ComponentBitSet ComponentBitSet { get; private set; } public ComponentStore(Dictionary typeToIndex) @@ -21,7 +16,7 @@ namespace Encompass public IEnumerable<(Type, TypedComponentStore)> StoresEnumerable() { - foreach (var entry in Stores) + foreach (var entry in _stores) { yield return (entry.Key, entry.Value); } @@ -29,16 +24,16 @@ namespace Encompass public virtual void RegisterComponentType() where TComponent : struct, IComponent { - if (!Stores.ContainsKey(typeof(TComponent))) + if (!_stores.ContainsKey(typeof(TComponent))) { var store = new TypedComponentStore(); - Stores.Add(typeof(TComponent), store); + _stores.Add(typeof(TComponent), store); } } private TypedComponentStore Lookup() where TComponent : struct, IComponent { - return Stores[typeof(TComponent)] as TypedComponentStore; + return _stores[typeof(TComponent)] as TypedComponentStore; } public bool Has(int entityID) where TComponent : struct, IComponent @@ -48,7 +43,7 @@ namespace Encompass public bool Has(Type type, int entityID) { - return Stores.ContainsKey(type) && Stores[type].Has(entityID); + return _stores.ContainsKey(type) && _stores[type].Has(entityID); } public BitSet512 EntityBitArray(int entityID) @@ -95,7 +90,7 @@ namespace Encompass public virtual void Remove(int entityID) { - foreach (var entry in Stores.Values) + foreach (var entry in _stores.Values) { entry.ForceRemove(entityID); } @@ -109,7 +104,7 @@ namespace Encompass public IEnumerable<(int, Type, IComponent)> AllInterfaceTyped() { - foreach (var store in Stores.Values) + foreach (var store in _stores.Values) { foreach (var thing in store.AllInterfaceTyped()) { @@ -130,7 +125,7 @@ namespace Encompass public virtual void ClearAllPriorities() { - foreach (var store in Stores.Values) + foreach (var store in _stores.Values) { store.ClearPriorities(); } @@ -139,7 +134,7 @@ namespace Encompass public virtual void ClearAll() { ComponentBitSet.Clear(); - foreach (var store in Stores.Values) + foreach (var store in _stores.Values) { store.Clear(); } @@ -147,7 +142,7 @@ namespace Encompass public void SwapWith(ComponentStore other) { - (Stores, other.Stores) = (other.Stores, Stores); + (_stores, other._stores) = (other._stores, _stores); (ComponentBitSet, other.ComponentBitSet) = (other.ComponentBitSet, ComponentBitSet); } diff --git a/encompass-cs/Collections/MessageStore.cs b/encompass-cs/Collections/MessageStore.cs index 5e7186f..a966fe6 100644 --- a/encompass-cs/Collections/MessageStore.cs +++ b/encompass-cs/Collections/MessageStore.cs @@ -5,17 +5,17 @@ namespace Encompass { internal class MessageStore { - private Dictionary Stores = new Dictionary(512); + private readonly Dictionary _stores = new Dictionary(512); private void RegisterMessageType() where TMessage : struct, IMessage { - Stores.Add(typeof(TMessage), new TypedMessageStore()); + _stores.Add(typeof(TMessage), new TypedMessageStore()); } private TypedMessageStore Lookup() where TMessage : struct, IMessage { - if (!Stores.ContainsKey(typeof(TMessage))) { RegisterMessageType(); } - return Stores[typeof(TMessage)] as TypedMessageStore; + if (!_stores.ContainsKey(typeof(TMessage))) { RegisterMessageType(); } + return _stores[typeof(TMessage)] as TypedMessageStore; } public void AddMessage(TMessage message) where TMessage : struct, IMessage @@ -60,7 +60,7 @@ namespace Encompass public void ProcessDelayedMessages(double dilatedDelta, double realtimeDelta) { - foreach (var store in Stores.Values) + foreach (var store in _stores.Values) { store.ProcessDelayedMessages(dilatedDelta, realtimeDelta); } @@ -68,7 +68,7 @@ namespace Encompass public void ClearAll() { - foreach (var store in Stores.Values) + foreach (var store in _stores.Values) { store.Clear(); } diff --git a/encompass-cs/Collections/TypedComponentStore.cs b/encompass-cs/Collections/TypedComponentStore.cs index fa766b5..9f3c9af 100644 --- a/encompass-cs/Collections/TypedComponentStore.cs +++ b/encompass-cs/Collections/TypedComponentStore.cs @@ -17,17 +17,17 @@ namespace Encompass internal class TypedComponentStore : TypedComponentStore where TComponent : struct, IComponent { - private readonly Dictionary indices = new Dictionary(512); - private readonly Dictionary priorities = new Dictionary(512); - private TComponent[] components = new TComponent[512]; + private readonly Dictionary _indices = new Dictionary(512); + private readonly Dictionary _priorities = new Dictionary(512); + private readonly TComponent[] _components = new TComponent[512]; private readonly IDManager _idManager = new IDManager(); - public override int Count { get => indices.Count; } + public override int Count { get => _indices.Count; } public unsafe ref readonly TComponent Get(int entityID) { - if (!indices.ContainsKey(entityID)) { throw new Exceptions.NoComponentOfTypeOnEntityException("No component of type {0} exists on Entity with ID {1}", typeof(TComponent), entityID); } - ref var refVal = ref components[indices[entityID]]; + if (!_indices.ContainsKey(entityID)) { throw new Exceptions.NoComponentOfTypeOnEntityException("No component of type {0} exists on Entity with ID {1}", typeof(TComponent), entityID); } + ref var refVal = ref _components[_indices[entityID]]; return ref Unsafe.AsRef(Unsafe.AsPointer(ref refVal)); } @@ -38,10 +38,10 @@ namespace Encompass public unsafe bool Set(int entityID, TComponent component, int priority) { - if (!priorities.ContainsKey(entityID) || priority < priorities[entityID]) + if (!_priorities.ContainsKey(entityID) || priority < _priorities[entityID]) { InternalSet(entityID, component); - priorities[entityID] = priority; + _priorities[entityID] = priority; return true; } @@ -50,22 +50,22 @@ namespace Encompass private unsafe void InternalSet(int entityID, TComponent component) { - if (!indices.ContainsKey(entityID)) + if (!_indices.ContainsKey(entityID)) { - indices[entityID] = _idManager.NextID(); + _indices[entityID] = _idManager.NextID(); } var ptr = Unsafe.AsPointer(ref component); - components[indices[entityID]] = Unsafe.AsRef(ptr); + _components[_indices[entityID]] = Unsafe.AsRef(ptr); } public override bool Remove(int entityID, int priority) { - if (!priorities.ContainsKey(entityID) || priority < priorities[entityID]) + if (!_priorities.ContainsKey(entityID) || priority < _priorities[entityID]) { - priorities[entityID] = priority; - indices.Remove(entityID); - priorities.Remove(entityID); + _priorities[entityID] = priority; + _indices.Remove(entityID); + _priorities.Remove(entityID); _idManager.Free(entityID); return true; } @@ -75,44 +75,44 @@ namespace Encompass public override void ForceRemove(int entityID) { - indices.Remove(entityID); - priorities.Remove(entityID); + _indices.Remove(entityID); + _priorities.Remove(entityID); _idManager.Free(entityID); } public override bool Has(int entityID) { - return indices.ContainsKey(entityID); + return _indices.ContainsKey(entityID); } public override void Clear() { - foreach (var entityID in indices.Keys) + foreach (var entityID in _indices.Keys) { _idManager.Free(entityID); } - indices.Clear(); - priorities.Clear(); + _indices.Clear(); + _priorities.Clear(); } public override void ClearPriorities() { - priorities.Clear(); + _priorities.Clear(); } public IEnumerable<(TComponent, int)> All() { - foreach (var kvp in indices) + foreach (var kvp in _indices) { - yield return (components[kvp.Value], kvp.Key); + yield return (_components[kvp.Value], kvp.Key); } } public override IEnumerable<(int, Type, IComponent)> AllInterfaceTyped() { - foreach (var kvp in indices) + foreach (var kvp in _indices) { - yield return (kvp.Key, typeof(TComponent), (IComponent)components[kvp.Value]); + yield return (kvp.Key, typeof(TComponent), (IComponent)_components[kvp.Value]); } } } diff --git a/encompass-cs/Collections/TypedMessageStore.cs b/encompass-cs/Collections/TypedMessageStore.cs index bfa7a8b..0a7a1e8 100644 --- a/encompass-cs/Collections/TypedMessageStore.cs +++ b/encompass-cs/Collections/TypedMessageStore.cs @@ -10,98 +10,98 @@ namespace Encompass internal class TypedMessageStore : TypedMessageStore where TMessage : struct, IMessage { - private readonly List store = new List(128); - private readonly List<(TMessage, double)> delayedStore = new List<(TMessage, double)>(128); - private readonly List<(TMessage, double)> delayedStoreIgnoringTimeDilation = new List<(TMessage, double)>(128); - private readonly Dictionary> entityToMessage = new Dictionary>(); + private readonly List _store = new List(128); + private readonly List<(TMessage, double)> _delayedStore = new List<(TMessage, double)>(128); + private readonly List<(TMessage, double)> _delayedStoreIgnoringTimeDilation = new List<(TMessage, double)>(128); + private readonly Dictionary> _entityToMessage = new Dictionary>(); public override void ProcessDelayedMessages(double dilatedDelta, double realtimeDelta) { - for (int i = delayedStore.Count - 1; i >= 0; i--) + for (var i = _delayedStore.Count - 1; i >= 0; i--) { - var (message, time) = delayedStore[i]; + var (message, time) = _delayedStore[i]; var updatedTime = time - dilatedDelta; if (updatedTime <= 0) { Add(message); - delayedStore.RemoveAt(i); + _delayedStore.RemoveAt(i); } else { - delayedStore[i] = (message, updatedTime); + _delayedStore[i] = (message, updatedTime); } } - for (int i = delayedStoreIgnoringTimeDilation.Count - 1; i >= 0; i--) + for (var i = _delayedStoreIgnoringTimeDilation.Count - 1; i >= 0; i--) { - var (message, time) = delayedStoreIgnoringTimeDilation[i]; + var (message, time) = _delayedStoreIgnoringTimeDilation[i]; var updatedTime = time - realtimeDelta; if (updatedTime <= 0) { Add(message); - delayedStoreIgnoringTimeDilation.RemoveAt(i); + _delayedStoreIgnoringTimeDilation.RemoveAt(i); } else { - delayedStoreIgnoringTimeDilation[i] = (message, updatedTime); + _delayedStoreIgnoringTimeDilation[i] = (message, updatedTime); } } } public void Add(TMessage message) { - store.Add(message); + _store.Add(message); if (message is IHasEntity entityMessage) { var entityID = entityMessage.Entity.ID; - if (!entityToMessage.ContainsKey(entityID)) { entityToMessage.Add(entityID, new List()); } - entityToMessage[entityID].Add(message); + if (!_entityToMessage.ContainsKey(entityID)) { _entityToMessage.Add(entityID, new List()); } + _entityToMessage[entityID].Add(message); } } public void Add(TMessage message, double time) { - delayedStore.Add((message, time)); + _delayedStore.Add((message, time)); } public void AddIgnoringTimeDilation(TMessage message, double time) { - delayedStoreIgnoringTimeDilation.Add((message, time)); + _delayedStoreIgnoringTimeDilation.Add((message, time)); } public TMessage First() { - return store[0]; + return _store[0]; } public bool Any() { - return store.Count > 0; + return _store.Count > 0; } public IEnumerable All() { - return store; + return _store; } public IEnumerable WithEntity(int entityID) { - return entityToMessage.ContainsKey(entityID) ? entityToMessage[entityID] : System.Linq.Enumerable.Empty(); + return _entityToMessage.ContainsKey(entityID) ? _entityToMessage[entityID] : System.Linq.Enumerable.Empty(); } public bool SomeWithEntity(int entityID) { - return entityToMessage.ContainsKey(entityID) && entityToMessage[entityID].Count > 0; + return _entityToMessage.ContainsKey(entityID) && _entityToMessage[entityID].Count > 0; } public override void Clear() { - store.Clear(); - foreach (var set in entityToMessage.Values) + _store.Clear(); + foreach (var set in _entityToMessage.Values) { set.Clear(); } diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index a82511b..1e7aa8c 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -5,68 +5,68 @@ namespace Encompass { internal class ComponentManager { - private readonly DrawLayerManager drawLayerManager; + private readonly DrawLayerManager _drawLayerManager; - private readonly ComponentStore existingComponentStore; - private readonly ComponentStore immediateComponentStore; - private readonly ComponentDeltaStore replayStore; - private ComponentStore upToDateComponentStore; + private readonly ComponentStore _existingComponentStore; + private readonly ComponentStore _immediateComponentStore; + private readonly ComponentDeltaStore _replayStore; + private readonly ComponentStore _upToDateComponentStore; public Dictionary TypeToIndex { get; } - private readonly HashSet entitiesMarkedForRemoval = new HashSet(); + private readonly HashSet _entitiesMarkedForRemoval = new HashSet(); - internal ComponentBitSet ImmediateBits { get { return immediateComponentStore.ComponentBitSet; } } - internal ComponentBitSet ExistingBits { get { return existingComponentStore.ComponentBitSet; } } + internal ComponentBitSet ImmediateBits { get { return _immediateComponentStore.ComponentBitSet; } } + internal ComponentBitSet ExistingBits { get { return _existingComponentStore.ComponentBitSet; } } public ComponentManager(DrawLayerManager drawLayerManager, Dictionary typeToIndex) { - this.drawLayerManager = drawLayerManager; - existingComponentStore = new ComponentStore(typeToIndex); - immediateComponentStore = new ComponentStore(typeToIndex); - replayStore = new ComponentDeltaStore(typeToIndex); - upToDateComponentStore = new ComponentStore(typeToIndex); + this._drawLayerManager = drawLayerManager; + _existingComponentStore = new ComponentStore(typeToIndex); + _immediateComponentStore = new ComponentStore(typeToIndex); + _replayStore = new ComponentDeltaStore(typeToIndex); + _upToDateComponentStore = new ComponentStore(typeToIndex); TypeToIndex = typeToIndex; } public void RegisterComponentType() where TComponent : struct, IComponent { - existingComponentStore.RegisterComponentType(); - immediateComponentStore.RegisterComponentType(); - replayStore.RegisterComponentType(); - upToDateComponentStore.RegisterComponentType(); + _existingComponentStore.RegisterComponentType(); + _immediateComponentStore.RegisterComponentType(); + _replayStore.RegisterComponentType(); + _upToDateComponentStore.RegisterComponentType(); } internal void SetExistingComponentStore(ComponentStore componentStore) { - existingComponentStore.SwapWith(componentStore); + _existingComponentStore.SwapWith(componentStore); } internal void SetUpToDateComponentStore(ComponentStore componentStore) { - upToDateComponentStore.SwapWith(componentStore); + _upToDateComponentStore.SwapWith(componentStore); } internal void RegisterDrawableComponent(int entityID, TComponent component, int layer) where TComponent : struct, IComponent { - drawLayerManager.RegisterComponentWithLayer(entityID, component, layer); + _drawLayerManager.RegisterComponentWithLayer(entityID, component, layer); } internal void WriteComponents() { - existingComponentStore.UpdateUsing(replayStore); - existingComponentStore.ClearAllPriorities(); - upToDateComponentStore.ClearAllPriorities(); - immediateComponentStore.ClearAll(); - replayStore.ClearAll(); + _existingComponentStore.UpdateUsing(_replayStore); + _existingComponentStore.ClearAllPriorities(); + _upToDateComponentStore.ClearAllPriorities(); + _immediateComponentStore.ClearAll(); + _replayStore.ClearAll(); } internal bool AddImmediateComponent(int entityID, TComponent component, int priority) where TComponent : struct, IComponent { - if (immediateComponentStore.Set(entityID, component, priority)) + if (_immediateComponentStore.Set(entityID, component, priority)) { - replayStore.Set(entityID, component); - upToDateComponentStore.Set(entityID, component); + _replayStore.Set(entityID, component); + _upToDateComponentStore.Set(entityID, component); return true; } @@ -75,32 +75,32 @@ namespace Encompass internal void AddImmediateComponent(int entityID, TComponent component) where TComponent : struct, IComponent { - immediateComponentStore.Set(entityID, component); - replayStore.Set(entityID, component); - upToDateComponentStore.Set(entityID, component); + _immediateComponentStore.Set(entityID, component); + _replayStore.Set(entityID, component); + _upToDateComponentStore.Set(entityID, component); } internal bool UpdateComponent(int entityID, TComponent component, int priority) where TComponent : struct, IComponent { - var result = upToDateComponentStore.Set(entityID, component, priority); + var result = _upToDateComponentStore.Set(entityID, component, priority); if (result) { - replayStore.Set(entityID, component); + _replayStore.Set(entityID, component); } return result; } internal void AddComponent(int entityID, TComponent component) where TComponent : struct, IComponent { - upToDateComponentStore.Set(entityID, component); - replayStore.Set(entityID, component); + _upToDateComponentStore.Set(entityID, component); + _replayStore.Set(entityID, component); } // existing or immediate reads internal IEnumerable<(TComponent, int)> ReadExistingAndImmediateComponentsByType() where TComponent : struct, IComponent { - return upToDateComponentStore.All(); + return _upToDateComponentStore.All(); } internal (TComponent, int) ReadFirstExistingOrImmediateComponentByType() where TComponent : struct, IComponent @@ -113,7 +113,7 @@ namespace Encompass internal bool SomeExistingOrImmediateComponent() where TComponent : struct, IComponent { - return upToDateComponentStore.Any(); + return _upToDateComponentStore.Any(); } // existing reads @@ -128,14 +128,14 @@ namespace Encompass internal bool SomeExistingComponent() where TComponent : struct, IComponent { - return existingComponentStore.Any(); + return _existingComponentStore.Any(); } // immediate reads internal IEnumerable<(TComponent, int)> ReadImmediateComponentsByType() where TComponent : struct, IComponent { - return immediateComponentStore.All(); + return _immediateComponentStore.All(); } internal (TComponent, int) ReadFirstImmediateComponentByType() where TComponent : struct, IComponent @@ -148,66 +148,66 @@ namespace Encompass internal bool SomeImmediateComponent() where TComponent : struct, IComponent { - return immediateComponentStore.Any(); + return _immediateComponentStore.Any(); } // component getters internal ref readonly TComponent ReadImmediateOrExistingComponentByEntityAndType(int entityID) where TComponent : struct, IComponent { - return ref upToDateComponentStore.Get(entityID); + return ref _upToDateComponentStore.Get(entityID); } internal ref readonly TComponent ReadExistingComponentByEntityAndType(int entityID) where TComponent : struct, IComponent { - return ref existingComponentStore.Get(entityID); + return ref _existingComponentStore.Get(entityID); } internal ref readonly TComponent ReadImmediateComponentByEntityAndType(int entityID) where TComponent : struct, IComponent { - return ref immediateComponentStore.Get(entityID); + return ref _immediateComponentStore.Get(entityID); } // has checkers internal bool HasExistingOrImmediateComponent(int entityID) where TComponent : struct, IComponent { - return upToDateComponentStore.Has(entityID); + return _upToDateComponentStore.Has(entityID); } internal bool HasExistingOrImmediateComponent(int entityID, Type type) { - return upToDateComponentStore.Has(type, entityID); + return _upToDateComponentStore.Has(type, entityID); } internal bool HasExistingComponent(int entityID) where TComponent : struct, IComponent { - return existingComponentStore.Has(entityID); + return _existingComponentStore.Has(entityID); } internal bool HasExistingComponent(int entityID, Type type) { - return existingComponentStore.Has(type, entityID); + return _existingComponentStore.Has(type, entityID); } internal bool HasImmediateComponent(int entityID) where TComponent : struct, IComponent { - return immediateComponentStore.Has(entityID); + return _immediateComponentStore.Has(entityID); } internal bool HasImmediateComponent(int entityID, Type type) { - return immediateComponentStore.Has(type, entityID); + return _immediateComponentStore.Has(type, entityID); } internal IEnumerable<(TComponent, int)> GetComponentsIncludingEntity() where TComponent : struct, IComponent { - return existingComponentStore.All(); + return _existingComponentStore.All(); } internal IEnumerable GetComponentsByType() where TComponent : struct, IComponent { - foreach (var pair in existingComponentStore.All()) + foreach (var pair in _existingComponentStore.All()) { yield return pair.Item1; } @@ -215,40 +215,40 @@ namespace Encompass internal ref readonly TComponent GetComponentByEntityAndType(int entityID) where TComponent : struct, IComponent { - return ref existingComponentStore.Get(entityID); + return ref _existingComponentStore.Get(entityID); } internal bool EntityHasComponentOfType(int entityID) where TComponent : struct, IComponent { - return existingComponentStore.Has(entityID); + return _existingComponentStore.Has(entityID); } internal void MarkAllComponentsOnEntityForRemoval(int entityID) { - entitiesMarkedForRemoval.Add(entityID); + _entitiesMarkedForRemoval.Add(entityID); } internal void RemoveMarkedComponents() { - foreach (var entityID in entitiesMarkedForRemoval) + foreach (var entityID in _entitiesMarkedForRemoval) { - existingComponentStore.Remove(entityID); - immediateComponentStore.Remove(entityID); - replayStore.Remove(entityID); - upToDateComponentStore.Remove(entityID); - drawLayerManager.UnRegisterEntityWithLayer(entityID); + _existingComponentStore.Remove(entityID); + _immediateComponentStore.Remove(entityID); + _replayStore.Remove(entityID); + _upToDateComponentStore.Remove(entityID); + _drawLayerManager.UnRegisterEntityWithLayer(entityID); } - entitiesMarkedForRemoval.Clear(); + _entitiesMarkedForRemoval.Clear(); } public bool RemoveImmediate(int entityID, int priority) where TComponent : struct, IComponent { - if (immediateComponentStore.Remove(entityID, priority)) + if (_immediateComponentStore.Remove(entityID, priority)) { - replayStore.Remove(entityID, priority); - upToDateComponentStore.Remove(entityID, priority); - drawLayerManager.UnRegisterComponentWithLayer(entityID); + _replayStore.Remove(entityID, priority); + _upToDateComponentStore.Remove(entityID, priority); + _drawLayerManager.UnRegisterComponentWithLayer(entityID); return true; } return false; @@ -256,16 +256,16 @@ namespace Encompass public void Remove(int entityID, int priority) where TComponent : struct, IComponent { - if (upToDateComponentStore.Remove(entityID, priority)) + if (_upToDateComponentStore.Remove(entityID, priority)) { - replayStore.Remove(entityID, priority); - drawLayerManager.UnRegisterComponentWithLayer(entityID); + _replayStore.Remove(entityID, priority); + _drawLayerManager.UnRegisterComponentWithLayer(entityID); } } public bool UpToDateEntityIsEmpty(int entityID) { - return upToDateComponentStore.EntityBitArray(entityID).AllFalse(); + return _upToDateComponentStore.EntityBitArray(entityID).AllFalse(); } } } diff --git a/encompass-cs/DrawLayerManager.cs b/encompass-cs/DrawLayerManager.cs index b738fce..32bdec3 100644 --- a/encompass-cs/DrawLayerManager.cs +++ b/encompass-cs/DrawLayerManager.cs @@ -7,39 +7,39 @@ namespace Encompass { internal class DrawLayerManager { - private readonly SortedList layerOrder = new SortedList(); + private readonly SortedList _layerOrder = new SortedList(); - private readonly Dictionary layerIndexToComponentStore = new Dictionary(512); - private readonly Dictionary> layerIndexToGeneralRenderers = new Dictionary>(512); + private readonly Dictionary _layerIndexToComponentStore = new Dictionary(512); + private readonly Dictionary> _layerIndexToGeneralRenderers = new Dictionary>(512); - private readonly Dictionary> typeToEntityToLayer = new Dictionary>(512); - private Dictionary typeToIndex; - public IEnumerable LayerOrder { get { return layerOrder.Values; } } + private readonly Dictionary> _typeToEntityToLayer = new Dictionary>(512); + private readonly Dictionary _typeToIndex; + public IEnumerable LayerOrder { get { return _layerOrder.Values; } } public DrawLayerManager(Dictionary typeToIndex) { - this.typeToIndex = typeToIndex; + _typeToIndex = typeToIndex; RegisterDrawLayer(0); } public void RegisterDrawLayer(int layer) { - if (!layerIndexToComponentStore.ContainsKey(layer)) + if (!_layerIndexToComponentStore.ContainsKey(layer)) { - layerOrder.Add(layer, layer); - layerIndexToGeneralRenderers.Add(layer, new HashSet()); - layerIndexToComponentStore.Add(layer, new ComponentStore(typeToIndex)); + _layerOrder.Add(layer, layer); + _layerIndexToGeneralRenderers.Add(layer, new HashSet()); + _layerIndexToComponentStore.Add(layer, new ComponentStore(_typeToIndex)); } } public void RegisterOrderedDrawable() where TComponent : struct, IComponent { - if (!typeToEntityToLayer.ContainsKey(typeof(TComponent))) + if (!_typeToEntityToLayer.ContainsKey(typeof(TComponent))) { - typeToEntityToLayer.Add(typeof(TComponent), new Dictionary(128)); + _typeToEntityToLayer.Add(typeof(TComponent), new Dictionary(128)); } - foreach (var pair in layerIndexToComponentStore) + foreach (var pair in _layerIndexToComponentStore) { pair.Value.RegisterComponentType(); } @@ -48,15 +48,15 @@ namespace Encompass public void RegisterGeneralRendererWithLayer(GeneralRenderer renderer, int layer) { RegisterDrawLayer(layer); - var set = layerIndexToGeneralRenderers[layer]; + var set = _layerIndexToGeneralRenderers[layer]; set.Add(renderer); } public void UnregisterGeneralRendererWithLayer(GeneralRenderer renderer, int layer) { - if (layerIndexToGeneralRenderers.ContainsKey(layer)) + if (_layerIndexToGeneralRenderers.ContainsKey(layer)) { - layerIndexToGeneralRenderers[layer].Remove(renderer); + _layerIndexToGeneralRenderers[layer].Remove(renderer); } } @@ -68,34 +68,34 @@ namespace Encompass public void RegisterComponentWithLayer(int entityID, TComponent component, int layer) where TComponent : struct, IComponent { - if (!layerIndexToComponentStore.ContainsKey(layer)) + if (!_layerIndexToComponentStore.ContainsKey(layer)) { throw new UndefinedLayerException("Layer {0} is not defined. Use WorldBuilder.RegisterDrawLayer to register the layer.", layer); } - if (typeToEntityToLayer[typeof(TComponent)].ContainsKey(entityID)) { UnRegisterComponentWithLayer(entityID); } + if (_typeToEntityToLayer[typeof(TComponent)].ContainsKey(entityID)) { UnRegisterComponentWithLayer(entityID); } - var set = layerIndexToComponentStore[layer]; + var set = _layerIndexToComponentStore[layer]; set.Set(entityID, component); - typeToEntityToLayer[typeof(TComponent)].Add(entityID, layer); + _typeToEntityToLayer[typeof(TComponent)].Add(entityID, layer); } public void UnRegisterComponentWithLayer(int entityID) where TComponent : struct, IComponent { - if (!typeToEntityToLayer.ContainsKey(typeof(TComponent))) { return; } + if (!_typeToEntityToLayer.ContainsKey(typeof(TComponent))) { return; } - if (typeToEntityToLayer[typeof(TComponent)].ContainsKey(entityID)) + if (_typeToEntityToLayer[typeof(TComponent)].ContainsKey(entityID)) { - var layer = typeToEntityToLayer[typeof(TComponent)][entityID]; - layerIndexToComponentStore[layer].ForceRemove(entityID); + var layer = _typeToEntityToLayer[typeof(TComponent)][entityID]; + _layerIndexToComponentStore[layer].ForceRemove(entityID); } - typeToEntityToLayer[typeof(TComponent)].Remove(entityID); + _typeToEntityToLayer[typeof(TComponent)].Remove(entityID); } public void UnRegisterEntityWithLayer(int entityID) { - foreach (var store in layerIndexToComponentStore.Values) + foreach (var store in _layerIndexToComponentStore.Values) { store.Remove(entityID); } @@ -103,15 +103,15 @@ namespace Encompass public IEnumerable GeneralRenderersByLayer(int layer) { - return layerIndexToGeneralRenderers.ContainsKey(layer) ? - layerIndexToGeneralRenderers[layer] : + return _layerIndexToGeneralRenderers.ContainsKey(layer) ? + _layerIndexToGeneralRenderers[layer] : Enumerable.Empty(); } public IEnumerable<(int, Type, IComponent)> AllInLayer(int layer) { - return layerIndexToComponentStore.ContainsKey(layer) ? - layerIndexToComponentStore[layer].AllInterfaceTyped() : + return _layerIndexToComponentStore.ContainsKey(layer) ? + _layerIndexToComponentStore[layer].AllInterfaceTyped() : Enumerable.Empty<(int, Type, IComponent)>(); } } diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index 2d55290..c371b50 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -14,104 +14,104 @@ namespace Encompass /// public abstract class Engine : IEquatable { - internal Guid ID; + internal Guid _id; - internal readonly HashSet readTypes = new HashSet(); - internal readonly HashSet readImmediateTypes = new HashSet(); - internal readonly HashSet sendTypes = new HashSet(); - internal readonly HashSet receiveTypes = new HashSet(); - internal readonly HashSet writeTypes = new HashSet(); - internal readonly HashSet writeImmediateTypes = new HashSet(); - internal readonly HashSet queryWithTypes = new HashSet(); - internal readonly HashSet queryWithoutTypes = new HashSet(); - internal readonly Dictionary writePriorities = new Dictionary(); - internal readonly int defaultWritePriority = 0; + internal readonly HashSet ReadTypes = new HashSet(); + internal readonly HashSet ReadImmediateTypes = new HashSet(); + internal readonly HashSet SendTypes = new HashSet(); + internal readonly HashSet ReceiveTypes = new HashSet(); + internal readonly HashSet WriteTypes = new HashSet(); + internal readonly HashSet WriteImmediateTypes = new HashSet(); + internal readonly HashSet QueryWithTypes = new HashSet(); + internal readonly HashSet QueryWithoutTypes = new HashSet(); + internal readonly Dictionary WritePriorities = new Dictionary(); + internal readonly int DefaultWritePriority = 0; /// /// If false, the Engine will ignore time dilation. /// - internal bool usesTimeDilation = true; - public bool TimeDilationActive { get => usesTimeDilation && timeManager.TimeDilationActive; } + internal bool _usesTimeDilation = true; + public bool TimeDilationActive { get => _usesTimeDilation && _timeManager.TimeDilationActive; } - private EntityManager entityManager; - private MessageManager messageManager; - private ComponentManager componentManager; - private TimeManager timeManager; - private TrackingManager trackingManager; + private EntityManager _entityManager; + private MessageManager _messageManager; + private ComponentManager _componentManager; + private TimeManager _timeManager; + private TrackingManager _trackingManager; - private EntitySetQuery entityQuery; + private EntitySetQuery _entityQuery; - private HashSet _trackedEntities = new HashSet(); + private readonly HashSet _trackedEntities = new HashSet(); protected IEnumerable TrackedEntities { get { foreach (var entityID in _trackedEntities) { - yield return entityManager.GetEntity(entityID); + yield return _entityManager.GetEntity(entityID); } } } - private HashSet _newlyCreatedEntities = new HashSet(); + private readonly HashSet _newlyCreatedEntities = new HashSet(); protected Engine() { - ID = Guid.NewGuid(); + _id = Guid.NewGuid(); var sendsAttribute = GetType().GetCustomAttribute(false); if (sendsAttribute != null) { - sendTypes = sendsAttribute.sendTypes; + SendTypes = sendsAttribute.SendTypes; } var activatesAttribute = GetType().GetCustomAttribute(false); if (activatesAttribute != null) { - writeImmediateTypes = activatesAttribute.writeImmediateTypes; + WriteImmediateTypes = activatesAttribute.WriteImmediateTypes; } var defaultWritePriorityAttribute = GetType().GetCustomAttribute(false); if (defaultWritePriorityAttribute != null) { - defaultWritePriority = defaultWritePriorityAttribute.writePriority; + DefaultWritePriority = defaultWritePriorityAttribute.WritePriority; } foreach (var writesAttribute in GetType().GetCustomAttributes(false)) { - writeTypes.UnionWith(writesAttribute.writeTypes); - writePriorities = new Dictionary[2] { writePriorities, writesAttribute.priorities }.SelectMany(dict => dict).ToDictionary(pair => pair.Key, pair => pair.Value); + WriteTypes.UnionWith(writesAttribute.WriteTypes); + WritePriorities = new Dictionary[2] { WritePriorities, writesAttribute.Priorities }.SelectMany(dict => dict).ToDictionary(pair => pair.Key, pair => pair.Value); } var receivesAttribute = GetType().GetCustomAttribute(false); if (receivesAttribute != null) { - receiveTypes = receivesAttribute.receiveTypes; + ReceiveTypes = receivesAttribute.ReceiveTypes; } var readsAttribute = GetType().GetCustomAttribute(false); if (readsAttribute != null) { - readTypes = readsAttribute.readTypes; + ReadTypes = readsAttribute.ReadTypes; } var readsImmediateAttribute = GetType().GetCustomAttribute(false); if (readsImmediateAttribute != null) { - readImmediateTypes = readsImmediateAttribute.readImmediateTypes; + ReadImmediateTypes = readsImmediateAttribute.ReadImmediateTypes; } var queryWithAttribute = GetType().GetCustomAttribute(false); if (queryWithAttribute != null) { - queryWithTypes = queryWithAttribute.queryWithTypes; + QueryWithTypes = queryWithAttribute.QueryWithTypes.ToHashSet(); } var queryWithoutAttribute = GetType().GetCustomAttribute(false); if (queryWithoutAttribute != null) { - queryWithoutTypes = queryWithoutAttribute.queryWithoutTypes; + QueryWithoutTypes = queryWithoutAttribute.QueryWithoutTypes; } } @@ -127,42 +127,42 @@ namespace Encompass public bool Equals(Engine other) { - return other.ID == ID; + return other._id == _id; } public override int GetHashCode() { - return ID.GetHashCode(); + return HashCode.Combine(_id); } internal void AssignEntityManager(EntityManager entityManager) { - this.entityManager = entityManager; + _entityManager = entityManager; } internal void AssignComponentManager(ComponentManager componentManager) { - this.componentManager = componentManager; + _componentManager = componentManager; } internal void AssignMessageManager(MessageManager messageManager) { - this.messageManager = messageManager; + _messageManager = messageManager; } internal void AssignTimeManager(TimeManager timeManager) { - this.timeManager = timeManager; + _timeManager = timeManager; } internal void AssignTrackingManager(TrackingManager trackingManager) { - this.trackingManager = trackingManager; + _trackingManager = trackingManager; } internal void CheckMessageRead() where TMessage : struct, IMessage { - if (!receiveTypes.Contains(typeof(TMessage))) + if (!ReceiveTypes.Contains(typeof(TMessage))) { throw new IllegalReadException("Engine {0} tried to read undeclared Message {1}", this.GetType().Name, typeof(TMessage).Name); } @@ -189,7 +189,7 @@ namespace Encompass /// protected Entity CreateEntity() { - var entity = entityManager.CreateEntity(); + var entity = _entityManager.CreateEntity(); _newlyCreatedEntities.Add(entity.ID); return entity; } @@ -199,7 +199,7 @@ namespace Encompass /// protected bool EntityExists(Entity entity) { - return entityManager.EntityExists(entity.ID); + return _entityManager.EntityExists(entity.ID); } /// @@ -207,7 +207,7 @@ namespace Encompass /// protected bool EntityExists(int entityID) { - return entityManager.EntityExists(entityID); + return _entityManager.EntityExists(entityID); } /// @@ -215,7 +215,7 @@ namespace Encompass /// protected Entity ReadEntity() where TComponent : struct, IComponent { - return entityManager.GetEntity(ReadComponentHelper().Item2); + return _entityManager.GetEntity(ReadComponentHelper().Item2); } /// @@ -225,7 +225,7 @@ namespace Encompass { foreach (var pair in ReadComponentsHelper()) { - yield return entityManager.GetEntity(pair.Item2); + yield return _entityManager.GetEntity(pair.Item2); } } @@ -233,24 +233,24 @@ namespace Encompass internal IEnumerable ReadComponentsFromWorld() where TComponent : struct, IComponent { - return componentManager.GetComponentsByType(); + return _componentManager.GetComponentsByType(); } private IEnumerable<(TComponent, int)> ReadComponentsHelper() where TComponent : struct, IComponent { - var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); - var existingRead = readTypes.Contains(typeof(TComponent)); + var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); + var existingRead = ReadTypes.Contains(typeof(TComponent)); if (existingRead && immediateRead) { - return componentManager.ReadExistingAndImmediateComponentsByType(); + return _componentManager.ReadExistingAndImmediateComponentsByType(); } else if (existingRead) { - return componentManager.GetComponentsIncludingEntity(); + return _componentManager.GetComponentsIncludingEntity(); } else if (immediateRead) { - return componentManager.ReadImmediateComponentsByType(); + return _componentManager.ReadImmediateComponentsByType(); } else { @@ -276,25 +276,25 @@ namespace Encompass { foreach (var (component, id) in ReadComponentsHelper()) { - yield return (component, entityManager.GetEntity(id)); + yield return (component, _entityManager.GetEntity(id)); } } private (TComponent, int) ReadComponentHelper() where TComponent : struct, IComponent { - var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); - var existingRead = readTypes.Contains(typeof(TComponent)); + var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); + var existingRead = ReadTypes.Contains(typeof(TComponent)); if (existingRead && immediateRead) { - return componentManager.ReadFirstExistingOrImmediateComponentByType(); + return _componentManager.ReadFirstExistingOrImmediateComponentByType(); } else if (existingRead) { - return componentManager.ReadFirstExistingComponentByType(); + return _componentManager.ReadFirstExistingComponentByType(); } else if (immediateRead) { - return componentManager.ReadFirstImmediateComponentByType(); + return _componentManager.ReadFirstImmediateComponentByType(); } else { @@ -316,7 +316,7 @@ namespace Encompass protected (TComponent, Entity) ReadComponentIncludingEntity() where TComponent : struct, IComponent { var (component, id) = ReadComponentHelper(); - return (component, entityManager.GetEntity(id)); + return (component, _entityManager.GetEntity(id)); } /// @@ -324,19 +324,19 @@ namespace Encompass /// protected bool SomeComponent() where TComponent : struct, IComponent { - var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); - var existingRead = readTypes.Contains(typeof(TComponent)); + var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); + var existingRead = ReadTypes.Contains(typeof(TComponent)); if (existingRead && immediateRead) { - return componentManager.SomeExistingOrImmediateComponent(); + return _componentManager.SomeExistingOrImmediateComponent(); } else if (existingRead) { - return componentManager.SomeExistingComponent(); + return _componentManager.SomeExistingComponent(); } else if (immediateRead) { - return componentManager.SomeImmediateComponent(); + return _componentManager.SomeImmediateComponent(); } else { @@ -346,19 +346,19 @@ namespace Encompass private ref readonly TComponent GetComponentHelper(int entityID) where TComponent : struct, IComponent { - var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); - var existingRead = readTypes.Contains(typeof(TComponent)); + var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); + var existingRead = ReadTypes.Contains(typeof(TComponent)); if (existingRead && immediateRead) { - return ref componentManager.ReadImmediateOrExistingComponentByEntityAndType(entityID); + return ref _componentManager.ReadImmediateOrExistingComponentByEntityAndType(entityID); } else if (existingRead) { - return ref componentManager.ReadExistingComponentByEntityAndType(entityID); + return ref _componentManager.ReadExistingComponentByEntityAndType(entityID); } else if (immediateRead) { - return ref componentManager.ReadImmediateComponentByEntityAndType(entityID); + return ref _componentManager.ReadImmediateComponentByEntityAndType(entityID); } else { @@ -388,20 +388,20 @@ namespace Encompass /// protected bool HasComponent(Entity entity) where TComponent : struct, IComponent { - var immediateRead = readImmediateTypes.Contains(typeof(TComponent)); - var existingRead = readTypes.Contains(typeof(TComponent)); + var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); + var existingRead = ReadTypes.Contains(typeof(TComponent)); if (immediateRead && existingRead) { - return componentManager.HasExistingOrImmediateComponent(entity.ID); + return _componentManager.HasExistingOrImmediateComponent(entity.ID); } else if (existingRead) { - return componentManager.HasExistingComponent(entity.ID); + return _componentManager.HasExistingComponent(entity.ID); } else if (immediateRead) { - return componentManager.HasImmediateComponent(entity.ID); + return _componentManager.HasImmediateComponent(entity.ID); } else { @@ -417,20 +417,20 @@ namespace Encompass /// protected bool HasComponent(Entity entity, Type type) { - var immediateRead = readImmediateTypes.Contains(type); - var existingRead = readTypes.Contains(type); + var immediateRead = ReadImmediateTypes.Contains(type); + var existingRead = ReadTypes.Contains(type); if (immediateRead && existingRead) { - return componentManager.HasExistingOrImmediateComponent(entity.ID, type); + return _componentManager.HasExistingOrImmediateComponent(entity.ID, type); } else if (existingRead) { - return componentManager.HasExistingComponent(entity.ID, type); + return _componentManager.HasExistingComponent(entity.ID, type); } else if (immediateRead) { - return componentManager.HasImmediateComponent(entity.ID, type); + return _componentManager.HasImmediateComponent(entity.ID, type); } else { @@ -446,35 +446,35 @@ namespace Encompass /// protected void SetComponent(Entity entity, TComponent component) where TComponent : struct, IComponent { - var priority = writePriorities.ContainsKey(typeof(TComponent)) ? writePriorities[typeof(TComponent)] : defaultWritePriority; + var priority = WritePriorities.ContainsKey(typeof(TComponent)) ? WritePriorities[typeof(TComponent)] : DefaultWritePriority; - if (!writeTypes.Contains(typeof(TComponent))) + if (!WriteTypes.Contains(typeof(TComponent))) { throw new IllegalWriteException("Engine {0} tried to update undeclared Component {1}", GetType().Name, typeof(TComponent).Name); } bool written; - if (writeImmediateTypes.Contains(typeof(TComponent))) + if (WriteImmediateTypes.Contains(typeof(TComponent))) { - written = componentManager.AddImmediateComponent(entity.ID, component, priority); + written = _componentManager.AddImmediateComponent(entity.ID, component, priority); if (written) { - trackingManager.ImmediateUpdateTracking(entity.ID, typeof(TComponent)); + _trackingManager.ImmediateUpdateTracking(entity.ID, typeof(TComponent)); } } else { - written = componentManager.UpdateComponent(entity.ID, component, priority); + written = _componentManager.UpdateComponent(entity.ID, component, priority); } - if (!componentManager.HasExistingComponent(entity.ID)) + if (!_componentManager.HasExistingComponent(entity.ID)) { - trackingManager.RegisterAddition(entity.ID, typeof(TComponent)); + _trackingManager.RegisterAddition(entity.ID, typeof(TComponent)); } if (written && component is IDrawableComponent drawableComponent) { - componentManager.RegisterDrawableComponent(entity.ID, component, drawableComponent.Layer); + _componentManager.RegisterDrawableComponent(entity.ID, component, drawableComponent.Layer); } } @@ -491,21 +491,21 @@ namespace Encompass throw new IllegalWriteException("AddComponent used on Entity that was not created in this context. Use SetComponent instead."); } - if (writeImmediateTypes.Contains(typeof(TComponent))) + if (WriteImmediateTypes.Contains(typeof(TComponent))) { - componentManager.AddImmediateComponent(entity.ID, component); - trackingManager.ImmediateUpdateTracking(entity.ID, typeof(TComponent)); + _componentManager.AddImmediateComponent(entity.ID, component); + _trackingManager.ImmediateUpdateTracking(entity.ID, typeof(TComponent)); } else { - componentManager.AddComponent(entity.ID, component); + _componentManager.AddComponent(entity.ID, component); } - trackingManager.RegisterAddition(entity.ID, typeof(TComponent)); + _trackingManager.RegisterAddition(entity.ID, typeof(TComponent)); if (component is IDrawableComponent drawableComponent) { - componentManager.RegisterDrawableComponent(entity.ID, component, drawableComponent.Layer); + _componentManager.RegisterDrawableComponent(entity.ID, component, drawableComponent.Layer); } } @@ -517,12 +517,12 @@ namespace Encompass /// protected void SendMessage(TMessage message) where TMessage : struct, IMessage { - if (!sendTypes.Contains(typeof(TMessage))) + if (!SendTypes.Contains(typeof(TMessage))) { throw new IllegalSendException("Engine {0} tried to send undeclared Message {1}", GetType().Name, typeof(TMessage).Name); } - messageManager.AddMessage(message); + _messageManager.AddMessage(message); } /// @@ -531,7 +531,7 @@ namespace Encompass /// The time in seconds that will elapse before the message is sent. protected void SendMessage(TMessage message, double time) where TMessage : struct, IMessage { - messageManager.AddMessage(message, time); + _messageManager.AddMessage(message, time); } /// @@ -540,7 +540,7 @@ namespace Encompass /// The time in seconds that will elapse before the message is sent. protected void SendMessageIgnoringTimeDilation(TMessage message, double time) where TMessage : struct, IMessage { - messageManager.AddMessageIgnoringTimeDilation(message, time); + _messageManager.AddMessageIgnoringTimeDilation(message, time); } /// @@ -552,7 +552,7 @@ namespace Encompass protected IEnumerable ReadMessages() where TMessage : struct, IMessage { CheckMessageRead(); - return messageManager.GetMessagesByType(); + return _messageManager.GetMessagesByType(); } /// @@ -564,7 +564,7 @@ namespace Encompass protected TMessage ReadMessage() where TMessage : struct, IMessage { CheckMessageRead(); - return messageManager.First(); + return _messageManager.First(); } /// @@ -576,7 +576,7 @@ namespace Encompass protected bool SomeMessage() where TMessage : struct, IMessage { CheckMessageRead(); - return messageManager.Any(); + return _messageManager.Any(); } /// @@ -585,7 +585,7 @@ namespace Encompass /// protected void Destroy(Entity entity) { - entityManager.MarkForDestroy(entity.ID); + _entityManager.MarkForDestroy(entity.ID); } /// @@ -616,28 +616,28 @@ namespace Encompass /// protected void RemoveComponent(Entity entity) where TComponent : struct, IComponent { - var priority = writePriorities.ContainsKey(typeof(TComponent)) ? writePriorities[typeof(TComponent)] : defaultWritePriority; + var priority = WritePriorities.ContainsKey(typeof(TComponent)) ? WritePriorities[typeof(TComponent)] : DefaultWritePriority; - if (!writeTypes.Contains(typeof(TComponent))) + if (!WriteTypes.Contains(typeof(TComponent))) { throw new IllegalWriteException("Engine {0} tried to remove undeclared Component {1}. Declare with Writes attribute.", GetType().Name, typeof(TComponent).Name); } - if (writeImmediateTypes.Contains(typeof(TComponent))) + if (WriteImmediateTypes.Contains(typeof(TComponent))) { - if (componentManager.RemoveImmediate(entity.ID, priority)) + if (_componentManager.RemoveImmediate(entity.ID, priority)) { - trackingManager.ImmediateUpdateTracking(entity.ID, typeof(TComponent)); + _trackingManager.ImmediateUpdateTracking(entity.ID, typeof(TComponent)); } } else { - componentManager.Remove(entity.ID, priority); + _componentManager.Remove(entity.ID, priority); } - if (componentManager.HasExistingComponent(entity.ID)) + if (_componentManager.HasExistingComponent(entity.ID)) { - trackingManager.RegisterRemoval(entity.ID, typeof(TComponent)); + _trackingManager.RegisterRemoval(entity.ID, typeof(TComponent)); } } @@ -652,7 +652,7 @@ namespace Encompass /// The time that will elapse before time is fully undilated. protected void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime) { - timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime); + _timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime); } /// @@ -667,7 +667,7 @@ namespace Encompass /// The time that will elapse before time is fully undilated. protected void ActivateTimeDilation(double factor, double easeInTime, System.Func easeInFunction, double activeTime, double easeOutTime) { - timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime); + _timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime); } /// @@ -682,7 +682,7 @@ namespace Encompass /// An easing function for the easing out of time dilation. protected void ActivateTimeDilation(double factor, double easeInTime, double activeTime, double easeOutTime, System.Func easeOutFunction) { - timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime, easeOutFunction); + _timeManager.ActivateTimeDilation(factor, easeInTime, activeTime, easeOutTime, easeOutFunction); } /// @@ -698,7 +698,7 @@ namespace Encompass /// An easing function for the easing out of time dilation. protected void ActivateTimeDilation(double factor, double easeInTime, System.Func easeInFunction, double activeTime, double easeOutTime, System.Func easeOutFunction) { - timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime, easeOutFunction); + _timeManager.ActivateTimeDilation(factor, easeInTime, easeInFunction, activeTime, easeOutTime, easeOutFunction); } /// @@ -710,7 +710,7 @@ namespace Encompass protected IEnumerable ReadMessagesWithEntity(Entity entity) where TMessage : struct, IMessage, IHasEntity { CheckMessageRead(); - return messageManager.WithEntity(entity.ID); + return _messageManager.WithEntity(entity.ID); } /// @@ -720,7 +720,7 @@ namespace Encompass protected TMessage ReadMessageWithEntity(Entity entity) where TMessage : struct, IMessage, IHasEntity { CheckMessageRead(); - return messageManager.WithEntitySingular(entity.ID); + return _messageManager.WithEntitySingular(entity.ID); } /// @@ -729,16 +729,16 @@ namespace Encompass protected bool SomeMessageWithEntity(Entity entity) where TMessage : struct, IMessage, IHasEntity { CheckMessageRead(); - return messageManager.SomeWithEntity(entity.ID); + return _messageManager.SomeWithEntity(entity.ID); } internal void CheckAndUpdateTracking(int entityID) { - if (_trackedEntities.Contains(entityID) && !entityQuery.CheckEntity(entityID, componentManager.ExistingBits)) + if (_trackedEntities.Contains(entityID) && !_entityQuery.CheckEntity(entityID, _componentManager.ExistingBits)) { _trackedEntities.Remove(entityID); } - else if (!_trackedEntities.Contains(entityID) && entityQuery.CheckEntity(entityID, componentManager.ExistingBits)) + else if (!_trackedEntities.Contains(entityID) && _entityQuery.CheckEntity(entityID, _componentManager.ExistingBits)) { _trackedEntities.Add(entityID); } @@ -746,11 +746,11 @@ namespace Encompass internal void ImmediateCheckAndUpdateTracking(int entityID) { - if (_trackedEntities.Contains(entityID) && !entityQuery.ImmediateCheckEntity(entityID, componentManager.ImmediateBits, componentManager.ExistingBits)) + if (_trackedEntities.Contains(entityID) && !_entityQuery.ImmediateCheckEntity(entityID, _componentManager.ImmediateBits, _componentManager.ExistingBits)) { _trackedEntities.Remove(entityID); } - else if (!_trackedEntities.Contains(entityID) && entityQuery.ImmediateCheckEntity(entityID, componentManager.ImmediateBits, componentManager.ExistingBits)) + else if (!_trackedEntities.Contains(entityID) && _entityQuery.ImmediateCheckEntity(entityID, _componentManager.ImmediateBits, _componentManager.ExistingBits)) { _trackedEntities.Add(entityID); } @@ -762,30 +762,30 @@ namespace Encompass internal void BuildEntityQuery() { var withMask = BitSet512.Zero; - foreach (var type in queryWithTypes) + foreach (var type in QueryWithTypes) { - withMask = withMask.Set(componentManager.TypeToIndex[type]); + withMask = withMask.Set(_componentManager.TypeToIndex[type]); } var withoutMask = BitSet512.Zero; - foreach (var type in queryWithoutTypes) + foreach (var type in QueryWithoutTypes) { - withoutMask = withoutMask.Set(componentManager.TypeToIndex[type]); + withoutMask = withoutMask.Set(_componentManager.TypeToIndex[type]); } var immediateMask = BitSet512.Zero; - foreach (var type in readImmediateTypes) + foreach (var type in ReadImmediateTypes) { - immediateMask = immediateMask.Set(componentManager.TypeToIndex[type]); + immediateMask = immediateMask.Set(_componentManager.TypeToIndex[type]); } var existingMask = BitSet512.Zero; - foreach (var type in readTypes) + foreach (var type in ReadTypes) { - existingMask = existingMask.Set(componentManager.TypeToIndex[type]); + existingMask = existingMask.Set(_componentManager.TypeToIndex[type]); } - entityQuery = new EntitySetQuery( + _entityQuery = new EntitySetQuery( withMask & immediateMask, withMask & existingMask, withoutMask & immediateMask, diff --git a/encompass-cs/Engines/Spawner.cs b/encompass-cs/Engines/Spawner.cs index 3ad21bf..a1f6e4e 100644 --- a/encompass-cs/Engines/Spawner.cs +++ b/encompass-cs/Engines/Spawner.cs @@ -13,10 +13,10 @@ namespace Encompass var readsAttribute = GetType().GetCustomAttribute(false); if (readsAttribute != null) { - readsAttribute.readTypes.Add(typeof(TMessage)); + readsAttribute.ReadTypes.Add(typeof(TMessage)); } - receiveTypes.Add(typeof(TMessage)); + ReceiveTypes.Add(typeof(TMessage)); } public override void Update(double dt) diff --git a/encompass-cs/Entity.cs b/encompass-cs/Entity.cs index 7287499..d7913ea 100644 --- a/encompass-cs/Entity.cs +++ b/encompass-cs/Entity.cs @@ -37,7 +37,7 @@ namespace Encompass public override int GetHashCode() { - return ID.GetHashCode(); + return HashCode.Combine(ID); } } } diff --git a/encompass-cs/EntityManager.cs b/encompass-cs/EntityManager.cs index c800281..a45f0a4 100644 --- a/encompass-cs/EntityManager.cs +++ b/encompass-cs/EntityManager.cs @@ -5,48 +5,48 @@ namespace Encompass { internal class EntityManager { - private readonly int entityCapacity; - private readonly IDManager idManager = new IDManager(); - private readonly HashSet IDs = new HashSet(); + private readonly int _entityCapacity; + private readonly IDManager _idManager = new IDManager(); + private readonly HashSet _ids = new HashSet(); - private readonly HashSet entitiesMarkedForDestroy = new HashSet(); + private readonly HashSet _entitiesMarkedForDestroy = new HashSet(); - private readonly ComponentManager componentManager; + private readonly ComponentManager _componentManager; public IEnumerable EntityIDs { - get { return IDs; } + get { return _ids; } } public EntityManager(ComponentManager componentManager, int entityCapacity) { - this.componentManager = componentManager; - this.entityCapacity = entityCapacity; + _componentManager = componentManager; + _entityCapacity = entityCapacity; } private int NextID() { - return idManager.NextID(); + return _idManager.NextID(); } public Entity CreateEntity() { - if (IDs.Count < entityCapacity) + if (_ids.Count < _entityCapacity) { var id = NextID(); var entity = new Entity(id); - IDs.Add(id); + _ids.Add(id); return entity; } else { - throw new EntityOverflowException("The number of entities has exceeded the entity capacity of {0}", entityCapacity); + throw new EntityOverflowException("The number of entities has exceeded the entity capacity of {0}", _entityCapacity); } } public bool EntityExists(int id) { - return IDs.Contains(id); + return _ids.Contains(id); } public Entity GetEntity(int id) @@ -61,20 +61,20 @@ namespace Encompass public void MarkForDestroy(int entityID) { - entitiesMarkedForDestroy.Add(entityID); + _entitiesMarkedForDestroy.Add(entityID); } public void DestroyMarkedEntities(IEnumerable engines) { - foreach (var entityID in entitiesMarkedForDestroy) + foreach (var entityID in _entitiesMarkedForDestroy) { foreach (var engine in engines) { engine.RegisterDestroyedEntity(entityID); } - componentManager.MarkAllComponentsOnEntityForRemoval(entityID); - IDs.Remove(entityID); - idManager.Free(entityID); + _componentManager.MarkAllComponentsOnEntityForRemoval(entityID); + _ids.Remove(entityID); + _idManager.Free(entityID); } - entitiesMarkedForDestroy.Clear(); + _entitiesMarkedForDestroy.Clear(); } // NOTE: this is very suboptimal @@ -82,7 +82,7 @@ namespace Encompass { foreach (var id in EntityIDs) { - if (componentManager.UpToDateEntityIsEmpty(id)) + if (_componentManager.UpToDateEntityIsEmpty(id)) { MarkForDestroy(id); } diff --git a/encompass-cs/IDManager.cs b/encompass-cs/IDManager.cs index 01bb529..360f580 100644 --- a/encompass-cs/IDManager.cs +++ b/encompass-cs/IDManager.cs @@ -4,25 +4,25 @@ namespace Encompass { internal class IDManager { - int nextID = 0; + int _nextID = 0; - private Stack availableIDs = new Stack(); + private readonly Stack _availableIDs = new Stack(); public int NextID() { - if (availableIDs.Count > 0) + if (_availableIDs.Count > 0) { - return availableIDs.Pop(); + return _availableIDs.Pop(); } else { - return nextID++; + return _nextID++; } } - public void Free(int ID) + public void Free(int id) { - availableIDs.Push(ID); + _availableIDs.Push(id); } } } diff --git a/encompass-cs/MessageManager.cs b/encompass-cs/MessageManager.cs index c9e53ae..c662b6e 100644 --- a/encompass-cs/MessageManager.cs +++ b/encompass-cs/MessageManager.cs @@ -4,69 +4,69 @@ namespace Encompass { internal class MessageManager { - private readonly TimeManager timeManager; - private readonly MessageStore messageStore = new MessageStore(); + private readonly TimeManager _timeManager; + private readonly MessageStore _messageStore = new MessageStore(); public MessageManager(TimeManager timeManager) { - this.timeManager = timeManager; + _timeManager = timeManager; } internal void AddMessage(TMessage message) where TMessage : struct, IMessage { - messageStore.AddMessage(message); + _messageStore.AddMessage(message); } internal void AddMessage(TMessage message, double time) where TMessage : struct, IMessage { - messageStore.AddMessage(message, time); + _messageStore.AddMessage(message, time); } internal void AddMessageIgnoringTimeDilation(TMessage message, double time) where TMessage : struct, IMessage { - messageStore.AddMessageIgnoringTimeDilation(message, time); + _messageStore.AddMessageIgnoringTimeDilation(message, time); } internal void ClearMessages() { - messageStore.ClearAll(); + _messageStore.ClearAll(); } internal void ProcessDelayedMessages(double dt) { - messageStore.ProcessDelayedMessages(dt * timeManager.TimeDilationFactor, dt); + _messageStore.ProcessDelayedMessages(dt * _timeManager.TimeDilationFactor, dt); } internal IEnumerable GetMessagesByType() where TMessage : struct, IMessage { - return messageStore.All(); + return _messageStore.All(); } internal bool Any() where TMessage : struct, IMessage { - return messageStore.Any(); + return _messageStore.Any(); } internal TMessage First() where TMessage : struct, IMessage { - return messageStore.First(); + return _messageStore.First(); } internal IEnumerable WithEntity(int entityID) where TMessage : struct, IMessage, IHasEntity { - return messageStore.WithEntity(entityID); + return _messageStore.WithEntity(entityID); } internal TMessage WithEntitySingular(int entityID) where TMessage : struct, IMessage, IHasEntity { - var enumerator = messageStore.WithEntity(entityID).GetEnumerator(); + var enumerator = _messageStore.WithEntity(entityID).GetEnumerator(); enumerator.MoveNext(); return enumerator.Current; } internal bool SomeWithEntity(int entityID) where TMessage : struct, IMessage, IHasEntity { - return messageStore.SomeWithEntity(entityID); + return _messageStore.SomeWithEntity(entityID); } } } diff --git a/encompass-cs/RenderManager.cs b/encompass-cs/RenderManager.cs index 529a431..6469c2f 100644 --- a/encompass-cs/RenderManager.cs +++ b/encompass-cs/RenderManager.cs @@ -5,40 +5,40 @@ namespace Encompass { internal class RenderManager { - private readonly EntityManager entityManager; - private readonly DrawLayerManager drawLayerManager; + private readonly EntityManager _entityManager; + private readonly DrawLayerManager _drawLayerManager; - private readonly Dictionary> drawComponentTypeToOrderedRenderer = new Dictionary>(256); + private readonly Dictionary> _drawComponentTypeToOrderedRenderer = new Dictionary>(256); public RenderManager(EntityManager entityManager, DrawLayerManager drawLayerManager) { - this.entityManager = entityManager; - this.drawLayerManager = drawLayerManager; + _entityManager = entityManager; + _drawLayerManager = drawLayerManager; } public void RegisterOrderedRenderer(Action renderAction) where TComponent : struct, IComponent { - drawComponentTypeToOrderedRenderer.Add(typeof(TComponent), renderAction); - drawLayerManager.RegisterOrderedDrawable(); + _drawComponentTypeToOrderedRenderer.Add(typeof(TComponent), renderAction); + _drawLayerManager.RegisterOrderedDrawable(); } public void RegisterGeneralRendererWithLayer(GeneralRenderer renderer, int layer) { - drawLayerManager.RegisterGeneralRendererWithLayer(renderer, layer); + _drawLayerManager.RegisterGeneralRendererWithLayer(renderer, layer); } public void Draw() { - foreach (var layer in drawLayerManager.LayerOrder) + foreach (var layer in _drawLayerManager.LayerOrder) { - var generalRendererSet = drawLayerManager.GeneralRenderersByLayer(layer); + var generalRendererSet = _drawLayerManager.GeneralRenderersByLayer(layer); - foreach (var (entityID, componentType, component) in drawLayerManager.AllInLayer(layer)) + foreach (var (entityID, componentType, component) in _drawLayerManager.AllInLayer(layer)) { - if (drawComponentTypeToOrderedRenderer.ContainsKey(componentType)) + if (_drawComponentTypeToOrderedRenderer.ContainsKey(componentType)) { - var internalRenderAction = drawComponentTypeToOrderedRenderer[componentType]; - internalRenderAction(entityManager.GetEntity(entityID), component); + var internalRenderAction = _drawComponentTypeToOrderedRenderer[componentType]; + internalRenderAction(_entityManager.GetEntity(entityID), component); } } diff --git a/encompass-cs/Renderer.cs b/encompass-cs/Renderer.cs index 9ac5887..f7f3b88 100644 --- a/encompass-cs/Renderer.cs +++ b/encompass-cs/Renderer.cs @@ -4,17 +4,17 @@ namespace Encompass { public abstract class Renderer { - internal EntityManager entityManager; - internal ComponentManager componentManager; + internal EntityManager _entityManager; + internal ComponentManager _componentManager; internal void AssignEntityManager(EntityManager entityManager) { - this.entityManager = entityManager; + _entityManager = entityManager; } internal void AssignComponentManager(ComponentManager componentManager) { - this.componentManager = componentManager; + _componentManager = componentManager; } protected IEnumerable ReadEntities() where TComponent : struct, IComponent @@ -32,14 +32,14 @@ namespace Encompass protected IEnumerable ReadComponents() where TComponent : struct, IComponent { - return componentManager.GetComponentsByType(); + return _componentManager.GetComponentsByType(); } protected IEnumerable<(TComponent, Entity)> ReadComponentsIncludingEntity() where TComponent : struct, IComponent { - foreach (var (component, id) in componentManager.GetComponentsIncludingEntity()) + foreach (var (component, id) in _componentManager.GetComponentsIncludingEntity()) { - yield return (component, entityManager.GetEntity(id)); + yield return (component, _entityManager.GetEntity(id)); } } @@ -59,17 +59,17 @@ namespace Encompass protected ref readonly TComponent GetComponent(Entity entity) where TComponent : struct, IComponent { - return ref componentManager.GetComponentByEntityAndType(entity.ID); + return ref _componentManager.GetComponentByEntityAndType(entity.ID); } protected bool HasComponent(Entity entity) where TComponent : struct, IComponent { - return componentManager.EntityHasComponentOfType(entity.ID); + return _componentManager.EntityHasComponentOfType(entity.ID); } protected bool SomeComponent() where TComponent : struct, IComponent { - return componentManager.SomeExistingComponent(); + return _componentManager.SomeExistingComponent(); } } } diff --git a/encompass-cs/TimeDilationData.cs b/encompass-cs/TimeDilationData.cs index b344589..e57901f 100644 --- a/encompass-cs/TimeDilationData.cs +++ b/encompass-cs/TimeDilationData.cs @@ -1,35 +1,56 @@ +using System; + namespace Encompass { internal struct TimeDilationData { - public double elapsedTime; - public double easeInTime; - public System.Func easeInFunction; - public double activeTime; - public double easeOutTime; - public System.Func easeOutFunction; - public double factor; + private readonly double _factor; public double Factor { get { - if (elapsedTime < easeInTime) + if (ElapsedTime < EaseInTime) { - return easeInFunction(elapsedTime, 1, factor - 1, easeInTime); + return EaseInFunction(ElapsedTime, 1, _factor - 1, EaseInTime); } - else if (elapsedTime < easeInTime + activeTime) + else if (ElapsedTime < EaseInTime + ActiveTime) { - return factor; + return _factor; } - else if (elapsedTime < easeInTime + activeTime + easeOutTime) + else if (ElapsedTime < EaseInTime + ActiveTime + EaseOutTime) { - var elapsedOutTime = elapsedTime - easeInTime - activeTime; - return easeOutFunction(elapsedOutTime, factor, 1 - factor, easeOutTime); + var elapsedOutTime = ElapsedTime - EaseInTime - ActiveTime; + return EaseOutFunction(elapsedOutTime, _factor, 1 - _factor, EaseOutTime); } return 1; } } + + public double ElapsedTime { get; set; } + public double EaseInTime { get; } + public Func EaseInFunction { get; } + public double ActiveTime { get; } + public double EaseOutTime { get; } + public Func EaseOutFunction { get; } + + public TimeDilationData( + double factor, + double easeInTime, + Func easeInfunction, + double activeTime, + double easeOutTime, + Func easeOutFunction + ) + { + _factor = factor; + EaseInTime = easeInTime; + EaseInFunction = easeInfunction; + ActiveTime = activeTime; + EaseOutTime = easeOutTime; + EaseOutFunction = easeOutFunction; + ElapsedTime = 0; + } } -} \ No newline at end of file +} diff --git a/encompass-cs/TimeManager.cs b/encompass-cs/TimeManager.cs index ee05939..19363d2 100644 --- a/encompass-cs/TimeManager.cs +++ b/encompass-cs/TimeManager.cs @@ -4,7 +4,7 @@ namespace Encompass { internal class TimeManager { - private readonly List timeDilationDatas = new List(32); + private readonly List _timeDilationDatas = new List(32); private double Linear(double t, double b, double c, double d) { @@ -15,36 +15,36 @@ namespace Encompass { get { - if (timeDilationDatas.Count == 0) { return 1; } + if (_timeDilationDatas.Count == 0) { return 1; } var average = 0.0; - foreach (var data in timeDilationDatas) + foreach (var data in _timeDilationDatas) { average += data.Factor; } - return average / timeDilationDatas.Count; + return average / _timeDilationDatas.Count; } } public bool TimeDilationActive { - get => timeDilationDatas.Count != 0; + get => _timeDilationDatas.Count != 0; } public void Update(double dt) { - for (var i = timeDilationDatas.Count - 1; i >= 0; i--) + for (var i = _timeDilationDatas.Count - 1; i >= 0; i--) { - var data = timeDilationDatas[i]; + var data = _timeDilationDatas[i]; - data.elapsedTime += dt; + data.ElapsedTime += dt; - if (data.elapsedTime > data.easeInTime + data.activeTime + data.easeOutTime) + if (data.ElapsedTime > data.EaseInTime + data.ActiveTime + data.EaseOutTime) { - timeDilationDatas.RemoveAt(i); + _timeDilationDatas.RemoveAt(i); } else { - timeDilationDatas[i] = data; + _timeDilationDatas[i] = data; } } } @@ -66,16 +66,15 @@ namespace Encompass public void ActivateTimeDilation(double factor, double easeInTime, System.Func easeInFunction, double activeTime, double easeOutTime, System.Func easeOutFunction) { - timeDilationDatas.Add(new TimeDilationData - { - elapsedTime = 0, - easeInTime = easeInTime, - easeInFunction = easeInFunction, - activeTime = activeTime, - easeOutTime = easeOutTime, - easeOutFunction = easeOutFunction, - factor = factor - }); + _timeDilationDatas.Add(new TimeDilationData + ( + factor, + easeInTime, + easeInFunction, + activeTime, + easeOutTime, + easeOutFunction + )); } } } diff --git a/encompass-cs/TrackingManager.cs b/encompass-cs/TrackingManager.cs index c9e7830..3acf34d 100644 --- a/encompass-cs/TrackingManager.cs +++ b/encompass-cs/TrackingManager.cs @@ -5,13 +5,13 @@ namespace Encompass { internal class TrackingManager { - private Dictionary> _immediateComponentTypesToEngines = new Dictionary>(); - private Dictionary> _componentTypesToEngines = new Dictionary>(); + private readonly Dictionary> _immediateComponentTypesToEngines = new Dictionary>(); + private readonly Dictionary> _componentTypesToEngines = new Dictionary>(); - private HashSet<(int, Type)> _additions = new HashSet<(int, Type)>(); - private HashSet<(int, Type)> _removals = new HashSet<(int, Type)>(); + private readonly HashSet<(int, Type)> _additions = new HashSet<(int, Type)>(); + private readonly HashSet<(int, Type)> _removals = new HashSet<(int, Type)>(); - private HashSet<(int, Engine)> _pairsToCheck = new HashSet<(int, Engine)>(); + private readonly HashSet<(int, Engine)> _pairsToCheck = new HashSet<(int, Engine)>(); public void RegisterComponentTypeToEngine(Type type, Engine engine) { diff --git a/encompass-cs/UberEngine.cs b/encompass-cs/UberEngine.cs index 7abfc7d..c6f55b4 100644 --- a/encompass-cs/UberEngine.cs +++ b/encompass-cs/UberEngine.cs @@ -7,18 +7,18 @@ namespace Encompass { internal class UberEngine : Engine { - private IEnumerable _componentTypes; - private IEnumerable _messageTypes; + private readonly IEnumerable _componentTypes; + private readonly IEnumerable _messageTypes; public Entity Entity { get; private set; } public UberEngine(IEnumerable componentTypes, IEnumerable messageTypes) { _componentTypes = componentTypes; _messageTypes = messageTypes; - readTypes.UnionWith(componentTypes); - writeTypes.UnionWith(componentTypes); - sendTypes.UnionWith(messageTypes); - receiveTypes.UnionWith(messageTypes); + ReadTypes.UnionWith(componentTypes); + WriteTypes.UnionWith(componentTypes); + SendTypes.UnionWith(messageTypes); + ReceiveTypes.UnionWith(messageTypes); } public void Write() @@ -63,6 +63,8 @@ namespace Encompass if (typeof(IHasEntity).IsAssignableFrom(type)) { CallGenericMethod(type, "ReadMessagesWithEntity", new Type[] { typeof(Entity) }, new object[] { Entity }); + CallGenericMethod(type, "ReadMessageWithEntity", new Type[] { typeof(Entity) }, new object[] { Entity }); + CallGenericMethod(type, "SomeMessageWithEntity", new Type[] { typeof(Entity) }, new object[] { Entity }); } } } diff --git a/encompass-cs/UberRenderer.cs b/encompass-cs/UberRenderer.cs index be4bde4..870e999 100644 --- a/encompass-cs/UberRenderer.cs +++ b/encompass-cs/UberRenderer.cs @@ -6,7 +6,7 @@ namespace Encompass { class UberRenderer : Renderer { - private IEnumerable _componentTypes; + private readonly IEnumerable _componentTypes; private Entity _entity; public UberRenderer(IEnumerable componentTypes) diff --git a/encompass-cs/World.cs b/encompass-cs/World.cs index b611d96..b0b181b 100644 --- a/encompass-cs/World.cs +++ b/encompass-cs/World.cs @@ -7,13 +7,13 @@ namespace Encompass /// public class World { - private readonly List enginesInOrder; - private readonly EntityManager entityManager; - private readonly ComponentManager componentManager; - private readonly TrackingManager trackingManager; - private readonly MessageManager messageManager; - private readonly TimeManager timeManager; - private readonly RenderManager renderManager; + private readonly List _enginesInOrder; + private readonly EntityManager _entityManager; + private readonly ComponentManager _componentManager; + private readonly TrackingManager _trackingManager; + private readonly MessageManager _messageManager; + private readonly TimeManager _timeManager; + private readonly RenderManager _renderManager; internal World( List enginesInOrder, @@ -25,13 +25,13 @@ namespace Encompass RenderManager renderManager ) { - this.enginesInOrder = enginesInOrder; - this.entityManager = entityManager; - this.componentManager = componentManager; - this.trackingManager = trackingManager; - this.messageManager = messageManager; - this.timeManager = timeManager; - this.renderManager = renderManager; + _enginesInOrder = enginesInOrder; + _entityManager = entityManager; + _componentManager = componentManager; + _trackingManager = trackingManager; + _messageManager = messageManager; + _timeManager = timeManager; + _renderManager = renderManager; } /// @@ -40,15 +40,15 @@ namespace Encompass /// The time in seconds that has passed since the previous frame. public void Update(double dt) { - trackingManager.UpdateTracking(); - messageManager.ProcessDelayedMessages(dt); - timeManager.Update(dt); + _trackingManager.UpdateTracking(); + _messageManager.ProcessDelayedMessages(dt); + _timeManager.Update(dt); - foreach (var engine in enginesInOrder) + foreach (var engine in _enginesInOrder) { - if (engine.usesTimeDilation) + if (engine._usesTimeDilation) { - engine.Update(dt * timeManager.TimeDilationFactor); + engine.Update(dt * _timeManager.TimeDilationFactor); } else { @@ -58,12 +58,12 @@ namespace Encompass engine.ClearNewlyCreatedEntities(); } - messageManager.ClearMessages(); - entityManager.PruneEmptyEntities(); - entityManager.DestroyMarkedEntities(enginesInOrder); + _messageManager.ClearMessages(); + _entityManager.PruneEmptyEntities(); + _entityManager.DestroyMarkedEntities(_enginesInOrder); - componentManager.RemoveMarkedComponents(); - componentManager.WriteComponents(); + _componentManager.RemoveMarkedComponents(); + _componentManager.WriteComponents(); } /// @@ -71,7 +71,7 @@ namespace Encompass /// public void Draw() { - renderManager.Draw(); + _renderManager.Draw(); } } } diff --git a/encompass-cs/WorldBuilder.cs b/encompass-cs/WorldBuilder.cs index 3145626..bdb9ee1 100644 --- a/encompass-cs/WorldBuilder.cs +++ b/encompass-cs/WorldBuilder.cs @@ -18,43 +18,43 @@ namespace Encompass /// public class WorldBuilder { - private readonly int entityCapacity; - private readonly List engines = new List(); - private readonly DirectedGraph engineGraph = GraphBuilder.DirectedGraph(); - private readonly ComponentStore startingExistingComponentStore; - private readonly ComponentStore startingUpToDateComponentStore; + private readonly int _entityCapacity; + private readonly List _engines = new List(); + private readonly DirectedGraph _engineGraph = GraphBuilder.DirectedGraph(); + private readonly ComponentStore _startingExistingComponentStore; + private readonly ComponentStore _startingUpToDateComponentStore; - private readonly ComponentManager componentManager; - private readonly EntityManager entityManager; - private readonly MessageManager messageManager; - private readonly TimeManager timeManager; - private readonly DrawLayerManager drawLayerManager; - private readonly RenderManager renderManager; - private readonly TrackingManager trackingManager; + private readonly ComponentManager _componentManager; + private readonly EntityManager _entityManager; + private readonly MessageManager _messageManager; + private readonly TimeManager _timeManager; + private readonly DrawLayerManager _drawLayerManager; + private readonly RenderManager _renderManager; + private readonly TrackingManager _trackingManager; - private readonly Dictionary> typeToReaders = new Dictionary>(); + private readonly Dictionary> _typeToReaders = new Dictionary>(); - private readonly HashSet senders = new HashSet(); + private readonly HashSet _senders = new HashSet(); - private readonly HashSet componentTypesToPreload = new HashSet(); + private readonly HashSet _componentTypesToPreload = new HashSet(); - private readonly HashSet messageTypes = new HashSet(); + private readonly HashSet _messageTypes = new HashSet(); - private readonly Dictionary typeToIndex = new Dictionary(); + private readonly Dictionary _typeToIndex = new Dictionary(); public WorldBuilder(int entityCapacity = 32768) { - this.entityCapacity = entityCapacity; - drawLayerManager = new DrawLayerManager(typeToIndex); - timeManager = new TimeManager(); - trackingManager = new TrackingManager(); - componentManager = new ComponentManager(drawLayerManager, typeToIndex); - messageManager = new MessageManager(timeManager); - entityManager = new EntityManager(componentManager, entityCapacity); - renderManager = new RenderManager(entityManager, drawLayerManager); + _entityCapacity = entityCapacity; + _drawLayerManager = new DrawLayerManager(_typeToIndex); + _timeManager = new TimeManager(); + _trackingManager = new TrackingManager(); + _componentManager = new ComponentManager(_drawLayerManager, _typeToIndex); + _messageManager = new MessageManager(_timeManager); + _entityManager = new EntityManager(_componentManager, entityCapacity); + _renderManager = new RenderManager(_entityManager, _drawLayerManager); - startingExistingComponentStore = new ComponentStore(typeToIndex); - startingUpToDateComponentStore = new ComponentStore(typeToIndex); + _startingExistingComponentStore = new ComponentStore(_typeToIndex); + _startingUpToDateComponentStore = new ComponentStore(_typeToIndex); } /// @@ -62,7 +62,7 @@ namespace Encompass /// public Entity CreateEntity() { - return entityManager.CreateEntity(); + return _entityManager.CreateEntity(); } /// @@ -70,7 +70,7 @@ namespace Encompass /// public void SendMessage(TMessage message) where TMessage : struct, IMessage { - messageManager.AddMessage(message); + _messageManager.AddMessage(message); } /// @@ -78,7 +78,7 @@ namespace Encompass /// public void SendMessage(TMessage message, double time) where TMessage : struct, IMessage { - messageManager.AddMessage(message, time); + _messageManager.AddMessage(message, time); } /// @@ -87,31 +87,31 @@ namespace Encompass public void SetComponent(Entity entity, TComponent component) where TComponent : struct, IComponent { RegisterComponentType(); - startingExistingComponentStore.Set(entity.ID, component); - startingUpToDateComponentStore.Set(entity.ID, component); + _startingExistingComponentStore.Set(entity.ID, component); + _startingUpToDateComponentStore.Set(entity.ID, component); if (component is IDrawableComponent drawableComponent) { - componentManager.RegisterDrawableComponent(entity.ID, component, drawableComponent.Layer); - drawLayerManager.RegisterOrderedDrawable(); + _componentManager.RegisterDrawableComponent(entity.ID, component, drawableComponent.Layer); + _drawLayerManager.RegisterOrderedDrawable(); } } internal void RegisterComponentType() where TComponent : struct, IComponent { - if (!typeToIndex.ContainsKey(typeof(TComponent))) + if (!_typeToIndex.ContainsKey(typeof(TComponent))) { - typeToIndex.Add(typeof(TComponent), typeToIndex.Count); - componentTypesToPreload.Add(typeof(TComponent)); - componentManager.RegisterComponentType(); - startingExistingComponentStore.RegisterComponentType(); - startingUpToDateComponentStore.RegisterComponentType(); + _typeToIndex.Add(typeof(TComponent), _typeToIndex.Count); + _componentTypesToPreload.Add(typeof(TComponent)); + _componentManager.RegisterComponentType(); + _startingExistingComponentStore.RegisterComponentType(); + _startingUpToDateComponentStore.RegisterComponentType(); } } internal void RegisterMessageTypes(IEnumerable types) { - messageTypes.UnionWith(types); + _messageTypes.UnionWith(types); } /// @@ -120,21 +120,21 @@ namespace Encompass /// An instance of an Engine. public Engine AddEngine(TEngine engine) where TEngine : Engine { - engine.AssignEntityManager(entityManager); - engine.AssignComponentManager(componentManager); - engine.AssignMessageManager(messageManager); - engine.AssignTimeManager(timeManager); - engine.AssignTrackingManager(trackingManager); + engine.AssignEntityManager(_entityManager); + engine.AssignComponentManager(_componentManager); + engine.AssignMessageManager(_messageManager); + engine.AssignTimeManager(_timeManager); + engine.AssignTrackingManager(_trackingManager); - engines.Add(engine); - engineGraph.AddNode(engine); + _engines.Add(engine); + _engineGraph.AddNode(engine); - var messageReceiveTypes = engine.receiveTypes; - var messageSendTypes = engine.sendTypes; + var messageReceiveTypes = engine.ReceiveTypes; + var messageSendTypes = engine.SendTypes; - RegisterMessageTypes(engine.receiveTypes.Union(engine.sendTypes)); + RegisterMessageTypes(engine.ReceiveTypes.Union(engine.SendTypes)); - foreach (var writeImmediateType in engine.writeImmediateTypes.Intersect(engine.readImmediateTypes)) + foreach (var writeImmediateType in engine.WriteImmediateTypes.Intersect(engine.ReadImmediateTypes)) { throw new EngineSelfCycleException("Engine {0} both writes and reads immediate Component {1}", engine.GetType().Name, writeImmediateType.Name); } @@ -144,28 +144,28 @@ namespace Encompass throw new EngineSelfCycleException("Engine {0} both receives and sends Message {1}", engine.GetType().Name, messageType.Name); } - if (messageSendTypes.Count > 0 || engine.writeImmediateTypes.Count > 0) + if (messageSendTypes.Count > 0 || engine.WriteImmediateTypes.Count > 0) { - senders.Add(engine); + _senders.Add(engine); } - foreach (var componentType in engine.queryWithTypes.Union(engine.queryWithoutTypes)) + foreach (var componentType in engine.QueryWithTypes.Union(engine.QueryWithoutTypes)) { - trackingManager.RegisterComponentTypeToEngine(componentType, engine); - if (engine.readImmediateTypes.Contains(componentType)) + _trackingManager.RegisterComponentTypeToEngine(componentType, engine); + if (engine.ReadImmediateTypes.Contains(componentType)) { - trackingManager.RegisterImmediateComponentTypeToEngine(componentType, engine); + _trackingManager.RegisterImmediateComponentTypeToEngine(componentType, engine); } } - foreach (var receiveType in engine.receiveTypes.Union(engine.readImmediateTypes)) + foreach (var receiveType in engine.ReceiveTypes.Union(engine.ReadImmediateTypes)) { - if (!typeToReaders.ContainsKey(receiveType)) + if (!_typeToReaders.ContainsKey(receiveType)) { - typeToReaders.Add(receiveType, new HashSet()); + _typeToReaders.Add(receiveType, new HashSet()); } - typeToReaders[receiveType].Add(engine); + _typeToReaders[receiveType].Add(engine); } return engine; @@ -177,7 +177,7 @@ namespace Encompass /// The draw layer to register. public void RegisterDrawLayer(int layer) { - drawLayerManager.RegisterDrawLayer(layer); + _drawLayerManager.RegisterDrawLayer(layer); } /// @@ -186,9 +186,9 @@ namespace Encompass public OrderedRenderer AddOrderedRenderer(OrderedRenderer renderer) where TComponent : struct, IComponent, IDrawableComponent { RegisterComponentType(); - renderer.AssignEntityManager(entityManager); - renderer.AssignComponentManager(componentManager); - renderManager.RegisterOrderedRenderer(renderer.InternalRender); + renderer.AssignEntityManager(_entityManager); + renderer.AssignComponentManager(_componentManager); + _renderManager.RegisterOrderedRenderer(renderer.InternalRender); return renderer; } @@ -200,29 +200,29 @@ namespace Encompass /// The layer at which the GeneralRenderer should render. Higher numbers draw over lower numbers. public TRenderer AddGeneralRenderer(TRenderer renderer, int layer) where TRenderer : GeneralRenderer { - renderer.AssignEntityManager(entityManager); - renderer.AssignComponentManager(componentManager); + renderer.AssignEntityManager(_entityManager); + renderer.AssignComponentManager(_componentManager); - renderManager.RegisterGeneralRendererWithLayer(renderer, layer); + _renderManager.RegisterGeneralRendererWithLayer(renderer, layer); return renderer; } private void BuildEngineGraph() { - foreach (var senderEngine in senders) + foreach (var senderEngine in _senders) { - foreach (var messageType in senderEngine.sendTypes.Union(senderEngine.writeImmediateTypes)) + foreach (var messageType in senderEngine.SendTypes.Union(senderEngine.WriteImmediateTypes)) { - if (typeToReaders.ContainsKey(messageType)) + if (_typeToReaders.ContainsKey(messageType)) { - foreach (var readerEngine in typeToReaders[messageType]) + foreach (var readerEngine in _typeToReaders[messageType]) { if (senderEngine != readerEngine) { - if (!engineGraph.Exists(senderEngine, readerEngine)) + if (!_engineGraph.Exists(senderEngine, readerEngine)) { - engineGraph.AddEdge(senderEngine, readerEngine); + _engineGraph.AddEdge(senderEngine, readerEngine); } } } @@ -240,9 +240,9 @@ namespace Encompass { BuildEngineGraph(); - if (engineGraph.Cyclic()) + if (_engineGraph.Cyclic()) { - var cycles = engineGraph.SimpleCycles(); + var cycles = _engineGraph.SimpleCycles(); var errorString = "Cycle(s) found in Engines: "; foreach (var cycle in cycles) { @@ -262,25 +262,25 @@ namespace Encompass var writePriorities = new Dictionary>(); var writeMessageToEngines = new Dictionary>(); - foreach (var engine in engines) + foreach (var engine in _engines) { if (engine.GetType().GetCustomAttribute() != null) { - engine.usesTimeDilation = false; + engine._usesTimeDilation = false; } var defaultWritePriorityAttribute = engine.GetType().GetCustomAttribute(false); - foreach (var writeType in engine.writeTypes) + foreach (var writeType in engine.WriteTypes) { int? priority = null; - if (engine.writePriorities.ContainsKey(writeType)) + if (engine.WritePriorities.ContainsKey(writeType)) { - priority = engine.writePriorities[writeType]; + priority = engine.WritePriorities[writeType]; } else if (defaultWritePriorityAttribute != null) { - priority = defaultWritePriorityAttribute.writePriority; + priority = defaultWritePriorityAttribute.WritePriority; } if (priority.HasValue) @@ -368,11 +368,11 @@ namespace Encompass } } - PreloadJIT(componentTypesToPreload, messageTypes); + PreloadJIT(_componentTypesToPreload, _messageTypes); var engineOrder = new List(); - foreach (var engine in engineGraph.TopologicalSort()) + foreach (var engine in _engineGraph.TopologicalSort()) { engineOrder.Add(engine); engine.BuildEntityQuery(); @@ -380,18 +380,18 @@ namespace Encompass var world = new World( engineOrder, - entityManager, - componentManager, - trackingManager, - messageManager, - timeManager, - renderManager + _entityManager, + _componentManager, + _trackingManager, + _messageManager, + _timeManager, + _renderManager ); - componentManager.SetExistingComponentStore(startingExistingComponentStore); - componentManager.SetUpToDateComponentStore(startingUpToDateComponentStore); + _componentManager.SetExistingComponentStore(_startingExistingComponentStore); + _componentManager.SetUpToDateComponentStore(_startingUpToDateComponentStore); - trackingManager.InitializeTracking(entityManager.EntityIDs); + _trackingManager.InitializeTracking(_entityManager.EntityIDs); return world; } @@ -406,10 +406,10 @@ namespace Encompass { var dummyTimeManager = new TimeManager(); var dummyMessageManager = new MessageManager(dummyTimeManager); - var dummyDrawLayerManager = new DrawLayerManager(typeToIndex); + var dummyDrawLayerManager = new DrawLayerManager(_typeToIndex); var dummyTrackingManager = new TrackingManager(); - var dummyComponentManager = new ComponentManager(dummyDrawLayerManager, typeToIndex); - var dummyEntityManager = new EntityManager(dummyComponentManager, entityCapacity); + var dummyComponentManager = new ComponentManager(dummyDrawLayerManager, _typeToIndex); + var dummyEntityManager = new EntityManager(dummyComponentManager, _entityCapacity); var dummyRenderManager = new RenderManager(dummyEntityManager, dummyDrawLayerManager); var prepEngineOrder = new List();