rename pending to immediate

pull/5/head
Evan Hemsley 2019-12-23 19:04:26 -08:00
parent 2076919f06
commit bd17a86dec
15 changed files with 212 additions and 217 deletions

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Encompass.Exceptions;
namespace Encompass
{
[AttributeUsage(AttributeTargets.Class)]
public class ReadsImmediate : Attribute
{
public readonly HashSet<Type> readImmediateTypes = new HashSet<Type>();
public ReadsImmediate(params Type[] readImmediateTypes)
{
foreach (var readImmediateType in readImmediateTypes)
{
var isComponent = readImmediateType.GetInterfaces().Contains(typeof(IComponent));
if (!isComponent)
{
throw new IllegalReadTypeException("{0} must be a Component", readImmediateType.Name);
}
this.readImmediateTypes.Add(readImmediateType);
}
}
}
}

View File

@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Encompass.Exceptions;
namespace Encompass
{
[AttributeUsage(AttributeTargets.Class)]
public class ReadsPending : Attribute
{
public readonly HashSet<Type> readPendingTypes = new HashSet<Type>();
public ReadsPending(params Type[] readPendingTypes)
{
foreach (var readPendingType in readPendingTypes)
{
var isComponent = readPendingType.GetInterfaces().Contains(typeof(IComponent));
if (!isComponent)
{
throw new IllegalReadTypeException("{0} must be a Component", readPendingType.Name);
}
this.readPendingTypes.Add(readPendingType);
}
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Encompass.Exceptions;
namespace Encompass
{
[AttributeUsage(AttributeTargets.Class)]
public class WritesImmediate : Attribute
{
public readonly HashSet<Type> writeImmediateTypes = new HashSet<Type>();
public WritesImmediate(params Type[] writeImmediateTypes)
{
foreach (var writeImmediateType in writeImmediateTypes)
{
var isComponent = writeImmediateType.GetInterfaces().Contains(typeof(IComponent));
if (!isComponent)
{
throw new IllegalWriteImmediateTypeException("{0} must be a Component", writeImmediateType.Name);
}
this.writeImmediateTypes.Add(writeImmediateType);
}
}
}
}

View File

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Encompass.Exceptions;
namespace Encompass
{
public class WritesPending : Attribute
{
public readonly HashSet<Type> writePendingTypes = new HashSet<Type>();
public WritesPending(params Type[] writePendingTypes)
{
foreach (var writePendingType in writePendingTypes)
{
var isComponent = writePendingType.GetInterfaces().Contains(typeof(IComponent));
if (!isComponent)
{
throw new IllegalWritePendingTypeException("{0} must be a Component", writePendingType.Name);
}
this.writePendingTypes.Add(writePendingType);
}
}
}
}

View File

@ -87,9 +87,9 @@ namespace Encompass
entitiesMarkedForRemoval.Clear();
}
public bool RemovePending<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
public bool RemoveImmediate<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
{
if (componentUpdateManager.RemovePending<TComponent>(entity, priority))
if (componentUpdateManager.RemoveImmediate<TComponent>(entity, priority))
{
drawLayerManager.UnRegisterComponentWithLayer<TComponent>(entity.ID);
return true;

View File

@ -7,8 +7,7 @@ namespace Encompass
internal class ComponentUpdateManager
{
private readonly ComponentStore existingComponentStore;
private readonly ComponentStore pendingComponentStore;
private readonly Dictionary<Type, Dictionary<Entity, int>> typeToEntityToPendingComponentPriority = new Dictionary<Type, Dictionary<Entity, int>>(128);
private readonly ComponentStore immediateComponentStore;
public Dictionary<Type, int> TypeToIndex { get; }
public ComponentStore UpToDateComponentStore { get; private set; }
@ -16,7 +15,7 @@ namespace Encompass
public ComponentUpdateManager(Dictionary<Type, int> typeToIndex)
{
existingComponentStore = new ComponentStore(typeToIndex);
pendingComponentStore = new ComponentStore(typeToIndex);
immediateComponentStore = new ComponentStore(typeToIndex);
UpToDateComponentStore = new ComponentStore(typeToIndex);
TypeToIndex = typeToIndex;
}
@ -24,20 +23,15 @@ namespace Encompass
public void RegisterComponentType<TComponent>() where TComponent : struct, IComponent
{
existingComponentStore.RegisterComponentType<TComponent>();
pendingComponentStore.RegisterComponentType<TComponent>();
immediateComponentStore.RegisterComponentType<TComponent>();
UpToDateComponentStore.RegisterComponentType<TComponent>();
}
internal void Clear()
{
existingComponentStore.ClearAll();
pendingComponentStore.ClearAll();
immediateComponentStore.ClearAll();
UpToDateComponentStore.ClearAll();
foreach (var dictionary in typeToEntityToPendingComponentPriority.Values)
{
dictionary.Clear();
}
}
internal void SetStartingComponentStore(ComponentStore componentStore)
@ -47,26 +41,26 @@ namespace Encompass
internal void AddExistingComponent<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
{
RegisterExistingOrPendingComponentMessage(entity, component);
RegisterExistingOrImmediateComponentMessage(entity, component);
existingComponentStore.Set(entity.ID, component);
}
internal bool AddPendingComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
internal bool AddImmediateComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
{
if (pendingComponentStore.Set(entity.ID, component, priority))
if (immediateComponentStore.Set(entity.ID, component, priority))
{
RegisterExistingOrPendingComponentMessage(entity, component);
RegisterExistingOrImmediateComponentMessage(entity, component);
return true;
}
return false;
}
internal bool RemovePending<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
internal bool RemoveImmediate<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
{
UpToDateComponentStore.Remove<TComponent>(entity.ID, priority);
return pendingComponentStore.Remove<TComponent>(entity.ID, priority);
return immediateComponentStore.Remove<TComponent>(entity.ID, priority);
}
internal bool Remove<TComponent>(Entity entity, int priority) where TComponent : struct, IComponent
@ -74,7 +68,7 @@ namespace Encompass
return UpToDateComponentStore.Remove<TComponent>(entity.ID, priority);
}
private void RegisterExistingOrPendingComponentMessage<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
private void RegisterExistingOrImmediateComponentMessage<TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
{
UpToDateComponentStore.Set(entity.ID, component);
}
@ -86,7 +80,7 @@ namespace Encompass
// general component reads by type
internal IEnumerable<(TComponent, int)> ReadExistingAndPendingComponentsByType<TComponent>() where TComponent : struct, IComponent
internal IEnumerable<(TComponent, int)> ReadExistingAndImmediateComponentsByType<TComponent>() where TComponent : struct, IComponent
{
return UpToDateComponentStore.All<TComponent>();
}
@ -96,17 +90,17 @@ namespace Encompass
return existingComponentStore.All<TComponent>();
}
internal IEnumerable<(TComponent, int)> ReadPendingComponentsByType<TComponent>() where TComponent : struct, IComponent
internal IEnumerable<(TComponent, int)> ReadImmediateComponentsByType<TComponent>() where TComponent : struct, IComponent
{
return pendingComponentStore.All<TComponent>();
return immediateComponentStore.All<TComponent>();
}
// singular component reads by type
internal (TComponent, int) ReadFirstExistingOrPendingComponentByType<TComponent>() where TComponent : struct, IComponent
internal (TComponent, int) ReadFirstExistingOrImmediateComponentByType<TComponent>() where TComponent : struct, IComponent
{
if (!SomeExistingOrPendingComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadExistingAndPendingComponentsByType<TComponent>().GetEnumerator();
if (!SomeExistingOrImmediateComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadExistingAndImmediateComponentsByType<TComponent>().GetEnumerator();
enumerator.MoveNext();
return enumerator.Current;
}
@ -119,17 +113,17 @@ namespace Encompass
return enumerator.Current;
}
internal (TComponent, int) ReadFirstPendingComponentByType<TComponent>() where TComponent : struct, IComponent
internal (TComponent, int) ReadFirstImmediateComponentByType<TComponent>() where TComponent : struct, IComponent
{
if (!SomePendingComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadPendingComponentsByType<TComponent>().GetEnumerator();
if (!SomeImmediateComponent<TComponent>()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); }
var enumerator = ReadImmediateComponentsByType<TComponent>().GetEnumerator();
enumerator.MoveNext();
return enumerator.Current;
}
// check if some component of type exists in the world
internal bool SomeExistingOrPendingComponent<TComponent>() where TComponent : struct, IComponent
internal bool SomeExistingOrImmediateComponent<TComponent>() where TComponent : struct, IComponent
{
return UpToDateComponentStore.Any<TComponent>();
}
@ -139,9 +133,9 @@ namespace Encompass
return existingComponentStore.Any<TComponent>();
}
internal bool SomePendingComponent<TComponent>() where TComponent : struct, IComponent
internal bool SomeImmediateComponent<TComponent>() where TComponent : struct, IComponent
{
return pendingComponentStore.Any<TComponent>();
return immediateComponentStore.Any<TComponent>();
}
// read components by entity and type
@ -151,19 +145,19 @@ namespace Encompass
return existingComponentStore.Get<TComponent>(entity.ID);
}
internal TComponent ReadPendingComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
internal TComponent ReadImmediateComponentByEntityAndType<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return pendingComponentStore.Get<TComponent>(entity.ID);
return immediateComponentStore.Get<TComponent>(entity.ID);
}
// check if entity has component of type
internal bool HasExistingOrPendingComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
internal bool HasExistingOrImmediateComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return UpToDateComponentStore.Has<TComponent>(entity.ID);
}
internal bool HasExistingOrPendingComponent(Entity entity, Type type)
internal bool HasExistingOrImmediateComponent(Entity entity, Type type)
{
return UpToDateComponentStore.Has(type, entity.ID);
}
@ -178,17 +172,17 @@ namespace Encompass
return existingComponentStore.Has(type, entity.ID);
}
internal bool HasPendingComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
internal bool HasImmediateComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
return pendingComponentStore.Has<TComponent>(entity.ID);
return immediateComponentStore.Has<TComponent>(entity.ID);
}
internal bool HasPendingComponent(Entity entity, Type type)
internal bool HasImmediateComponent(Entity entity, Type type)
{
return pendingComponentStore.Has(type, entity.ID);
return immediateComponentStore.Has(type, entity.ID);
}
internal ComponentBitSet PendingBits { get { return pendingComponentStore.ComponentBitSet; } }
internal ComponentBitSet ImmediateBits { get { return immediateComponentStore.ComponentBitSet; } }
internal ComponentBitSet ExistingBits { get { return existingComponentStore.ComponentBitSet; } }
}
}

