mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Ecs changes
- BitArray has always at least sizeof(uint) bits - Renamed Entity to EcsEntity - Added value parameter to EcsWorld.AssignComponent - Matched EcsWorld generic parameters - Added Scene - Added Entity
This commit is contained in:
@@ -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<TransformComponent>(entity);
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace GlitchyEditor.EditWindows
|
||||
}
|
||||
}
|
||||
|
||||
private void ImGuiPrintEntityTree(TreeNode<Entity> tree)
|
||||
private void ImGuiPrintEntityTree(TreeNode<EcsEntity> 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<Entity> root = scope .(.InvalidEntity);
|
||||
TreeNode<EcsEntity> root = scope .(.InvalidEntity);
|
||||
|
||||
TreeNode<Entity> AddEntity(Entity entity)
|
||||
TreeNode<EcsEntity> AddEntity(EcsEntity entity)
|
||||
{
|
||||
var parent = _editor.World.GetComponent<ParentComponent>(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<ParentComponent>(movedEntity);
|
||||
|
||||
|
||||
+18
-16
@@ -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<Entity> _selectedEntities = new .() ~ delete _;
|
||||
private List<EcsEntity> _selectedEntities = new .() ~ delete _;
|
||||
|
||||
public EcsWorld World => _world;
|
||||
public EcsWorld World => _ecsWorld;
|
||||
|
||||
public List<Entity> SelectedEntities => _selectedEntities;
|
||||
public List<EcsEntity> 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<TransformComponent>(entity);
|
||||
var transformComponent = ref *_ecsWorld.AssignComponent<TransformComponent>(entity);
|
||||
transformComponent = TransformComponent();
|
||||
|
||||
var nameComponent = ref *_world.AssignComponent<DebugNameComponent>(entity);
|
||||
var nameComponent = ref *_ecsWorld.AssignComponent<DebugNameComponent>(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<ParentComponent>(selectedEntity);
|
||||
var parentComponent = _ecsWorld.GetComponent<ParentComponent>(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<Entity> entities)
|
||||
internal void FindChildren(EcsEntity entity, List<EcsEntity> entities)
|
||||
{
|
||||
for(var (child, childParent) in _world.Enumerate<ParentComponent>())
|
||||
for(var (child, childParent) in _ecsWorld.Enumerate<ParentComponent>())
|
||||
{
|
||||
if(childParent.Entity == entity)
|
||||
{
|
||||
@@ -93,7 +95,7 @@ namespace GlitchyEditor
|
||||
/// Deletes all selected entities and their children.
|
||||
internal void DeleteSelectedEntities()
|
||||
{
|
||||
List<Entity> entities = scope .();
|
||||
List<EcsEntity> 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();
|
||||
|
||||
@@ -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<DebugNameComponent>();
|
||||
_world.Register<TransformComponent>();
|
||||
@@ -66,18 +66,18 @@ namespace GlitchyEditor
|
||||
_world.Register<SkinnedMeshRendererComponent>();
|
||||
_world.Register<CameraComponent>();
|
||||
_world.Register<AnimationComponent>();
|
||||
}
|
||||
}*/
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user