fix style issues
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
ffc052ded3
commit
7f89e9b4a0
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Encompass
|
|||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class QueryWith : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> queryWithTypes = new HashSet<Type>();
|
||||
public readonly HashSet<Type> QueryWithTypes = new HashSet<Type>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Encompass
|
|||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class QueryWithout : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> queryWithoutTypes = new HashSet<Type>();
|
||||
public readonly HashSet<Type> QueryWithoutTypes = new HashSet<Type>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Encompass
|
|||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class Reads : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> readTypes = new HashSet<Type>();
|
||||
public readonly HashSet<Type> ReadTypes = new HashSet<Type>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Encompass
|
|||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ReadsImmediate : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> readImmediateTypes = new HashSet<Type>();
|
||||
public readonly HashSet<Type> ReadImmediateTypes = new HashSet<Type>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Encompass
|
|||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class Receives : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> receiveTypes;
|
||||
public readonly HashSet<Type> ReceiveTypes;
|
||||
|
||||
public Receives(params Type[] receiveTypes)
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ namespace Encompass
|
|||
}
|
||||
}
|
||||
|
||||
this.receiveTypes = new HashSet<Type>(receiveTypes);
|
||||
ReceiveTypes = new HashSet<Type>(receiveTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Encompass
|
|||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class Sends : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> sendTypes;
|
||||
public readonly HashSet<Type> SendTypes;
|
||||
|
||||
public Sends(params Type[] sendTypes)
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ namespace Encompass
|
|||
}
|
||||
}
|
||||
|
||||
this.sendTypes = new HashSet<Type>(sendTypes);
|
||||
this.SendTypes = new HashSet<Type>(sendTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ namespace Encompass
|
|||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
|
||||
public class Writes : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> writeTypes = new HashSet<Type>();
|
||||
public Dictionary<Type, int> priorities = new Dictionary<Type, int>();
|
||||
public readonly HashSet<Type> WriteTypes = new HashSet<Type>();
|
||||
public readonly Dictionary<Type, int> Priorities = new Dictionary<Type, int>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Encompass
|
|||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class WritesImmediate : Attribute
|
||||
{
|
||||
public readonly HashSet<Type> writeImmediateTypes = new HashSet<Type>();
|
||||
public readonly HashSet<Type> WriteImmediateTypes = new HashSet<Type>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,49 +6,49 @@ namespace Encompass
|
|||
{
|
||||
internal class ComponentBitSet
|
||||
{
|
||||
Dictionary<int, BitSet512> entities = new Dictionary<int, BitSet512>();
|
||||
Dictionary<Type, int> TypeToIndex { get; }
|
||||
private readonly Dictionary<int, BitSet512> _entities = new Dictionary<int, BitSet512>();
|
||||
private readonly Dictionary<Type, int> _typeToIndex;
|
||||
|
||||
public ComponentBitSet(Dictionary<Type, int> 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<TComponent>(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<TComponent>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,9 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Encompass
|
||||
{
|
||||
public struct MutableComponentEntityPair<TComponent> where TComponent : struct, IComponent
|
||||
{
|
||||
public TComponent component;
|
||||
}
|
||||
|
||||
internal class ComponentStore
|
||||
{
|
||||
private Dictionary<Type, TypedComponentStore> Stores = new Dictionary<Type, TypedComponentStore>(512);
|
||||
private Dictionary<Type, TypedComponentStore> _stores = new Dictionary<Type, TypedComponentStore>(512);
|
||||
public ComponentBitSet ComponentBitSet { get; private set; }
|
||||
|
||||
public ComponentStore(Dictionary<Type, int> 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<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
if (!Stores.ContainsKey(typeof(TComponent)))
|
||||
if (!_stores.ContainsKey(typeof(TComponent)))
|
||||
{
|
||||
var store = new TypedComponentStore<TComponent>();
|
||||
Stores.Add(typeof(TComponent), store);
|
||||
_stores.Add(typeof(TComponent), store);
|
||||
}
|
||||
}
|
||||
|
||||
private TypedComponentStore<TComponent> Lookup<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
return Stores[typeof(TComponent)] as TypedComponentStore<TComponent>;
|
||||
return _stores[typeof(TComponent)] as TypedComponentStore<TComponent>;
|
||||
}
|
||||
|
||||
public bool Has<TComponent>(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,17 +5,17 @@ namespace Encompass
|
|||
{
|
||||
internal class MessageStore
|
||||
{
|
||||
private Dictionary<Type, TypedMessageStore> Stores = new Dictionary<Type, TypedMessageStore>(512);
|
||||
private readonly Dictionary<Type, TypedMessageStore> _stores = new Dictionary<Type, TypedMessageStore>(512);
|
||||
|
||||
private void RegisterMessageType<TMessage>() where TMessage : struct, IMessage
|
||||
{
|
||||
Stores.Add(typeof(TMessage), new TypedMessageStore<TMessage>());
|
||||
_stores.Add(typeof(TMessage), new TypedMessageStore<TMessage>());
|
||||
}
|
||||
|
||||
private TypedMessageStore<TMessage> Lookup<TMessage>() where TMessage : struct, IMessage
|
||||
{
|
||||
if (!Stores.ContainsKey(typeof(TMessage))) { RegisterMessageType<TMessage>(); }
|
||||
return Stores[typeof(TMessage)] as TypedMessageStore<TMessage>;
|
||||
if (!_stores.ContainsKey(typeof(TMessage))) { RegisterMessageType<TMessage>(); }
|
||||
return _stores[typeof(TMessage)] as TypedMessageStore<TMessage>;
|
||||
}
|
||||
|
||||
public void AddMessage<TMessage>(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();
|
||||
}
|
||||
|
|
|
@ -17,17 +17,17 @@ namespace Encompass
|
|||
|
||||
internal class TypedComponentStore<TComponent> : TypedComponentStore where TComponent : struct, IComponent
|
||||
{
|
||||
private readonly Dictionary<int, int> indices = new Dictionary<int, int>(512);
|
||||
private readonly Dictionary<int, int> priorities = new Dictionary<int, int>(512);
|
||||
private TComponent[] components = new TComponent[512];
|
||||
private readonly Dictionary<int, int> _indices = new Dictionary<int, int>(512);
|
||||
private readonly Dictionary<int, int> _priorities = new Dictionary<int, int>(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<TComponent>(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<TComponent>(ptr);
|
||||
_components[_indices[entityID]] = Unsafe.AsRef<TComponent>(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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,98 +10,98 @@ namespace Encompass
|
|||
|
||||
internal class TypedMessageStore<TMessage> : TypedMessageStore where TMessage : struct, IMessage
|
||||
{
|
||||
private readonly List<TMessage> store = new List<TMessage>(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<int, List<TMessage>> entityToMessage = new Dictionary<int, List<TMessage>>();
|
||||
private readonly List<TMessage> _store = new List<TMessage>(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<int, List<TMessage>> _entityToMessage = new Dictionary<int, List<TMessage>>();
|
||||
|
||||
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<TMessage>()); }
|
||||
entityToMessage[entityID].Add(message);
|
||||
if (!_entityToMessage.ContainsKey(entityID)) { _entityToMessage.Add(entityID, new List<TMessage>()); }
|
||||
_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<TMessage> All()
|
||||
{
|
||||
return store;
|
||||
return _store;
|
||||
}
|
||||
|
||||
public IEnumerable<TMessage> WithEntity(int entityID)
|
||||
{
|
||||
return entityToMessage.ContainsKey(entityID) ? entityToMessage[entityID] : System.Linq.Enumerable.Empty<TMessage>();
|
||||
return _entityToMessage.ContainsKey(entityID) ? _entityToMessage[entityID] : System.Linq.Enumerable.Empty<TMessage>();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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<Type, int> TypeToIndex { get; }
|
||||
|
||||
private readonly HashSet<int> entitiesMarkedForRemoval = new HashSet<int>();
|
||||
private readonly HashSet<int> _entitiesMarkedForRemoval = new HashSet<int>();
|
||||
|
||||
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<Type, int> 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<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
existingComponentStore.RegisterComponentType<TComponent>();
|
||||
immediateComponentStore.RegisterComponentType<TComponent>();
|
||||
replayStore.RegisterComponentType<TComponent>();
|
||||
upToDateComponentStore.RegisterComponentType<TComponent>();
|
||||
_existingComponentStore.RegisterComponentType<TComponent>();
|
||||
_immediateComponentStore.RegisterComponentType<TComponent>();
|
||||
_replayStore.RegisterComponentType<TComponent>();
|
||||
_upToDateComponentStore.RegisterComponentType<TComponent>();
|
||||
}
|
||||
|
||||
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<TComponent>(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<TComponent>(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<TComponent>(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<TComponent>(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<TComponent>(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<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
return upToDateComponentStore.All<TComponent>();
|
||||
return _upToDateComponentStore.All<TComponent>();
|
||||
}
|
||||
|
||||
internal (TComponent, int) ReadFirstExistingOrImmediateComponentByType<TComponent>() where TComponent : struct, IComponent
|
||||
|
@ -113,7 +113,7 @@ namespace Encompass
|
|||
|
||||
internal bool SomeExistingOrImmediateComponent<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
return upToDateComponentStore.Any<TComponent>();
|
||||
return _upToDateComponentStore.Any<TComponent>();
|
||||
}
|
||||
|
||||
// existing reads
|
||||
|
@ -128,14 +128,14 @@ namespace Encompass
|
|||
|
||||
internal bool SomeExistingComponent<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
return existingComponentStore.Any<TComponent>();
|
||||
return _existingComponentStore.Any<TComponent>();
|
||||
}
|
||||
|
||||
// immediate reads
|
||||
|
||||
internal IEnumerable<(TComponent, int)> ReadImmediateComponentsByType<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
return immediateComponentStore.All<TComponent>();
|
||||
return _immediateComponentStore.All<TComponent>();
|
||||
}
|
||||
|
||||
internal (TComponent, int) ReadFirstImmediateComponentByType<TComponent>() where TComponent : struct, IComponent
|
||||
|
@ -148,66 +148,66 @@ namespace Encompass
|
|||
|
||||
internal bool SomeImmediateComponent<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
return immediateComponentStore.Any<TComponent>();
|
||||
return _immediateComponentStore.Any<TComponent>();
|
||||
}
|
||||
|
||||
// component getters
|
||||
|
||||
internal ref readonly TComponent ReadImmediateOrExistingComponentByEntityAndType<TComponent>(int entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
return ref upToDateComponentStore.Get<TComponent>(entityID);
|
||||
return ref _upToDateComponentStore.Get<TComponent>(entityID);
|
||||
}
|
||||
|
||||
internal ref readonly TComponent ReadExistingComponentByEntityAndType<TComponent>(int entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
return ref existingComponentStore.Get<TComponent>(entityID);
|
||||
return ref _existingComponentStore.Get<TComponent>(entityID);
|
||||
}
|
||||
|
||||
internal ref readonly TComponent ReadImmediateComponentByEntityAndType<TComponent>(int entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
return ref immediateComponentStore.Get<TComponent>(entityID);
|
||||
return ref _immediateComponentStore.Get<TComponent>(entityID);
|
||||
}
|
||||
|
||||
// has checkers
|
||||
|
||||
internal bool HasExistingOrImmediateComponent<TComponent>(int entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
return upToDateComponentStore.Has<TComponent>(entityID);
|
||||
return _upToDateComponentStore.Has<TComponent>(entityID);
|
||||
}
|
||||
|
||||
internal bool HasExistingOrImmediateComponent(int entityID, Type type)
|
||||
{
|
||||
return upToDateComponentStore.Has(type, entityID);
|
||||
return _upToDateComponentStore.Has(type, entityID);
|
||||
}
|
||||
|
||||
internal bool HasExistingComponent<TComponent>(int entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
return existingComponentStore.Has<TComponent>(entityID);
|
||||
return _existingComponentStore.Has<TComponent>(entityID);
|
||||
}
|
||||
|
||||
internal bool HasExistingComponent(int entityID, Type type)
|
||||
{
|
||||
return existingComponentStore.Has(type, entityID);
|
||||
return _existingComponentStore.Has(type, entityID);
|
||||
}
|
||||
|
||||
internal bool HasImmediateComponent<TComponent>(int entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
return immediateComponentStore.Has<TComponent>(entityID);
|
||||
return _immediateComponentStore.Has<TComponent>(entityID);
|
||||
}
|
||||
|
||||
internal bool HasImmediateComponent(int entityID, Type type)
|
||||
{
|
||||
return immediateComponentStore.Has(type, entityID);
|
||||
return _immediateComponentStore.Has(type, entityID);
|
||||
}
|
||||
|
||||
internal IEnumerable<(TComponent, int)> GetComponentsIncludingEntity<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
return existingComponentStore.All<TComponent>();
|
||||
return _existingComponentStore.All<TComponent>();
|
||||
}
|
||||
|
||||
internal IEnumerable<TComponent> GetComponentsByType<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
foreach (var pair in existingComponentStore.All<TComponent>())
|
||||
foreach (var pair in _existingComponentStore.All<TComponent>())
|
||||
{
|
||||
yield return pair.Item1;
|
||||
}
|
||||
|
@ -215,40 +215,40 @@ namespace Encompass
|
|||
|
||||
internal ref readonly TComponent GetComponentByEntityAndType<TComponent>(int entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
return ref existingComponentStore.Get<TComponent>(entityID);
|
||||
return ref _existingComponentStore.Get<TComponent>(entityID);
|
||||
}
|
||||
|
||||
internal bool EntityHasComponentOfType<TComponent>(int entityID) where TComponent : struct, IComponent
|
||||
{
|
||||
return existingComponentStore.Has<TComponent>(entityID);
|
||||
return _existingComponentStore.Has<TComponent>(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<TComponent>(int entityID, int priority) where TComponent : struct, IComponent
|
||||
{
|
||||
if (immediateComponentStore.Remove<TComponent>(entityID, priority))
|
||||
if (_immediateComponentStore.Remove<TComponent>(entityID, priority))
|
||||
{
|
||||
replayStore.Remove<TComponent>(entityID, priority);
|
||||
upToDateComponentStore.Remove<TComponent>(entityID, priority);
|
||||
drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entityID);
|
||||
_replayStore.Remove<TComponent>(entityID, priority);
|
||||
_upToDateComponentStore.Remove<TComponent>(entityID, priority);
|
||||
_drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entityID);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -256,16 +256,16 @@ namespace Encompass
|
|||
|
||||
public void Remove<TComponent>(int entityID, int priority) where TComponent : struct, IComponent
|
||||
{
|
||||
if (upToDateComponentStore.Remove<TComponent>(entityID, priority))
|
||||
if (_upToDateComponentStore.Remove<TComponent>(entityID, priority))
|
||||
{
|
||||
replayStore.Remove<TComponent>(entityID, priority);
|
||||
drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entityID);
|
||||
_replayStore.Remove<TComponent>(entityID, priority);
|
||||
_drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entityID);
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpToDateEntityIsEmpty(int entityID)
|
||||
{
|
||||
return upToDateComponentStore.EntityBitArray(entityID).AllFalse();
|
||||
return _upToDateComponentStore.EntityBitArray(entityID).AllFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,39 +7,39 @@ namespace Encompass
|
|||
{
|
||||
internal class DrawLayerManager
|
||||
{
|
||||
private readonly SortedList<int, int> layerOrder = new SortedList<int, int>();
|
||||
private readonly SortedList<int, int> _layerOrder = new SortedList<int, int>();
|
||||
|
||||
private readonly Dictionary<int, ComponentStore> layerIndexToComponentStore = new Dictionary<int, ComponentStore>(512);
|
||||
private readonly Dictionary<int, HashSet<GeneralRenderer>> layerIndexToGeneralRenderers = new Dictionary<int, HashSet<GeneralRenderer>>(512);
|
||||
private readonly Dictionary<int, ComponentStore> _layerIndexToComponentStore = new Dictionary<int, ComponentStore>(512);
|
||||
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);
|
||||
private Dictionary<Type, int> typeToIndex;
|
||||
public IEnumerable<int> LayerOrder { get { return layerOrder.Values; } }
|
||||
private readonly Dictionary<Type, Dictionary<int, int>> _typeToEntityToLayer = new Dictionary<Type, Dictionary<int, int>>(512);
|
||||
private readonly Dictionary<Type, int> _typeToIndex;
|
||||
public IEnumerable<int> LayerOrder { get { return _layerOrder.Values; } }
|
||||
|
||||
public DrawLayerManager(Dictionary<Type, int> 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<GeneralRenderer>());
|
||||
layerIndexToComponentStore.Add(layer, new ComponentStore(typeToIndex));
|
||||
_layerOrder.Add(layer, layer);
|
||||
_layerIndexToGeneralRenderers.Add(layer, new HashSet<GeneralRenderer>());
|
||||
_layerIndexToComponentStore.Add(layer, new ComponentStore(_typeToIndex));
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterOrderedDrawable<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
if (!typeToEntityToLayer.ContainsKey(typeof(TComponent)))
|
||||
if (!_typeToEntityToLayer.ContainsKey(typeof(TComponent)))
|
||||
{
|
||||
typeToEntityToLayer.Add(typeof(TComponent), new Dictionary<int, int>(128));
|
||||
_typeToEntityToLayer.Add(typeof(TComponent), new Dictionary<int, int>(128));
|
||||
}
|
||||
|
||||
foreach (var pair in layerIndexToComponentStore)
|
||||
foreach (var pair in _layerIndexToComponentStore)
|
||||
{
|
||||
pair.Value.RegisterComponentType<TComponent>();
|
||||
}
|
||||
|
@ -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<TComponent>(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<TComponent>(entityID); }
|
||||
if (_typeToEntityToLayer[typeof(TComponent)].ContainsKey(entityID)) { UnRegisterComponentWithLayer<TComponent>(entityID); }
|
||||
|
||||
var set = layerIndexToComponentStore[layer];
|
||||
var set = _layerIndexToComponentStore[layer];
|
||||
set.Set<TComponent>(entityID, component);
|
||||
|
||||
typeToEntityToLayer[typeof(TComponent)].Add(entityID, layer);
|
||||
_typeToEntityToLayer[typeof(TComponent)].Add(entityID, layer);
|
||||
}
|
||||
|
||||
public void UnRegisterComponentWithLayer<TComponent>(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<TComponent>(entityID);
|
||||
var layer = _typeToEntityToLayer[typeof(TComponent)][entityID];
|
||||
_layerIndexToComponentStore[layer].ForceRemove<TComponent>(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<GeneralRenderer> GeneralRenderersByLayer(int layer)
|
||||
{
|
||||
return layerIndexToGeneralRenderers.ContainsKey(layer) ?
|
||||
layerIndexToGeneralRenderers[layer] :
|
||||
return _layerIndexToGeneralRenderers.ContainsKey(layer) ?
|
||||
_layerIndexToGeneralRenderers[layer] :
|
||||
Enumerable.Empty<GeneralRenderer>();
|
||||
}
|
||||
|
||||
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)>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,104 +14,104 @@ namespace Encompass
|
|||
/// </summary>
|
||||
public abstract class Engine : IEquatable<Engine>
|
||||
{
|
||||
internal Guid ID;
|
||||
internal Guid _id;
|
||||
|
||||
internal readonly HashSet<Type> readTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> readImmediateTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> sendTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> receiveTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> writeTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> writeImmediateTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> queryWithTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> queryWithoutTypes = new HashSet<Type>();
|
||||
internal readonly Dictionary<Type, int> writePriorities = new Dictionary<Type, int>();
|
||||
internal readonly int defaultWritePriority = 0;
|
||||
internal readonly HashSet<Type> ReadTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> ReadImmediateTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> SendTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> ReceiveTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> WriteTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> WriteImmediateTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> QueryWithTypes = new HashSet<Type>();
|
||||
internal readonly HashSet<Type> QueryWithoutTypes = new HashSet<Type>();
|
||||
internal readonly Dictionary<Type, int> WritePriorities = new Dictionary<Type, int>();
|
||||
internal readonly int DefaultWritePriority = 0;
|
||||
|
||||
/// <summary>
|
||||
/// If false, the Engine will ignore time dilation.
|
||||
/// </summary>
|
||||
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<int> _trackedEntities = new HashSet<int>();
|
||||
private readonly HashSet<int> _trackedEntities = new HashSet<int>();
|
||||
protected IEnumerable<Entity> TrackedEntities
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var entityID in _trackedEntities)
|
||||
{
|
||||
yield return entityManager.GetEntity(entityID);
|
||||
yield return _entityManager.GetEntity(entityID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<int> _newlyCreatedEntities = new HashSet<int>();
|
||||
private readonly HashSet<int> _newlyCreatedEntities = new HashSet<int>();
|
||||
|
||||
protected Engine()
|
||||
{
|
||||
ID = Guid.NewGuid();
|
||||
_id = Guid.NewGuid();
|
||||
|
||||
var sendsAttribute = GetType().GetCustomAttribute<Sends>(false);
|
||||
if (sendsAttribute != null)
|
||||
{
|
||||
sendTypes = sendsAttribute.sendTypes;
|
||||
SendTypes = sendsAttribute.SendTypes;
|
||||
}
|
||||
|
||||
var activatesAttribute = GetType().GetCustomAttribute<WritesImmediate>(false);
|
||||
if (activatesAttribute != null)
|
||||
{
|
||||
writeImmediateTypes = activatesAttribute.writeImmediateTypes;
|
||||
WriteImmediateTypes = activatesAttribute.WriteImmediateTypes;
|
||||
}
|
||||
|
||||
var defaultWritePriorityAttribute = GetType().GetCustomAttribute<DefaultWritePriority>(false);
|
||||
|
||||
if (defaultWritePriorityAttribute != null)
|
||||
{
|
||||
defaultWritePriority = defaultWritePriorityAttribute.writePriority;
|
||||
DefaultWritePriority = defaultWritePriorityAttribute.WritePriority;
|
||||
}
|
||||
|
||||
foreach (var writesAttribute in GetType().GetCustomAttributes<Writes>(false))
|
||||
{
|
||||
writeTypes.UnionWith(writesAttribute.writeTypes);
|
||||
writePriorities = new Dictionary<Type, int>[2] { writePriorities, writesAttribute.priorities }.SelectMany(dict => dict).ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
WriteTypes.UnionWith(writesAttribute.WriteTypes);
|
||||
WritePriorities = new Dictionary<Type, int>[2] { WritePriorities, writesAttribute.Priorities }.SelectMany(dict => dict).ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
}
|
||||
|
||||
var receivesAttribute = GetType().GetCustomAttribute<Receives>(false);
|
||||
if (receivesAttribute != null)
|
||||
{
|
||||
receiveTypes = receivesAttribute.receiveTypes;
|
||||
ReceiveTypes = receivesAttribute.ReceiveTypes;
|
||||
}
|
||||
|
||||
var readsAttribute = GetType().GetCustomAttribute<Reads>(false);
|
||||
if (readsAttribute != null)
|
||||
{
|
||||
readTypes = readsAttribute.readTypes;
|
||||
ReadTypes = readsAttribute.ReadTypes;
|
||||
}
|
||||
|
||||
var readsImmediateAttribute = GetType().GetCustomAttribute<ReadsImmediate>(false);
|
||||
if (readsImmediateAttribute != null)
|
||||
{
|
||||
readImmediateTypes = readsImmediateAttribute.readImmediateTypes;
|
||||
ReadImmediateTypes = readsImmediateAttribute.ReadImmediateTypes;
|
||||
}
|
||||
|
||||
var queryWithAttribute = GetType().GetCustomAttribute<QueryWith>(false);
|
||||
if (queryWithAttribute != null)
|
||||
{
|
||||
queryWithTypes = queryWithAttribute.queryWithTypes;
|
||||
QueryWithTypes = queryWithAttribute.QueryWithTypes.ToHashSet();
|
||||
}
|
||||
|
||||
var queryWithoutAttribute = GetType().GetCustomAttribute<QueryWithout>(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;
|
||||
}
|
||||