diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index 3f47d27..864d310 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -26,7 +26,7 @@ namespace GlitchyEditor.EditWindows if(_editor.SelectedEntities.Count == 1) { - Entity entity = _editor.SelectedEntities.Front; + EcsEntity entity = _editor.SelectedEntities.Front; ShowComponents(entity); } @@ -34,7 +34,7 @@ namespace GlitchyEditor.EditWindows ImGui.End(); } - private void ShowComponents(Entity entity) + private void ShowComponents(EcsEntity entity) { NameComponentEditor.Show(_editor.World, entity); TransformComponentEditor.Show(_editor.World, entity); @@ -43,7 +43,7 @@ namespace GlitchyEditor.EditWindows static class NameComponentEditor { - public static void Show(EcsWorld world, Entity entity) + public static void Show(EcsWorld world, EcsEntity entity) { char8[128] nameBuffer = default; @@ -78,7 +78,7 @@ namespace GlitchyEditor.EditWindows static class TransformComponentEditor { - public static void Show(EcsWorld world, Entity entity) + public static void Show(EcsWorld world, EcsEntity entity) { TransformComponent* component = world.GetComponent(entity); diff --git a/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf b/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf index 0ff530c..e5a81b2 100644 --- a/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf +++ b/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf @@ -111,7 +111,7 @@ namespace GlitchyEditor.EditWindows } } - private void ImGuiPrintEntityTree(TreeNode tree) + private void ImGuiPrintEntityTree(TreeNode tree) { String name = null; @@ -140,7 +140,7 @@ namespace GlitchyEditor.EditWindows if(ImGui.BeginDragDropSource()) { - ImGui.SetDragDropPayload("DND_Entity", &tree.Value, sizeof(Entity)); + ImGui.SetDragDropPayload("DND_Entity", &tree.Value, sizeof(EcsEntity)); ImGui.Text(name); @@ -153,13 +153,13 @@ namespace GlitchyEditor.EditWindows if(payload != null) { - Log.ClientLogger.AssertDebug(payload.DataSize == sizeof(Entity)); + Log.ClientLogger.AssertDebug(payload.DataSize == sizeof(EcsEntity)); - Entity movedEntity = *(Entity*)payload.Data; + EcsEntity movedEntity = *(EcsEntity*)payload.Data; bool dropLegal = true; - Entity walker = tree.Value; + EcsEntity walker = tree.Value; // make sure the dropped entity is not a parent of the entity we dropped it on. while(true) @@ -230,9 +230,9 @@ namespace GlitchyEditor.EditWindows { // Show entity hierarchy as tree - TreeNode root = scope .(.InvalidEntity); + TreeNode root = scope .(.InvalidEntity); - TreeNode AddEntity(Entity entity) + TreeNode AddEntity(EcsEntity entity) { var parent = _editor.World.GetComponent(entity); @@ -264,9 +264,9 @@ namespace GlitchyEditor.EditWindows if(payload != null) { - Log.ClientLogger.AssertDebug(payload.DataSize == sizeof(Entity)); + Log.ClientLogger.AssertDebug(payload.DataSize == sizeof(EcsEntity)); - Entity movedEntity = *(Entity*)payload.Data; + EcsEntity movedEntity = *(EcsEntity*)payload.Data; _editor.World.RemoveComponent(movedEntity); diff --git a/GlitchyEditor/src/Editor.bf b/GlitchyEditor/src/Editor.bf index 8c07677..18e3616 100644 --- a/GlitchyEditor/src/Editor.bf +++ b/GlitchyEditor/src/Editor.bf @@ -9,26 +9,28 @@ namespace GlitchyEditor { class Editor { - private EcsWorld _world; + private EcsWorld _ecsWorld; + private Scene _scene; private EntityHierarchyWindow _entityHierarchyWindow = new .(this) ~ delete _; private ComponentEditWindow _componentEditWindow = new .(this) ~ delete _; private SceneViewportWindow _sceneViewportWindow = new .(this) ~ delete _; - private List _selectedEntities = new .() ~ delete _; + private List _selectedEntities = new .() ~ delete _; - public EcsWorld World => _world; + public EcsWorld World => _ecsWorld; - public List SelectedEntities => _selectedEntities; + public List SelectedEntities => _selectedEntities; public EntityHierarchyWindow EntityHierarchyWindow => _entityHierarchyWindow; public ComponentEditWindow ComponentEditWindow => _componentEditWindow; public SceneViewportWindow SceneViewportWindow => _sceneViewportWindow; /// Creates a new editor for the given world - public this(EcsWorld world) + public this(Scene scene) { - _world = world; + _scene = scene; + _ecsWorld = _scene.[Friend]_ecsWorld; } public void Update() @@ -39,14 +41,14 @@ namespace GlitchyEditor } /// Creates a new entity with a transform component. - internal Entity CreateEntityWithTransform() + internal EcsEntity CreateEntityWithTransform() { - var entity = _world.NewEntity(); + var entity = _ecsWorld.NewEntity(); - var transformComponent = ref *_world.AssignComponent(entity); + var transformComponent = ref *_ecsWorld.AssignComponent(entity); transformComponent = TransformComponent(); - var nameComponent = ref *_world.AssignComponent(entity); + var nameComponent = ref *_ecsWorld.AssignComponent(entity); nameComponent.SetName("Entity"); return entity; @@ -56,11 +58,11 @@ namespace GlitchyEditor /// Returns whether or not all selected entities have the same parent. internal bool AllSelectionsOnSameLevel() { - Entity? parent = .InvalidEntity; + EcsEntity? parent = .InvalidEntity; for(var selectedEntity in _selectedEntities) { - var parentComponent = _world.GetComponent(selectedEntity); + var parentComponent = _ecsWorld.GetComponent(selectedEntity); if(parent == .InvalidEntity) { @@ -76,9 +78,9 @@ namespace GlitchyEditor } /// Finds all children of the given entity and stores their IDs in the given list. - internal void FindChildren(Entity entity, List entities) + internal void FindChildren(EcsEntity entity, List entities) { - for(var (child, childParent) in _world.Enumerate()) + for(var (child, childParent) in _ecsWorld.Enumerate()) { if(childParent.Entity == entity) { @@ -93,7 +95,7 @@ namespace GlitchyEditor /// Deletes all selected entities and their children. internal void DeleteSelectedEntities() { - List entities = scope .(); + List entities = scope .(); for(var entity in _selectedEntities) { @@ -104,7 +106,7 @@ namespace GlitchyEditor for(var entity in entities) { - _world.RemoveEntity(entity); + _ecsWorld.RemoveEntity(entity); } _selectedEntities.Clear(); diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index af29e0e..cea5f5f 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -20,7 +20,7 @@ namespace GlitchyEditor BlendState _alphaBlendState ~ _?.ReleaseRef(); BlendState _opaqueBlendState ~ _?.ReleaseRef(); - EcsWorld _world = new EcsWorld() ~ delete _; + Scene _scene = new Scene() ~ delete _; Editor _editor ~ delete _; @@ -33,7 +33,7 @@ namespace GlitchyEditor Application.Get().Window.IsVSync = false; InitGraphics(); - InitEcs(); + //InitEcs(); InitEditor(); } @@ -56,7 +56,7 @@ namespace GlitchyEditor _viewportTarget.SamplerState = SamplerStateManager.LinearClamp; } - private void InitEcs() + /*private void InitEcs() { _world.Register(); _world.Register(); @@ -66,18 +66,18 @@ namespace GlitchyEditor _world.Register(); _world.Register(); _world.Register(); - } + }*/ private void InitEditor() { - _editor = new Editor(_world); + _editor = new Editor(_scene); _editor.SceneViewportWindow.ViewportSizeChangedEvent.Add(new (s, e) => ViewportSizeChanged(s, e)); _cameraController = new .(_context.SwapChain.AspectRatio); _cameraController.CameraPosition = .(0, 0, -5); _cameraController.TranslationSpeed = 10; - _editor.[Friend]CreateEntityWithTransform(); + //_editor.[Friend]CreateEntityWithTransform(); _editor.SceneViewportWindow._camera = _cameraController.Camera; } @@ -87,7 +87,7 @@ namespace GlitchyEditor if(_editor.SceneViewportWindow.HasFocus && Input.IsMouseButtonPressed(.RightButton)) _cameraController.Update(gameTime); - TransformSystem.Update(_world); + //TransformSystem.Update(_world); RenderCommand.Clear(_viewportTarget, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0); @@ -98,11 +98,18 @@ namespace GlitchyEditor RenderCommand.SetBlendState(_opaqueBlendState); - Renderer.BeginScene(_cameraController.Camera); + //Renderer.BeginScene(_cameraController.Camera); - DebugRenderer.Render(_world); + //DebugRenderer.Render(_scene.[Friend]_ecsWorld); - Renderer.EndScene(); + //Renderer.EndScene(); + + Renderer2D.BeginScene(_cameraController.Camera); + + _scene.Update(gameTime); + + Renderer2D.EndScene(); + RenderCommand.Clear(null, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0); diff --git a/GlitchyEngine/src/Content/ModelLoader.bf b/GlitchyEngine/src/Content/ModelLoader.bf index 5d5912f..8cfe94f 100644 --- a/GlitchyEngine/src/Content/ModelLoader.bf +++ b/GlitchyEngine/src/Content/ModelLoader.bf @@ -33,9 +33,9 @@ namespace GlitchyEngine.Content CGLTF.Free(data); } - private static void NodesToEntities(CGLTF.Data* data, CGLTF.Node* node, Entity? parentEntity, EcsWorld world, Effect validationEffect, Material material, List clips) + private static void NodesToEntities(CGLTF.Data* data, CGLTF.Node* node, EcsEntity? parentEntity, EcsWorld world, Effect validationEffect, Material material, List clips) { - Entity entity = world.NewEntity(); + EcsEntity entity = world.NewEntity(); #if DEBUG var nameComponent = world.AssignComponent(entity); @@ -122,7 +122,7 @@ namespace GlitchyEngine.Content { for(var primitive in node.Mesh.Primitives) { - Entity meshEntity = world.NewEntity(); + EcsEntity meshEntity = world.NewEntity(); var meshParent = world.AssignComponent(meshEntity); meshParent.Entity = entity; diff --git a/GlitchyEngine/src/Math/BitArray.bf b/GlitchyEngine/src/Math/BitArray.bf index 4f3b4ee..6f92eaf 100644 --- a/GlitchyEngine/src/Math/BitArray.bf +++ b/GlitchyEngine/src/Math/BitArray.bf @@ -18,6 +18,11 @@ namespace GlitchyEngine.Math public this(int initialCapacity = sizeof(uint)) { + var initialCapacity; + + if (initialCapacity < sizeof(uint)) + initialCapacity = sizeof(uint); + EnsureCapacity(initialCapacity); } diff --git a/GlitchyEngine/src/Renderer/Renderer.bf b/GlitchyEngine/src/Renderer/Renderer.bf index a67a077..9230616 100644 --- a/GlitchyEngine/src/Renderer/Renderer.bf +++ b/GlitchyEngine/src/Renderer/Renderer.bf @@ -79,7 +79,7 @@ namespace GlitchyEngine.Renderer LineGeometry.SetVertexLayout(layout..ReleaseRefNoDelete()); } - public static void BeginScene(EcsWorld world, Entity cameraEntity) + public static void BeginScene(EcsWorld world, EcsEntity cameraEntity) { Debug.Profiler.ProfileRendererFunction!(); diff --git a/GlitchyEngine/src/World/Components.bf b/GlitchyEngine/src/World/Components.bf new file mode 100644 index 0000000..eae02b1 --- /dev/null +++ b/GlitchyEngine/src/World/Components.bf @@ -0,0 +1,34 @@ +using GlitchyEngine.Math; + +namespace GlitchyEngine.World +{ + struct SimpleTransformComponent + { + public Matrix Transform = Matrix.Identity; + + public this() + { + + } + + public this(Matrix transform) + { + Transform = transform; + } + } + + struct SpriterRendererComponent + { + public ColorRGBA Color = .White; + + public this() + { + + } + + public this(ColorRGBA color) + { + Color = color; + } + } +} \ No newline at end of file diff --git a/GlitchyEngine/src/World/EcsEntity.bf b/GlitchyEngine/src/World/EcsEntity.bf new file mode 100644 index 0000000..134561a --- /dev/null +++ b/GlitchyEngine/src/World/EcsEntity.bf @@ -0,0 +1,30 @@ +using System; + +using internal GlitchyEngine.World; + +namespace GlitchyEngine.World +{ + public struct EcsEntity : uint64 + { + // Binary Format: + // Bits: [0 - 31] [32 - 64] + // Data: Version Index + + [Inline] + internal uint32 Version => (uint32)this; + + [Inline] + internal uint32 Index => (uint32)(this >> 32); + + [Inline] + static internal EcsEntity CreateEntityID(uint32 index, uint32 version) + { + return ((uint64)index << 32) | version; + } + + [Inline] + internal bool IsValid => Index != InvalidEntity.Index; + + public const EcsEntity InvalidEntity = CreateEntityID(uint32.MaxValue, 0); + } +} \ No newline at end of file diff --git a/GlitchyEngine/src/World/EcsWorld.bf b/GlitchyEngine/src/World/EcsWorld.bf index 262f630..e17a685 100644 --- a/GlitchyEngine/src/World/EcsWorld.bf +++ b/GlitchyEngine/src/World/EcsWorld.bf @@ -10,7 +10,7 @@ namespace GlitchyEngine.World { const int MaxEntities = 1024; - internal typealias BitmaskEntry = (Entity ID, BitArray ComponentMask); + internal typealias BitmaskEntry = (EcsEntity ID, BitArray ComponentMask); internal List _entities = new .(); List _freeIndices = new List() ~ delete _; @@ -40,11 +40,11 @@ namespace GlitchyEngine.World delete _componentPools; } - + /** * Registers a new Component. */ - public void Register() where T: struct + public void Register() where T: struct, new { uint32 id = (uint32)_componentPools.Count; ComponentPool componentPool = new ComponentPool(MaxEntities); @@ -55,7 +55,7 @@ namespace GlitchyEngine.World /** * Registers a new Component. */ - public void Register() where T: struct, IDisposableComponent + public void Register() where T: struct, new, IDisposableComponent { uint32 id = (uint32)_componentPools.Count; ComponentPool componentPool = new ComponentPool(MaxEntities); @@ -88,23 +88,23 @@ namespace GlitchyEngine.World /** * Creates a new Entity and returns its ID. */ - public Entity NewEntity() + public EcsEntity NewEntity() { - Entity entity; + EcsEntity entity; // Reuse freed entity slot if(_freeIndices.Count > 0) { uint32 index = _freeIndices.PopBack(); - entity = Entity.CreateEntityID(index, _entities[index].ID.Version); + entity = EcsEntity.CreateEntityID(index, _entities[index].ID.Version); _entities[index].ID = entity; } // Create new entity slot else { - entity = Entity.CreateEntityID((.)_entities.Count, 0); + entity = EcsEntity.CreateEntityID((.)_entities.Count, 0); _entities.Add((entity, new BitArray(_componentPools.Count))); } @@ -114,7 +114,7 @@ namespace GlitchyEngine.World /** * Removes the specified Entity from the World. */ - public void RemoveEntity(Entity entity) + public void RemoveEntity(EcsEntity entity) { var listEntity = ref _entities[entity.Index]; if(entity != listEntity.ID) @@ -123,7 +123,7 @@ namespace GlitchyEngine.World DisposeComponents(listEntity); // Invalidate entry and increment version - listEntity.ID = Entity.CreateEntityID(Entity.InvalidEntity.Index, entity.Version + 1); + listEntity.ID = EcsEntity.CreateEntityID(EcsEntity.InvalidEntity.Index, entity.Version + 1); _entities[entity.Index].ComponentMask.Clear(); _freeIndices.Add(entity.Index); @@ -152,7 +152,7 @@ namespace GlitchyEngine.World /** * Assigns a component of type T to the specified entity and returns it. */ - public T* AssignComponent(Entity entity) where T : struct, new + public T* AssignComponent(EcsEntity entity, T value = T()) where T : struct, new { if(entity.Index > _entities.Count) return null; @@ -165,8 +165,12 @@ namespace GlitchyEngine.World ComponentPoolEntry entry; if(!_componentPools.TryGetValue(typeof(T), out entry)) { - Log.EngineLogger.AssertDebug(false, scope $"Tried to assign unregistered component type {typeof(T)}"); - return null; + Register(); + + entry = _componentPools[typeof(T)]; + + //Log.EngineLogger.AssertDebug(false, scope $"Tried to assign unregistered component type {typeof(T)}"); + //return null; } // TODO: is it a problem to assign a component again? @@ -177,7 +181,7 @@ namespace GlitchyEngine.World T* component = (T*)entry.Pool.Get(entity.Index); - *component = T(); + *component = value; return component; } @@ -185,7 +189,7 @@ namespace GlitchyEngine.World /** * Removes a component of type T from the specified entity. */ - public void RemoveComponent(Entity entity) where T : struct + public void RemoveComponent(EcsEntity entity) where T : struct, new { if(entity.Index > _entities.Count) return; @@ -205,7 +209,7 @@ namespace GlitchyEngine.World listEntity.ComponentMask[entry.Id] = false; } - public void RemoveComponent(Entity entity) where T : struct, IDisposableComponent + public void RemoveComponent(EcsEntity entity) where T : struct, new, IDisposableComponent { if(entity.Index > _entities.Count) return; @@ -228,7 +232,21 @@ namespace GlitchyEngine.World DisposeComponent(entry.Pool.Get(entity.Index)); } - public T* GetComponent(Entity entity) where T : struct + /// Returns whether or not the given entity has the specified component. + public bool HasComponent(EcsEntity entity) where T : struct, new + { + var listEntity = ref _entities[entity.Index]; + if(entity != listEntity.ID) + return false; + + ComponentPoolEntry entry; + if(!_componentPools.TryGetValue(typeof(T), out entry)) + return false; + + return listEntity.ComponentMask[entry.Id]; + } + + public T* GetComponent(EcsEntity entity) where T : struct, new { var listEntity = ref _entities[entity.Index]; if(entity != listEntity.ID) @@ -244,7 +262,7 @@ namespace GlitchyEngine.World return (.)entry.Pool.Get(entity.Index); } - + public WorldEnumerator Enumerate(params Type[] componentTypes) { return WorldEnumerator(this, componentTypes); @@ -279,7 +297,7 @@ namespace GlitchyEngine.World world.Register(); - Entity entity = world.NewEntity(); + EcsEntity entity = world.NewEntity(); TransformComponent* myComp = world.AssignComponent(entity); myComp.LocalTransform = Matrix.Identity; @@ -289,7 +307,7 @@ namespace GlitchyEngine.World world.RemoveComponent(entity); - Entity entity2 = world.NewEntity(); + EcsEntity entity2 = world.NewEntity(); world.AssignComponent(entity2); world.RemoveEntity(entity); @@ -330,7 +348,7 @@ namespace GlitchyEngine.World // Test dispose on component removal { // Create entity with disposable component. - Entity entity = world.NewEntity(); + EcsEntity entity = world.NewEntity(); var component = world.AssignComponent(entity); component.IsDisposed = false; @@ -342,7 +360,7 @@ namespace GlitchyEngine.World // Test dispose on entity removal { // Create entity with disposable component. - Entity entity = world.NewEntity(); + EcsEntity entity = world.NewEntity(); var component = world.AssignComponent(entity); component.IsDisposed = false; diff --git a/GlitchyEngine/src/World/Entity.bf b/GlitchyEngine/src/World/Entity.bf index 097eeb0..227a40c 100644 --- a/GlitchyEngine/src/World/Entity.bf +++ b/GlitchyEngine/src/World/Entity.bf @@ -4,27 +4,53 @@ using internal GlitchyEngine.World; namespace GlitchyEngine.World { - public struct Entity : uint64 - { - // Binary Format: - // Bits: [0 - 31] [32 - 64] - // Data: Version Index + public struct Entity + { + private EcsEntity _entity = .InvalidEntity; - [Inline] - internal uint32 Version => (uint32)this; + private Scene _scene = null; - [Inline] - internal uint32 Index => (uint32)(this >> 32); - - [Inline] - static internal Entity CreateEntityID(uint32 index, uint32 version) + public EcsEntity Handle => _entity; + + public Scene Scene => _scene; + + public this() { - return ((uint64)index << 32) | version; + } + + public this(EcsEntity entity, Scene scene) + { + _entity = entity; + _scene = scene; + } + + public bool IsValid => _entity.IsValid; + + public T* AddComponent(T value = T()) where T: struct, new + { + Log.EngineLogger.AssertDebug(!HasComponent(), scope $"Entity already has component."); + + return _scene._ecsWorld.AssignComponent(_entity, value); + } + + public T* GetComponent() where T: struct, new + { + Log.EngineLogger.AssertDebug(HasComponent(), "Entity doesn't have component!"); + + return _scene._ecsWorld.GetComponent(_entity); } - [Inline] - internal bool IsValid => Index != InvalidEntity.Index; + public bool HasComponent() where T: struct, new + { + return _scene._ecsWorld.HasComponent(_entity); + } + + public void RemoveComponent() where T: struct, new + { + Log.EngineLogger.AssertDebug(HasComponent(), "Entity doesn't have component!"); + + _scene._ecsWorld.RemoveComponent(_entity); + } - public const Entity InvalidEntity = ((uint64)uint32.MaxValue << 32) | 0;//TODO: Report bug: CreateEntityID(uint32.MaxValue, 0); } } diff --git a/GlitchyEngine/src/World/ParentComponent.bf b/GlitchyEngine/src/World/ParentComponent.bf index a6ece24..ef5e821 100644 --- a/GlitchyEngine/src/World/ParentComponent.bf +++ b/GlitchyEngine/src/World/ParentComponent.bf @@ -5,6 +5,6 @@ namespace GlitchyEngine.World */ public struct ParentComponent { - public Entity Entity; + public EcsEntity Entity; } } diff --git a/GlitchyEngine/src/World/Scene.bf b/GlitchyEngine/src/World/Scene.bf new file mode 100644 index 0000000..7a2c9e1 --- /dev/null +++ b/GlitchyEngine/src/World/Scene.bf @@ -0,0 +1,48 @@ +using GlitchyEngine.Math; +using GlitchyEngine.Renderer; +using System; + +namespace GlitchyEngine.World +{ + class Scene + { + internal EcsWorld _ecsWorld = new .() ~ delete _; + + public this() + { + Entity entity = CreateEntity(); + entity.AddComponent(.(ColorRGBA(0.2f, 0.9f, 0.15f))); + } + + public ~this() + { + } + + public void Update(GameTime gameTime) + { + //TransformSystem.Update(_ecsWorld); + + for (var (entity, transform, sprite) in _ecsWorld.Enumerate()) + { + Renderer2D.DrawQuad(transform.Transform, sprite.Color); + } + + } + + public Entity CreateEntity(String name = "") + { + Entity entity = Entity(_ecsWorld.NewEntity(), this); + entity.AddComponent(.(.Identity)); + + let nameComponent = entity.AddComponent(); + nameComponent.SetName(name.IsEmpty ? "Entity" : name); + + return entity; + } + + public void DestroyEntity(Entity entity) + { + _ecsWorld.RemoveEntity(entity.Handle); + } + } +} \ No newline at end of file diff --git a/GlitchyEngine/src/World/TransformSystem.bf b/GlitchyEngine/src/World/TransformSystem.bf index 1a3e8ca..e3afb5c 100644 --- a/GlitchyEngine/src/World/TransformSystem.bf +++ b/GlitchyEngine/src/World/TransformSystem.bf @@ -16,7 +16,7 @@ namespace GlitchyEngine.World } } - private static void UpdateEntity(Entity entity, TransformComponent* transform, EcsWorld world) + private static void UpdateEntity(EcsEntity entity, TransformComponent* transform, EcsWorld world) { // Todo: test scaling with deep hierarchies! diff --git a/GlitchyEngine/src/World/WorldEnumerator.bf b/GlitchyEngine/src/World/WorldEnumerator.bf index a678cf2..d46bad2 100644 --- a/GlitchyEngine/src/World/WorldEnumerator.bf +++ b/GlitchyEngine/src/World/WorldEnumerator.bf @@ -6,7 +6,7 @@ using internal GlitchyEngine.World; namespace GlitchyEngine.World { - public struct WorldEnumerator : IEnumerator, IDisposable + public struct WorldEnumerator : IEnumerator, IDisposable { internal EcsWorld _world; internal BitArray _bitMask; @@ -37,14 +37,14 @@ namespace GlitchyEngine.World } } - public Result GetNext() mut + public Result GetNext() mut { while(_currentEntry < _endEntry) { EcsWorld.BitmaskEntry* entry = _currentEntry++; // Skip deleted entities - if(entry.ID.Index == Entity.InvalidEntity.Index) + if(entry.ID.Index == EcsEntity.InvalidEntity.Index) continue; // Check whether or not mask matches @@ -61,7 +61,7 @@ namespace GlitchyEngine.World } } - public struct WorldEnumerator : WorldEnumerator, IEnumerator<(Entity Entity, TComponent* Component)> where TComponent : struct + public struct WorldEnumerator : WorldEnumerator, IEnumerator<(EcsEntity Entity, TComponent* Component)> where TComponent : struct { internal EcsWorld.ComponentPoolEntry* _componentPool; @@ -70,9 +70,9 @@ namespace GlitchyEngine.World _componentPool = &world.GetComponentPool(); } - public new Result<(Entity Entity, TComponent* Component)> GetNext() mut + public new Result<(EcsEntity Entity, TComponent* Component)> GetNext() mut { - Result entity = base.GetNext(); + Result entity = base.GetNext(); if(entity case .Err) return .Err; @@ -84,7 +84,7 @@ namespace GlitchyEngine.World } public struct WorldEnumerator : WorldEnumerator, - IEnumerator<(Entity Entity, TComponent0* Component0, TComponent1* Component1)> + IEnumerator<(EcsEntity Entity, TComponent0* Component0, TComponent1* Component1)> where TComponent0 : struct where TComponent1 : struct { internal EcsWorld.ComponentPoolEntry* _componentPool0; @@ -96,9 +96,9 @@ namespace GlitchyEngine.World _componentPool1 = &world.GetComponentPool(); } - public new Result<(Entity Entity, TComponent0* Component0, TComponent1* Component1)> GetNext() mut + public new Result<(EcsEntity Entity, TComponent0* Component0, TComponent1* Component1)> GetNext() mut { - Result entity = base.GetNext(); + Result entity = base.GetNext(); if(entity case .Err) return .Err; @@ -111,7 +111,7 @@ namespace GlitchyEngine.World } public struct WorldEnumerator : WorldEnumerator, - IEnumerator<(Entity Entity, TComponent0* Component0, TComponent1* Component1, TComponent2* Component2)> + IEnumerator<(EcsEntity Entity, TComponent0* Component0, TComponent1* Component1, TComponent2* Component2)> where TComponent0 : struct where TComponent1 : struct where TComponent2 : struct { internal EcsWorld.ComponentPoolEntry* _componentPool0; @@ -125,9 +125,9 @@ namespace GlitchyEngine.World _componentPool2 = &world.GetComponentPool(); } - public new Result<(Entity Entity, TComponent0* Component0, TComponent1* Component1, TComponent2* Component2)> GetNext() mut + public new Result<(EcsEntity Entity, TComponent0* Component0, TComponent1* Component1, TComponent2* Component2)> GetNext() mut { - Result entity = base.GetNext(); + Result entity = base.GetNext(); if(entity case .Err) return .Err; @@ -141,7 +141,7 @@ namespace GlitchyEngine.World } public struct WorldEnumerator : WorldEnumerator, - IEnumerator<(Entity Entity, TComponent0* Component0, TComponent1* Component1, TComponent2* Component2, TComponent3* Component3)> + IEnumerator<(EcsEntity Entity, TComponent0* Component0, TComponent1* Component1, TComponent2* Component2, TComponent3* Component3)> where TComponent0 : struct where TComponent1 : struct where TComponent2 : struct where TComponent3 : struct { internal EcsWorld.ComponentPoolEntry* _componentPool0; @@ -157,9 +157,9 @@ namespace GlitchyEngine.World _componentPool3 = &world.GetComponentPool(); } - public new Result<(Entity Entity, TComponent0* Component0, TComponent1* Component1, TComponent2* Component2, TComponent3* Component3)> GetNext() mut + public new Result<(EcsEntity Entity, TComponent0* Component0, TComponent1* Component1, TComponent2* Component2, TComponent3* Component3)> GetNext() mut { - Result entity = base.GetNext(); + Result entity = base.GetNext(); if(entity case .Err) return .Err; diff --git a/Sandbox/src/ExampleLayer.bf b/Sandbox/src/ExampleLayer.bf index 97b09d4..064a780 100644 --- a/Sandbox/src/ExampleLayer.bf +++ b/Sandbox/src/ExampleLayer.bf @@ -249,8 +249,8 @@ namespace Sandbox } } - Entity evenCrazierParent; - Entity crazyParent; + EcsEntity evenCrazierParent; + EcsEntity crazyParent; Material testMaterial1 ~ _?.ReleaseRef(); Material testMaterial2 ~ _?.ReleaseRef();