diff --git a/encompass-cs/Collections/TypedComponentStore.cs b/encompass-cs/Collections/TypedComponentStore.cs index 3f41e56..e1caa24 100644 --- a/encompass-cs/Collections/TypedComponentStore.cs +++ b/encompass-cs/Collections/TypedComponentStore.cs @@ -54,8 +54,7 @@ namespace Encompass _indices[entityID] = _idManager.NextID(); } - var ptr = Unsafe.AsPointer(ref component); - _components[_indices[entityID]] = Unsafe.AsRef(ptr); + _components[_indices[entityID]] = Unsafe.AsRef(Unsafe.AsPointer(ref component)); } public override bool Remove(int entityID, int priority) @@ -63,9 +62,7 @@ namespace Encompass if (!_priorities.ContainsKey(entityID) || priority < _priorities[entityID]) { _priorities[entityID] = priority; - _indices.Remove(entityID); - _priorities.Remove(entityID); - _idManager.Free(entityID); + ForceRemove(entityID); return true; } diff --git a/encompass-cs/DrawLayerManager.cs b/encompass-cs/DrawLayerManager.cs index b8b8653..3c14f21 100644 --- a/encompass-cs/DrawLayerManager.cs +++ b/encompass-cs/DrawLayerManager.cs @@ -9,7 +9,7 @@ namespace Encompass { private readonly SortedList _layerOrder = new SortedList(); - private readonly Dictionary>> _layerIndexToComponentStore = new Dictionary>>(); + private readonly Dictionary>> _layerIndexToTypeToID = new Dictionary>>(); private readonly Dictionary> _layerIndexToGeneralRenderers = new Dictionary>(512); private readonly Dictionary> _typeToEntityToLayer = new Dictionary>(512); @@ -22,11 +22,11 @@ namespace Encompass public void RegisterDrawLayer(int layer) { - if (!_layerIndexToComponentStore.ContainsKey(layer)) + if (!_layerIndexToTypeToID.ContainsKey(layer)) { _layerOrder.Add(layer, layer); _layerIndexToGeneralRenderers.Add(layer, new HashSet()); - _layerIndexToComponentStore.Add(layer, new Dictionary>()); + _layerIndexToTypeToID.Add(layer, new Dictionary>()); } } @@ -37,7 +37,7 @@ namespace Encompass _typeToEntityToLayer.Add(typeof(TComponent), new Dictionary(128)); } - foreach (var pair in _layerIndexToComponentStore) + foreach (var pair in _layerIndexToTypeToID) { if (!pair.Value.ContainsKey(typeof(TComponent))) { @@ -55,14 +55,14 @@ namespace Encompass public void RegisterComponentWithLayer(int entityID, int layer) where TComponent : struct, IComponent { - if (!_layerIndexToComponentStore.ContainsKey(layer)) + if (!_layerIndexToTypeToID.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); } - var set = _layerIndexToComponentStore[layer][typeof(TComponent)]; + var set = _layerIndexToTypeToID[layer][typeof(TComponent)]; set.Add(entityID); _typeToEntityToLayer[typeof(TComponent)].Add(entityID, layer); @@ -75,14 +75,14 @@ namespace Encompass if (_typeToEntityToLayer[typeof(TComponent)].ContainsKey(entityID)) { var layer = _typeToEntityToLayer[typeof(TComponent)][entityID]; - _layerIndexToComponentStore[layer][typeof(TComponent)].Remove(entityID); + _layerIndexToTypeToID[layer][typeof(TComponent)].Remove(entityID); } _typeToEntityToLayer[typeof(TComponent)].Remove(entityID); } public void UnRegisterEntityWithLayer(int entityID) { - foreach (var store in _layerIndexToComponentStore.Values) + foreach (var store in _layerIndexToTypeToID.Values) { foreach (var set in store.Values) { @@ -100,7 +100,7 @@ namespace Encompass public IEnumerable<(int, Type)> AllInLayer(int layer) { - foreach (var kvp in _layerIndexToComponentStore[layer]) + foreach (var kvp in _layerIndexToTypeToID[layer]) { foreach (var id in kvp.Value) { diff --git a/encompass-cs/Interfaces/IDrawableComponent.cs b/encompass-cs/Interfaces/IDrawableComponent.cs index e292d90..d150624 100644 --- a/encompass-cs/Interfaces/IDrawableComponent.cs +++ b/encompass-cs/Interfaces/IDrawableComponent.cs @@ -2,6 +2,6 @@ namespace Encompass { public interface IDrawableComponent { - int Layer { get; set; } + int Layer { get; } } -} \ No newline at end of file +}