View File

@ -17,11 +17,11 @@ namespace Encompass
internal Guid ID;
internal readonly HashSet<Type> readTypes = new HashSet<Type>();
internal readonly HashSet<Type> readPendingTypes = 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> writePendingTypes = 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>();
@ -51,10 +51,10 @@ namespace Encompass
sendTypes = sendsAttribute.sendTypes;
}
var activatesAttribute = GetType().GetCustomAttribute<WritesPending>(false);
var activatesAttribute = GetType().GetCustomAttribute<WritesImmediate>(false);
if (activatesAttribute != null)
{
writePendingTypes = activatesAttribute.writePendingTypes;
writeImmediateTypes = activatesAttribute.writeImmediateTypes;
}
var defaultWritePriorityAttribute = GetType().GetCustomAttribute<DefaultWritePriority>(false);
@ -82,10 +82,10 @@ namespace Encompass
readTypes = readsAttribute.readTypes;
}
var readsPendingAttribute = GetType().GetCustomAttribute<ReadsPending>(false);
if (readsPendingAttribute != null)
var readsImmediateAttribute = GetType().GetCustomAttribute<ReadsImmediate>(false);
if (readsImmediateAttribute != null)
{
readPendingTypes = readsPendingAttribute.readPendingTypes;
readImmediateTypes = readsImmediateAttribute.readImmediateTypes;
}
var queryWithAttribute = GetType().GetCustomAttribute<QueryWith>(false);
@ -196,19 +196,19 @@ namespace Encompass
private IEnumerable<(TComponent, int)> ReadComponentsHelper<TComponent>() where TComponent : struct, IComponent
{
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var immediateRead = readImmediateTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && pendingRead)
if (existingRead && immediateRead)
{
return componentUpdateManager.ReadExistingAndPendingComponentsByType<TComponent>();
return componentUpdateManager.ReadExistingAndImmediateComponentsByType<TComponent>();
}
else if (existingRead)
{
return componentUpdateManager.ReadExistingComponentsByType<TComponent>();
}
else if (pendingRead)
else if (immediateRead)
{
return componentUpdateManager.ReadPendingComponentsByType<TComponent>();
return componentUpdateManager.ReadImmediateComponentsByType<TComponent>();
}
else
{
@ -248,19 +248,19 @@ namespace Encompass
private (TComponent, int) ReadComponentHelper<TComponent>() where TComponent : struct, IComponent
{
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var immediateRead = readImmediateTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && pendingRead)
if (existingRead && immediateRead)
{
return componentUpdateManager.ReadFirstExistingOrPendingComponentByType<TComponent>();
return componentUpdateManager.ReadFirstExistingOrImmediateComponentByType<TComponent>();
}
else if (existingRead)
{
return componentUpdateManager.ReadFirstExistingComponentByType<TComponent>();
}
else if (pendingRead)
else if (immediateRead)
{
return componentUpdateManager.ReadFirstPendingComponentByType<TComponent>();
return componentUpdateManager.ReadFirstImmediateComponentByType<TComponent>();
}
else
{
@ -290,19 +290,19 @@ namespace Encompass
/// </summary>
protected bool SomeComponent<TComponent>() where TComponent : struct, IComponent
{
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var immediateRead = readImmediateTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && pendingRead)
if (existingRead && immediateRead)
{
return componentUpdateManager.SomeExistingOrPendingComponent<TComponent>();
return componentUpdateManager.SomeExistingOrImmediateComponent<TComponent>();
}
else if (existingRead)
{
return componentUpdateManager.SomeExistingComponent<TComponent>();
}
else if (pendingRead)
else if (immediateRead)
{
return componentUpdateManager.SomePendingComponent<TComponent>();
return componentUpdateManager.SomeImmediateComponent<TComponent>();
}
else
{
@ -312,13 +312,13 @@ namespace Encompass
private TComponent GetComponentHelper<TComponent>(Entity entity) where TComponent : struct, IComponent
{
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var immediateRead = readImmediateTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
if (existingRead && pendingRead)
if (existingRead && immediateRead)
{
if (componentUpdateManager.HasPendingComponent<TComponent>(entity))
if (componentUpdateManager.HasImmediateComponent<TComponent>(entity))
{
return componentUpdateManager.ReadPendingComponentByEntityAndType<TComponent>(entity);
return componentUpdateManager.ReadImmediateComponentByEntityAndType<TComponent>(entity);
}
else if (componentUpdateManager.HasExistingComponent<TComponent>(entity))
{
@ -333,9 +333,9 @@ namespace Encompass
{
return componentUpdateManager.ReadExistingComponentByEntityAndType<TComponent>(entity);
}
else if (pendingRead)
else if (immediateRead)
{
return componentUpdateManager.ReadPendingComponentByEntityAndType<TComponent>(entity);
return componentUpdateManager.ReadImmediateComponentByEntityAndType<TComponent>(entity);
}
else
{
@ -365,20 +365,20 @@ namespace Encompass
/// </exception>
protected bool HasComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
{
var pendingRead = readPendingTypes.Contains(typeof(TComponent));
var immediateRead = readImmediateTypes.Contains(typeof(TComponent));
var existingRead = readTypes.Contains(typeof(TComponent));
if (pendingRead && existingRead)
if (immediateRead && existingRead)
{
return componentUpdateManager.HasExistingOrPendingComponent<TComponent>(entity);
return componentUpdateManager.HasExistingOrImmediateComponent<TComponent>(entity);
}
else if (existingRead)
{
return componentUpdateManager.HasExistingComponent<TComponent>(entity);
}
else if (pendingRead)
else if (immediateRead)
{
return componentUpdateManager.HasPendingComponent<TComponent>(entity);
return componentUpdateManager.HasImmediateComponent<TComponent>(entity);
}
else
{
@ -394,20 +394,20 @@ namespace Encompass
/// </exception>
protected bool HasComponent(Entity entity, Type type)
{
var pendingRead = readPendingTypes.Contains(type);
var immediateRead = readImmediateTypes.Contains(type);
var existingRead = readTypes.Contains(type);
if (pendingRead && existingRead)
if (immediateRead && existingRead)
{
return componentUpdateManager.HasExistingOrPendingComponent(entity, type);
return componentUpdateManager.HasExistingOrImmediateComponent(entity, type);
}
else if (existingRead)
{
return componentUpdateManager.HasExistingComponent(entity, type);
}
else if (pendingRead)
else if (immediateRead)
{
return componentUpdateManager.HasPendingComponent(entity, type);
return componentUpdateManager.HasImmediateComponent(entity, type);
}
else
{
@ -431,9 +431,9 @@ namespace Encompass
}
bool written;
if (writePendingTypes.Contains(typeof(TComponent)))
if (writeImmediateTypes.Contains(typeof(TComponent)))
{
written = AddPendingComponent(entity, component, priority);
written = AddImmediateComponent(entity, component, priority);
}
else
{
@ -485,9 +485,9 @@ namespace Encompass
componentUpdateManager.AddExistingComponent(entity, component);
}
internal bool AddPendingComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
internal bool AddImmediateComponent<TComponent>(Entity entity, TComponent component, int priority) where TComponent : struct, IComponent
{
return componentUpdateManager.AddPendingComponent(entity, component, priority);
return componentUpdateManager.AddImmediateComponent(entity, component, priority);
}
/// <summary>
@ -577,9 +577,9 @@ namespace Encompass
throw new IllegalWriteException("Engine {0} tried to remove undeclared Component {1}. Declare with Writes attribute.", GetType().Name, typeof(TComponent).Name);
}
if (writePendingTypes.Contains(typeof(TComponent)))
if (writeImmediateTypes.Contains(typeof(TComponent)))
{
componentManager.RemovePending<TComponent>(entity, priority);
componentManager.RemoveImmediate<TComponent>(entity, priority);
}
else
{
@ -649,7 +649,7 @@ namespace Encompass
protected IEnumerable<Entity> QueryEntities()
{
foreach (var entity in entityQuery.FilterEntities(entityManager.Entities, componentUpdateManager.PendingBits, componentUpdateManager.ExistingBits))
foreach (var entity in entityQuery.FilterEntities(entityManager.Entities, componentUpdateManager.ImmediateBits, componentUpdateManager.ExistingBits))
{
yield return entity;
}
@ -672,10 +672,10 @@ namespace Encompass
withoutMask = withoutMask.Set(componentUpdateManager.TypeToIndex[type]);
}
var pendingMask = BitSetBuilder.Zeroes();
foreach (var type in readPendingTypes)
var immediateMask = BitSetBuilder.Zeroes();
foreach (var type in readImmediateTypes)
{
pendingMask = pendingMask.Set(componentUpdateManager.TypeToIndex[type]);
immediateMask = immediateMask.Set(componentUpdateManager.TypeToIndex[type]);
}
var existingMask = BitSetBuilder.Zeroes();
@ -685,9 +685,9 @@ namespace Encompass
}
entityQuery = new EntitySetQuery(
withMask.And(pendingMask),
withMask.And(immediateMask),
withMask.And(existingMask),
withoutMask.And(pendingMask),
withoutMask.And(immediateMask),
withoutMask.And(existingMask),
withMask.Not()
);

View File

@ -6,35 +6,35 @@ namespace Encompass
{
internal struct EntitySetQuery
{
private BitSet WithPendingMask { get; }
private BitSet WithImmediateMask { get; }
private BitSet WithExistingMask { get; }
private BitSet WithoutPendingMask { get; }
private BitSet WithoutImmediateMask { get; }
private BitSet WithoutExistingMask { get; }
private BitSet NotWithMask { get; }
internal EntitySetQuery(BitSet withPendingMask, BitSet withExistingMask, BitSet withoutPendingMask, BitSet withoutExistingMask, BitSet notWithMask)
internal EntitySetQuery(BitSet withImmediateMask, BitSet withExistingMask, BitSet withoutImmediateMask, BitSet withoutExistingMask, BitSet notWithMask)
{
WithPendingMask = withPendingMask;
WithImmediateMask = withImmediateMask;
WithExistingMask = withExistingMask;
WithoutPendingMask = withoutPendingMask;
WithoutImmediateMask = withoutImmediateMask;
WithoutExistingMask = withoutExistingMask;
NotWithMask = notWithMask;
}
public IEnumerable<Entity> FilterEntities(IEnumerable<Entity> entities, ComponentBitSet pendingBitLookup, ComponentBitSet existingBitLookup)
public IEnumerable<Entity> FilterEntities(IEnumerable<Entity> entities, ComponentBitSet immediateBitLookup, ComponentBitSet existingBitLookup)
{
foreach (var entity in entities)
{
var pendingBits = pendingBitLookup.EntityBitArray(entity.ID);
var immediateBits = immediateBitLookup.EntityBitArray(entity.ID);
var existingBits = existingBitLookup.EntityBitArray(entity.ID);
var pending = WithPendingMask.And(pendingBits);
var immediate = WithImmediateMask.And(immediateBits);
var existing = WithExistingMask.And(existingBits);
var withCheck = pending.Or(existing).Or(NotWithMask);
var withCheck = immediate.Or(existing).Or(NotWithMask);
var pendingForbidden = WithoutPendingMask.And(pendingBits).Not();
var immediateForbidden = WithoutImmediateMask.And(immediateBits).Not();
var existingForbidden = WithoutExistingMask.And(existingBits).Not();
var withoutCheck = pendingForbidden.And(existingForbidden);
var withoutCheck = immediateForbidden.And(existingForbidden);
if (withCheck.And(withoutCheck).AllTrue()) { yield return entity; }
}

View File

@ -1,10 +1,10 @@
using System;
using System;
namespace Encompass.Exceptions
{
public class IllegalWritePendingException : Exception
public class IllegalWriteImmediateException : Exception
{
public IllegalWritePendingException(
public IllegalWriteImmediateException(
string format,
params object[] args
) : base(string.Format(format, args)) { }

View File

@ -2,9 +2,9 @@ using System;
namespace Encompass.Exceptions
{
public class IllegalWritePendingTypeException : Exception
public class IllegalWriteImmediateTypeException : Exception
{
public IllegalWritePendingTypeException(
public IllegalWriteImmediateTypeException(
string format,
params object[] args
) : base(string.Format(format, args)) { }

View File

@ -141,9 +141,9 @@ namespace Encompass
RegisterMessageTypes(engine.receiveTypes.Union(engine.sendTypes));
foreach (var writePendingType in engine.writePendingTypes.Intersect(engine.readPendingTypes))
foreach (var writeImmediateType in engine.writeImmediateTypes.Intersect(engine.readImmediateTypes))
{
throw new EngineSelfCycleException("Engine {0} both writes and reads pending Component {1}", engine.GetType().Name, writePendingType.Name);
throw new EngineSelfCycleException("Engine {0} both writes and reads immediate Component {1}", engine.GetType().Name, writeImmediateType.Name);
}
foreach (var messageType in messageReceiveTypes.Intersect(messageSendTypes))
@ -151,17 +151,17 @@ namespace Encompass
throw new EngineSelfCycleException("Engine {0} both receives and sends Message {1}", engine.GetType().Name, messageType.Name);
}
if (messageSendTypes.Count > 0 || engine.writePendingTypes.Count > 0)
if (messageSendTypes.Count > 0 || engine.writeImmediateTypes.Count > 0)
{
senders.Add(engine);
}
foreach (var componentType in engine.readTypes.Union(engine.writeTypes).Union(engine.readPendingTypes))
foreach (var componentType in engine.readTypes.Union(engine.writeTypes).Union(engine.readImmediateTypes))
{
AddComponentTypeToRegister(componentType);
}
foreach (var receiveType in engine.receiveTypes.Union(engine.readPendingTypes))
foreach (var receiveType in engine.receiveTypes.Union(engine.readImmediateTypes))
{
if (!typeToReaders.ContainsKey(receiveType))
{
@ -214,7 +214,7 @@ namespace Encompass
{
foreach (var senderEngine in senders)
{
foreach (var messageType in senderEngine.sendTypes.Union(senderEngine.writePendingTypes))
foreach (var messageType in senderEngine.sendTypes.Union(senderEngine.writeImmediateTypes))
{
if (typeToReaders.ContainsKey(messageType))
{

View File

@ -97,7 +97,7 @@ namespace Tests
}
[Reads(typeof(MockComponent))]
[WritesPending(typeof(MockComponent))]
[WritesImmediate(typeof(MockComponent))]
[Writes(typeof(MockComponent))]
class OverwriteEngine : Engine
{
@ -110,7 +110,7 @@ namespace Tests
}
}
[ReadsPending(typeof(MockComponent))]
[ReadsImmediate(typeof(MockComponent))]
[Reads(typeof(MockComponent))]
class ReadMockComponentEngine : Engine
{
@ -193,7 +193,7 @@ namespace Tests
}
}
[WritesPending(typeof(MockComponent))]
[WritesImmediate(typeof(MockComponent))]
[Receives(typeof(AddMockComponentMessage))]
[Writes(typeof(MockComponent))]
class AddMockComponentEngine : Engine
@ -207,7 +207,7 @@ namespace Tests
}
}
[ReadsPending(typeof(MockComponent))]
[ReadsImmediate(typeof(MockComponent))]
class HasMockComponentEngine : Engine
{
private Entity entity;
@ -464,8 +464,8 @@ namespace Tests
}
[Receives(typeof(CheckHasMockComponentMessage))]
[ReadsPending(typeof(MockComponent))]
class CheckHasPendingMockComponentEngine : Engine
[ReadsImmediate(typeof(MockComponent))]
class CheckHasImmediateMockComponentEngine : Engine
{
public override void Update(double dt)
{

View File

@ -625,7 +625,7 @@ namespace Tests
}
[Reads(typeof(MockComponent))]
[WritesPending(typeof(MockComponent))]
[WritesImmediate(typeof(MockComponent))]
[Writes(typeof(MockComponent))]
class AddAndRemoveMockComponentEngine : Engine
{
@ -641,8 +641,8 @@ namespace Tests
static Entity entityResult;
[ReadsPending(typeof(MockComponent))]
class GetEntityFromPendingReadComponents : Engine
[ReadsImmediate(typeof(MockComponent))]
class GetEntityFromImmediateReadComponents : Engine
{
public override void Update(double dt)
{
@ -651,11 +651,11 @@ namespace Tests
}
[Test]
public void GetEntityFromPendingComponentID()
public void GetEntityFromImmediateComponentID()
{
var worldBuilder = new WorldBuilder();
worldBuilder.AddEngine(new AddAndRemoveMockComponentEngine());
worldBuilder.AddEngine(new GetEntityFromPendingReadComponents());
worldBuilder.AddEngine(new GetEntityFromImmediateReadComponents());
var entity = worldBuilder.CreateEntity();
worldBuilder.SetComponent(entity, new MockComponent());
@ -756,7 +756,7 @@ namespace Tests
}
[Receives(typeof(MockMessage))]
[WritesPending(typeof(MockComponent))]
[WritesImmediate(typeof(MockComponent))]
[Writes(typeof(MockComponent), 1)]
class ActivateComponentEngine : Engine
{
@ -770,7 +770,7 @@ namespace Tests
}
}
[ReadsPending(typeof(MockComponent))]
[ReadsImmediate(typeof(MockComponent))]
[Writes(typeof(MockComponent), 0)]
class RemoveComponentEngine : Engine
{
@ -1251,9 +1251,9 @@ namespace Tests
}
[Reads(typeof(MockComponent))]
[WritesPending(typeof(MockComponentB))]
[WritesImmediate(typeof(MockComponentB))]
[Writes(typeof(MockComponentB), 0)]
class AddPendingComponentEngine : Engine
class AddImmediateComponentEngine : Engine
{
public override void Update(double dt)
{
@ -1264,13 +1264,13 @@ namespace Tests
}
}
[ReadsPending(typeof(MockComponentB))]
[ReadsImmediate(typeof(MockComponentB))]
[QueryWith(typeof(MockComponentB))]
class EntityQueryWithPendingComponentsEngine : Engine
class EntityQueryWithImmediateComponentsEngine : Engine
{
private List<Entity> entities;
public EntityQueryWithPendingComponentsEngine(List<Entity> entities)
public EntityQueryWithImmediateComponentsEngine(List<Entity> entities)
{
this.entities = entities;
}
@ -1283,7 +1283,7 @@ namespace Tests
}
[Test]
public void EntitiesWithPendingComponents()
public void EntitiesWithImmediateComponents()
{
var worldBuilder = new WorldBuilder();
@ -1293,8 +1293,8 @@ namespace Tests
worldBuilder.SetComponent(entity, new MockComponent());
var queriedEntities = new List<Entity>();
worldBuilder.AddEngine(new AddPendingComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithPendingComponentsEngine(queriedEntities));
worldBuilder.AddEngine(new AddImmediateComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithImmediateComponentsEngine(queriedEntities));
var world = worldBuilder.Build();
@ -1303,13 +1303,13 @@ namespace Tests
queriedEntities.ToArray().Should().BeEquivalentTo(new Entity[] { entity });
}
[ReadsPending(typeof(MockComponentB))]
[ReadsImmediate(typeof(MockComponentB))]
[QueryWithout(typeof(MockComponentB))]
class EntityQueryWithoutPendingComponentsEngine : Engine
class EntityQueryWithoutImmediateComponentsEngine : Engine
{
private List<Entity> entities;
public EntityQueryWithoutPendingComponentsEngine(List<Entity> entities)
public EntityQueryWithoutImmediateComponentsEngine(List<Entity> entities)
{
this.entities = entities;
}
@ -1322,7 +1322,7 @@ namespace Tests
}
[Test]
public void EntitiesWithoutPendingComponents()
public void EntitiesWithoutImmediateComponents()
{
var worldBuilder = new WorldBuilder();
@ -1332,8 +1332,8 @@ namespace Tests
worldBuilder.SetComponent(entity, new MockComponent());
var queriedEntities = new List<Entity>();
worldBuilder.AddEngine(new AddPendingComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithoutPendingComponentsEngine(queriedEntities));
worldBuilder.AddEngine(new AddImmediateComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithoutImmediateComponentsEngine(queriedEntities));
var world = worldBuilder.Build();
@ -1343,10 +1343,10 @@ namespace Tests
}
[Reads(typeof(MockComponentC), typeof(MockComponentD))]
[WritesPending(typeof(MockComponent), typeof(MockComponentB))]
[WritesImmediate(typeof(MockComponent), typeof(MockComponentB))]
[Writes(typeof(MockComponent), 0)]
[Writes(typeof(MockComponentB), 0)]
class ConditionallyAddPendingComponentsEngine : Engine
class ConditionallyAddImmediateComponentsEngine : Engine
{
public override void Update(double dt)
{
@ -1363,14 +1363,14 @@ namespace Tests
}
}
[ReadsPending(typeof(MockComponent), typeof(MockComponentB))]
[ReadsImmediate(typeof(MockComponent), typeof(MockComponentB))]
[QueryWith(typeof(MockComponent))]
[QueryWithout(typeof(MockComponentB))]
class EntityQueryWithAndWithoutPendingComponentsEngine : Engine
class EntityQueryWithAndWithoutImmediateComponentsEngine : Engine
{
private List<Entity> entities;
public EntityQueryWithAndWithoutPendingComponentsEngine(List<Entity> entities)
public EntityQueryWithAndWithoutImmediateComponentsEngine(List<Entity> entities)
{
this.entities = entities;
}
@ -1384,7 +1384,7 @@ namespace Tests
}
[Test]
public void EntitiesWithAndWithoutPendingComponents()
public void EntitiesWithAndWithoutImmediateComponents()
{
var worldBuilder = new WorldBuilder();
@ -1396,8 +1396,8 @@ namespace Tests
worldBuilder.SetComponent(entityC, new MockComponentD());
var queriedEntities = new List<Entity>();
worldBuilder.AddEngine(new ConditionallyAddPendingComponentsEngine());
worldBuilder.AddEngine(new EntityQueryWithAndWithoutPendingComponentsEngine(queriedEntities));
worldBuilder.AddEngine(new ConditionallyAddImmediateComponentsEngine());
worldBuilder.AddEngine(new EntityQueryWithAndWithoutImmediateComponentsEngine(queriedEntities));
var world = worldBuilder.Build();
@ -1407,9 +1407,9 @@ namespace Tests
}
[Reads(typeof(MockComponentC))]
[WritesPending(typeof(MockComponentB))]
[WritesImmediate(typeof(MockComponentB))]
[Writes(typeof(MockComponentB), 0)]
class ConditionallyAddPendingComponentEngine : Engine
class ConditionallyAddImmediateComponentEngine : Engine
{
public override void Update(double dt)
{
@ -1420,14 +1420,14 @@ namespace Tests
}
}
[ReadsPending(typeof(MockComponentB))]
[ReadsImmediate(typeof(MockComponentB))]
[Reads(typeof(MockComponent))]
[QueryWith(typeof(MockComponent), typeof(MockComponentB))]
class EntityQueryWithPendingAndNonPendingComponents : Engine
class EntityQueryWithImmediateAndNonImmediateComponents : Engine
{
private List<Entity> entities;
public EntityQueryWithPendingAndNonPendingComponents(List<Entity> entities)
public EntityQueryWithImmediateAndNonImmediateComponents(List<Entity> entities)
{
this.entities = entities;
}
@ -1440,7 +1440,7 @@ namespace Tests
}
[Test]
public void EntitiesWithPendingAndNonPendingComponents()
public void EntitiesWithImmediateAndNonImmediateComponents()
{
var worldBuilder = new WorldBuilder();
@ -1453,8 +1453,8 @@ namespace Tests
worldBuilder.SetComponent(entityC, new MockComponentD());
var queriedEntities = new List<Entity>();
worldBuilder.AddEngine(new ConditionallyAddPendingComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithPendingAndNonPendingComponents(queriedEntities));
worldBuilder.AddEngine(new ConditionallyAddImmediateComponentEngine());
worldBuilder.AddEngine(new EntityQueryWithImmediateAndNonImmediateComponents(queriedEntities));
var world = worldBuilder.Build();

View File

@ -19,7 +19,7 @@ namespace Tests
}
}
[WritesPending(typeof(TestComponent))]
[WritesImmediate(typeof(TestComponent))]
[Writes(typeof(TestComponent))]
class TestSpawner : Spawner<SpawnMessageA>
{

View File

@ -153,7 +153,7 @@ namespace Tests
[Receives(typeof(SetMessage))]
[Writes(typeof(AComponent), 0)]
[WritesPending(typeof(AComponent))]
[WritesImmediate(typeof(AComponent))]
class AEngine : Engine
{
public override void Update(double dt)
@ -167,7 +167,7 @@ namespace Tests
[Receives(typeof(SetMessage))]
[Writes(typeof(AComponent), 1)]
[WritesPending(typeof(AComponent))]
[WritesImmediate(typeof(AComponent))]
class BEngine : Engine
{
public override void Update(double dt)
@ -181,7 +181,7 @@ namespace Tests
static AComponent resultComponent;
[ReadsPending(typeof(AComponent))]
[ReadsImmediate(typeof(AComponent))]
class ReadComponentEngine : Engine
{
public override void Update(double dt)
@ -222,7 +222,7 @@ namespace Tests
[Receives(typeof(SetMessage))]
[Writes(typeof(AComponent))]
[WritesPending(typeof(AComponent))]
[WritesImmediate(typeof(AComponent))]
[Encompass.DefaultWritePriority(4)]
class AEngine : Engine
{
@ -238,7 +238,7 @@ namespace Tests
[Receives(typeof(SetMessage))]
[Writes(typeof(AComponent), 3)]
[WritesPending(typeof(AComponent))]
[WritesImmediate(typeof(AComponent))]
class BEngine : Engine
{
public override void Update(double dt)
@ -252,7 +252,7 @@ namespace Tests
[Receives(typeof(SetMessage))]
[Writes(typeof(AComponent), 2)]
[WritesPending(typeof(AComponent))]
[WritesImmediate(typeof(AComponent))]
class CEngine : Engine
{
public override void Update(double dt)
@ -266,7 +266,7 @@ namespace Tests
static AComponent resultComponent;
[ReadsPending(typeof(AComponent))]
[ReadsImmediate(typeof(AComponent))]
class ReadComponentEngine : Engine
{
public override void Update(double dt)