Allow opening a scene on launch

+ don't resize on load/new scene
This commit is contained in:
Simon Lübeß
2023-07-17 02:19:49 +02:00
parent 1641bafd06
commit 28155ec92c
4 changed files with 56 additions and 58 deletions
+1
View File
@@ -8,3 +8,4 @@ StartupObject = "GlitchyEngine.Program"
[Configs.Debug.Win64] [Configs.Debug.Win64]
PreBuildCmds = ["dotnet build \"$(ProjectDir)/SandboxProject/Assets/Scripts/Sandbox.csproj\" -c Debug"] PreBuildCmds = ["dotnet build \"$(ProjectDir)/SandboxProject/Assets/Scripts/Sandbox.csproj\" -c Debug"]
DebugCommandArguments = "\"content\\Scenes\\physics2D.scene\""
+4 -4
View File
@@ -9,9 +9,9 @@ namespace GlitchyEditor
{ {
EditorContentManager _contentManager; EditorContentManager _contentManager;
public this() public this(String[] args)
{ {
PushLayer(new EditorLayer(_contentManager)); PushLayer(new EditorLayer(args, _contentManager));
} }
protected override IContentManager InitContentManager() protected override IContentManager InitContentManager()
@@ -39,9 +39,9 @@ namespace GlitchyEditor
} }
[Export, LinkName("CreateApplication")] [Export, LinkName("CreateApplication")]
public static Application CreateApplication() public static Application CreateApplication(String[] args)
{ {
return new EditorApp(); return new EditorApp(args);
} }
} }
} }
+48 -51
View File
@@ -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; Application.Get().Window.IsVSync = true;
@@ -99,18 +99,18 @@ namespace GlitchyEditor
InitGraphics(); InitGraphics();
_editorScene = new Scene();
SetReference!(_activeScene, _editorScene);
_gameSceneRenderer = new SceneRenderer(); _gameSceneRenderer = new SceneRenderer();
_editorSceneRenderer = 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; _camera.RenderTarget = _cameraTarget;
InitEditor(); InitEditor();
NewScene(); if (args.Count >= 1)
LoadSceneFile(args[0]);
else
NewScene();
} }
private void InitGraphics() private void InitGraphics()
@@ -505,7 +505,7 @@ namespace GlitchyEditor
{ {
if (_sceneState == .Play) if (_sceneState == .Play)
_activeScene.OnRuntimeStop(); _activeScene.OnRuntimeStop();
else else if (_sceneState == .Simulate)
_activeScene.OnSimulationStop(); _activeScene.OnSimulationStop();
SetReference!(_activeScene, _editorScene); SetReference!(_activeScene, _editorScene);
@@ -517,12 +517,15 @@ namespace GlitchyEditor
_isPaused = false; _isPaused = false;
/* 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). * Update the viewport size because if the game windows size changed in
*/ * "Game"-mode the updated aspect-rations will reset once we go back
GameViewportSizeChanged(null, _editor.GameViewportWindow.ViewportSize); * into "Editor"-mode (because Game-Mode works on a copy of the scene).
*/
GameViewportSizeChanged(null, _editor.GameViewportWindow.ViewportSize);
}
} }
/// Creates a new scene. /// Creates a new scene.
@@ -532,44 +535,41 @@ namespace GlitchyEditor
SceneFilePath = null; SceneFilePath = null;
Scene newScene = new Scene(); using (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
{ {
let cameraEntity = newScene.CreateEntity("Camera"); _camera.Position = .(-1.5f, 1.5f, -2.5f);
let transform = cameraEntity.Transform; _camera.RotationEuler = .(MathHelper.ToRadians(25), MathHelper.ToRadians(35), 0);
transform.Position = float3(0, 2, -5);
transform.RotationEuler = float3(0, MathHelper.ToRadians(25), 0);
let camera = cameraEntity.AddComponent<CameraComponent>(); // Create a default camera
camera.Primary = true; {
camera.Camera.ProjectionType = .InfinitePerspective; let cameraEntity = newScene.CreateEntity("Camera");
camera.Camera.PerspectiveFovY = MathHelper.ToRadians(75); let transform = cameraEntity.Transform;
camera.Camera.PerspectiveNearPlane = 0.1f; transform.Position = float3(0, 2, -5);
transform.RotationEuler = float3(0, MathHelper.ToRadians(25), 0);
let camera = cameraEntity.AddComponent<CameraComponent>();
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<LightComponent>();
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<LightComponent>();
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. /// 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()) using (Scene newScene = new Scene())
{ {
var vpSize = _editor.SceneViewportWindow.ViewportSize;
newScene.OnViewportResize((.)vpSize.X, (.)vpSize.Y);
SceneSerializer serializer = scope .(newScene); SceneSerializer serializer = scope .(newScene);
let result = serializer.Deserialize(SceneFilePath); let result = serializer.Deserialize(SceneFilePath);
+2 -2
View File
@@ -8,7 +8,7 @@ namespace GlitchyEngine
class Program class Program
{ {
[LinkName("CreateApplication")] [LinkName("CreateApplication")]
static extern Application CreateApplication(); static extern Application CreateApplication(String[] args);
public static int Main(String[] args) public static int Main(String[] args)
{ {
@@ -23,7 +23,7 @@ namespace GlitchyEngine
Stopwatch initWatch = scope Stopwatch(); Stopwatch initWatch = scope Stopwatch();
app = CreateApplication(); app = CreateApplication(args);
initWatch.Stop(); initWatch.Stop();