Skip to content

Commit

Permalink
compile time check of window type and input type (TheCherno#190)
Browse files Browse the repository at this point in the history
Adds Window::Create and Input::Create function into one place
  • Loading branch information
LewyIsChewy authored and LovelySanta committed Jan 12, 2020
1 parent 3531a50 commit 554fb3f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
21 changes: 21 additions & 0 deletions Hazel/src/Hazel/Core/Input.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "hzpch.h"
#include "Hazel/Core/Input.h"

#ifdef HZ_PLATFORM_WINDOWS
#include "Platform/Windows/WindowsInput.h"
#endif

namespace Hazel {

Scope<Input> Input::s_Instance = Input::Create();

Scope<Input> Input::Create()
{
#ifdef HZ_PLATFORM_WINDOWS
return CreateScope<WindowsInput>();
#else
HZ_CORE_ASSERT(false, "Unknown platform!");
return nullptr;
#endif
}
}
2 changes: 2 additions & 0 deletions Hazel/src/Hazel/Core/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Hazel {
inline static std::pair<float, float> GetMousePosition() { return s_Instance->GetMousePositionImpl(); }
inline static float GetMouseX() { return s_Instance->GetMouseXImpl(); }
inline static float GetMouseY() { return s_Instance->GetMouseYImpl(); }

static Scope<Input> Create();
protected:
virtual bool IsKeyPressedImpl(KeyCode key) = 0;

Expand Down
21 changes: 21 additions & 0 deletions Hazel/src/Hazel/Core/Window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "hzpch.h"
#include "Hazel/Core/Window.h"

#ifdef HZ_PLATFORM_WINDOWS
#include "Platform/Windows/WindowsWindow.h"
#endif

namespace Hazel
{

Scope<Window> Window::Create(const WindowProps& props)
{
#ifdef HZ_PLATFORM_WINDOWS
return CreateScope<WindowsWindow>(props);
#else
HZ_CORE_ASSERT(false, "Unknown platform!");
return nullptr;
#endif
}

}
2 changes: 0 additions & 2 deletions Hazel/src/Platform/Windows/WindowsInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

namespace Hazel {

Scope<Input> Input::s_Instance = CreateScope<WindowsInput>();

bool WindowsInput::IsKeyPressedImpl(KeyCode key)
{
auto window = static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow());
Expand Down
5 changes: 0 additions & 5 deletions Hazel/src/Platform/Windows/WindowsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ namespace Hazel {
HZ_CORE_ERROR("GLFW Error ({0}): {1}", error, description);
}

Scope<Window> Window::Create(const WindowProps& props)
{
return CreateScope<WindowsWindow>(props);
}

WindowsWindow::WindowsWindow(const WindowProps& props)
{
HZ_PROFILE_FUNCTION();
Expand Down

0 comments on commit 554fb3f

Please sign in to comment.