optimize singular entity message read
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
971993f605
commit
5a536e6123
|
@ -53,6 +53,11 @@ namespace Encompass
|
||||||
return Lookup<TMessage>().WithEntity(entityID);
|
return Lookup<TMessage>().WithEntity(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ref readonly TMessage FirstWithEntity<TMessage>(int entityID) where TMessage : struct, IMessage
|
||||||
|
{
|
||||||
|
return ref Lookup<TMessage>().FirstWithEntity(entityID);
|
||||||
|
}
|
||||||
|
|
||||||
public bool SomeWithEntity<TMessage>(int entityID) where TMessage : struct, IMessage, IHasEntity
|
public bool SomeWithEntity<TMessage>(int entityID) where TMessage : struct, IMessage, IHasEntity
|
||||||
{
|
{
|
||||||
return Lookup<TMessage>().SomeWithEntity(entityID);
|
return Lookup<TMessage>().SomeWithEntity(entityID);
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Encompass
|
||||||
private readonly TMessage[] _store = new TMessage[128];
|
private readonly TMessage[] _store = new TMessage[128];
|
||||||
private readonly List<(TMessage, double)> _delayedStore = new List<(TMessage, double)>(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 List<(TMessage, double)> _delayedStoreIgnoringTimeDilation = new List<(TMessage, double)>(128);
|
||||||
private readonly Dictionary<int, HashSet<int>> _entityToIndices = new Dictionary<int, HashSet<int>>();
|
private readonly Dictionary<int, List<int>> _entityToIndices = new Dictionary<int, List<int>>();
|
||||||
|
|
||||||
public override void ProcessDelayedMessages(double dilatedDelta, double realtimeDelta)
|
public override void ProcessDelayedMessages(double dilatedDelta, double realtimeDelta)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ namespace Encompass
|
||||||
if (message is IHasEntity entityMessage)
|
if (message is IHasEntity entityMessage)
|
||||||
{
|
{
|
||||||
var entityID = entityMessage.Entity.ID;
|
var entityID = entityMessage.Entity.ID;
|
||||||
if (!_entityToIndices.ContainsKey(entityID)) { _entityToIndices.Add(entityID, new HashSet<int>()); }
|
if (!_entityToIndices.ContainsKey(entityID)) { _entityToIndices.Add(entityID, new List<int>()); }
|
||||||
_entityToIndices[entityID].Add(index);
|
_entityToIndices[entityID].Add(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,11 @@ namespace Encompass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ref readonly TMessage FirstWithEntity(int entityID)
|
||||||
|
{
|
||||||
|
return ref _store[_entityToIndices[entityID][0]];
|
||||||
|
}
|
||||||
|
|
||||||
public bool SomeWithEntity(int entityID)
|
public bool SomeWithEntity(int entityID)
|
||||||
{
|
{
|
||||||
return _entityToIndices.ContainsKey(entityID) && _entityToIndices[entityID].Count > 0;
|
return _entityToIndices.ContainsKey(entityID) && _entityToIndices[entityID].Count > 0;
|
||||||
|
|
|
@ -58,11 +58,9 @@ namespace Encompass
|
||||||
return _messageStore.WithEntity<TMessage>(entityID);
|
return _messageStore.WithEntity<TMessage>(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal TMessage WithEntitySingular<TMessage>(int entityID) where TMessage : struct, IMessage, IHasEntity
|
internal ref readonly TMessage WithEntitySingular<TMessage>(int entityID) where TMessage : struct, IMessage, IHasEntity
|
||||||
{
|
{
|
||||||
var enumerator = _messageStore.WithEntity<TMessage>(entityID).GetEnumerator();
|
return ref _messageStore.FirstWithEntity<TMessage>(entityID);
|
||||||
enumerator.MoveNext();
|
|
||||||
return enumerator.Current;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool SomeWithEntity<TMessage>(int entityID) where TMessage : struct, IMessage, IHasEntity
|
internal bool SomeWithEntity<TMessage>(int entityID) where TMessage : struct, IMessage, IHasEntity
|
||||||
|
|
Loading…
Reference in New Issue