From 28155ec92c0e92c8b6228cdc977dd4a7c9279a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Mon, 17 Jul 2023 02:19:49 +0200 Subject: [PATCH] Allow opening a scene on launch + don't resize on load/new scene --- GlitchyEditor/BeefProj.toml | 1 + GlitchyEditor/src/EditorApp.bf | 8 +-- GlitchyEditor/src/EditorLayer.bf | 101 +++++++++++++++---------------- GlitchyEngine/src/Program.bf | 4 +- 4 files changed, 56 insertions(+), 58 deletions(-) diff --git a/GlitchyEditor/BeefProj.toml b/GlitchyEditor/BeefProj.toml index 22cae92..3f5d0f0 100644 --- a/GlitchyEditor/BeefProj.toml +++ b/GlitchyEditor/BeefProj.toml @@ -8,3 +8,4 @@ StartupObject = "GlitchyEngine.Program" [Configs.Debug.Win64] PreBuildCmds = ["dotnet build \"$(ProjectDir)/SandboxProject/Assets/Scripts/Sandbox.csproj\" -c Debug"] +DebugCommandArguments = "\"content\\Scenes\\physics2D.scene\"" diff --git a/GlitchyEditor/src/EditorApp.bf b/GlitchyEditor/src/EditorApp.bf index dbc7802..a4ccec8 100644 --- a/GlitchyEditor/src/EditorApp.bf +++ b/GlitchyEditor/src/EditorApp.bf @@ -9,9 +9,9 @@ namespace GlitchyEditor { EditorContentManager _contentManager; - public this() + public this(String[] args) { - PushLayer(new EditorLayer(_contentManager)); + PushLayer(new EditorLayer(args, _contentManager)); } protected override IContentManager InitContentManager() @@ -39,9 +39,9 @@ namespace GlitchyEditor } [Export, LinkName("CreateApplication")] - public static Application CreateApplication() + public static Application CreateApplication(String[] args) { - return new EditorApp(); + return new EditorApp(args); } } } diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index 083f6be..88abe18 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -91,7 +91,7 @@ namespace GlitchyEditor } } - public this(EditorContentManager contentManager) : base("Editor") + public this(String[] args, EditorContentManager contentManager) : base("Editor") { Application.Get().Window.IsVSync = true; @@ -99,18 +99,18 @@ namespace GlitchyEditor InitGraphics(); - _editorScene = new Scene(); - SetReference!(_activeScene, _editorScene); - _gameSceneRenderer = new SceneRenderer(); _editorSceneRenderer = new SceneRenderer(); - _camera = EditorCamera(float3(3.5f, 1.25f, 2.75f), Quaternion.FromEulerAngles(MathHelper.ToRadians(40), MathHelper.ToRadians(25), 0), MathHelper.ToRadians(75), 0.1f, 1); + _camera = EditorCamera(float3(-3f, 3f, -3f), Quaternion.FromEulerAngles(MathHelper.ToRadians(40), MathHelper.ToRadians(25), 0), MathHelper.ToRadians(75), 0.1f, 1); _camera.RenderTarget = _cameraTarget; InitEditor(); - NewScene(); + if (args.Count >= 1) + LoadSceneFile(args[0]); + else + NewScene(); } private void InitGraphics() @@ -505,7 +505,7 @@ namespace GlitchyEditor { if (_sceneState == .Play) _activeScene.OnRuntimeStop(); - else + else if (_sceneState == .Simulate) _activeScene.OnSimulationStop(); SetReference!(_activeScene, _editorScene); @@ -517,12 +517,15 @@ namespace GlitchyEditor _isPaused = false; - /* - * Update the viewport size because if the game windows size changed in - * "Game"-mode the updated aspect-rations will reset once we go back - * into "Editor"-mode (because Game-Mode works on a copy of the scene). - */ - GameViewportSizeChanged(null, _editor.GameViewportWindow.ViewportSize); + if (_activeScene != null) + { + /* + * Update the viewport size because if the game windows size changed in + * "Game"-mode the updated aspect-rations will reset once we go back + * into "Editor"-mode (because Game-Mode works on a copy of the scene). + */ + GameViewportSizeChanged(null, _editor.GameViewportWindow.ViewportSize); + } } /// Creates a new scene. @@ -532,44 +535,41 @@ namespace GlitchyEditor SceneFilePath = null; - Scene newScene = new Scene(); - - _camera.Position = .(-1.5f, 1.5f, -2.5f); - _camera.RotationEuler = .(MathHelper.ToRadians(25), MathHelper.ToRadians(35), 0); - - // Create a default camera + using (Scene newScene = new Scene()) { - let cameraEntity = newScene.CreateEntity("Camera"); - let transform = cameraEntity.Transform; - transform.Position = float3(0, 2, -5); - transform.RotationEuler = float3(0, MathHelper.ToRadians(25), 0); - - let camera = cameraEntity.AddComponent(); - camera.Primary = true; - camera.Camera.ProjectionType = .InfinitePerspective; - camera.Camera.PerspectiveFovY = MathHelper.ToRadians(75); - camera.Camera.PerspectiveNearPlane = 0.1f; + _camera.Position = .(-1.5f, 1.5f, -2.5f); + _camera.RotationEuler = .(MathHelper.ToRadians(25), MathHelper.ToRadians(35), 0); + + // Create a default camera + { + let cameraEntity = newScene.CreateEntity("Camera"); + let transform = cameraEntity.Transform; + transform.Position = float3(0, 2, -5); + transform.RotationEuler = float3(0, MathHelper.ToRadians(25), 0); + + let camera = cameraEntity.AddComponent(); + camera.Primary = true; + camera.Camera.ProjectionType = .InfinitePerspective; + camera.Camera.PerspectiveFovY = MathHelper.ToRadians(75); + camera.Camera.PerspectiveNearPlane = 0.1f; + } + + // Create a default light source + { + let lightEntity = newScene.CreateEntity("Light"); + let transform = lightEntity.Transform; + transform.Position = .(-3, 4, -1.5f); + transform.RotationEuler = .(MathHelper.ToRadians(20), MathHelper.ToRadians(75), MathHelper.ToRadians(20)); + + let light = lightEntity.AddComponent(); + light.SceneLight.Illuminance = 10.0f; + light.SceneLight.Color = .(1.0f, 0.95f, 0.8f); + } + + SetReference!(_editorScene, newScene); + _editor.CurrentScene = _editorScene; + SetReference!(_activeScene, _editorScene); } - - // Create a default light source - { - let lightEntity = newScene.CreateEntity("Light"); - let transform = lightEntity.Transform; - transform.Position = .(-3, 4, -1.5f); - transform.RotationEuler = .(MathHelper.ToRadians(20), MathHelper.ToRadians(75), MathHelper.ToRadians(20)); - - let light = lightEntity.AddComponent(); - light.SceneLight.Illuminance = 10.0f; - light.SceneLight.Color = .(1.0f, 0.95f, 0.8f); - } - - _editorScene.ReleaseRef(); - _editorScene = newScene; - _editor.CurrentScene = _editorScene; - var vpSize = _editor.SceneViewportWindow.ViewportSize; - _editorScene.OnViewportResize((.)vpSize.X, (.)vpSize.Y); - - SetReference!(_activeScene, _editorScene); } /// Saves the scene in the file that is was loaded from or saved to last. If there is no such path (i.e. it is a new scene) the save file dialog will open. @@ -622,9 +622,6 @@ namespace GlitchyEditor using (Scene newScene = new Scene()) { - var vpSize = _editor.SceneViewportWindow.ViewportSize; - newScene.OnViewportResize((.)vpSize.X, (.)vpSize.Y); - SceneSerializer serializer = scope .(newScene); let result = serializer.Deserialize(SceneFilePath); diff --git a/GlitchyEngine/src/Program.bf b/GlitchyEngine/src/Program.bf index ae79d10..27508a3 100644 --- a/GlitchyEngine/src/Program.bf +++ b/GlitchyEngine/src/Program.bf @@ -8,7 +8,7 @@ namespace GlitchyEngine class Program { [LinkName("CreateApplication")] - static extern Application CreateApplication(); + static extern Application CreateApplication(String[] args); public static int Main(String[] args) { @@ -23,7 +23,7 @@ namespace GlitchyEngine Stopwatch initWatch = scope Stopwatch(); - app = CreateApplication(); + app = CreateApplication(args); initWatch.Stop();