From 506aee8c37e146b57a7a021a3262d85e1f537b38 Mon Sep 17 00:00:00 2001 From: Evan Hemsley <2342303+ehemsley@users.noreply.github.com> Date: Wed, 4 Dec 2019 20:50:08 -0800 Subject: [PATCH] started rewriting managers to not reference interfaces --- encompass-cs/Collections/ComponentStore.cs | 61 +++++++++ encompass-cs/ComponentManager.cs | 14 +-- encompass-cs/ComponentMessageManager.cs | 137 ++++++++------------- encompass-cs/Engine.cs | 57 +-------- encompass-cs/EntityManager.cs | 6 +- encompass-cs/MessageManager.cs | 2 +- encompass-cs/TimeManager.cs | 2 +- encompass-cs/WorldBuilder.cs | 2 +- encompass-cs/encompass-cs.csproj | 8 +- test/ComponentTest.cs | 39 ------ 10 files changed, 131 insertions(+), 197 deletions(-) create mode 100644 encompass-cs/Collections/ComponentStore.cs diff --git a/encompass-cs/Collections/ComponentStore.cs b/encompass-cs/Collections/ComponentStore.cs new file mode 100644 index 0000000..5d857b1 --- /dev/null +++ b/encompass-cs/Collections/ComponentStore.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; + +namespace Encompass +{ + internal class ComponentStore + { + private readonly Dictionary Stores = new Dictionary(); + private readonly Dictionary ClearMethods = new Dictionary(); + + private Dictionary Lookup() where TComponent : struct, IComponent + { + if (!Stores.ContainsKey(typeof(TComponent))) + { + var dictionary = new Dictionary(); + Stores.Add(typeof(TComponent), dictionary); + ClearMethods.Add(typeof(TComponent), dictionary.Clear); + } + + return Stores[typeof(TComponent)] as Dictionary; + } + + public bool Has(Guid id) where TComponent : struct, IComponent + { + return Lookup().ContainsKey(id); + } + + public TComponent Get(Guid id) where TComponent : struct, IComponent + { + return Lookup()[id]; + } + + public void Set(Type type, Guid id, IComponent component) + { + (Stores[type] as Dictionary)[id] = component; + } + + public void Set(Guid id, TComponent component) where TComponent : struct, IComponent + { + Lookup()[id] = component; + } + + public void Remove(Guid id) where TComponent : struct, IComponent + { + Lookup().Remove(id); + } + + public void Clear() where TComponent : struct, IComponent + { + Lookup().Clear(); + } + + public void ClearAll() + { + foreach (var type in Stores.Keys) + { + ClearMethods[type](); + } + } + } +} diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index f76d76e..08340f4 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -11,7 +11,7 @@ namespace Encompass private readonly DrawLayerManager drawLayerManager; private readonly Dictionary componentIDToType = new Dictionary(); - private readonly Dictionary IDToComponent = new Dictionary(); + private readonly ComponentStore IDToComponent = new ComponentStore(); private readonly Dictionary> entityIDToComponentIDs = new Dictionary>(); private readonly Dictionary componentIDToEntityID = new Dictionary(); @@ -79,7 +79,7 @@ namespace Encompass internal void AddComponent(Entity entity, Type type, Guid componentID, IComponent component) { - IDToComponent[componentID] = component; + IDToComponent.Set(type, componentID, component); componentIDToEntityID[componentID] = entity.ID; componentIDToType[componentID] = type; entityIDToComponentTypeToComponentID[entity.ID][type] = componentID; @@ -133,7 +133,7 @@ namespace Encompass { if (typeToComponentIDs.TryGetValue(typeof(TComponent), out HashSet idSet)) { - return idSet.Select(id => (id, (TComponent)IDToComponent[id])); + return idSet.Select(id => (id, IDToComponent.Get(id))); } return Enumerable.Empty<(Guid, TComponent)>(); } @@ -142,7 +142,7 @@ namespace Encompass { if (entityIDToComponentTypeToComponentID.ContainsKey(entity.ID) && entityIDToComponentTypeToComponentID[entity.ID].TryGetValue(typeof(TComponent), out Guid id)) { - return (id, (TComponent)IDToComponent[id]); + return (id, IDToComponent.Get(id)); } throw new NoComponentOfTypeOnEntityException("No Component of type {0} exists on Entity {1}", typeof(TComponent).Name, entity.ID); @@ -165,7 +165,7 @@ namespace Encompass internal IComponent GetComponentByID(Guid componentID) { - if (IDToComponent.ContainsKey(componentID)) + if (IDToComponent.Has(componentID)) { return IDToComponent[componentID]; } @@ -230,7 +230,7 @@ namespace Encompass componentsMarkedForRemoval.Clear(); } - private void Remove(Guid componentID) + private void Remove(Guid componentID) where TComponent : struct, IComponent { var type = componentIDToType[componentID]; @@ -245,7 +245,7 @@ namespace Encompass entityIDToComponentTypeToComponentID[entityID].Remove(type); } - IDToComponent.Remove(componentID); + IDToComponent.Remove(componentID); componentIDToType.Remove(componentID); componentIDToEntityID.Remove(componentID); typeToComponentIDs[type].Remove(componentID); diff --git a/encompass-cs/ComponentMessageManager.cs b/encompass-cs/ComponentMessageManager.cs index 8541880..d9d6d59 100644 --- a/encompass-cs/ComponentMessageManager.cs +++ b/encompass-cs/ComponentMessageManager.cs @@ -1,14 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; -using Collections.Pooled; using Encompass.Exceptions; namespace Encompass { class ComponentMessageManager { - private readonly Dictionary componentIDToComponent = new Dictionary(); + private readonly ComponentStore componentIDToComponent = new ComponentStore(); private readonly Dictionary componentIDToType = new Dictionary(); private readonly Dictionary componentIDToEntityID = new Dictionary(); @@ -17,38 +16,15 @@ namespace Encompass private readonly Dictionary> componentMessageTypeToPendingComponentIDs = new Dictionary>(); private readonly Dictionary> componentMessageTypeToComponentIDs = new Dictionary>(); - private readonly Dictionary> entityToTypeToExistingComponentID = new Dictionary>(); - private readonly Dictionary> entityToTypeToPendingComponentID = new Dictionary>(); - private readonly Dictionary> entityToTypeToComponentID = new Dictionary>(); + private readonly Dictionary> typeToEntityToExistingComponentID = new Dictionary>(); + private readonly Dictionary> typeToEntityToPendingComponentID = new Dictionary>(); + private readonly Dictionary> typeToEntityToComponentID = new Dictionary>(); - private readonly Dictionary> entityToTypeToPendingComponentPriority = new Dictionary>(); - - internal void RegisterEntity(Entity entity) - { - entityToTypeToComponentID[entity] = new PooledDictionary(); - entityToTypeToPendingComponentID[entity] = new PooledDictionary(); - entityToTypeToPendingComponentPriority[entity] = new PooledDictionary(); - entityToTypeToExistingComponentID[entity] = new PooledDictionary(); - } - - internal void RegisterDestroyedEntity(Entity entity) - { - entityToTypeToComponentID[entity].Dispose(); - entityToTypeToComponentID.Remove(entity); - - entityToTypeToPendingComponentID[entity].Dispose(); - entityToTypeToPendingComponentID.Remove(entity); - - entityToTypeToPendingComponentPriority[entity].Dispose(); - entityToTypeToPendingComponentPriority.Remove(entity); - - entityToTypeToExistingComponentID[entity].Dispose(); - entityToTypeToExistingComponentID.Remove(entity); - } + private readonly Dictionary> typeToEntityToPendingComponentPriority = new Dictionary>(); internal void ClearMessages() { - componentIDToComponent.Clear(); + componentIDToComponent.ClearAll(); componentIDToType.Clear(); componentIDToEntityID.Clear(); @@ -67,22 +43,22 @@ namespace Encompass set.Clear(); } - foreach (var dictionary in entityToTypeToExistingComponentID.Values) + foreach (var dictionary in typeToEntityToExistingComponentID.Values) { dictionary.Clear(); } - foreach (var dictionary in entityToTypeToPendingComponentID.Values) + foreach (var dictionary in typeToEntityToPendingComponentID.Values) { dictionary.Clear(); } - foreach (var dictionary in entityToTypeToComponentID.Values) + foreach (var dictionary in typeToEntityToComponentID.Values) { dictionary.Clear(); } - foreach (var dictionary in entityToTypeToPendingComponentPriority.Values) + foreach (var dictionary in typeToEntityToPendingComponentPriority.Values) { dictionary.Clear(); } @@ -99,9 +75,14 @@ namespace Encompass componentMessageTypeToExistingComponentIDs[typeof(TComponent)].Add(componentMessage.componentID); - if (!entityToTypeToExistingComponentID[componentMessage.entity].ContainsKey(typeof(TComponent))) + if (!typeToEntityToExistingComponentID.ContainsKey(typeof(TComponent))) { - entityToTypeToExistingComponentID[componentMessage.entity].Add(typeof(TComponent), componentMessage.componentID); + typeToEntityToExistingComponentID.Add(typeof(TComponent), new Dictionary()); + } + + if (!typeToEntityToExistingComponentID[typeof(TComponent)].ContainsKey(componentMessage.entity)) + { + typeToEntityToExistingComponentID[typeof(TComponent)].Add(componentMessage.entity, componentMessage.componentID); } else { @@ -118,19 +99,25 @@ namespace Encompass componentMessageTypeToPendingComponentIDs.Add(typeof(TComponent), new HashSet()); } - if (!entityToTypeToPendingComponentID[pendingComponentMessage.entity].ContainsKey(typeof(TComponent))) + if (!typeToEntityToPendingComponentID.ContainsKey(typeof(TComponent))) { - entityToTypeToPendingComponentID[pendingComponentMessage.entity].Add(typeof(TComponent), pendingComponentMessage.componentID); - entityToTypeToPendingComponentPriority[pendingComponentMessage.entity].Add(typeof(TComponent), pendingComponentMessage.priority); + typeToEntityToPendingComponentID.Add(typeof(TComponent), new Dictionary()); + typeToEntityToPendingComponentPriority.Add(typeof(TComponent), new Dictionary()); + } + + if (!typeToEntityToPendingComponentID[typeof(TComponent)].ContainsKey(pendingComponentMessage.entity)) + { + typeToEntityToPendingComponentID[typeof(TComponent)].Add(pendingComponentMessage.entity, pendingComponentMessage.componentID); + typeToEntityToPendingComponentPriority[typeof(TComponent)].Add(pendingComponentMessage.entity, pendingComponentMessage.priority); componentMessageTypeToPendingComponentIDs[typeof(TComponent)].Add(pendingComponentMessage.componentID); } else { - if (pendingComponentMessage.priority < entityToTypeToPendingComponentPriority[pendingComponentMessage.entity][typeof(TComponent)]) + if (pendingComponentMessage.priority < typeToEntityToPendingComponentPriority[typeof(TComponent)][pendingComponentMessage.entity]) { - componentMessageTypeToPendingComponentIDs[typeof(TComponent)].Remove(entityToTypeToPendingComponentID[pendingComponentMessage.entity][typeof(TComponent)]); - entityToTypeToPendingComponentID[pendingComponentMessage.entity][typeof(TComponent)] = pendingComponentMessage.componentID; - entityToTypeToPendingComponentPriority[pendingComponentMessage.entity][typeof(TComponent)] = pendingComponentMessage.priority; + componentMessageTypeToPendingComponentIDs[typeof(TComponent)].Remove(typeToEntityToPendingComponentID[typeof(TComponent)][pendingComponentMessage.entity]); + typeToEntityToPendingComponentID[typeof(TComponent)][pendingComponentMessage.entity] = pendingComponentMessage.componentID; + typeToEntityToPendingComponentPriority[typeof(TComponent)][pendingComponentMessage.entity] = pendingComponentMessage.priority; componentMessageTypeToPendingComponentIDs[typeof(TComponent)].Add(pendingComponentMessage.componentID); } } @@ -138,7 +125,7 @@ namespace Encompass private void RegisterExistingOrPendingComponentMessage(Entity entity, Guid componentID, TComponent component) where TComponent : struct, IComponent { - componentIDToComponent[componentID] = component; + componentIDToComponent.Set(componentID, component); componentIDToEntityID[componentID] = entity.ID; componentIDToType[componentID] = typeof(TComponent); @@ -148,7 +135,11 @@ namespace Encompass } componentMessageTypeToComponentIDs[typeof(TComponent)].Add(componentID); - entityToTypeToComponentID[entity][typeof(TComponent)] = componentID; + if (!typeToEntityToComponentID.ContainsKey(typeof(TComponent))) + { + typeToEntityToComponentID.Add(typeof(TComponent), new Dictionary()); + } + typeToEntityToComponentID[typeof(TComponent)][entity] = componentID; } // general component reads by type @@ -157,7 +148,7 @@ namespace Encompass { if (componentMessageTypeToComponentIDs.TryGetValue(typeof(TComponent), out HashSet idSet)) { - return idSet.Select(id => (id, (TComponent)componentIDToComponent[id])); + return idSet.Select(id => (id, componentIDToComponent.Get(id))); } return Enumerable.Empty<(Guid, TComponent)>(); @@ -167,7 +158,7 @@ namespace Encompass { if (componentMessageTypeToExistingComponentIDs.TryGetValue(typeof(TComponent), out HashSet idSet)) { - return idSet.Select(id => (id, (TComponent)componentIDToComponent[id])); + return idSet.Select(id => (id, componentIDToComponent.Get(id))); } return Enumerable.Empty<(Guid, TComponent)>(); @@ -177,7 +168,7 @@ namespace Encompass { if (componentMessageTypeToPendingComponentIDs.TryGetValue(typeof(TComponent), out HashSet idSet)) { - return idSet.Select(id => (id, (TComponent)componentIDToComponent[id])); + return idSet.Select(id => (id, componentIDToComponent.Get(id))); } return Enumerable.Empty<(Guid, TComponent)>(); @@ -239,9 +230,9 @@ namespace Encompass internal (Guid, TComponent) ReadExistingComponentByEntityAndType(Entity entity) where TComponent : struct, IComponent { - if (entityToTypeToExistingComponentID.ContainsKey(entity) && entityToTypeToExistingComponentID[entity].TryGetValue(typeof(TComponent), out Guid id)) + if (typeToEntityToExistingComponentID.ContainsKey(typeof(TComponent)) && typeToEntityToExistingComponentID[typeof(TComponent)].TryGetValue(entity, out Guid id)) { - return (id, (TComponent)componentIDToComponent[id]); + return (id, componentIDToComponent.Get(id)); } else { @@ -249,23 +240,11 @@ namespace Encompass } } - internal (Guid, IComponent) ReadExistingComponentByEntityAndType(Entity entity, Type type) - { - if (entityToTypeToExistingComponentID.ContainsKey(entity) && entityToTypeToExistingComponentID[entity].TryGetValue(type, out Guid id)) - { - return (id, componentIDToComponent[id]); - } - else - { - throw new NoComponentOfTypeOnEntityException("No Component of type {0} exists on Entity {1}", type.Name, entity.ID); - } - } - internal (Guid, TComponent) ReadPendingComponentByEntityAndType(Entity entity) where TComponent : struct, IComponent { - if (entityToTypeToPendingComponentID.ContainsKey(entity) && entityToTypeToPendingComponentID[entity].TryGetValue(typeof(TComponent), out Guid id)) + if (typeToEntityToPendingComponentID.ContainsKey(typeof(TComponent)) && typeToEntityToPendingComponentID[typeof(TComponent)].TryGetValue(entity, out Guid id)) { - return (id, (TComponent)componentIDToComponent[id]); + return (id, componentIDToComponent.Get(id)); } else { @@ -273,55 +252,43 @@ namespace Encompass } } - internal (Guid, IComponent) ReadPendingComponentByEntityAndType(Entity entity, Type type) - { - if (entityToTypeToPendingComponentID.ContainsKey(entity) && entityToTypeToPendingComponentID[entity].TryGetValue(type, out Guid id)) - { - return (id, componentIDToComponent[id]); - } - else - { - throw new NoComponentOfTypeOnEntityException("No Component of type {0} exists on Entity {1}", type.Name, entity.ID); - } - } - // check if entity has component of type internal bool HasExistingOrPendingComponent(Entity entity) where TComponent : struct, IComponent { - return entityToTypeToComponentID.ContainsKey(entity) && entityToTypeToComponentID[entity].ContainsKey(typeof(TComponent)); + return typeToEntityToComponentID.ContainsKey(typeof(TComponent)) && typeToEntityToComponentID[typeof(TComponent)].ContainsKey(entity); } internal bool HasExistingOrPendingComponent(Entity entity, Type type) { - return entityToTypeToComponentID.ContainsKey(entity) && entityToTypeToComponentID[entity].ContainsKey(type); + return typeToEntityToComponentID.ContainsKey(type) && typeToEntityToComponentID[type].ContainsKey(entity); } internal bool HasExistingComponent(Entity entity) where TComponent : struct, IComponent { - return entityToTypeToExistingComponentID.ContainsKey(entity) && entityToTypeToExistingComponentID[entity].ContainsKey(typeof(TComponent)); + return typeToEntityToExistingComponentID.ContainsKey(typeof(TComponent)) && typeToEntityToExistingComponentID[typeof(TComponent)].ContainsKey(entity); } internal bool HasExistingComponent(Entity entity, Type type) { - return entityToTypeToExistingComponentID.ContainsKey(entity) && entityToTypeToExistingComponentID[entity].ContainsKey(type); + return typeToEntityToExistingComponentID.ContainsKey(type) && typeToEntityToExistingComponentID[type].ContainsKey(entity); } internal bool HasPendingComponent(Entity entity) where TComponent : struct, IComponent { - return entityToTypeToPendingComponentID.ContainsKey(entity) && entityToTypeToPendingComponentID[entity].ContainsKey(typeof(TComponent)); + return typeToEntityToPendingComponentID.ContainsKey(typeof(TComponent)) && typeToEntityToPendingComponentID[typeof(TComponent)].ContainsKey(entity); } internal bool HasPendingComponent(Entity entity, Type type) { - return entityToTypeToPendingComponentID.ContainsKey(entity) && entityToTypeToPendingComponentID[entity].ContainsKey(type); + return typeToEntityToPendingComponentID.ContainsKey(type) && typeToEntityToPendingComponentID[type].ContainsKey(entity); } - internal IComponent GetComponentByID(Guid componentID) + internal TComponent GetComponentByID(Guid componentID) where TComponent : struct, IComponent { - if (componentIDToComponent.ContainsKey(componentID)) + if (componentIDToComponent.Has(componentID)) { - return componentIDToComponent[componentID]; + return componentIDToComponent.Get(componentID); } else { diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index 1ca83d5..fcf6288 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -183,7 +183,7 @@ namespace Encompass /// protected Entity ReadEntity() where TComponent : struct, IComponent { - var (id, component) = ReadComponentHelper(); + var (id, _) = ReadComponentHelper(); return GetEntityByComponentID(id); } @@ -216,7 +216,7 @@ namespace Encompass throw new ComponentTypeMismatchException("Expected Component to be of type {0} but was actually of type {1}", typeof(TComponent).Name, componentMessageManager.GetComponentTypeByID(componentID).Name); } - return (TComponent)componentMessageManager.GetComponentByID(componentID); + return componentMessageManager.GetComponentByID(componentID); } // these next two are for the ComponentMessageEmitter only @@ -380,57 +380,6 @@ namespace Encompass return GetComponentHelper(entity).Item2; } - private (Guid, IComponent) GetComponentHelper(Entity entity, Type type) - { - var pending = typeof(PendingComponentMessage<>).MakeGenericType(type); - var existing = typeof(ComponentMessage<>).MakeGenericType(type); - - var pendingRead = receiveTypes.Contains(pending); - var existingRead = receiveTypes.Contains(existing); - - if (existingRead && pendingRead) - { - if (componentMessageManager.HasPendingComponent(entity, pending)) - { - return componentMessageManager.ReadPendingComponentByEntityAndType(entity, pending); - } - else if (componentMessageManager.HasExistingComponent(entity, existing)) - { - return componentMessageManager.ReadExistingComponentByEntityAndType(entity, existing); - } - else - { - throw new NoComponentOfTypeOnEntityException("No Component of type {0} exists on Entity {1}", type.Name, entity.ID); - } - } - else if (existingRead) - { - return componentMessageManager.ReadExistingComponentByEntityAndType(entity, existing); - } - else if (pendingRead) - { - return componentMessageManager.ReadPendingComponentByEntityAndType(entity, pending); - } - else - { - throw new IllegalReadException("Engine {0} tried to read undeclared Component {1}", GetType().Name, type.Name); - } - } - - /// - /// Returns a Component with the specified Type that exists on the Entity. - /// - /// - /// Thrown when the Entity does not have a Component of the specified Type - /// - /// - /// Thrown when the Engine does not declare that it reads the given Component Type. - /// - protected IComponent GetComponent(Entity entity, Type type) - { - return GetComponentHelper(entity, type).Item2; - } - /// /// Returns true if the Entity has a Component of the given Type. /// @@ -673,7 +622,7 @@ namespace Encompass { if (!HasComponent(entity)) { return false; } - var (componentID, component) = GetComponentHelper(entity); + var (componentID, _) = GetComponentHelper(entity); RemoveComponent(componentID); diff --git a/encompass-cs/EntityManager.cs b/encompass-cs/EntityManager.cs index 6a6e525..466b7da 100644 --- a/encompass-cs/EntityManager.cs +++ b/encompass-cs/EntityManager.cs @@ -12,12 +12,10 @@ namespace Encompass private readonly HashSet entitiesMarkedForDestroy = new HashSet(); private readonly ComponentManager componentManager; - private readonly ComponentMessageManager componentMessageManager; - public EntityManager(ComponentManager componentManager, ComponentMessageManager componentMessageManager) + public EntityManager(ComponentManager componentManager) { this.componentManager = componentManager; - this.componentMessageManager = componentMessageManager; } public Entity CreateEntity() @@ -26,7 +24,6 @@ namespace Encompass var entity = new Entity(id); IDToEntity[id] = entity; componentManager.RegisterEntity(id); - componentMessageManager.RegisterEntity(entity); return entity; } @@ -56,7 +53,6 @@ namespace Encompass { foreach (var entityID in entitiesMarkedForDestroy) { - componentMessageManager.RegisterDestroyedEntity(GetEntity(entityID)); componentManager.MarkAllComponentsOnEntityForRemoval(entityID); IDToEntity.Remove(entityID); componentManager.RegisterDestroyedEntity(entityID); diff --git a/encompass-cs/MessageManager.cs b/encompass-cs/MessageManager.cs index 7846092..c967d67 100644 --- a/encompass-cs/MessageManager.cs +++ b/encompass-cs/MessageManager.cs @@ -6,7 +6,7 @@ namespace Encompass { internal class MessageManager { - private TimeManager timeManager; + private readonly TimeManager timeManager; private readonly Dictionary> messageTypeToMessages = new Dictionary>(); diff --git a/encompass-cs/TimeManager.cs b/encompass-cs/TimeManager.cs index 4c23dee..79cfe8f 100644 --- a/encompass-cs/TimeManager.cs +++ b/encompass-cs/TimeManager.cs @@ -5,7 +5,7 @@ namespace Encompass { internal class TimeManager { - private List timeDilationDatas = new List(); + private readonly List timeDilationDatas = new List(32); private double Linear(double t, double b, double c, double d) { diff --git a/encompass-cs/WorldBuilder.cs b/encompass-cs/WorldBuilder.cs index 77802de..65b9c28 100644 --- a/encompass-cs/WorldBuilder.cs +++ b/encompass-cs/WorldBuilder.cs @@ -42,7 +42,7 @@ namespace Encompass componentManager = new ComponentManager(drawLayerManager); messageManager = new MessageManager(timeManager); componentMessageManager = new ComponentMessageManager(); - entityManager = new EntityManager(componentManager, componentMessageManager); + entityManager = new EntityManager(componentManager); renderManager = new RenderManager(componentManager, drawLayerManager, entityManager); } diff --git a/encompass-cs/encompass-cs.csproj b/encompass-cs/encompass-cs.csproj index 30aae01..52f3410 100644 --- a/encompass-cs/encompass-cs.csproj +++ b/encompass-cs/encompass-cs.csproj @@ -9,7 +9,7 @@ Moonside Games Encompass ECS https://github.com/encompass-ecs - + Evan Hemsley 2019 Encompass is an engine-agnostic Hyper ECS framework to help you code games, or other kinds of simulations. true @@ -19,11 +19,11 @@ True - + - - + + diff --git a/test/ComponentTest.cs b/test/ComponentTest.cs index e7c5c54..3c6d061 100644 --- a/test/ComponentTest.cs +++ b/test/ComponentTest.cs @@ -267,45 +267,6 @@ namespace Tests Assert.AreEqual(mockComponent, gottenMockComponent); } - - [Receives(typeof(EntityMessage))] - [Reads(typeof(MockComponent))] - class GetMockComponentByRuntimeType : Engine - { - public override void Update(double dt) - { - foreach (var entityMessage in ReadMessages()) - { - gottenMockComponent = (MockComponent)GetComponent(entityMessage.entity, typeof(MockComponent)); - } - } - } - - [Test] - public void GetComponentByRuntimeType() - { - var worldBuilder = new WorldBuilder(); - worldBuilder.AddEngine(new GetMockComponentEngine()); - - var entity = worldBuilder.CreateEntity(); - - MockComponent mockComponent; - mockComponent.myInt = 3; - mockComponent.myString = "hello"; - - worldBuilder.SetComponent(entity, mockComponent); - - EntityMessage entityMessage; - entityMessage.entity = entity; - worldBuilder.SendMessage(entityMessage); - - var world = worldBuilder.Build(); - - world.Update(0.01); - - Assert.AreEqual(mockComponent, gottenMockComponent); - } - struct HasComponentTestMessage : IMessage { public Entity entity;