2024-10-13 00:08:01 +02:00
|
|
|
|
using MoonTools.ECS;
|
2024-10-15 00:41:45 +02:00
|
|
|
|
using Nerfed.Editor.Systems;
|
2024-10-13 00:08:01 +02:00
|
|
|
|
using Nerfed.Runtime;
|
2024-10-13 01:05:46 +02:00
|
|
|
|
using Nerfed.Runtime.Components;
|
2024-10-13 00:08:01 +02:00
|
|
|
|
using Nerfed.Runtime.Systems;
|
2024-10-15 00:41:45 +02:00
|
|
|
|
using Nerfed.Runtime.Util;
|
2024-10-13 00:08:01 +02:00
|
|
|
|
using System.Numerics;
|
2024-07-11 23:46:32 +02:00
|
|
|
|
|
|
|
|
|
namespace Nerfed.Editor;
|
2024-07-05 12:56:37 +02:00
|
|
|
|
|
|
|
|
|
internal class Program
|
2024-07-05 12:21:17 +02:00
|
|
|
|
{
|
2024-10-13 00:08:01 +02:00
|
|
|
|
private static readonly World world = new World();
|
|
|
|
|
private static List<MoonTools.ECS.System> systems = new List<MoonTools.ECS.System>();
|
2024-10-15 00:41:45 +02:00
|
|
|
|
public static List<MoonTools.ECS.System> editorSystems = new List<MoonTools.ECS.System>();
|
2024-10-13 00:08:01 +02:00
|
|
|
|
|
2024-07-05 14:32:58 +02:00
|
|
|
|
private static void Main(string[] args)
|
2024-07-05 12:21:17 +02:00
|
|
|
|
{
|
2024-07-12 23:10:44 +02:00
|
|
|
|
Engine.OnInitialize += HandleOnInitialize;
|
|
|
|
|
Engine.OnUpdate += HandleOnUpdate;
|
|
|
|
|
Engine.OnRender += HandleOnRender;
|
|
|
|
|
Engine.OnQuit += HandleOnQuit;
|
|
|
|
|
|
2024-07-05 14:32:58 +02:00
|
|
|
|
Engine.Run(args);
|
2024-07-05 12:21:17 +02:00
|
|
|
|
}
|
2024-07-12 23:10:44 +02:00
|
|
|
|
|
|
|
|
|
private static void HandleOnInitialize()
|
|
|
|
|
{
|
2024-10-15 00:41:45 +02:00
|
|
|
|
//systems.Add(new ParentSystem(world));
|
2024-10-13 01:05:46 +02:00
|
|
|
|
systems.Add(new LocalToWorldSystem(world));
|
2024-10-19 23:41:05 +02:00
|
|
|
|
editorSystems.Add(new EditorProfilerWindow(world));
|
2024-10-15 00:41:45 +02:00
|
|
|
|
editorSystems.Add(new EditorHierarchyWindow(world));
|
2024-10-13 00:08:01 +02:00
|
|
|
|
|
2024-10-15 00:41:45 +02:00
|
|
|
|
Entity ent1 = world.CreateEntity("parent");
|
2024-10-15 22:29:19 +02:00
|
|
|
|
world.Set(ent1, new Root());
|
2024-10-13 00:08:01 +02:00
|
|
|
|
world.Set(ent1, new LocalTransform(new Vector3(1, 0, 0), Quaternion.Identity, Vector3.One));
|
|
|
|
|
|
2024-10-15 00:41:45 +02:00
|
|
|
|
Entity ent2 = world.CreateEntity("child");
|
2024-10-13 00:08:01 +02:00
|
|
|
|
world.Set(ent2, new LocalTransform(new Vector3(0, 1, 0), Quaternion.Identity, Vector3.One));
|
2024-10-15 00:41:45 +02:00
|
|
|
|
Transform.SetParent(world, ent2, ent1);
|
|
|
|
|
|
|
|
|
|
Entity ent3 = world.CreateEntity("entity3");
|
|
|
|
|
world.Set(ent3, new Root());
|
|
|
|
|
Transform.SetParent(world, ent3, ent2);
|
|
|
|
|
|
|
|
|
|
Entity ent4 = world.CreateEntity("entity4");
|
|
|
|
|
world.Set(ent4, new Root());
|
|
|
|
|
|
|
|
|
|
Entity ent5 = world.CreateBaseEntity("entity5");
|
2024-10-13 00:08:01 +02:00
|
|
|
|
|
2024-10-20 03:51:59 +02:00
|
|
|
|
for (int i = 0; i < 256; i++)
|
2024-10-19 23:41:05 +02:00
|
|
|
|
{
|
|
|
|
|
Entity newEnt = world.CreateBaseEntity();
|
|
|
|
|
world.Set(newEnt, new LocalTransform(new Vector3(i, i, i), Quaternion.Identity, Vector3.One));
|
|
|
|
|
|
|
|
|
|
Entity parent = newEnt;
|
2024-10-20 03:51:59 +02:00
|
|
|
|
for (int j = 0; j < 2; j++) {
|
2024-10-19 23:41:05 +02:00
|
|
|
|
Entity newChildEnt = world.CreateEntity();
|
|
|
|
|
world.Set(newChildEnt, new LocalTransform(new Vector3(j, j, j), Quaternion.Identity, Vector3.One));
|
|
|
|
|
Transform.SetParent(world, newChildEnt, parent);
|
|
|
|
|
parent = newChildEnt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-12 23:10:44 +02:00
|
|
|
|
// Open project.
|
|
|
|
|
// Setip EditorGui.
|
|
|
|
|
EditorGui.Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void HandleOnUpdate()
|
|
|
|
|
{
|
2024-10-13 00:08:01 +02:00
|
|
|
|
foreach (MoonTools.ECS.System system in systems)
|
|
|
|
|
{
|
2024-10-20 03:51:59 +02:00
|
|
|
|
using ProfilerScope scope = new(system.GetType().Name);
|
|
|
|
|
system.Update(Engine.Timestep);
|
2024-10-13 00:08:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-19 23:41:05 +02:00
|
|
|
|
using (new ProfilerScope("EditorGui.Update"))
|
|
|
|
|
{
|
|
|
|
|
// Editor Update.
|
|
|
|
|
EditorGui.Update();
|
|
|
|
|
}
|
2024-07-12 23:10:44 +02:00
|
|
|
|
|
|
|
|
|
// Try Catch UserCode Update.
|
2024-10-15 00:41:45 +02:00
|
|
|
|
|
2024-10-19 23:41:05 +02:00
|
|
|
|
using (new ProfilerScope("world.FinishUpdate"))
|
|
|
|
|
{
|
|
|
|
|
world.FinishUpdate();
|
|
|
|
|
}
|
2024-07-12 23:10:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void HandleOnRender()
|
|
|
|
|
{
|
2024-10-20 03:51:59 +02:00
|
|
|
|
using (new ProfilerScope("EditorGui.Render"))
|
|
|
|
|
{
|
|
|
|
|
EditorGui.Render();
|
|
|
|
|
}
|
2024-07-12 23:10:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void HandleOnQuit()
|
|
|
|
|
{
|
|
|
|
|
EditorGui.Quit();
|
|
|
|
|
}
|
|
|
|
|
}
|