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]
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;
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);
}
}
}
+13 -16
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;
@@ -99,17 +99,17 @@ 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();
if (args.Count >= 1)
LoadSceneFile(args[0]);
else
NewScene();
}
@@ -505,7 +505,7 @@ namespace GlitchyEditor
{
if (_sceneState == .Play)
_activeScene.OnRuntimeStop();
else
else if (_sceneState == .Simulate)
_activeScene.OnSimulationStop();
SetReference!(_activeScene, _editorScene);
@@ -517,6 +517,8 @@ namespace GlitchyEditor
_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
@@ -524,6 +526,7 @@ namespace GlitchyEditor
*/
GameViewportSizeChanged(null, _editor.GameViewportWindow.ViewportSize);
}
}
/// Creates a new scene.
private void NewScene()
@@ -532,8 +535,8 @@ namespace GlitchyEditor
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);
@@ -563,14 +566,11 @@ namespace GlitchyEditor
light.SceneLight.Color = .(1.0f, 0.95f, 0.8f);
}
_editorScene.ReleaseRef();
_editorScene = newScene;
SetReference!(_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.
private void SaveScene()
@@ -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);
+2 -2
View File
@@ -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();