From 812fe10ca1d55a7a13c1d186f0e7f76ff5fb0d14 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Sat, 21 Mar 2020 17:38:35 -0700 Subject: [PATCH] remove unmanaged constraint from component storage --- encompass-cs/Collections/ComponentStore.cs | 22 +++--- encompass-cs/Collections/FixedArray.cs | 69 ------------------- encompass-cs/Collections/Replayer.cs | 2 +- .../Collections/TypedComponentStore.cs | 6 +- encompass-cs/ComponentManager.cs | 52 +++++++------- encompass-cs/Engine.cs | 36 +++++----- encompass-cs/RenderManager.cs | 2 +- encompass-cs/Renderer.cs | 18 ++--- encompass-cs/Renderers/OrderedRenderer.cs | 2 +- encompass-cs/WorldBuilder.cs | 6 +- 10 files changed, 73 insertions(+), 142 deletions(-) delete mode 100644 encompass-cs/Collections/FixedArray.cs diff --git a/encompass-cs/Collections/ComponentStore.cs b/encompass-cs/Collections/ComponentStore.cs index 2743e68..719180d 100644 --- a/encompass-cs/Collections/ComponentStore.cs +++ b/encompass-cs/Collections/ComponentStore.cs @@ -16,7 +16,7 @@ namespace Encompass ComponentBitSet = new ComponentBitSet(typeToIndex); } - public virtual void RegisterComponentType() where TComponent : unmanaged + public virtual void RegisterComponentType() where TComponent : struct { if (!_stores.ContainsKey(typeof(TComponent))) { @@ -27,13 +27,13 @@ namespace Encompass if (!_typeToIndex.ContainsKey(typeof(TComponent))) { _typeToIndex.Add(typeof(TComponent), _typeToIndex.Count); } } - private TypedComponentStore Lookup() where TComponent : unmanaged + private TypedComponentStore Lookup() where TComponent : struct { RegisterComponentType(); return _stores[typeof(TComponent)] as TypedComponentStore; } - public bool Has(int entityID) where TComponent : unmanaged + public bool Has(int entityID) where TComponent : struct { return Lookup().Has(entityID); } @@ -48,18 +48,18 @@ namespace Encompass return ComponentBitSet.EntityBitArray(entityID); } - public ref readonly TComponent Get(int entityID) where TComponent : unmanaged + public ref readonly TComponent Get(int entityID) where TComponent : struct { return ref Lookup().Get(entityID); } - public virtual void Set(int entityID, TComponent component) where TComponent : unmanaged + public virtual void Set(int entityID, TComponent component) where TComponent : struct { Lookup().Set(entityID, component); ComponentBitSet.Set(entityID); } - public virtual bool Set(int entityID, TComponent component, int priority) where TComponent : unmanaged + public virtual bool Set(int entityID, TComponent component, int priority) where TComponent : struct { if (Lookup().Set(entityID, component, priority)) { @@ -69,7 +69,7 @@ namespace Encompass return false; } - public virtual bool Remove(int entityID, int priority) where TComponent : unmanaged + public virtual bool Remove(int entityID, int priority) where TComponent : struct { if (Lookup().Remove(entityID, priority)) { @@ -79,7 +79,7 @@ namespace Encompass return false; } - public void ForceRemove(int entityID) where TComponent : unmanaged + public void ForceRemove(int entityID) where TComponent : struct { Lookup().ForceRemove(entityID); ComponentBitSet.RemoveComponent(entityID); @@ -94,17 +94,17 @@ namespace Encompass ComponentBitSet.RemoveEntity(entityID); } - public bool Any() where TComponent : unmanaged + public bool Any() where TComponent : struct { return Lookup().Count > 0; } - public IEnumerable<(TComponent, int)> All() where TComponent : unmanaged + public IEnumerable<(TComponent, int)> All() where TComponent : struct { return Lookup().All(); } - public void Clear() where TComponent : unmanaged + public void Clear() where TComponent : struct { Lookup().Clear(); } diff --git a/encompass-cs/Collections/FixedArray.cs b/encompass-cs/Collections/FixedArray.cs deleted file mode 100644 index 242e9c6..0000000 --- a/encompass-cs/Collections/FixedArray.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -internal unsafe class FixedArray : IDisposable where T : unmanaged -{ - private void* _buffer; - - public int Length { get; private set; } - - public T this[int i] - { - get { return ReadElement(_buffer, i); } - set { WriteElement(_buffer, i, value); } - } - - public unsafe FixedArray(int length, bool clearMemory = false) - { - var bufferSize = Marshal.SizeOf() * length; - _buffer = (void*)Alloc(bufferSize); - - if (clearMemory) - { - Memset(_buffer, 0, bufferSize); - } - - Length = length; - } - - public ref T ByRef(int i) - { - return ref *(T*)((byte*)_buffer + i * sizeof(T)); - } - - void IDisposable.Dispose() - { - Free((IntPtr)_buffer); - _buffer = null; - Length = 0; - } - - private static T ReadElement(void* buffer, int i) - { - return *(T*)((byte*)buffer + i * sizeof(T)); - } - - private static void WriteElement(void* buffer, int i, T value) - { - *(T*)((byte*)buffer + i * sizeof(T)) = value; - } - - private unsafe static IntPtr Alloc(int size) - { - return Marshal.AllocHGlobal(size); - } - - public unsafe static void Free(IntPtr ptr) - { - if (ptr != IntPtr.Zero) - { - Marshal.FreeHGlobal(ptr); - } - } - - private unsafe static void Memset(void* ptr, byte value, int count) - { - Unsafe.InitBlock(ptr, value, (uint)count); - } -} diff --git a/encompass-cs/Collections/Replayer.cs b/encompass-cs/Collections/Replayer.cs index 0bb9414..46f184a 100644 --- a/encompass-cs/Collections/Replayer.cs +++ b/encompass-cs/Collections/Replayer.cs @@ -10,7 +10,7 @@ namespace Encompass public abstract void Clear(); } - internal class Replayer : Replayer where TComponent : unmanaged + internal class Replayer : Replayer where TComponent : struct { private readonly ComponentDeltaStore _deltaStore; private readonly HashSet _removals = new HashSet(); diff --git a/encompass-cs/Collections/TypedComponentStore.cs b/encompass-cs/Collections/TypedComponentStore.cs index 8ae25b6..cc77e07 100644 --- a/encompass-cs/Collections/TypedComponentStore.cs +++ b/encompass-cs/Collections/TypedComponentStore.cs @@ -14,11 +14,11 @@ namespace Encompass public abstract void ClearPriorities(); } - internal unsafe class TypedComponentStore : TypedComponentStore where TComponent : unmanaged + internal unsafe class TypedComponentStore : TypedComponentStore where TComponent : struct { private readonly Dictionary _indices = new Dictionary(512); private readonly Dictionary _priorities = new Dictionary(512); - private readonly FixedArray _components = new FixedArray(512); // TODO: allow specify size + private readonly TComponent[] _components = new TComponent[512]; // TODO: allow specify size private readonly IDManager _idManager = new IDManager(); public override int Count { get => _indices.Count; } @@ -26,7 +26,7 @@ namespace Encompass 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); } - return ref _components.ByRef(_indices[entityID]); + return ref _components[_indices[entityID]]; } public unsafe void Set(int entityID, TComponent component) diff --git a/encompass-cs/ComponentManager.cs b/encompass-cs/ComponentManager.cs index da1a782..aacdc6a 100644 --- a/encompass-cs/ComponentManager.cs +++ b/encompass-cs/ComponentManager.cs @@ -29,7 +29,7 @@ namespace Encompass TypeToIndex = typeToIndex; } - public void RegisterComponentType() where TComponent : unmanaged + public void RegisterComponentType() where TComponent : struct { _existingComponentStore.RegisterComponentType(); _immediateComponentStore.RegisterComponentType(); @@ -47,7 +47,7 @@ namespace Encompass _upToDateComponentStore.SwapWith(componentStore); } - internal void RegisterDrawableComponent(int entityID, int layer) where TComponent : unmanaged + internal void RegisterDrawableComponent(int entityID, int layer) where TComponent : struct { _drawLayerManager.RegisterComponentWithLayer(entityID, layer); } @@ -61,7 +61,7 @@ namespace Encompass _replayStore.ClearAll(); } - internal bool AddImmediateComponent(int entityID, TComponent component, int priority) where TComponent : unmanaged + internal bool AddImmediateComponent(int entityID, TComponent component, int priority) where TComponent : struct { if (_immediateComponentStore.Set(entityID, component, priority)) { @@ -73,14 +73,14 @@ namespace Encompass return false; } - internal void AddImmediateComponent(int entityID, TComponent component) where TComponent : unmanaged + internal void AddImmediateComponent(int entityID, TComponent component) where TComponent : struct { _immediateComponentStore.Set(entityID, component); _replayStore.Set(entityID, component); _upToDateComponentStore.Set(entityID, component); } - internal bool UpdateComponent(int entityID, TComponent component, int priority) where TComponent : unmanaged + internal bool UpdateComponent(int entityID, TComponent component, int priority) where TComponent : struct { var result = _upToDateComponentStore.Set(entityID, component, priority); if (result) @@ -90,7 +90,7 @@ namespace Encompass return result; } - internal void AddComponent(int entityID, TComponent component) where TComponent : unmanaged + internal void AddComponent(int entityID, TComponent component) where TComponent : struct { _upToDateComponentStore.Set(entityID, component); _replayStore.Set(entityID, component); @@ -98,12 +98,12 @@ namespace Encompass // existing or immediate reads - internal IEnumerable<(TComponent, int)> ReadExistingAndImmediateComponentsByType() where TComponent : unmanaged + internal IEnumerable<(TComponent, int)> ReadExistingAndImmediateComponentsByType() where TComponent : struct { return _upToDateComponentStore.All(); } - internal (TComponent, int) ReadFirstExistingOrImmediateComponentByType() where TComponent : unmanaged + internal (TComponent, int) ReadFirstExistingOrImmediateComponentByType() where TComponent : struct { if (!SomeExistingOrImmediateComponent()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); } var enumerator = ReadExistingAndImmediateComponentsByType().GetEnumerator(); @@ -111,14 +111,14 @@ namespace Encompass return enumerator.Current; } - internal bool SomeExistingOrImmediateComponent() where TComponent : unmanaged + internal bool SomeExistingOrImmediateComponent() where TComponent : struct { return _upToDateComponentStore.Any(); } // existing reads - internal (TComponent, int) ReadFirstExistingComponentByType() where TComponent : unmanaged + internal (TComponent, int) ReadFirstExistingComponentByType() where TComponent : struct { if (!SomeExistingComponent()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); } var enumerator = GetComponentsIncludingEntity().GetEnumerator(); @@ -126,19 +126,19 @@ namespace Encompass return enumerator.Current; } - internal bool SomeExistingComponent() where TComponent : unmanaged + internal bool SomeExistingComponent() where TComponent : struct { return _existingComponentStore.Any(); } // immediate reads - internal IEnumerable<(TComponent, int)> ReadImmediateComponentsByType() where TComponent : unmanaged + internal IEnumerable<(TComponent, int)> ReadImmediateComponentsByType() where TComponent : struct { return _immediateComponentStore.All(); } - internal (TComponent, int) ReadFirstImmediateComponentByType() where TComponent : unmanaged + internal (TComponent, int) ReadFirstImmediateComponentByType() where TComponent : struct { if (!SomeImmediateComponent()) { throw new Exceptions.NoComponentOfTypeException($"No Component with type {typeof(TComponent)} exists"); } var enumerator = ReadImmediateComponentsByType().GetEnumerator(); @@ -146,31 +146,31 @@ namespace Encompass return enumerator.Current; } - internal bool SomeImmediateComponent() where TComponent : unmanaged + internal bool SomeImmediateComponent() where TComponent : struct { return _immediateComponentStore.Any(); } // component getters - internal ref readonly TComponent ReadImmediateOrExistingComponentByEntityAndType(int entityID) where TComponent : unmanaged + internal ref readonly TComponent ReadImmediateOrExistingComponentByEntityAndType(int entityID) where TComponent : struct { return ref _upToDateComponentStore.Get(entityID); } - internal ref readonly TComponent ReadExistingComponentByEntityAndType(int entityID) where TComponent : unmanaged + internal ref readonly TComponent ReadExistingComponentByEntityAndType(int entityID) where TComponent : struct { return ref _existingComponentStore.Get(entityID); } - internal ref readonly TComponent ReadImmediateComponentByEntityAndType(int entityID) where TComponent : unmanaged + internal ref readonly TComponent ReadImmediateComponentByEntityAndType(int entityID) where TComponent : struct { return ref _immediateComponentStore.Get(entityID); } // has checkers - internal bool HasExistingOrImmediateComponent(int entityID) where TComponent : unmanaged + internal bool HasExistingOrImmediateComponent(int entityID) where TComponent : struct { return _upToDateComponentStore.Has(entityID); } @@ -180,7 +180,7 @@ namespace Encompass return _upToDateComponentStore.Has(type, entityID); } - internal bool HasExistingComponent(int entityID) where TComponent : unmanaged + internal bool HasExistingComponent(int entityID) where TComponent : struct { return _existingComponentStore.Has(entityID); } @@ -190,7 +190,7 @@ namespace Encompass return _existingComponentStore.Has(type, entityID); } - internal bool HasImmediateComponent(int entityID) where TComponent : unmanaged + internal bool HasImmediateComponent(int entityID) where TComponent : struct { return _immediateComponentStore.Has(entityID); } @@ -200,12 +200,12 @@ namespace Encompass return _immediateComponentStore.Has(type, entityID); } - internal IEnumerable<(TComponent, int)> GetComponentsIncludingEntity() where TComponent : unmanaged + internal IEnumerable<(TComponent, int)> GetComponentsIncludingEntity() where TComponent : struct { return _existingComponentStore.All(); } - internal IEnumerable GetComponentsByType() where TComponent : unmanaged + internal IEnumerable GetComponentsByType() where TComponent : struct { foreach (var pair in _existingComponentStore.All()) { @@ -213,12 +213,12 @@ namespace Encompass } } - internal ref readonly TComponent GetComponentByEntityAndType(int entityID) where TComponent : unmanaged + internal ref readonly TComponent GetComponentByEntityAndType(int entityID) where TComponent : struct { return ref _existingComponentStore.Get(entityID); } - internal bool EntityHasComponentOfType(int entityID) where TComponent : unmanaged + internal bool EntityHasComponentOfType(int entityID) where TComponent : struct { return _existingComponentStore.Has(entityID); } @@ -242,7 +242,7 @@ namespace Encompass _entitiesMarkedForRemoval.Clear(); } - public bool RemoveImmediate(int entityID, int priority) where TComponent : unmanaged + public bool RemoveImmediate(int entityID, int priority) where TComponent : struct { if (_immediateComponentStore.Remove(entityID, priority)) { @@ -254,7 +254,7 @@ namespace Encompass return false; } - public void Remove(int entityID, int priority) where TComponent : unmanaged + public void Remove(int entityID, int priority) where TComponent : struct { if (_upToDateComponentStore.Remove(entityID, priority)) { diff --git a/encompass-cs/Engine.cs b/encompass-cs/Engine.cs index bc29221..1116c0c 100644 --- a/encompass-cs/Engine.cs +++ b/encompass-cs/Engine.cs @@ -213,7 +213,7 @@ namespace Encompass /// /// Returns an Entity containing the specified Component type. /// - protected Entity ReadEntity() where TComponent : unmanaged + protected Entity ReadEntity() where TComponent : struct { return _entityManager.GetEntity(ReadComponentHelper().Item2); } @@ -221,7 +221,7 @@ namespace Encompass /// /// Returns all Entities containing the specified Component type. /// - protected IEnumerable ReadEntities() where TComponent : unmanaged + protected IEnumerable ReadEntities() where TComponent : struct { foreach (var pair in ReadComponentsHelper()) { @@ -231,12 +231,12 @@ namespace Encompass // these next two are for the ComponentMessageEmitter only - internal IEnumerable ReadComponentsFromWorld() where TComponent : unmanaged + internal IEnumerable ReadComponentsFromWorld() where TComponent : struct { return _componentManager.GetComponentsByType(); } - private IEnumerable<(TComponent, int)> ReadComponentsHelper() where TComponent : unmanaged + private IEnumerable<(TComponent, int)> ReadComponentsHelper() where TComponent : struct { var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); var existingRead = ReadTypes.Contains(typeof(TComponent)); @@ -261,7 +261,7 @@ namespace Encompass /// /// Returns all of the Components with the specified Component Type. /// - protected IEnumerable ReadComponents() where TComponent : unmanaged + protected IEnumerable ReadComponents() where TComponent : struct { foreach (var pair in ReadComponentsHelper()) { @@ -272,7 +272,7 @@ namespace Encompass /// /// Returns all of the components of the specified type including an Entity reference for each Component. /// - protected IEnumerable<(TComponent, Entity)> ReadComponentsIncludingEntity() where TComponent : unmanaged + protected IEnumerable<(TComponent, Entity)> ReadComponentsIncludingEntity() where TComponent : struct { foreach (var (component, id) in ReadComponentsHelper()) { @@ -280,7 +280,7 @@ namespace Encompass } } - private (TComponent, int) ReadComponentHelper() where TComponent : unmanaged + private (TComponent, int) ReadComponentHelper() where TComponent : struct { var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); var existingRead = ReadTypes.Contains(typeof(TComponent)); @@ -305,7 +305,7 @@ namespace Encompass /// /// Returns a Component with the specified Component Type. If multiples exist, an arbitrary Component is returned. /// - protected TComponent ReadComponent() where TComponent : unmanaged + protected TComponent ReadComponent() where TComponent : struct { return ReadComponentHelper().Item1; } @@ -313,7 +313,7 @@ namespace Encompass /// /// Returns a component of the specified type including its Entity reference. If multiples exist, an arbitrary Component is returned. /// - protected (TComponent, Entity) ReadComponentIncludingEntity() where TComponent : unmanaged + protected (TComponent, Entity) ReadComponentIncludingEntity() where TComponent : struct { var (component, id) = ReadComponentHelper(); return (component, _entityManager.GetEntity(id)); @@ -322,7 +322,7 @@ namespace Encompass /// /// Returns true if any Component with the specified Component Type exists. /// - protected bool SomeComponent() where TComponent : unmanaged + protected bool SomeComponent() where TComponent : struct { var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); var existingRead = ReadTypes.Contains(typeof(TComponent)); @@ -344,7 +344,7 @@ namespace Encompass } } - private ref readonly TComponent GetComponentHelper(int entityID) where TComponent : unmanaged + private ref readonly TComponent GetComponentHelper(int entityID) where TComponent : struct { var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); var existingRead = ReadTypes.Contains(typeof(TComponent)); @@ -375,7 +375,7 @@ namespace Encompass /// /// Thrown when the Engine does not declare that it reads the given Component Type. /// - protected ref readonly TComponent GetComponent(Entity entity) where TComponent : unmanaged + protected ref readonly TComponent GetComponent(Entity entity) where TComponent : struct { return ref GetComponentHelper(entity.ID); } @@ -386,7 +386,7 @@ namespace Encompass /// /// Thrown when the Engine does not declare that is Reads the given Component Type. /// - protected bool HasComponent(Entity entity) where TComponent : unmanaged + protected bool HasComponent(Entity entity) where TComponent : struct { var immediateRead = ReadImmediateTypes.Contains(typeof(TComponent)); var existingRead = ReadTypes.Contains(typeof(TComponent)); @@ -444,7 +444,7 @@ namespace Encompass /// /// Thrown when the Engine does not declare that it Writes the given Component Type. /// - protected void SetComponent(Entity entity, TComponent component) where TComponent : unmanaged + protected void SetComponent(Entity entity, TComponent component) where TComponent : struct { var priority = WritePriorities.ContainsKey(typeof(TComponent)) ? WritePriorities[typeof(TComponent)] : DefaultWritePriority; @@ -484,7 +484,7 @@ namespace Encompass /// /// Thrown when the Engine does not declare that it Writes the given Component Type. /// - protected void AddComponent(Entity entity, TComponent component) where TComponent : unmanaged + protected void AddComponent(Entity entity, TComponent component) where TComponent : struct { if (!EntityCreatedThisFrame(entity.ID)) { @@ -592,7 +592,7 @@ namespace Encompass /// Destroys an arbitrary Entity containing a Component of the specified Type. /// Entity destruction takes place after all the Engines have been processed by World Update. /// - protected void DestroyWith() where TComponent : unmanaged + protected void DestroyWith() where TComponent : struct { Destroy(ReadEntity()); } @@ -601,7 +601,7 @@ namespace Encompass /// Destroys all Entities containing a Component of the specified Type. /// Entity destruction takes place after all the Engines have been processed by World Update. /// - protected void DestroyAllWith() where TComponent : unmanaged + protected void DestroyAllWith() where TComponent : struct { foreach (var entity in ReadEntities()) { @@ -614,7 +614,7 @@ namespace Encompass /// Note that the Engine must Read the Component type that is being removed. /// If a Component with the specified type does not exist on the Entity, returns false and does not mutate the Entity. /// - protected void RemoveComponent(Entity entity) where TComponent : unmanaged + protected void RemoveComponent(Entity entity) where TComponent : struct { var priority = WritePriorities.ContainsKey(typeof(TComponent)) ? WritePriorities[typeof(TComponent)] : DefaultWritePriority; diff --git a/encompass-cs/RenderManager.cs b/encompass-cs/RenderManager.cs index 0fa030b..f2031ae 100644 --- a/encompass-cs/RenderManager.cs +++ b/encompass-cs/RenderManager.cs @@ -16,7 +16,7 @@ namespace Encompass _drawLayerManager = drawLayerManager; } - public void RegisterOrderedRenderer(Action renderAction) where TComponent : unmanaged + public void RegisterOrderedRenderer(Action renderAction) where TComponent : struct { _drawComponentTypeToOrderedRenderer.Add(typeof(TComponent), renderAction); _drawLayerManager.RegisterOrderedDrawable(); diff --git a/encompass-cs/Renderer.cs b/encompass-cs/Renderer.cs index 07939f2..2b9d513 100644 --- a/encompass-cs/Renderer.cs +++ b/encompass-cs/Renderer.cs @@ -17,7 +17,7 @@ namespace Encompass _componentManager = componentManager; } - protected IEnumerable ReadEntities() where TComponent : unmanaged + protected IEnumerable ReadEntities() where TComponent : struct { foreach (var pair in ReadComponentsIncludingEntity()) { @@ -25,17 +25,17 @@ namespace Encompass } } - protected Entity ReadEntity() where TComponent : unmanaged + protected Entity ReadEntity() where TComponent : struct { return ReadComponentIncludingEntity().Item2; } - protected IEnumerable ReadComponents() where TComponent : unmanaged + protected IEnumerable ReadComponents() where TComponent : struct { return _componentManager.GetComponentsByType(); } - protected IEnumerable<(TComponent, Entity)> ReadComponentsIncludingEntity() where TComponent : unmanaged + protected IEnumerable<(TComponent, Entity)> ReadComponentsIncludingEntity() where TComponent : struct { foreach (var (component, id) in _componentManager.GetComponentsIncludingEntity()) { @@ -43,31 +43,31 @@ namespace Encompass } } - protected TComponent ReadComponent() where TComponent : unmanaged + protected TComponent ReadComponent() where TComponent : struct { var enumerator = ReadComponents().GetEnumerator(); enumerator.MoveNext(); return enumerator.Current; } - protected (TComponent, Entity) ReadComponentIncludingEntity() where TComponent : unmanaged + protected (TComponent, Entity) ReadComponentIncludingEntity() where TComponent : struct { var enumerator = ReadComponentsIncludingEntity().GetEnumerator(); enumerator.MoveNext(); return enumerator.Current; } - protected ref readonly TComponent GetComponent(Entity entity) where TComponent : unmanaged + protected ref readonly TComponent GetComponent(Entity entity) where TComponent : struct { return ref _componentManager.GetComponentByEntityAndType(entity.ID); } - protected bool HasComponent(Entity entity) where TComponent : unmanaged + protected bool HasComponent(Entity entity) where TComponent : struct { return _componentManager.EntityHasComponentOfType(entity.ID); } - protected bool SomeComponent() where TComponent : unmanaged + protected bool SomeComponent() where TComponent : struct { return _componentManager.SomeExistingComponent(); } diff --git a/encompass-cs/Renderers/OrderedRenderer.cs b/encompass-cs/Renderers/OrderedRenderer.cs index a8458ae..da480df 100644 --- a/encompass-cs/Renderers/OrderedRenderer.cs +++ b/encompass-cs/Renderers/OrderedRenderer.cs @@ -5,7 +5,7 @@ namespace Encompass /// /// OrdereredRenderer provides a structure for the common pattern of wishing to draw a specific DrawComponent at a specific layer. /// - public abstract class OrderedRenderer : Renderer where TComponent : unmanaged, IDrawableComponent + public abstract class OrderedRenderer : Renderer where TComponent : struct, IDrawableComponent { public abstract void Render(Entity entity, in TComponent drawComponent); diff --git a/encompass-cs/WorldBuilder.cs b/encompass-cs/WorldBuilder.cs index 461c159..17eb320 100644 --- a/encompass-cs/WorldBuilder.cs +++ b/encompass-cs/WorldBuilder.cs @@ -84,7 +84,7 @@ namespace Encompass /// /// Sets Component data for the specified Component Type on the specified Entity. /// - public void SetComponent(Entity entity, TComponent component) where TComponent : unmanaged + public void SetComponent(Entity entity, TComponent component) where TComponent : struct { RegisterComponentType(); _startingExistingComponentStore.Set(entity.ID, component); @@ -97,7 +97,7 @@ namespace Encompass } } - internal void RegisterComponentType() where TComponent : unmanaged + internal void RegisterComponentType() where TComponent : struct { if (!_typeToIndex.ContainsKey(typeof(TComponent))) { @@ -183,7 +183,7 @@ namespace Encompass /// /// Adds the specified OrderedRenderer to the World. /// - public OrderedRenderer AddOrderedRenderer(OrderedRenderer renderer) where TComponent : unmanaged, IDrawableComponent + public OrderedRenderer AddOrderedRenderer(OrderedRenderer renderer) where TComponent : struct, IDrawableComponent { RegisterComponentType(); renderer.AssignEntityManager(_entityManager);