Skip to content

Commit

Permalink
Added ApplicationSpecification along with ability to set working dire…
Browse files Browse the repository at this point in the history
…ctory

- Set working directory for Sandbox to be Hazelnut (Sandbox should work out of the box now)
  • Loading branch information
TheCherno committed Jul 4, 2022
1 parent b14d9aa commit e3ae311
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
11 changes: 8 additions & 3 deletions Hazel/src/Hazel/Core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 10 additions & 3 deletions Hazel/src/Hazel/Core/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Window> m_Window;
ImGuiLayer* m_ImGuiLayer;
bool m_Running = true;
Expand Down
10 changes: 8 additions & 2 deletions Sandbox/src/SandboxApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}

0 comments on commit e3ae311

Please sign in to comment.