more cleanup
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
63e9ca63c0
commit
b6ae9eaebc
|
@ -54,8 +54,7 @@ namespace Encompass
|
|||
_indices[entityID] = _idManager.NextID();
|
||||
}
|
||||
|
||||
var ptr = Unsafe.AsPointer(ref component);
|
||||
_components[_indices[entityID]] = Unsafe.AsRef<TComponent>(ptr);
|
||||
_components[_indices[entityID]] = Unsafe.AsRef<TComponent>(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Encompass
|
|||
{
|
||||
private readonly SortedList<int, int> _layerOrder = new SortedList<int, int>();
|
||||
|
||||
private readonly Dictionary<int, Dictionary<Type, HashSet<int>>> _layerIndexToComponentStore = new Dictionary<int, Dictionary<Type, HashSet<int>>>();
|
||||
private readonly Dictionary<int, Dictionary<Type, HashSet<int>>> _layerIndexToTypeToID = new Dictionary<int, Dictionary<Type, HashSet<int>>>();
|
||||
private readonly Dictionary<int, HashSet<GeneralRenderer>> _layerIndexToGeneralRenderers = new Dictionary<int, HashSet<GeneralRenderer>>(512);
|
||||
|
||||
private readonly Dictionary<Type, Dictionary<int, int>> _typeToEntityToLayer = new Dictionary<Type, Dictionary<int, int>>(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<GeneralRenderer>());
|
||||
_layerIndexToComponentStore.Add(layer, new Dictionary<Type, HashSet<int>>());
|
||||
_layerIndexToTypeToID.Add(layer, new Dictionary<Type, HashSet<int>>());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace Encompass
|
|||
_typeToEntityToLayer.Add(typeof(TComponent), new Dictionary<int, int>(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<TComponent>(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<TComponent>(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)
|
||||
{
|
||||
|
|
|
@ -2,6 +2,6 @@ namespace Encompass
|
|||
{
|
||||
public interface IDrawableComponent
|
||||
{
|
||||
int Layer { get; set; }
|
||||
int Layer { get; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue