diff --git a/TitanEngine/Engine.vcxproj b/TitanEngine/Engine.vcxproj index e870e40..e53f643 100644 --- a/TitanEngine/Engine.vcxproj +++ b/TitanEngine/Engine.vcxproj @@ -82,6 +82,8 @@ src;vendor\spdlog\include;vendor\GLFW\include;%(AdditionalIncludeDirectories) EditAndContinue Disabled + MultiThreadedDebug + /MD /MDd %(AdditionalOptions) stdcpp17 Level3 @@ -106,7 +108,8 @@ true false true - /MT %(AdditionalOptions) + MultiThreaded + /MD /MT %(AdditionalOptions) stdcpp17 Level3 @@ -132,6 +135,8 @@ true false true + MultiThreaded + /MD %(AdditionalOptions) stdcpp17 Level3 diff --git a/TitanEngine/src/Platform/Windows/WindowsWindow.cpp b/TitanEngine/src/Platform/Windows/WindowsWindow.cpp index 1ceb12e..ed52877 100644 --- a/TitanEngine/src/Platform/Windows/WindowsWindow.cpp +++ b/TitanEngine/src/Platform/Windows/WindowsWindow.cpp @@ -1,10 +1,17 @@ #include "tipch.h" #include "WindowsWindow.h" +#include +#include +#include namespace Titan { static bool s_GLFWInitialized = false; + static void GLFWErrorCallback(int error, const char* description) { + TITAN_CORE_ERROR("GLFWError ({0}):\n{1}", error, description); + } + Window* Window::Create(const WindowProps& props) { return new WindowsWindow(props); @@ -33,7 +40,7 @@ namespace Titan { // TODO: glfwTerminate on system shutdown int success = glfwInit(); TI_CORE_ASSERT(success, "Could not intialize GLFW!"); - + glfwSetErrorCallback(GLFWErrorCallback); s_GLFWInitialized = true; } @@ -41,6 +48,84 @@ namespace Titan { glfwMakeContextCurrent(m_Window); glfwSetWindowUserPointer(m_Window, &m_Data); SetVSync(true); + + //Set GLFW callbacks + glfwSetWindowSizeCallback(m_Window, [](GLFWwindow* window, int width, int height) + { + WindowData& data = *(WindowData*) glfwGetWindowUserPointer(window); + data.Width = width; + data.Height = height; + + WindowResizeEvent event(width, height); + data.EventCallback(event); + }); + + glfwSetWindowCloseCallback(m_Window, [](GLFWwindow* window) + { + WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); + WindowCloseEvent event; + data.EventCallback(event); + }); + + glfwSetKeyCallback(m_Window, [](GLFWwindow* window, int key, int scancode, int action, int modes) { + WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); + switch (action) + { + case GLFW_PRESS: + { + KeyPressedEvent event(key, 0); + data.EventCallback(event); + break; + } + case GLFW_RELEASE: + { + KeyReleasedEvent event(key); + data.EventCallback(event); + break; + } + case GLFW_REPEAT: + { + KeyPressedEvent event(key, 1); + data.EventCallback(event); + break; + } + } + }); + + glfwSetMouseButtonCallback(m_Window, [](GLFWwindow* window, int button, int action, int modes) + { + WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); + + switch (action) + { + case GLFW_PRESS: + { + MouseButtonPressedEvent event(button); + data.EventCallback(event); + break; + } + case GLFW_RELEASE: + { + MouseButtonReleasedEvent event(button); + data.EventCallback(event); + break; + } + } + }); + + glfwSetScrollCallback(m_Window, [](GLFWwindow* window, double xOffset, double yOffset) { + WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); + + MouseScrolledEvent event((float)xOffset, (float)yOffset); + data.EventCallback(event); + }); + + glfwSetCursorPosCallback(m_Window, [](GLFWwindow* window, double xPos, double yPos) { + WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); + + MouseMovedEvent event((float)xPos, (float)yPos); + data.EventCallback(event); + }); } void WindowsWindow::Shutdown() diff --git a/TitanEngine/src/Titan/Application.cpp b/TitanEngine/src/Titan/Application.cpp index 2f28bd2..96df680 100644 --- a/TitanEngine/src/Titan/Application.cpp +++ b/TitanEngine/src/Titan/Application.cpp @@ -9,9 +9,12 @@ namespace Titan { +#define BIND_EVENT_FN(x) std::bind(&x, this, std::placeholders::_1) + Application::Application() { m_Window = std::unique_ptr(Window::Create()); + m_Window->SetEventCallback(BIND_EVENT_FN(Application::OnEvent)); } Application::~Application() @@ -22,10 +25,24 @@ namespace Titan { { while (m_Running) { - glClearColor(1, 0, 1, 1); + glClearColor(0, 0, 1, 1); glClear(GL_COLOR_BUFFER_BIT); m_Window->OnUpdate(); } } + void Application::OnEvent(Event& e) + { + EventDispatcher dispatcher(e); + dispatcher.Dispatch(BIND_EVENT_FN(Application::OnWindowClosed)); + + TITAN_CORE_TRACE("{0}", e.ToString()); + } + + bool Application::OnWindowClosed(WindowCloseEvent& e) + { + m_Running = false; + return true; + } + } diff --git a/TitanEngine/src/Titan/Application.h b/TitanEngine/src/Titan/Application.h index 642fd47..682512d 100644 --- a/TitanEngine/src/Titan/Application.h +++ b/TitanEngine/src/Titan/Application.h @@ -3,6 +3,7 @@ #include "Core.h" #include "Titan/Log.h" #include "Window.h" +#include "Events/ApplicationEvent.h" namespace Titan { @@ -13,7 +14,11 @@ namespace Titan { virtual ~Application(); void Run(); + + void OnEvent(Event& e); private: + bool OnWindowClosed(WindowCloseEvent& e); + std::unique_ptr m_Window; bool m_Running = true; }; diff --git a/bin/Debug-windows-x86_64/Engine/Engine.dll b/bin/Debug-windows-x86_64/Engine/Engine.dll index 9e6c540..e3199b0 100644 Binary files a/bin/Debug-windows-x86_64/Engine/Engine.dll and b/bin/Debug-windows-x86_64/Engine/Engine.dll differ diff --git a/bin/Debug-windows-x86_64/Engine/Engine.exp b/bin/Debug-windows-x86_64/Engine/Engine.exp index 212de71..a8510e5 100644 Binary files a/bin/Debug-windows-x86_64/Engine/Engine.exp and b/bin/Debug-windows-x86_64/Engine/Engine.exp differ diff --git a/bin/Debug-windows-x86_64/Engine/Engine.lib b/bin/Debug-windows-x86_64/Engine/Engine.lib index 7c79404..acccd56 100644 Binary files a/bin/Debug-windows-x86_64/Engine/Engine.lib and b/bin/Debug-windows-x86_64/Engine/Engine.lib differ diff --git a/bin/Debug-windows-x86_64/Engine/Engine.pdb b/bin/Debug-windows-x86_64/Engine/Engine.pdb index ada6f1b..b84e8f4 100644 Binary files a/bin/Debug-windows-x86_64/Engine/Engine.pdb and b/bin/Debug-windows-x86_64/Engine/Engine.pdb differ diff --git a/bin/Debug-windows-x86_64/Sandbox/Engine.dll b/bin/Debug-windows-x86_64/Sandbox/Engine.dll index 9e6c540..e3199b0 100644 Binary files a/bin/Debug-windows-x86_64/Sandbox/Engine.dll and b/bin/Debug-windows-x86_64/Sandbox/Engine.dll differ diff --git a/bin/Debug-windows-x86_64/Sandbox/Sandbox.exe b/bin/Debug-windows-x86_64/Sandbox/Sandbox.exe index 4368fb3..ee3d5b1 100644 Binary files a/bin/Debug-windows-x86_64/Sandbox/Sandbox.exe and b/bin/Debug-windows-x86_64/Sandbox/Sandbox.exe differ diff --git a/bin/Debug-windows-x86_64/Sandbox/Sandbox.pdb b/bin/Debug-windows-x86_64/Sandbox/Sandbox.pdb index 93a297d..c5d014c 100644 Binary files a/bin/Debug-windows-x86_64/Sandbox/Sandbox.pdb and b/bin/Debug-windows-x86_64/Sandbox/Sandbox.pdb differ diff --git a/premake5.lua b/premake5.lua index 6fcb200..8a9ab33 100644 --- a/premake5.lua +++ b/premake5.lua @@ -49,8 +49,7 @@ project "Engine" "opengl32.lib" } - staticruntime "on" - runtime "Release" + buildoptions "/MD" filter "system:windows" cppdialect "C++17" @@ -70,8 +69,7 @@ project "Engine" filter "configurations:Debug" defines "TI_DEBUG" symbols "On" - staticruntime "on" - runtime "Debug" + buildoptions "/MDd" filter "configurations:Release" defines "TI_RELEASE"