From e3ae3115d1162c26ff7b3294c0dd676396f0e3ad Mon Sep 17 00:00:00 2001 From: TheCherno Date: Mon, 4 Jul 2022 19:30:31 +1000 Subject: [PATCH] Added ApplicationSpecification along with ability to set working directory - Set working directory for Sandbox to be Hazelnut (Sandbox should work out of the box now) --- Hazel/src/Hazel/Core/Application.cpp | 11 ++++++++--- Hazel/src/Hazel/Core/Application.h | 13 ++++++++++--- Sandbox/src/SandboxApp.cpp | 10 ++++++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Hazel/src/Hazel/Core/Application.cpp b/Hazel/src/Hazel/Core/Application.cpp index 011144d19..008c58b16 100644 --- a/Hazel/src/Hazel/Core/Application.cpp +++ b/Hazel/src/Hazel/Core/Application.cpp @@ -12,14 +12,19 @@ namespace Hazel { Application* Application::s_Instance = nullptr; - Application::Application(const std::string& name, ApplicationCommandLineArgs args) - : m_CommandLineArgs(args) + Application::Application(const ApplicationSpecification& specification) + : m_Specification(specification) { HZ_PROFILE_FUNCTION(); HZ_CORE_ASSERT(!s_Instance, "Application already exists!"); s_Instance = this; - m_Window = Window::Create(WindowProps(name)); + + // Set working directory here + if (!m_Specification.WorkingDirectory.empty()) + std::filesystem::current_path(m_Specification.WorkingDirectory); + + m_Window = Window::Create(WindowProps(m_Specification.Name)); m_Window->SetEventCallback(HZ_BIND_EVENT_FN(Application::OnEvent)); Renderer::Init(); diff --git a/Hazel/src/Hazel/Core/Application.h b/Hazel/src/Hazel/Core/Application.h index 133a1f632..236b22da3 100644 --- a/Hazel/src/Hazel/Core/Application.h +++ b/Hazel/src/Hazel/Core/Application.h @@ -27,10 +27,17 @@ namespace Hazel { } }; + struct ApplicationSpecification + { + std::string Name = "Hazel Application"; + std::string WorkingDirectory; + ApplicationCommandLineArgs CommandLineArgs; + }; + class Application { public: - Application(const std::string& name = "Hazel App", ApplicationCommandLineArgs args = ApplicationCommandLineArgs()); + Application(const ApplicationSpecification& specification); virtual ~Application(); void OnEvent(Event& e); @@ -46,13 +53,13 @@ namespace Hazel { static Application& Get() { return *s_Instance; } - ApplicationCommandLineArgs GetCommandLineArgs() const { return m_CommandLineArgs; } + const ApplicationSpecification& GetSpecification() const { return m_Specification; } private: void Run(); bool OnWindowClose(WindowCloseEvent& e); bool OnWindowResize(WindowResizeEvent& e); private: - ApplicationCommandLineArgs m_CommandLineArgs; + ApplicationSpecification m_Specification; Scope m_Window; ImGuiLayer* m_ImGuiLayer; bool m_Running = true; diff --git a/Sandbox/src/SandboxApp.cpp b/Sandbox/src/SandboxApp.cpp index 6f105c011..ea0570ddd 100644 --- a/Sandbox/src/SandboxApp.cpp +++ b/Sandbox/src/SandboxApp.cpp @@ -7,7 +7,8 @@ class Sandbox : public Hazel::Application { public: - Sandbox(Hazel::ApplicationCommandLineArgs args) + Sandbox(const Hazel::ApplicationSpecification& specification) + : Hazel::Application(specification) { // PushLayer(new ExampleLayer()); PushLayer(new Sandbox2D()); @@ -20,5 +21,10 @@ class Sandbox : public Hazel::Application Hazel::Application* Hazel::CreateApplication(Hazel::ApplicationCommandLineArgs args) { - return new Sandbox(args); + ApplicationSpecification spec; + spec.Name = "Sandbox"; + spec.WorkingDirectory = "../Hazelnut"; + spec.CommandLineArgs = args; + + return new Sandbox(spec); }