From 751f064c68217afe3e5acf90b7dfea13ecd3b236 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 05:09:21 -0500 Subject: [PATCH 1/9] feat: scalfold for build CLI command --- Prowl.Editor/Editor/CLI/CliBuildOptions.cs | 25 ++++++++++++++ Prowl.Editor/Editor/CLI/README.md | 3 ++ Prowl.Editor/Program.cs | 38 ++++++++++++++-------- 3 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 Prowl.Editor/Editor/CLI/CliBuildOptions.cs create mode 100644 Prowl.Editor/Editor/CLI/README.md diff --git a/Prowl.Editor/Editor/CLI/CliBuildOptions.cs b/Prowl.Editor/Editor/CLI/CliBuildOptions.cs new file mode 100644 index 000000000..864472dca --- /dev/null +++ b/Prowl.Editor/Editor/CLI/CliBuildOptions.cs @@ -0,0 +1,25 @@ +// This file is part of the Prowl Game Engine +// Licensed under the MIT License. See the LICENSE file in the project root for details. + +using CommandLine; + +namespace Prowl.Editor.Editor.CLI; + +/// +/// Command line options for the `build` command. +/// +[Verb("build", false, HelpText = "build a given project")] +internal class CliBuildOptions +{ + /// + /// The path of the project to be open. + /// + [Option('p', "project", Required = false, HelpText = "Project path")] + public required DirectoryInfo ProjectPath { get; set; } + + /// + /// The path of the output files. + /// + [Option('o', "output", Required = false, HelpText = "Output directory path")] + public required DirectoryInfo Output { get; set; } +} diff --git a/Prowl.Editor/Editor/CLI/README.md b/Prowl.Editor/Editor/CLI/README.md new file mode 100644 index 000000000..688068c67 --- /dev/null +++ b/Prowl.Editor/Editor/CLI/README.md @@ -0,0 +1,3 @@ +Command Line (CLI) options + +These classes map the optional commands that Prowl accept from the Console/Terminal/Command line. diff --git a/Prowl.Editor/Program.cs b/Prowl.Editor/Program.cs index dc14a181f..fb49f2c75 100644 --- a/Prowl.Editor/Program.cs +++ b/Prowl.Editor/Program.cs @@ -14,18 +14,22 @@ namespace Prowl.Editor; public static class Program { - private static bool IsReloadingExternalAssemblies { get; set; } public static void RegisterReloadOfExternalAssemblies() => IsReloadingExternalAssemblies = true; + private static bool IsReloadingExternalAssemblies { get; set; } private static bool s_createdDefaultWindows; private static bool s_opened; public static int Main(string[] args) { - return Parser.Default.ParseArguments(args) + // CommandLineParser what command line arguments where used. `open` is the default option, + // so there is not need to call "prowl.exe open", only "prowl.exe". + return Parser.Default.ParseArguments(args) .MapResult( + // the default option, so there is not need to call "prowl.exe open", only "prowl.exe" (CliOpenOptions options) => Run(options), (CliCreateOptions options) => CreateCommand(options), - errs => 1); // error + (CliBuildOptions options) => BuildCommand(options), + errs => 1); // the command do not exist, finish the program as an error } private static int CreateCommand(CliCreateOptions options) @@ -60,7 +64,6 @@ private static int Run(CliOpenOptions options) Application.Update += () => { - if (!s_opened && options?.ProjectPath is not null && options.ProjectPath.Exists) { Project.Open(new Project(options.ProjectPath)); @@ -83,18 +86,23 @@ private static int Run(CliOpenOptions options) s_createdDefaultWindows = true; //new EditorMainMenubar(); var console = EditorGuiManager.DockWindowTo(new ConsoleWindow(), null, Docking.DockZone.Center); - var assetbrowser = EditorGuiManager.DockWindowTo(new AssetsBrowserWindow(), console, Docking.DockZone.Center); + var assetbrowser = + EditorGuiManager.DockWindowTo(new AssetsBrowserWindow(), console, Docking.DockZone.Center); // Add Asset Tree, When we do this AssetBrowser node will subdivide into two children - var assettree = EditorGuiManager.DockWindowTo(new AssetsTreeWindow(), assetbrowser, Docking.DockZone.Left, 0.2f); + var assettree = EditorGuiManager.DockWindowTo(new AssetsTreeWindow(), assetbrowser, + Docking.DockZone.Left, 0.2f); // So for the Inspector we need to use the Child to dock now - var inspector = EditorGuiManager.DockWindowTo(new InspectorWindow(), assetbrowser.Child[1], Docking.DockZone.Right, 0.75f); + var inspector = EditorGuiManager.DockWindowTo(new InspectorWindow(), assetbrowser.Child[1], + Docking.DockZone.Right, 0.75f); // Now Asset Browser is Subdivided twice, assetbrowser = assetbrowser.Child[1].Child[0]; - var game = EditorGuiManager.DockWindowTo(new GameWindow(), assetbrowser, Docking.DockZone.Top, 0.65f); + var game = EditorGuiManager.DockWindowTo(new GameWindow(), assetbrowser, Docking.DockZone.Top, + 0.65f); var scene = EditorGuiManager.DockWindowTo(new SceneViewWindow(), game, Docking.DockZone.Center); // and finally hierarchy on top of asset tree - var hierarchy = EditorGuiManager.DockWindowTo(new HierarchyWindow(), assettree, Docking.DockZone.Top, 0.65f); + var hierarchy = EditorGuiManager.DockWindowTo(new HierarchyWindow(), assettree, + Docking.DockZone.Top, 0.65f); // new ProjectSettingsWindow(); // new PreferencesWindow(); @@ -149,17 +157,19 @@ private static int Run(CliOpenOptions options) Graphics.EndFrame(); }; - Application.Quitting += () => - { - - }; + Application.Quitting += () => { }; Application.Run("Prowl Editor", 1920, 1080, new EditorAssetProvider(), true); return 0; } - public static void CheckReloadingAssemblies() + private static int BuildCommand(CliBuildOptions options) + { + throw new NotImplementedException(); + } + + private static void CheckReloadingAssemblies() { if (IsReloadingExternalAssemblies) { From 675130b3c77ae6e9d8554b12c017406e027c9c7d Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 05:09:21 -0500 Subject: [PATCH 2/9] chore: code reorganization and typos --- Prowl.Editor/Program.cs | 253 +++++++++++++++++++++------------------- Prowl.Runtime/Debug.cs | 28 ++--- 2 files changed, 145 insertions(+), 136 deletions(-) diff --git a/Prowl.Editor/Program.cs b/Prowl.Editor/Program.cs index fb49f2c75..8e32006d9 100644 --- a/Prowl.Editor/Program.cs +++ b/Prowl.Editor/Program.cs @@ -22,21 +22,21 @@ public static class Program public static int Main(string[] args) { // CommandLineParser what command line arguments where used. `open` is the default option, - // so there is not need to call "prowl.exe open", only "prowl.exe". + // so there is no need to call "prowl.exe open", only "prowl.exe". return Parser.Default.ParseArguments(args) .MapResult( - // the default option, so there is not need to call "prowl.exe open", only "prowl.exe" + // the default option, so there is no need to call "prowl.exe open", only "prowl.exe" (CliOpenOptions options) => Run(options), (CliCreateOptions options) => CreateCommand(options), (CliBuildOptions options) => BuildCommand(options), - errs => 1); // the command do not exist, finish the program as an error + _ => 1); // the command do not exist, finish the program as an error } private static int CreateCommand(CliCreateOptions options) { Console.WriteLine("Creating a new project"); - if (options?.ProjectPath is not null && !options.ProjectPath.Exists) + if (!options.ProjectPath.Exists) { Project.CreateNew(options.ProjectPath); } @@ -59,94 +59,91 @@ private static int Run(CliOpenOptions options) ImporterAttribute.GenerateLookUp(); // Start with the project window open - new ProjectsWindow(); + _ = new ProjectsWindow(); }; Application.Update += () => { - if (!s_opened && options?.ProjectPath is not null && options.ProjectPath.Exists) + if (!s_opened && options.ProjectPath.Exists) { Project.Open(new Project(options.ProjectPath)); s_opened = true; } - //EditorGui.SetupDock(); AssetDatabase.InternalUpdate(); - if (PlayMode.Current == PlayMode.Mode.Editing) // Dont recompile scripts unless were in editor mode + if (PlayMode.Current == PlayMode.Mode.Editing) // Don't recompile scripts unless were in editor mode CheckReloadingAssemblies(); + if (!Project.HasProject) + { + return; + } + + Physics.Initialize(); + // Editor-specific update code - if (Project.HasProject) + if (!s_createdDefaultWindows) + { + s_createdDefaultWindows = true; + + var console = EditorGuiManager.DockWindowTo(new ConsoleWindow(), null, Docking.DockZone.Center); + var assetBrowser = + EditorGuiManager.DockWindowTo(new AssetsBrowserWindow(), console, Docking.DockZone.Center); + // Add Asset Tree, When we do this AssetBrowser node will subdivide into two children + var assetTree = EditorGuiManager.DockWindowTo(new AssetsTreeWindow(), assetBrowser, + Docking.DockZone.Left, 0.2f); + // So for the Inspector we need to use the Child to dock now + EditorGuiManager.DockWindowTo(new InspectorWindow(), assetBrowser?.Child[1], + Docking.DockZone.Right, 0.75f); + // Now Asset Browser is Subdivided twice, + assetBrowser = assetBrowser?.Child[1].Child[0]; + var game = EditorGuiManager.DockWindowTo(new GameWindow(), assetBrowser, Docking.DockZone.Top, + 0.65f); + EditorGuiManager.DockWindowTo(new SceneViewWindow(), game, Docking.DockZone.Center); + + // and finally hierarchy on top of asset tree + EditorGuiManager.DockWindowTo(new HierarchyWindow(), assetTree, + Docking.DockZone.Top, 0.65f); + } + + Application.DataPath = Project.Active?.ProjectPath; + + if (GeneralPreferences.Instance.LockFPS) + { + Graphics.VSync = false; + Screen.FramesPerSecond = GeneralPreferences.Instance.TargetFPS; + } + else { - Physics.Initialize(); - - if (!s_createdDefaultWindows) - { - s_createdDefaultWindows = true; - //new EditorMainMenubar(); - var console = EditorGuiManager.DockWindowTo(new ConsoleWindow(), null, Docking.DockZone.Center); - var assetbrowser = - EditorGuiManager.DockWindowTo(new AssetsBrowserWindow(), console, Docking.DockZone.Center); - // Add Asset Tree, When we do this AssetBrowser node will subdivide into two children - var assettree = EditorGuiManager.DockWindowTo(new AssetsTreeWindow(), assetbrowser, - Docking.DockZone.Left, 0.2f); - // So for the Inspector we need to use the Child to dock now - var inspector = EditorGuiManager.DockWindowTo(new InspectorWindow(), assetbrowser.Child[1], - Docking.DockZone.Right, 0.75f); - // Now Asset Browser is Subdivided twice, - assetbrowser = assetbrowser.Child[1].Child[0]; - var game = EditorGuiManager.DockWindowTo(new GameWindow(), assetbrowser, Docking.DockZone.Top, - 0.65f); - var scene = EditorGuiManager.DockWindowTo(new SceneViewWindow(), game, Docking.DockZone.Center); - - // and finally hierarchy on top of asset tree - var hierarchy = EditorGuiManager.DockWindowTo(new HierarchyWindow(), assettree, - Docking.DockZone.Top, 0.65f); - - // new ProjectSettingsWindow(); - // new PreferencesWindow(); - // new AssetSelectorWindow(typeof(Texture2D), (guid, fileid) => { }); - } - - Application.DataPath = Project.Active.ProjectPath; - - if (GeneralPreferences.Instance.LockFPS) - { - Graphics.VSync = false; - Screen.FramesPerSecond = GeneralPreferences.Instance.TargetFPS; - } - else - { - Graphics.VSync = GeneralPreferences.Instance.VSync; - Screen.FramesPerSecond = 0; - } - - if (Hotkeys.IsHotkeyDown("SaveSceneAs", new() { Key = Key.S, Ctrl = true, Shift = true })) - EditorGuiManager.SaveSceneAs(); - else if (Hotkeys.IsHotkeyDown("SaveScene", new() { Key = Key.S, Ctrl = true })) - EditorGuiManager.SaveScene(); - - Application.IsPlaying = PlayMode.Current == PlayMode.Mode.Playing; - - - try - { - bool hasGameWindow = GameWindow.LastFocused != null && GameWindow.LastFocused.IsAlive; - // Push GameWindow's input handler - if (hasGameWindow) Input.PushHandler((GameWindow.LastFocused.Target as GameWindow).InputHandler); - - PlayMode.GameTime.Update(); - Time.TimeStack.Push(PlayMode.GameTime); - SceneManager.Update(); - Time.TimeStack.Pop(); - - if (hasGameWindow) Input.PopHandler(); - } - catch (Exception e) - { - Debug.LogError("Scene Update Error: " + e.ToString()); - } + Graphics.VSync = GeneralPreferences.Instance.VSync; + Screen.FramesPerSecond = 0; + } + + if (Hotkeys.IsHotkeyDown("SaveSceneAs", new() { Key = Key.S, Ctrl = true, Shift = true })) + EditorGuiManager.SaveSceneAs(); + else if (Hotkeys.IsHotkeyDown("SaveScene", new() { Key = Key.S, Ctrl = true })) + EditorGuiManager.SaveScene(); + + Application.isPlaying = PlayMode.Current == PlayMode.Mode.Playing; + + + try + { + bool hasGameWindow = GameWindow.LastFocused.IsAlive; + // Push GameWindow's input handler + if (hasGameWindow) Input.PushHandler((GameWindow.LastFocused.Target as GameWindow)!.InputHandler); + + PlayMode.GameTime.Update(); + Time.TimeStack.Push(PlayMode.GameTime); + SceneManager.Update(); + Time.TimeStack.Pop(); + + if (hasGameWindow) Input.PopHandler(); + } + catch (Exception e) + { + Debug.LogError($"Scene Update Error: {e}"); } }; @@ -166,61 +163,73 @@ private static int Run(CliOpenOptions options) private static int BuildCommand(CliBuildOptions options) { - throw new NotImplementedException(); + Console.WriteLine($"Building project at {options.ProjectPath}"); + if (!options.ProjectPath.Exists) + { + _ = new Project(options.ProjectPath); + } + else + { + Console.WriteLine("Path is not valid or already exists"); + } + + return 0; } private static void CheckReloadingAssemblies() { - if (IsReloadingExternalAssemblies) + if (!IsReloadingExternalAssemblies) { - IsReloadingExternalAssemblies = false; + return; + } + + IsReloadingExternalAssemblies = false; + + if (Project.Active is not null && Project.HasProject) + { + SceneManager.StoreScene(); + SceneManager.Clear(); + + try + { + // Unload External Assemblies + AssemblyManager.Unload(); + + var active = Project.Active; + + DirectoryInfo temp = active.TempDirectory; + DirectoryInfo bin = new DirectoryInfo(Path.Combine(temp.FullName, "bin")); + DirectoryInfo debug = new DirectoryInfo(Path.Combine(bin.FullName, "Debug")); - if (Project.HasProject) + // Delete everything under Temp\Bin + if (bin.Exists) + Directory.Delete(bin.FullName, true); + bin.Create(); + + // Compile the Projects + Project.Compile(active.Assembly_Proj.FullName, debug); + Project.Compile(active.Editor_Assembly_Proj.FullName, debug); + + // Reload the External Assemblies + AssemblyManager.LoadExternalAssembly(active.Editor_Assembly_DLL.FullName, true); + AssemblyManager.LoadExternalAssembly(active.Assembly_DLL.FullName, true); + } + catch (Exception e) { - SceneManager.StoreScene(); - SceneManager.Clear(); - - try - { - // Unload External Assemblies - AssemblyManager.Unload(); - - Project active = Project.Active; - - DirectoryInfo temp = active.TempDirectory; - DirectoryInfo bin = new DirectoryInfo(Path.Combine(temp.FullName, "bin")); - DirectoryInfo debug = new DirectoryInfo(Path.Combine(bin.FullName, "Debug")); - - // Delete everything under Temp\Bin - if (bin.Exists) - Directory.Delete(bin.FullName, true); - bin.Create(); - - // Compile the Projects - Project.Compile(active.Assembly_Proj.FullName, debug); - Project.Compile(active.Editor_Assembly_Proj.FullName, debug); - - // Reload the External Assemblies - AssemblyManager.LoadExternalAssembly(active.Editor_Assembly_DLL.FullName, true); - AssemblyManager.LoadExternalAssembly(active.Assembly_DLL.FullName, true); - } - catch (Exception e) - { - Debug.LogError($"Error reloading assemblies: {e.Message}"); - Debug.LogError(e.StackTrace); - } - finally - { - OnAssemblyLoadAttribute.Invoke(); - - SceneManager.RestoreScene(); - SceneManager.ClearStoredScene(); - } + Debug.LogError($"Error reloading assemblies: {e.Message}"); + Debug.LogError($"{e.StackTrace}"); } - else + finally { - Debug.LogError("Cannot reload assemblies, No project loaded."); + OnAssemblyLoadAttribute.Invoke(); + + SceneManager.RestoreScene(); + SceneManager.ClearStoredScene(); } } + else + { + Debug.LogError("Cannot reload assemblies, No project loaded."); + } } } diff --git a/Prowl.Runtime/Debug.cs b/Prowl.Runtime/Debug.cs index eba84d5b5..41b7fbf44 100644 --- a/Prowl.Runtime/Debug.cs +++ b/Prowl.Runtime/Debug.cs @@ -20,23 +20,23 @@ public enum LogSeverity Exception = 1 << 4 } - public delegate void OnLog(string message, DebugStackTrace? stackTrace, LogSeverity logSeverity); - -public record DebugStackFrame(int line, int column, string? fileName = null, MethodBase? methodBase = null) +/// +/// A single registry of Debug Stack, pointing to method, file and line +/// +/// +/// +/// +/// +public record DebugStackFrame(int Line, int Column, string? FileName = null, MethodBase? MethodBase = null) { - public override string ToString() - { - if (methodBase != null) - return $"In {methodBase.DeclaringType.Name}.{methodBase.Name} at {fileName}:{line}:{column}"; - else - return $"At {fileName}:{line}:{column}"; - } + public override string ToString() => MethodBase != null + ? $"In {MethodBase.DeclaringType.Name}.{MethodBase.Name} at {FileName}:{Line}:{Column}" + : $"At {FileName}:{Line}:{Column}"; } - -public record DebugStackTrace(params DebugStackFrame[] stackFrames) +public record DebugStackTrace(params DebugStackFrame[] StackFrames) { public static explicit operator DebugStackTrace(StackTrace stackTrace) { @@ -56,8 +56,8 @@ public override string ToString() { StringBuilder sb = new(); - for (int i = 0; i < stackFrames.Length; i++) - sb.AppendLine($"\t{stackFrames[i]}"); + foreach (var t in StackFrames) + sb.AppendLine($"\t{t}"); return sb.ToString(); } From ea63cb8ff7af257d1abbe47734fa23800f08795c Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 05:09:21 -0500 Subject: [PATCH 3/9] chore: CliOptionsBase for repetitive code --- Prowl.Editor/Editor/CLI/CliBuildOptions.cs | 8 +------- Prowl.Editor/Editor/CLI/CliCreateOptions.cs | 7 +------ Prowl.Editor/Editor/CLI/CliOpenOptions.cs | 9 +-------- Prowl.Editor/Editor/CLI/CliOptionsBase.cs | 18 ++++++++++++++++++ Prowl.Editor/Program.cs | 17 ++++++++--------- 5 files changed, 29 insertions(+), 30 deletions(-) create mode 100644 Prowl.Editor/Editor/CLI/CliOptionsBase.cs diff --git a/Prowl.Editor/Editor/CLI/CliBuildOptions.cs b/Prowl.Editor/Editor/CLI/CliBuildOptions.cs index 864472dca..debd042bc 100644 --- a/Prowl.Editor/Editor/CLI/CliBuildOptions.cs +++ b/Prowl.Editor/Editor/CLI/CliBuildOptions.cs @@ -9,14 +9,8 @@ namespace Prowl.Editor.Editor.CLI; /// Command line options for the `build` command. /// [Verb("build", false, HelpText = "build a given project")] -internal class CliBuildOptions +internal class CliBuildOptions : CliOptionsBase { - /// - /// The path of the project to be open. - /// - [Option('p', "project", Required = false, HelpText = "Project path")] - public required DirectoryInfo ProjectPath { get; set; } - /// /// The path of the output files. /// diff --git a/Prowl.Editor/Editor/CLI/CliCreateOptions.cs b/Prowl.Editor/Editor/CLI/CliCreateOptions.cs index 0e80d49f0..13072592b 100644 --- a/Prowl.Editor/Editor/CLI/CliCreateOptions.cs +++ b/Prowl.Editor/Editor/CLI/CliCreateOptions.cs @@ -9,11 +9,6 @@ namespace Prowl.Editor.Editor.CLI; /// Command line options for the `create` command. /// [Verb("create", false, HelpText = "create a project")] -internal class CliCreateOptions +internal class CliCreateOptions : CliOptionsBase { - /// - /// The path of the project to be created. - /// - [Option('p', "project", Required = false, HelpText = "Project path", Default = "./")] - public required DirectoryInfo ProjectPath { get; set; } } diff --git a/Prowl.Editor/Editor/CLI/CliOpenOptions.cs b/Prowl.Editor/Editor/CLI/CliOpenOptions.cs index 9a2fef7e7..213372657 100644 --- a/Prowl.Editor/Editor/CLI/CliOpenOptions.cs +++ b/Prowl.Editor/Editor/CLI/CliOpenOptions.cs @@ -9,11 +9,4 @@ namespace Prowl.Editor.Editor.CLI; /// Command line options for the `open` command. /// [Verb("open", true, HelpText = "Open a given project")] -internal class CliOpenOptions -{ - /// - /// The path of the project to be open. - /// - [Option('p', "project", Required = false, HelpText = "Project path")] - public required DirectoryInfo ProjectPath { get; set; } -} +internal class CliOpenOptions : CliOptionsBase { } diff --git a/Prowl.Editor/Editor/CLI/CliOptionsBase.cs b/Prowl.Editor/Editor/CLI/CliOptionsBase.cs new file mode 100644 index 000000000..fb647c887 --- /dev/null +++ b/Prowl.Editor/Editor/CLI/CliOptionsBase.cs @@ -0,0 +1,18 @@ +// This file is part of the Prowl Game Engine +// Licensed under the MIT License. See the LICENSE file in the project root for details. + +using CommandLine; + +namespace Prowl.Editor.Editor.CLI; + +/// +/// Repetitive options. +/// +internal class CliOptionsBase +{ + /// + /// The path of the project to perform the command (open, build, create, etc). + /// + [Option('p', "project", Required = false, HelpText = "Project path")] + public required DirectoryInfo? ProjectPath { get; init; } +} diff --git a/Prowl.Editor/Program.cs b/Prowl.Editor/Program.cs index 8e32006d9..58ed72949 100644 --- a/Prowl.Editor/Program.cs +++ b/Prowl.Editor/Program.cs @@ -36,7 +36,7 @@ private static int CreateCommand(CliCreateOptions options) { Console.WriteLine("Creating a new project"); - if (!options.ProjectPath.Exists) + if (options.ProjectPath is not null && !options.ProjectPath.Exists) { Project.CreateNew(options.ProjectPath); } @@ -64,12 +64,6 @@ private static int Run(CliOpenOptions options) Application.Update += () => { - if (!s_opened && options.ProjectPath.Exists) - { - Project.Open(new Project(options.ProjectPath)); - s_opened = true; - } - AssetDatabase.InternalUpdate(); if (PlayMode.Current == PlayMode.Mode.Editing) // Don't recompile scripts unless were in editor mode @@ -127,7 +121,6 @@ private static int Run(CliOpenOptions options) Application.isPlaying = PlayMode.Current == PlayMode.Mode.Playing; - try { bool hasGameWindow = GameWindow.LastFocused.IsAlive; @@ -151,6 +144,12 @@ private static int Run(CliOpenOptions options) { EditorGuiManager.Update(); + if (!s_opened && options.ProjectPath is not null && options.ProjectPath.Exists) + { + Project.Open(new Project(options.ProjectPath)); + s_opened = true; + } + Graphics.EndFrame(); }; @@ -164,7 +163,7 @@ private static int Run(CliOpenOptions options) private static int BuildCommand(CliBuildOptions options) { Console.WriteLine($"Building project at {options.ProjectPath}"); - if (!options.ProjectPath.Exists) + if (options.ProjectPath is not null && !options.ProjectPath.Exists) { _ = new Project(options.ProjectPath); } From 9686cf6bdaf8be6b36c63d2219dc6683bbe9f89c Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 05:09:21 -0500 Subject: [PATCH 4/9] refactor: AssetRef code fixes and optimizations --- Prowl.Editor/Build/ProjectBuilder.cs | 18 ++++++++++++++ Prowl.Editor/Program.cs | 37 ++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/Prowl.Editor/Build/ProjectBuilder.cs b/Prowl.Editor/Build/ProjectBuilder.cs index e86960bb7..b8e525679 100644 --- a/Prowl.Editor/Build/ProjectBuilder.cs +++ b/Prowl.Editor/Build/ProjectBuilder.cs @@ -1,6 +1,9 @@ // This file is part of the Prowl Game Engine // Licensed under the MIT License. See the LICENSE file in the project root for details. +using System.Reflection; + +using Prowl.Editor.Utilities; using Prowl.Runtime; namespace Prowl.Editor.Build; @@ -35,6 +38,21 @@ public void StartBuild(AssetRef[] scenes, DirectoryInfo output) { Debug.LogError($"Failed to build project: {e.Message}"); } + + public static IEnumerable GetAll() + { + foreach (Assembly editorAssembly in AssemblyManager.ExternalAssemblies.Append(typeof(Program).Assembly)) + { + List derivedTypes = EditorUtils.GetDerivedTypes(typeof(ProjectBuilder), editorAssembly); + foreach (Type type in derivedTypes) + { + if (type.IsAbstract) + continue; + + yield return (ProjectBuilder)Activator.CreateInstance(type); + } + } + } } protected abstract void Build(AssetRef[] scenes, DirectoryInfo output); diff --git a/Prowl.Editor/Program.cs b/Prowl.Editor/Program.cs index 58ed72949..09de1051e 100644 --- a/Prowl.Editor/Program.cs +++ b/Prowl.Editor/Program.cs @@ -1,11 +1,15 @@ // This file is part of the Prowl Game Engine // Licensed under the MIT License. See the LICENSE file in the project root for details. +using System.Globalization; + using CommandLine; using Prowl.Editor.Assets; +using Prowl.Editor.Build; using Prowl.Editor.Editor.CLI; using Prowl.Editor.Preferences; +using Prowl.Editor.ProjectSettings; using Prowl.Runtime; using Prowl.Runtime.SceneManagement; using Prowl.Runtime.Utils; @@ -36,15 +40,14 @@ private static int CreateCommand(CliCreateOptions options) { Console.WriteLine("Creating a new project"); - if (options.ProjectPath is not null && !options.ProjectPath.Exists) - { - Project.CreateNew(options.ProjectPath); - } - else + if (options.ProjectPath is null || options.ProjectPath.Exists) { Console.WriteLine("Path is not valid or already exists"); + return 1; } + Project.CreateNew(options.ProjectPath); + return 0; } @@ -162,16 +165,30 @@ private static int Run(CliOpenOptions options) private static int BuildCommand(CliBuildOptions options) { - Console.WriteLine($"Building project at {options.ProjectPath}"); - if (options.ProjectPath is not null && !options.ProjectPath.Exists) + Console.WriteLine($"Building project from\t'{options.ProjectPath}'"); + if (options.ProjectPath is null || !options.ProjectPath.Exists) { - _ = new Project(options.ProjectPath); + Console.WriteLine("Path is not valid or already exists"); + return 1; } - else + + var pathBuild = new DirectoryInfo(Path.Combine(options.ProjectPath.ToString(), "Builds", + DateTime.UtcNow.ToString("yyyyMMddHHmmss"))); + + Console.WriteLine($"Building path\t\t'{pathBuild}'"); + if (pathBuild.Exists) { - Console.WriteLine("Path is not valid or already exists"); + Console.WriteLine("Build path is not valid or already exists"); + return 1; } + var project = new Project(options.ProjectPath); + Project.Open(project); + Application.DataPath = options.ProjectPath.ToString(); + pathBuild.Create(); + var builders = ProjectBuilder.GetAll().ToList(); + Application.AssetProvider = new EditorAssetProvider(); + builders[0]?.StartBuild(BuildProjectSetting.Instance.Scenes, pathBuild); return 0; } From 8bb925c2456ca570d242c363f1d9098544daaee0 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 05:09:21 -0500 Subject: [PATCH 5/9] refactor: reuse Project.BoundedLog --- Prowl.Editor/Build/Desktop_Player.cs | 247 ++++++++++++++------------- Prowl.Editor/Build/ProjectBuilder.cs | 106 ++++++------ Prowl.Editor/Project.cs | 55 +++--- 3 files changed, 208 insertions(+), 200 deletions(-) diff --git a/Prowl.Editor/Build/Desktop_Player.cs b/Prowl.Editor/Build/Desktop_Player.cs index fbe70a9bd..b3c1526ed 100644 --- a/Prowl.Editor/Build/Desktop_Player.cs +++ b/Prowl.Editor/Build/Desktop_Player.cs @@ -7,152 +7,153 @@ using Prowl.Runtime; using Prowl.Runtime.Utils; -namespace Prowl.Editor.Build; - -public class Desktop_Player : ProjectBuilder +namespace Prowl.Editor.Build { - public enum Target - { - [Text("Win x64")] win_x64, - [Text("Win ARM x64")] win_arm64, - [Text("Win x86")] win_x86, - - [Text("Linux x64")] linux_x64, - [Text("Linux x86")] linux_x86, - - [Text("OSX")] osx, - [Text("OSX x64")] osx_x64, - [Text("OSX ARM x64")] osx_arm64, - - Universal - } - public Target target = Target.win_x64; - - public enum Configuration + public class Desktop_Player : ProjectBuilder { - Debug, - Release - } - public Configuration configuration = Configuration.Release; - - public enum AssetPacking - { - [Text("All Assets")] All, - [Text("Used Assets")] Used - } - public AssetPacking assetPacking = AssetPacking.Used; - + public enum Target + { + [Text("Win x64")] win_x64, + [Text("Win ARM x64")] win_arm64, + [Text("Win x86")] win_x86, - protected override void Build(AssetRef[] scenes, DirectoryInfo output) - { - output.Create(); - string BuildDataPath = Path.Combine(output.FullName, "GameData"); - Directory.CreateDirectory(BuildDataPath); + [Text("Linux x64")] linux_x64, + [Text("Linux x86")] linux_x86, + [Text("OSX")] osx, + [Text("OSX x64")] osx_x64, + [Text("OSX ARM x64")] osx_arm64, - BoundedLog($"Compiling project assembly to {output.FullName}..."); - if (!Project.Compile(Project.Active.Assembly_Proj.FullName, output, configuration == Configuration.Release)) - { - Debug.LogError($"Failed to compile Project assembly!"); - return; + Universal } + public Target target = Target.win_x64; - BoundedLog($"Exporting and Packing assets to {BuildDataPath}..."); - if (assetPacking == AssetPacking.All) + public enum Configuration { - AssetDatabase.ExportAllBuildPackages(new DirectoryInfo(BuildDataPath)); - } - else - { - HashSet assets = []; - foreach (var scene in scenes) - AssetDatabase.GetDependenciesDeep(scene.AssetID, ref assets); - - // Include all Shaders in the build for the time being - foreach (var shader in AssetDatabase.GetAllAssetsOfType()) - assets.Add(shader.Item2); - - AssetDatabase.ExportBuildPackages(assets.ToArray(), new DirectoryInfo(BuildDataPath)); + Debug, + Release } + public Configuration configuration = Configuration.Release; - - BoundedLog($"Packing scenes..."); - for (int i = 0; i < scenes.Length; i++) + public enum AssetPacking { - BoundedLog($"Packing scene_{i}.prowl..."); - var scene = scenes[i]; - SerializedProperty tag = Serializer.Serialize(scene.Res!); - BinaryTagConverter.WriteToFile(tag, new FileInfo(Path.Combine(BuildDataPath, $"scene_{i}.prowl"))); + [Text("All Assets")] All, + [Text("Used Assets")] Used } + public AssetPacking assetPacking = AssetPacking.Used; - BoundedLog($"Preparing project settings..."); - // Find all ScriptableSingletons with the specified location - foreach (var type in RuntimeUtils.GetTypesWithAttribute()) - if (Attribute.GetCustomAttribute(type, typeof(FilePathAttribute)) is FilePathAttribute attribute) - if (attribute.FileLocation == FilePathAttribute.Location.Setting) - { - // Use Reflection to find the CopyTo method - MethodInfo copyTo = type.BaseType.GetMethod("CopyTo", BindingFlags.Static | BindingFlags.NonPublic); - if (copyTo is null) + protected override void Build(AssetRef[] scenes, DirectoryInfo output) + { + output.Create(); + string BuildDataPath = Path.Combine(output.FullName, "GameData"); + Directory.CreateDirectory(BuildDataPath); + + + Project.BoundedLog($"Compiling project assembly to {output.FullName}..."); + if (!Project.Compile(Project.Active.Assembly_Proj.FullName, output, configuration == Configuration.Release)) + { + Debug.LogError($"Failed to compile Project assembly!"); + return; + } + + Project.BoundedLog($"Exporting and Packing assets to {BuildDataPath}..."); + if (assetPacking == AssetPacking.All) + { + AssetDatabase.ExportAllBuildPackages(new DirectoryInfo(BuildDataPath)); + } + else + { + HashSet assets = []; + foreach (var scene in scenes) + AssetDatabase.GetDependenciesDeep(scene.AssetID, ref assets); + + // Include all Shaders in the build for the time being + foreach (var shader in AssetDatabase.GetAllAssetsOfType()) + assets.Add(shader.Item2); + + AssetDatabase.ExportBuildPackages(assets.ToArray(), new DirectoryInfo(BuildDataPath)); + } + + + Project.BoundedLog($"Packing scenes..."); + for (int i = 0; i < scenes.Length; i++) + { + Project.BoundedLog($"Packing scene_{i}.prowl..."); + var scene = scenes[i]; + SerializedProperty tag = Serializer.Serialize(scene.Res!); + BinaryTagConverter.WriteToFile(tag, new FileInfo(Path.Combine(BuildDataPath, $"scene_{i}.prowl"))); + } + + + Project.BoundedLog($"Preparing project settings..."); + // Find all ScriptableSingletons with the specified location + foreach (var type in RuntimeUtils.GetTypesWithAttribute()) + if (Attribute.GetCustomAttribute(type, typeof(FilePathAttribute)) is FilePathAttribute attribute) + if (attribute.FileLocation == FilePathAttribute.Location.Setting) { - Debug.LogError($"Failed to find CopyTo method for {type.Name}"); - continue; + // Use Reflection to find the CopyTo method + MethodInfo copyTo = type.BaseType.GetMethod("CopyTo", BindingFlags.Static | BindingFlags.NonPublic); + if (copyTo is null) + { + Debug.LogError($"Failed to find CopyTo method for {type.Name}"); + continue; + } + + // Invoke the CopyTo method + string? test = BuildDataPath; + copyTo.Invoke(null, [test]); } - // Invoke the CopyTo method - string? test = BuildDataPath; - copyTo.Invoke(null, [test]); - } - - BoundedLog($"Copying Desktop player to {output.FullName}..."); - // Our executable folder contains "Players\Desktop" which we need to copy over the contents - string playerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Players", "Desktop"); - if (!Directory.Exists(playerPath)) - { - Debug.LogError($"Failed to find Desktop player at {playerPath}"); - return; - } + Project.BoundedLog($"Copying Desktop player to {output.FullName}..."); + // Our executable folder contains "Players\Desktop" which we need to copy over the contents + string playerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Players", "Desktop"); + if (!Directory.Exists(playerPath)) + { + Debug.LogError($"Failed to find Desktop player at {playerPath}"); + return; + } - // Copy the contents of the Desktop player to the output directory, Files and Directories - var allDirectories = Directory.GetDirectories(playerPath, "*", SearchOption.AllDirectories); - foreach (var directory in allDirectories) - Directory.CreateDirectory(directory.Replace(playerPath, output.FullName)); + // Copy the contents of the Desktop player to the output directory, Files and Directories + var allDirectories = Directory.GetDirectories(playerPath, "*", SearchOption.AllDirectories); + foreach (var directory in allDirectories) + Directory.CreateDirectory(directory.Replace(playerPath, output.FullName)); - var allFiles = Directory.GetFiles(playerPath, "*", SearchOption.AllDirectories); - foreach (var file in allFiles) - File.Copy(file, file.Replace(playerPath, output.FullName), true); + var allFiles = Directory.GetFiles(playerPath, "*", SearchOption.AllDirectories); + foreach (var file in allFiles) + File.Copy(file, file.Replace(playerPath, output.FullName), true); - // Strip files we dont need for our target - if (target != Target.Universal) - CleanupRuntimes(output); + // Strip files we dont need for our target + if (target != Target.Universal) + CleanupRuntimes(output); - Debug.Log("**********************************************************************************************************************"); - Debug.Log($"Successfully built project!"); + Debug.Log("**********************************************************************************************************************"); + Debug.Log($"Successfully built project!"); - // Open the Build folder - AssetDatabase.OpenPath(output); - } + // Open the Build folder + AssetDatabase.OpenPath(output); + } - private void CleanupRuntimes(DirectoryInfo output) - { - string runtimesPath = Path.Combine(output.FullName, "runtimes"); - if (!Directory.Exists(runtimesPath)) - return; - - // Remove all runtimes except the one we need - string targetRuntime = target.ToString().ToLower().Replace("_", "-"); - // Remove all but the target runtime - foreach (var runtime in Directory.GetDirectories(runtimesPath)) - if (!runtime.Contains(targetRuntime)) - Directory.Delete(runtime, true); - - // Copy all remaining files into the root output directory - foreach (var file in Directory.GetFiles(runtimesPath, "*", SearchOption.AllDirectories)) - File.Copy(file, Path.Combine(output.FullName, Path.GetFileName(file)), true); - - // Remove the runtimes folder - Directory.Delete(runtimesPath, true); + private void CleanupRuntimes(DirectoryInfo output) + { + string runtimesPath = Path.Combine(output.FullName, "runtimes"); + if (!Directory.Exists(runtimesPath)) + return; + + // Remove all runtimes except the one we need + string targetRuntime = target.ToString().ToLower().Replace("_", "-"); + // Remove all but the target runtime + foreach (var runtime in Directory.GetDirectories(runtimesPath)) + if (!runtime.Contains(targetRuntime)) + Directory.Delete(runtime, true); + + // Copy all remaining files into the root output directory + foreach (var file in Directory.GetFiles(runtimesPath, "*", SearchOption.AllDirectories)) + File.Copy(file, Path.Combine(output.FullName, Path.GetFileName(file)), true); + + // Remove the runtimes folder + Directory.Delete(runtimesPath, true); + } } } diff --git a/Prowl.Editor/Build/ProjectBuilder.cs b/Prowl.Editor/Build/ProjectBuilder.cs index b8e525679..9154db66e 100644 --- a/Prowl.Editor/Build/ProjectBuilder.cs +++ b/Prowl.Editor/Build/ProjectBuilder.cs @@ -6,37 +6,65 @@ using Prowl.Editor.Utilities; using Prowl.Runtime; -namespace Prowl.Editor.Build; - -public abstract class ProjectBuilder +namespace Prowl.Editor.Build { - public void StartBuild(AssetRef[] scenes, DirectoryInfo output) + public abstract class ProjectBuilder { - if (!Project.HasProject) + public void StartBuild(AssetRef[] scenes, DirectoryInfo output) { - Debug.LogError($"No Project Loaded..."); - return; - } + if (!Project.HasProject) + { + Debug.LogError($"No Project Loaded..."); + return; + } - if (!AreScenesValid(scenes)) - return; + if (!AreScenesValid(scenes)) + return; - Debug.Log($"Starting Project Build..."); - BoundedLog($"Creating Directories..."); + Debug.Log($"Starting Project Build..."); + Project.BoundedLog($"Creating Directories..."); - if (output.Exists) - { - BoundedLog($"Deleting existing build directory..."); - output.Delete(true); - } + if (output.Exists) + { + Project.BoundedLog($"Deleting existing build directory..."); + output.Delete(true); + } - try - { - Build(scenes, output); + try + { + Build(scenes, output); + } + catch (Exception e) + { + Debug.LogError($"Failed to build project: {e.Message}"); + } } - catch (Exception e) + + protected abstract void Build(AssetRef[] scenes, DirectoryInfo output); + + private bool AreScenesValid(AssetRef[] scenes) { - Debug.LogError($"Failed to build project: {e.Message}"); + if (scenes == null) + { + Debug.LogError($"At least 1 Scene must be assigned in the Build Project Settings Window"); + return false; + } + + if (scenes.Length <= 0) + { + Debug.LogError($"At least 1 Scene must be assigned in the Build Project Settings Window"); + return false; + } + + // Make sure all scenes are valid + foreach (var scene in scenes) + if (!scene.IsAvailable) + { + Debug.LogError($"Scene {scene.Name} is not available, please assign a valid available scene"); + return false; + } + + return true; } public static IEnumerable GetAll() @@ -54,38 +82,4 @@ public static IEnumerable GetAll() } } } - - protected abstract void Build(AssetRef[] scenes, DirectoryInfo output); - - private bool AreScenesValid(AssetRef[] scenes) - { - if (scenes == null) - { - Debug.LogError($"Atleast 1 Scene must be assigned in the Build Project Settings Window"); - return false; - } - - if (scenes.Length <= 0) - { - Debug.LogError($"Atleast 1 Scene must be assigned in the Build Project Settings Window"); - return false; - } - - // Make sure all scenes are valid - foreach (var scene in scenes) - if (!scene.IsAvailable) - { - Debug.LogError($"Scene {scene.Name} is not available, please assign a valid available scene"); - return false; - } - - return true; - } - - protected void BoundedLog(string message) - { - Debug.Log("**********************************************************************************************************************"); - Debug.Log(message); - Debug.Log("**********************************************************************************************************************"); - } } diff --git a/Prowl.Editor/Project.cs b/Prowl.Editor/Project.cs index 0486265c7..37f630e42 100644 --- a/Prowl.Editor/Project.cs +++ b/Prowl.Editor/Project.cs @@ -43,7 +43,6 @@ public class Project #region Public Methods - internal void Refresh() { ProjectDirectory.Refresh(); @@ -96,7 +95,8 @@ public static bool Open(Project project) { if (!project.IsValid()) { - Runtime.Debug.LogError($"Invalid project '{project.Name}' at path '{project.ProjectPath}'. Validate that all core project directories are intact."); + Runtime.Debug.LogError( + $"Invalid project '{project.Name}' at path '{project.ProjectPath}'. Validate that all core project directories are intact."); return false; } @@ -115,7 +115,8 @@ public static bool Open(Project project) AssetDatabase.Update(false, true); // Ensure packages are all loaded in AssetDatabase.AddRootFolder("Assets"); - AssetDatabase.Update(true, true); // Not that all folders are in we can unload anything thats not in the project anymore since last session + AssetDatabase.Update(true, + true); // Not that all folders are in we can unload anything thats not in the project anymore since last session #warning TODO: Record last opened scene and try to open it SceneManager.InstantiateNewScene(); @@ -162,7 +163,7 @@ public bool IsValid() AssetDirectory.Refresh(); return ProjectDirectory.Exists && - AssetDirectory.Exists; + AssetDirectory.Exists; } @@ -182,7 +183,8 @@ private static void CreateDefaults(Project project) #warning TODO: Only copy if the file doesn't exist, or if somehow if the engine version is different or something... // Copy embedded defaults to rootFolder, this is just actual Files, so Image.png, not the asset variants - foreach (string file in Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(x => x.StartsWith("Prowl.Editor.EmbeddedResources.DefaultAssets."))) + foreach (string file in Assembly.GetExecutingAssembly().GetManifestResourceNames() + .Where(x => x.StartsWith("Prowl.Editor.EmbeddedResources.DefaultAssets."))) { string[] nodes = file.Split('.'); string fileName = nodes[^2]; @@ -233,12 +235,14 @@ public static bool Compile(string csprojPath, DirectoryInfo output, bool isRelea // Default -> Windows processInfo.FileName = "cmd.exe"; - processInfo.Arguments = $"/c dotnet build \"{Path.GetFileName(csprojPath)}\"" + (isRelease ? " --configuration Release" : ""); + processInfo.Arguments = $"/c dotnet build \"{Path.GetFileName(csprojPath)}\"" + + (isRelease ? " --configuration Release" : ""); if (RuntimeUtils.IsMac() || RuntimeUtils.IsLinux()) { processInfo.FileName = "/bin/bash"; - processInfo.Arguments = $"-c \"dotnet build '{Path.GetFileName(csprojPath)}'\"" + (isRelease ? " --configuration Release" : ""); + processInfo.Arguments = $"-c \"dotnet build '{Path.GetFileName(csprojPath)}'\"" + + (isRelease ? " --configuration Release" : ""); } Process process = Process.Start(processInfo) ?? throw new Exception(); @@ -270,9 +274,11 @@ public static bool Compile(string csprojPath, DirectoryInfo output, bool isRelea int exitCode = process.ExitCode; process.Close(); - BoundedLog($"Exit Code: '{exitCode}'"); - - BoundedLog($"{(exitCode == 0 ? "Successfully" : "Failed to")} compile external assembly!"); + BoundedLog( + $""" + Exit Code: '{exitCode}' + {(exitCode == 0 ? "Successfully" : "Failed to")} compile external assembly! + """, exitCode == 0 ? LogSeverity.Success: LogSeverity.Error); return exitCode == 0; } @@ -281,7 +287,6 @@ public static bool Compile(string csprojPath, DirectoryInfo output, bool isRelea #region Private Methods - private static string GetIncludesFrom(IEnumerable filePaths) { List includeElements = new(); @@ -297,9 +302,11 @@ private static void GenerateCSProjectFiles(Project project, DirectoryInfo output if (!HasProject) throw new Exception("No Project Loaded, Cannot generate CS Project Files!"); Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); - Assembly gameEngineAssembly = loadedAssemblies.FirstOrDefault(assembly => assembly.GetName().Name == "Prowl.Runtime") + Assembly gameEngineAssembly = + loadedAssemblies.FirstOrDefault(assembly => assembly.GetName().Name == "Prowl.Runtime") ?? throw new Exception("Failed to find Prowl.Runtime Assembly!"); - Assembly gameEditorAssembly = loadedAssemblies.FirstOrDefault(assembly => assembly.GetName().Name == "Prowl.Editor") + Assembly gameEditorAssembly = + loadedAssemblies.FirstOrDefault(assembly => assembly.GetName().Name == "Prowl.Editor") ?? throw new Exception("Failed to find Prowl.Editor Assembly!"); // Get all references by Prowl.Runtime @@ -339,10 +346,10 @@ private static void GenerateCSProjectFiles(Project project, DirectoryInfo output "; string referencesXML = string.Join("\n", references.Select(assembly => - $"" + - $"{assembly.Location}" + - "false" + - "")); + $"" + + $"{assembly.Location}" + + "false" + + "")); string gameproj = @$" @@ -390,11 +397,17 @@ private static void GenerateCSProjectFiles(Project project, DirectoryInfo output Runtime.Debug.Log("Finished Updating Build Information"); } - private static void BoundedLog(string message) + public static void BoundedLog(string message, LogSeverity severity = LogSeverity.Normal) { - Runtime.Debug.Log("**********************************************************************************************************************"); - Runtime.Debug.Log(message); - Runtime.Debug.Log("**********************************************************************************************************************"); + Action logFunc = severity switch + { + LogSeverity.Success => Runtime.Debug.LogSuccess, + LogSeverity.Error => Runtime.Debug.LogError, + _ => Runtime.Debug.Log + }; + logFunc( + "**********************************************************************************************************************"); + logFunc(message); } #endregion From 0339e8001fdcbb5f42b48909d22c7a7a37411608 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 05:22:09 -0500 Subject: [PATCH 6/9] feat: rebase with the latest dev --- Prowl.Editor/Editor/ConsoleWindow.cs | 36 ++--- Prowl.Editor/Program.cs | 6 +- Prowl.Runtime/Debug.cs | 135 +++++++++--------- .../RenderPipeline/DefaultRenderPipeline.cs | 4 +- 4 files changed, 90 insertions(+), 91 deletions(-) diff --git a/Prowl.Editor/Editor/ConsoleWindow.cs b/Prowl.Editor/Editor/ConsoleWindow.cs index e93330ec1..e63debc5b 100644 --- a/Prowl.Editor/Editor/ConsoleWindow.cs +++ b/Prowl.Editor/Editor/ConsoleWindow.cs @@ -53,20 +53,20 @@ private static bool FastCompareMessage(LogMessage log, string message, DebugStac if ((log.trace == null) != (stackTrace == null)) return false; - if (log.trace != null && log.trace.stackFrames.Length != stackTrace.stackFrames.Length) + if (log.trace != null && log.trace.StackFrames.Length != stackTrace.StackFrames.Length) return false; // Slower checks later // Check stack frame 0 earlier since it potentially avoids comparing big messages. - if (stackTrace != null && stackTrace.stackFrames.Length > 0) + if (stackTrace != null && stackTrace.StackFrames.Length > 0) { - DebugStackFrame frame = log.trace.stackFrames[0]; - DebugStackFrame frame2 = stackTrace.stackFrames[0]; + DebugStackFrame frame = log.trace.StackFrames[0]; + DebugStackFrame frame2 = stackTrace.StackFrames[0]; - if (frame.line != frame2.line && frame.column != frame2.column) + if (frame.Line != frame2.Line && frame.Column != frame2.Column) return false; - if (frame.fileName != frame2.fileName) + if (frame.FileName != frame2.FileName) return false; } @@ -76,15 +76,15 @@ private static bool FastCompareMessage(LogMessage log, string message, DebugStac // Potentially slowest check last if (log.trace != null) { - for (int i = 1; i < log.trace.stackFrames.Length; i++) + for (int i = 1; i < log.trace.StackFrames.Length; i++) { - DebugStackFrame frame = log.trace.stackFrames[i]; - DebugStackFrame frame2 = stackTrace.stackFrames[i]; + DebugStackFrame frame = log.trace.StackFrames[i]; + DebugStackFrame frame2 = stackTrace.StackFrames[i]; - if (frame.line != frame2.line && frame.column != frame2.column) + if (frame.Line != frame2.Line && frame.Column != frame2.Column) return false; - if (frame.fileName != frame2.fileName) + if (frame.FileName != frame2.FileName) return false; } } @@ -242,7 +242,7 @@ private void DrawMessage(LogMessage message, int index) textRect.x += 7.5; - bool hasTrace = message.trace != null && message.trace.stackFrames.Length > 0; + bool hasTrace = message.trace != null && message.trace.StackFrames.Length > 0; Vector2 textPos = textRect.Position; textPos.y += (rect.height / 2) - (7.5 + (hasTrace ? 5 : 0)); @@ -271,7 +271,7 @@ private void DrawMessage(LogMessage message, int index) { textPos.y += 15; - DebugStackFrame frame = message.trace!.stackFrames[0]; + DebugStackFrame frame = message.trace!.StackFrames[0]; string frameText = frame.ToString(); @@ -311,11 +311,11 @@ private bool DrawExpandedMessage(LogMessage message) gui.Draw2D.DrawText(Font.DefaultFont, selMsg, 20, textPos, color); } - if (message.trace != null && message.trace.stackFrames.Length != 0) + if (message.trace != null && message.trace.StackFrames.Length != 0) { - for (int i = 0; i < message.trace.stackFrames.Length; i++) + for (int i = 0; i < message.trace.StackFrames.Length; i++) { - DebugStackFrame frame = message.trace.stackFrames[i]; + DebugStackFrame frame = message.trace.StackFrames[i]; string frameText = frame.ToString(); Vector2 frameSize = Font.DefaultFont.CalcTextSize(frameText, font_size: 21, 0); @@ -364,10 +364,10 @@ private bool DrawExpandedMessage(LogMessage message) private static void OpenStackFrame(DebugStackFrame frame) { - if (frame.fileName == null) + if (frame.FileName == null) return; - AssetDatabase.OpenPath(new FileInfo(frame.fileName), frame.line, frame.column); + AssetDatabase.OpenPath(new FileInfo(frame.FileName), frame.Line, frame.Column); } diff --git a/Prowl.Editor/Program.cs b/Prowl.Editor/Program.cs index 09de1051e..e2632fefa 100644 --- a/Prowl.Editor/Program.cs +++ b/Prowl.Editor/Program.cs @@ -54,7 +54,7 @@ private static int CreateCommand(CliCreateOptions options) private static int Run(CliOpenOptions options) { // set global Culture to invariant - Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Application.Initialize += () => { // Editor-specific initialization code @@ -122,7 +122,7 @@ private static int Run(CliOpenOptions options) else if (Hotkeys.IsHotkeyDown("SaveScene", new() { Key = Key.S, Ctrl = true })) EditorGuiManager.SaveScene(); - Application.isPlaying = PlayMode.Current == PlayMode.Mode.Playing; + Application.IsPlaying = PlayMode.Current == PlayMode.Mode.Playing; try { @@ -188,7 +188,7 @@ private static int BuildCommand(CliBuildOptions options) pathBuild.Create(); var builders = ProjectBuilder.GetAll().ToList(); Application.AssetProvider = new EditorAssetProvider(); - builders[0]?.StartBuild(BuildProjectSetting.Instance.Scenes, pathBuild); + builders[0].StartBuild(BuildProjectSetting.Instance.Scenes, pathBuild); return 0; } diff --git a/Prowl.Runtime/Debug.cs b/Prowl.Runtime/Debug.cs index 41b7fbf44..1c06da025 100644 --- a/Prowl.Runtime/Debug.cs +++ b/Prowl.Runtime/Debug.cs @@ -20,22 +20,21 @@ public enum LogSeverity Exception = 1 << 4 } + public delegate void OnLog(string message, DebugStackTrace? stackTrace, LogSeverity logSeverity); -/// -/// A single registry of Debug Stack, pointing to method, file and line -/// -/// -/// -/// -/// + public record DebugStackFrame(int Line, int Column, string? FileName = null, MethodBase? MethodBase = null) { - public override string ToString() => MethodBase != null - ? $"In {MethodBase.DeclaringType.Name}.{MethodBase.Name} at {FileName}:{Line}:{Column}" - : $"At {FileName}:{Line}:{Column}"; + public override string ToString() + { + return MethodBase != null + ? $"In {MethodBase.DeclaringType.Name}.{MethodBase.Name} at {FileName}:{Line}:{Column}" + : $"At {FileName}:{Line}:{Column}"; + } } + public record DebugStackTrace(params DebugStackFrame[] StackFrames) { public static explicit operator DebugStackTrace(StackTrace stackTrace) @@ -56,8 +55,8 @@ public override string ToString() { StringBuilder sb = new(); - foreach (var t in StackFrames) - sb.AppendLine($"\t{t}"); + foreach (var stackFrame in StackFrames) + sb.AppendLine($"\t{stackFrame}"); return sb.ToString(); } @@ -206,12 +205,12 @@ public static (Mesh? wire, Mesh? solid) GetGizmoDrawData(bool cameraRelative, Ve public class GizmoBuilder { - private struct MeshData + private readonly struct MeshData { - public List s_vertices = []; - public List s_uvs = []; - public List s_colors = []; - public List s_indices = []; + public readonly List Vertices = []; + public readonly List Uvs = []; + public readonly List Colors = []; + public readonly List Indices = []; public MeshData() { @@ -219,27 +218,27 @@ public MeshData() public readonly void Clear() { - s_vertices.Clear(); - s_uvs.Clear(); - s_colors.Clear(); - s_indices.Clear(); + Vertices.Clear(); + Uvs.Clear(); + Colors.Clear(); + Indices.Clear(); } } - private MeshData _wireData = new(); - private MeshData _solidData = new(); + private readonly MeshData _wireData = new(); + private readonly MeshData _solidData = new(); private Mesh? _wire; private Mesh? _solid; public struct IconDrawCall { - public Texture2D texture; - public Vector3 center; - public float scale; - public Color color; + public Texture2D Texture; + public Vector3 Center; + public float Scale; + public Color Color; } - private List _icons = []; + private readonly List _icons = []; public void Clear() @@ -255,36 +254,36 @@ public void Clear() private void AddLine(Vector3 a, Vector3 b, Color color) { - int index = _wireData.s_vertices.Count; - _wireData.s_vertices.Add(a); - _wireData.s_vertices.Add(b); + int index = _wireData.Vertices.Count; + _wireData.Vertices.Add(a); + _wireData.Vertices.Add(b); - _wireData.s_colors.Add(color); - _wireData.s_colors.Add(color); + _wireData.Colors.Add(color); + _wireData.Colors.Add(color); - _wireData.s_indices.Add(index); - _wireData.s_indices.Add(index + 1); + _wireData.Indices.Add(index); + _wireData.Indices.Add(index + 1); } - private void AddTriangle(Vector3 a, Vector3 b, Vector3 c, Vector2 a_uv, Vector2 b_uv, Vector2 c_uv, Color color) + private void AddTriangle(Vector3 a, Vector3 b, Vector3 c, Vector2 aUv, Vector2 bUv, Vector2 cUv, Color color) { - int index = _solidData.s_vertices.Count; + int index = _solidData.Vertices.Count; - _solidData.s_vertices.Add(a); - _solidData.s_vertices.Add(b); - _solidData.s_vertices.Add(c); + _solidData.Vertices.Add(a); + _solidData.Vertices.Add(b); + _solidData.Vertices.Add(c); - _solidData.s_uvs.Add(a_uv); - _solidData.s_uvs.Add(b_uv); - _solidData.s_uvs.Add(c_uv); + _solidData.Uvs.Add(aUv); + _solidData.Uvs.Add(bUv); + _solidData.Uvs.Add(cUv); - _solidData.s_colors.Add(color); - _solidData.s_colors.Add(color); - _solidData.s_colors.Add(color); + _solidData.Colors.Add(color); + _solidData.Colors.Add(color); + _solidData.Colors.Add(color); - _solidData.s_indices.Add(index); - _solidData.s_indices.Add(index + 1); - _solidData.s_indices.Add(index + 2); + _solidData.Indices.Add(index); + _solidData.Indices.Add(index + 1); + _solidData.Indices.Add(index + 2); } public void DrawLine(Vector3 start, Vector3 end, Color color) => AddLine(start, end, color); @@ -489,7 +488,7 @@ public void DrawWireCone(Vector3 start, Vector3 direction, float radius, Color c private Vector3 GetPerpendicularVector(Vector3 v) { - Vector3 result = Vector3.right; + Vector3 result; if (Math.Abs(v.x) > 0.1f) result = new Vector3(v.y, -v.x, 0); else if (Math.Abs(v.y) > 0.1f) @@ -509,7 +508,7 @@ public void DrawArrow(Vector3 start, Vector3 direction, Color color) } - public void DrawIcon(Texture2D icon, Vector3 center, float scale, Color color) => _icons.Add(new IconDrawCall { texture = icon, center = center, scale = scale, color = color }); + public void DrawIcon(Texture2D icon, Vector3 center, float scale, Color color) => _icons.Add(new IconDrawCall { Texture = icon, Center = center, Scale = scale, Color = color }); public void DrawText(Font font, string text, Vector3 position, Color color) // TODO: Try to share the same code from UI rendering to avoid duplicate Text rendering code { @@ -518,7 +517,7 @@ public void DrawText(Font font, string text, Vector3 position, Color color) // T public (Mesh? wire, Mesh? solid) UpdateMesh(bool cameraRelative, Vector3 cameraPosition) { - bool hasWire = _wireData.s_vertices.Count > 0; + bool hasWire = _wireData.Vertices.Count > 0; if (hasWire) { _wire ??= new() @@ -527,25 +526,25 @@ public void DrawText(Font font, string text, Vector3 position, Color color) // T IndexFormat = IndexFormat.UInt16, }; - _wire.Vertices = [.. _wireData.s_vertices]; - _wire.Colors = [.. _wireData.s_colors]; - _wire.Indices16 = _wireData.s_indices.Select(i => (ushort)i).ToArray(); + _wire.Vertices = [.. _wireData.Vertices]; + _wire.Colors = [.. _wireData.Colors]; + _wire.Indices16 = _wireData.Indices.Select(i => (ushort)i).ToArray(); if (cameraRelative) { // Convert vertices to be relative to the camera - System.Numerics.Vector3[] vertices = new System.Numerics.Vector3[_wireData.s_vertices.Count]; - for (int i = 0; i < _wireData.s_vertices.Count; i++) - vertices[i] = _wireData.s_vertices[i] - cameraPosition; + System.Numerics.Vector3[] vertices = new System.Numerics.Vector3[_wireData.Vertices.Count]; + for (int i = 0; i < _wireData.Vertices.Count; i++) + vertices[i] = _wireData.Vertices[i] - cameraPosition; _wire.Vertices = vertices; } else { - _wire.Vertices = [.. _wireData.s_vertices]; + _wire.Vertices = [.. _wireData.Vertices]; } } - bool hasSolid = _solidData.s_vertices.Count > 0; + bool hasSolid = _solidData.Vertices.Count > 0; if (hasSolid) { _solid ??= new() @@ -557,19 +556,19 @@ public void DrawText(Font font, string text, Vector3 position, Color color) // T if (cameraRelative) { // Convert vertices to be relative to the camera - System.Numerics.Vector3[] vertices2 = new System.Numerics.Vector3[_solidData.s_vertices.Count]; - for (int i = 0; i < _solidData.s_vertices.Count; i++) - vertices2[i] = _solidData.s_vertices[i] - cameraPosition; + System.Numerics.Vector3[] vertices2 = new System.Numerics.Vector3[_solidData.Vertices.Count]; + for (int i = 0; i < _solidData.Vertices.Count; i++) + vertices2[i] = _solidData.Vertices[i] - cameraPosition; _solid.Vertices = vertices2; } else { - _solid.Vertices = [.. _solidData.s_vertices]; + _solid.Vertices = [.. _solidData.Vertices]; } - _solid.Colors = [.. _solidData.s_colors]; - _solid.UV = [.. _solidData.s_uvs]; - _solid.Indices16 = _solidData.s_indices.Select(i => (ushort)i).ToArray(); + _solid.Colors = [.. _solidData.Colors]; + _solid.UV = [.. _solidData.Uvs]; + _solid.Indices16 = _solidData.Indices.Select(i => (ushort)i).ToArray(); } return ( @@ -577,7 +576,7 @@ public void DrawText(Font font, string text, Vector3 position, Color color) // T hasSolid ? _solid : null ); } - + public List GetIcons() { return _icons; diff --git a/Prowl.Runtime/Rendering/RenderPipeline/DefaultRenderPipeline.cs b/Prowl.Runtime/Rendering/RenderPipeline/DefaultRenderPipeline.cs index 2a7ede9b4..6ea7ecda0 100644 --- a/Prowl.Runtime/Rendering/RenderPipeline/DefaultRenderPipeline.cs +++ b/Prowl.Runtime/Rendering/RenderPipeline/DefaultRenderPipeline.cs @@ -173,13 +173,13 @@ public override void Render(Framebuffer target, Camera camera, in RenderingData foreach (GizmoBuilder.IconDrawCall icon in icons) { - Vector3 center = icon.center; + Vector3 center = icon.Center; if (cameraRelative) center -= cameraPosition; Matrix4x4 billboard = Matrix4x4.CreateBillboard(center, Vector3.zero, camera.Transform.up, camera.Transform.forward); buffer.SetMatrix("_Matrix_VP", (billboard * vp).ToFloat()); - buffer.SetTexture("_MainTexture", icon.texture); + buffer.SetTexture("_MainTexture", icon.Texture); buffer.DrawSingle(s_quadMesh); } From bd5b640af6c305c489099bee5ae0f89835941594 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 11:07:40 -0500 Subject: [PATCH 7/9] refactor: reimplementing stuff after the rebase from dev --- Prowl.Editor/Build/ProjectBuilder.cs | 2 ++ Prowl.Editor/Program.cs | 24 +++++++++++++++++----- Prowl.Runtime/Utils/ScriptableSingleton.cs | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Prowl.Editor/Build/ProjectBuilder.cs b/Prowl.Editor/Build/ProjectBuilder.cs index 9154db66e..6f20be4f3 100644 --- a/Prowl.Editor/Build/ProjectBuilder.cs +++ b/Prowl.Editor/Build/ProjectBuilder.cs @@ -3,6 +3,7 @@ using System.Reflection; +using Prowl.Editor.Assets; using Prowl.Editor.Utilities; using Prowl.Runtime; @@ -18,6 +19,7 @@ public void StartBuild(AssetRef[] scenes, DirectoryInfo output) return; } + AssetDatabase.Update(); if (!AreScenesValid(scenes)) return; diff --git a/Prowl.Editor/Program.cs b/Prowl.Editor/Program.cs index e2632fefa..faa764ac4 100644 --- a/Prowl.Editor/Program.cs +++ b/Prowl.Editor/Program.cs @@ -163,32 +163,46 @@ private static int Run(CliOpenOptions options) return 0; } + /// + /// Build the final version of the game via command line `prowl build --project PATH` + /// + /// Command Line options for build command + /// private static int BuildCommand(CliBuildOptions options) { - Console.WriteLine($"Building project from\t'{options.ProjectPath}'"); + Debug.Log($"Building project from\t'{options.ProjectPath}'"); if (options.ProjectPath is null || !options.ProjectPath.Exists) { - Console.WriteLine("Path is not valid or already exists"); + Debug.LogError("Path is not valid or already exists"); return 1; } var pathBuild = new DirectoryInfo(Path.Combine(options.ProjectPath.ToString(), "Builds", DateTime.UtcNow.ToString("yyyyMMddHHmmss"))); - Console.WriteLine($"Building path\t\t'{pathBuild}'"); + Debug.Log($"Building output path\t'{pathBuild}'"); if (pathBuild.Exists) { - Console.WriteLine("Build path is not valid or already exists"); + Debug.LogError("Build path is not valid or already exists"); return 1; } + // Open the project, and if it's ok, load it var project = new Project(options.ProjectPath); Project.Open(project); + + // Set up the app Application.DataPath = options.ProjectPath.ToString(); + Application.AssetProvider = new EditorAssetProvider(); + + AssetDatabase.Update(); + + // TODO: instead calling the builders[0], use a command line argument pathBuild.Create(); var builders = ProjectBuilder.GetAll().ToList(); - Application.AssetProvider = new EditorAssetProvider(); builders[0].StartBuild(BuildProjectSetting.Instance.Scenes, pathBuild); + + // TODO: since StartBuild return void, we cannot say if the code executed fine return 0; } diff --git a/Prowl.Runtime/Utils/ScriptableSingleton.cs b/Prowl.Runtime/Utils/ScriptableSingleton.cs index 461f28998..e7a849691 100644 --- a/Prowl.Runtime/Utils/ScriptableSingleton.cs +++ b/Prowl.Runtime/Utils/ScriptableSingleton.cs @@ -72,7 +72,7 @@ protected string GetFilePath(string? dataPath) ArgumentNullException.ThrowIfNull(dataPath); // Persistent across sessions for a single project - if (Application.IsEditor == false) + if (Application.IsRunning && Application.IsEditor == false) throw new InvalidOperationException("Editor Settings are only available in the editor"); directory = Path.Combine(dataPath, "ProjectSettings", "Editor"); break; From 6d8bd02c59cd3fdea11cd40389756c52a874a4e2 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 11:49:52 -0500 Subject: [PATCH 8/9] fix: revert from dev --- Prowl.Editor/Build/Desktop_Player.cs | 247 +++++++++++++-------------- 1 file changed, 123 insertions(+), 124 deletions(-) diff --git a/Prowl.Editor/Build/Desktop_Player.cs b/Prowl.Editor/Build/Desktop_Player.cs index b3c1526ed..fbe70a9bd 100644 --- a/Prowl.Editor/Build/Desktop_Player.cs +++ b/Prowl.Editor/Build/Desktop_Player.cs @@ -7,153 +7,152 @@ using Prowl.Runtime; using Prowl.Runtime.Utils; -namespace Prowl.Editor.Build +namespace Prowl.Editor.Build; + +public class Desktop_Player : ProjectBuilder { - public class Desktop_Player : ProjectBuilder + public enum Target { - public enum Target - { - [Text("Win x64")] win_x64, - [Text("Win ARM x64")] win_arm64, - [Text("Win x86")] win_x86, + [Text("Win x64")] win_x64, + [Text("Win ARM x64")] win_arm64, + [Text("Win x86")] win_x86, - [Text("Linux x64")] linux_x64, - [Text("Linux x86")] linux_x86, + [Text("Linux x64")] linux_x64, + [Text("Linux x86")] linux_x86, - [Text("OSX")] osx, - [Text("OSX x64")] osx_x64, - [Text("OSX ARM x64")] osx_arm64, + [Text("OSX")] osx, + [Text("OSX x64")] osx_x64, + [Text("OSX ARM x64")] osx_arm64, - Universal - } - public Target target = Target.win_x64; + Universal + } + public Target target = Target.win_x64; - public enum Configuration + public enum Configuration + { + Debug, + Release + } + public Configuration configuration = Configuration.Release; + + public enum AssetPacking + { + [Text("All Assets")] All, + [Text("Used Assets")] Used + } + public AssetPacking assetPacking = AssetPacking.Used; + + + protected override void Build(AssetRef[] scenes, DirectoryInfo output) + { + output.Create(); + string BuildDataPath = Path.Combine(output.FullName, "GameData"); + Directory.CreateDirectory(BuildDataPath); + + + BoundedLog($"Compiling project assembly to {output.FullName}..."); + if (!Project.Compile(Project.Active.Assembly_Proj.FullName, output, configuration == Configuration.Release)) { - Debug, - Release + Debug.LogError($"Failed to compile Project assembly!"); + return; } - public Configuration configuration = Configuration.Release; - public enum AssetPacking + BoundedLog($"Exporting and Packing assets to {BuildDataPath}..."); + if (assetPacking == AssetPacking.All) { - [Text("All Assets")] All, - [Text("Used Assets")] Used + AssetDatabase.ExportAllBuildPackages(new DirectoryInfo(BuildDataPath)); } - public AssetPacking assetPacking = AssetPacking.Used; + else + { + HashSet assets = []; + foreach (var scene in scenes) + AssetDatabase.GetDependenciesDeep(scene.AssetID, ref assets); + // Include all Shaders in the build for the time being + foreach (var shader in AssetDatabase.GetAllAssetsOfType()) + assets.Add(shader.Item2); - protected override void Build(AssetRef[] scenes, DirectoryInfo output) + AssetDatabase.ExportBuildPackages(assets.ToArray(), new DirectoryInfo(BuildDataPath)); + } + + + BoundedLog($"Packing scenes..."); + for (int i = 0; i < scenes.Length; i++) { - output.Create(); - string BuildDataPath = Path.Combine(output.FullName, "GameData"); - Directory.CreateDirectory(BuildDataPath); - - - Project.BoundedLog($"Compiling project assembly to {output.FullName}..."); - if (!Project.Compile(Project.Active.Assembly_Proj.FullName, output, configuration == Configuration.Release)) - { - Debug.LogError($"Failed to compile Project assembly!"); - return; - } - - Project.BoundedLog($"Exporting and Packing assets to {BuildDataPath}..."); - if (assetPacking == AssetPacking.All) - { - AssetDatabase.ExportAllBuildPackages(new DirectoryInfo(BuildDataPath)); - } - else - { - HashSet assets = []; - foreach (var scene in scenes) - AssetDatabase.GetDependenciesDeep(scene.AssetID, ref assets); - - // Include all Shaders in the build for the time being - foreach (var shader in AssetDatabase.GetAllAssetsOfType()) - assets.Add(shader.Item2); - - AssetDatabase.ExportBuildPackages(assets.ToArray(), new DirectoryInfo(BuildDataPath)); - } - - - Project.BoundedLog($"Packing scenes..."); - for (int i = 0; i < scenes.Length; i++) - { - Project.BoundedLog($"Packing scene_{i}.prowl..."); - var scene = scenes[i]; - SerializedProperty tag = Serializer.Serialize(scene.Res!); - BinaryTagConverter.WriteToFile(tag, new FileInfo(Path.Combine(BuildDataPath, $"scene_{i}.prowl"))); - } - - - Project.BoundedLog($"Preparing project settings..."); - // Find all ScriptableSingletons with the specified location - foreach (var type in RuntimeUtils.GetTypesWithAttribute()) - if (Attribute.GetCustomAttribute(type, typeof(FilePathAttribute)) is FilePathAttribute attribute) - if (attribute.FileLocation == FilePathAttribute.Location.Setting) + BoundedLog($"Packing scene_{i}.prowl..."); + var scene = scenes[i]; + SerializedProperty tag = Serializer.Serialize(scene.Res!); + BinaryTagConverter.WriteToFile(tag, new FileInfo(Path.Combine(BuildDataPath, $"scene_{i}.prowl"))); + } + + + BoundedLog($"Preparing project settings..."); + // Find all ScriptableSingletons with the specified location + foreach (var type in RuntimeUtils.GetTypesWithAttribute()) + if (Attribute.GetCustomAttribute(type, typeof(FilePathAttribute)) is FilePathAttribute attribute) + if (attribute.FileLocation == FilePathAttribute.Location.Setting) + { + // Use Reflection to find the CopyTo method + MethodInfo copyTo = type.BaseType.GetMethod("CopyTo", BindingFlags.Static | BindingFlags.NonPublic); + if (copyTo is null) { - // Use Reflection to find the CopyTo method - MethodInfo copyTo = type.BaseType.GetMethod("CopyTo", BindingFlags.Static | BindingFlags.NonPublic); - if (copyTo is null) - { - Debug.LogError($"Failed to find CopyTo method for {type.Name}"); - continue; - } - - // Invoke the CopyTo method - string? test = BuildDataPath; - copyTo.Invoke(null, [test]); + Debug.LogError($"Failed to find CopyTo method for {type.Name}"); + continue; } + // Invoke the CopyTo method + string? test = BuildDataPath; + copyTo.Invoke(null, [test]); + } + - Project.BoundedLog($"Copying Desktop player to {output.FullName}..."); - // Our executable folder contains "Players\Desktop" which we need to copy over the contents - string playerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Players", "Desktop"); - if (!Directory.Exists(playerPath)) - { - Debug.LogError($"Failed to find Desktop player at {playerPath}"); - return; - } + BoundedLog($"Copying Desktop player to {output.FullName}..."); + // Our executable folder contains "Players\Desktop" which we need to copy over the contents + string playerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Players", "Desktop"); + if (!Directory.Exists(playerPath)) + { + Debug.LogError($"Failed to find Desktop player at {playerPath}"); + return; + } - // Copy the contents of the Desktop player to the output directory, Files and Directories - var allDirectories = Directory.GetDirectories(playerPath, "*", SearchOption.AllDirectories); - foreach (var directory in allDirectories) - Directory.CreateDirectory(directory.Replace(playerPath, output.FullName)); + // Copy the contents of the Desktop player to the output directory, Files and Directories + var allDirectories = Directory.GetDirectories(playerPath, "*", SearchOption.AllDirectories); + foreach (var directory in allDirectories) + Directory.CreateDirectory(directory.Replace(playerPath, output.FullName)); - var allFiles = Directory.GetFiles(playerPath, "*", SearchOption.AllDirectories); - foreach (var file in allFiles) - File.Copy(file, file.Replace(playerPath, output.FullName), true); + var allFiles = Directory.GetFiles(playerPath, "*", SearchOption.AllDirectories); + foreach (var file in allFiles) + File.Copy(file, file.Replace(playerPath, output.FullName), true); - // Strip files we dont need for our target - if (target != Target.Universal) - CleanupRuntimes(output); + // Strip files we dont need for our target + if (target != Target.Universal) + CleanupRuntimes(output); - Debug.Log("**********************************************************************************************************************"); - Debug.Log($"Successfully built project!"); + Debug.Log("**********************************************************************************************************************"); + Debug.Log($"Successfully built project!"); - // Open the Build folder - AssetDatabase.OpenPath(output); - } + // Open the Build folder + AssetDatabase.OpenPath(output); + } - private void CleanupRuntimes(DirectoryInfo output) - { - string runtimesPath = Path.Combine(output.FullName, "runtimes"); - if (!Directory.Exists(runtimesPath)) - return; - - // Remove all runtimes except the one we need - string targetRuntime = target.ToString().ToLower().Replace("_", "-"); - // Remove all but the target runtime - foreach (var runtime in Directory.GetDirectories(runtimesPath)) - if (!runtime.Contains(targetRuntime)) - Directory.Delete(runtime, true); - - // Copy all remaining files into the root output directory - foreach (var file in Directory.GetFiles(runtimesPath, "*", SearchOption.AllDirectories)) - File.Copy(file, Path.Combine(output.FullName, Path.GetFileName(file)), true); - - // Remove the runtimes folder - Directory.Delete(runtimesPath, true); - } + private void CleanupRuntimes(DirectoryInfo output) + { + string runtimesPath = Path.Combine(output.FullName, "runtimes"); + if (!Directory.Exists(runtimesPath)) + return; + + // Remove all runtimes except the one we need + string targetRuntime = target.ToString().ToLower().Replace("_", "-"); + // Remove all but the target runtime + foreach (var runtime in Directory.GetDirectories(runtimesPath)) + if (!runtime.Contains(targetRuntime)) + Directory.Delete(runtime, true); + + // Copy all remaining files into the root output directory + foreach (var file in Directory.GetFiles(runtimesPath, "*", SearchOption.AllDirectories)) + File.Copy(file, Path.Combine(output.FullName, Path.GetFileName(file)), true); + + // Remove the runtimes folder + Directory.Delete(runtimesPath, true); } } From 0c4a0d52179f88f82114a9940697f7d97620ca51 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Tue, 17 Sep 2024 11:51:57 -0500 Subject: [PATCH 9/9] fix: revert from dev --- .../Rendering/RenderPipeline/DefaultRenderPipeline.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Prowl.Runtime/Rendering/RenderPipeline/DefaultRenderPipeline.cs b/Prowl.Runtime/Rendering/RenderPipeline/DefaultRenderPipeline.cs index 6ea7ecda0..2a7ede9b4 100644 --- a/Prowl.Runtime/Rendering/RenderPipeline/DefaultRenderPipeline.cs +++ b/Prowl.Runtime/Rendering/RenderPipeline/DefaultRenderPipeline.cs @@ -173,13 +173,13 @@ public override void Render(Framebuffer target, Camera camera, in RenderingData foreach (GizmoBuilder.IconDrawCall icon in icons) { - Vector3 center = icon.Center; + Vector3 center = icon.center; if (cameraRelative) center -= cameraPosition; Matrix4x4 billboard = Matrix4x4.CreateBillboard(center, Vector3.zero, camera.Transform.up, camera.Transform.forward); buffer.SetMatrix("_Matrix_VP", (billboard * vp).ToFloat()); - buffer.SetTexture("_MainTexture", icon.Texture); + buffer.SetTexture("_MainTexture", icon.texture); buffer.DrawSingle(s_quadMesh); }