diff options
| author | hachem <im@hachem.wtf> | 2026-08-20 02:27:02 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-20 02:40:07 +0200 |
| commit | 5b361d81dbd2af0d0e99b9eb1adebea76ff05db0 (patch) | |
| tree | 34db1df17e8c7248aeeb92156d635d31c2484e3f /src/Core | |
| parent | e3abaaf59777258ba06705135a0cafcb5918ad12 (diff) | |
[chore]: MASSIVE refactor + more vulkan bs
Diffstat (limited to 'src/Core')
| -rw-r--r-- | src/Core/Application.cpp | 216 | ||||
| -rw-r--r-- | src/Core/Application.h | 66 | ||||
| -rw-r--r-- | src/Core/Camera.cpp | 214 | ||||
| -rw-r--r-- | src/Core/Camera.h | 193 | ||||
| -rw-r--r-- | src/Core/Event.h | 206 | ||||
| -rw-r--r-- | src/Core/HDRIManager.cpp | 64 | ||||
| -rw-r--r-- | src/Core/HDRIManager.h | 47 | ||||
| -rw-r--r-- | src/Core/Log.cpp | 154 | ||||
| -rw-r--r-- | src/Core/Log.h | 147 | ||||
| -rw-r--r-- | src/Core/Memory.h | 16 | ||||
| -rw-r--r-- | src/Core/SettingsManager.cpp | 200 | ||||
| -rw-r--r-- | src/Core/SettingsManager.h | 80 | ||||
| -rw-r--r-- | src/Core/State.h | 18 | ||||
| -rw-r--r-- | src/Core/StateManager.cpp | 88 | ||||
| -rw-r--r-- | src/Core/StateManager.h | 40 | ||||
| -rw-r--r-- | src/Core/ThemeManager.cpp | 291 | ||||
| -rw-r--r-- | src/Core/ThemeManager.h | 27 | ||||
| -rw-r--r-- | src/Core/Window.cpp | 220 | ||||
| -rw-r--r-- | src/Core/Window.h | 94 |
19 files changed, 775 insertions, 1606 deletions
diff --git a/src/Core/Application.cpp b/src/Core/Application.cpp index c73dc6d..667fc73 100644 --- a/src/Core/Application.cpp +++ b/src/Core/Application.cpp @@ -1,87 +1,87 @@ -#include "Application.h" +#include "application.h" -#include "Rendering/Renderer.h" -#include "SettingsManager.h" +#include "rendering/renderer.h" +#include "settings_manager.h" -#include "States/SimulationState.h" -#include "States/ConfigState.h" -#include "States/WorldBuilderState.h" +#include "states/simulation_state.h" +#include "states/config_state.h" +#include "states/world_builder_state.h" #include <GLFW/glfw3.h> #include <imgui.h> #include <ImGuizmo.h> -#include "Platform/Vulkan/VulkanRenderer.h" +#include "platform/vulkan/vulkan_renderer.h" #ifdef __APPLE__ -#include "Platform/Metal/MetalContext.h" -#include "Platform/Vulkan/VulkanContext.h" +#include "platform/metal/metal_context.h" +#include "platform/vulkan/vulkan_context.h" #endif namespace Donut { - Application* Application::s_Instance = nullptr; + Application* Application::s_instance = nullptr; Application::Application(const std::string& name, int width, int height) - : m_Running(true), m_Minimized(false) + : m_running(true), m_minimized(false) { - s_Instance = this; + s_instance = this; // Select the render API before the window is created: the window is // built differently for Vulkan (GLFW_NO_API) than for OpenGL. - Logger::Init(); - SettingsManager::Initialize(); + Logger::init(); + SettingsManager::initialize(); { - const auto& settings = SettingsManager::GetSettingsConst(); - RendererAPI::SetAPI(settings.graphics.renderAPI == "Vulkan" + const auto& settings = SettingsManager::get_settings_const(); + RendererAPI::set_api(settings.graphics.render_api == "Vulkan" ? RendererAPI::API::Vulkan : RendererAPI::API::OpenGL); } - if (RendererAPI::GetAPI() == RendererAPI::API::Vulkan) - VulkanPrepareGLFW(); // must precede glfwInit() inside the Window ctor + if (RendererAPI::get_api() == RendererAPI::API::Vulkan) + vulkan_prepare_glfw(); // must precede glfwInit() inside the Window ctor - m_Window = CreateScope<Window>(name, width, height); - m_Window->SetEventCallback([this](Event& event) + m_window = create_scope<Window>(name, width, height); + m_window->set_event_callback([this](Event& event) { - OnEvent(event); + on_event(event); }); - OnInit(); + on_init(); } Application::~Application() { - OnShutdown(); - s_Instance = nullptr; + on_shutdown(); + s_instance = nullptr; } - void Application::Run() + auto Application::run() -> void { - while (m_Running) + while (m_running) { - if (m_VulkanRenderer) + if (m_vulkan_renderer) { glfwPollEvents(); // before the ImGui frame so input is current - if (!m_Minimized) - m_VulkanRenderer->DrawFrame(glm::vec4(0.05f, 0.06f, 0.10f, 1.0f), - [this] { BuildVulkanUI(); }); + if (!m_minimized) + m_vulkan_renderer->draw_frame(glm::vec4(0.05f, 0.06f, 0.10f, 1.0f), + [this] { build_vulkan_ui(); }); } else { - if (!m_Minimized) + if (!m_minimized) { - OnUpdate(); - OnRender(); + on_update(); + on_render(); } - m_Window->OnUpdate(); // polls events + swaps buffers (OpenGL) + m_window->on_update(); // polls events + swaps buffers (OpenGL) } } } - void Application::BuildVulkanUI() + auto Application::build_vulkan_ui() -> void { // Placeholder UI proving the ImGui Vulkan backend renders. The real - // application UI (states' OnImUIRender) moves here once the scene is + // application UI (states' on_im_ui_render) moves here once the scene is // ported to Vulkan (B-3). ImGui::Begin("Donut - Vulkan backend"); ImGui::Text("Geodesic black hole through Vulkan (MoltenVK)."); @@ -92,145 +92,145 @@ namespace Donut ImGui::End(); } - void Application::Close() + auto Application::close() -> void { - m_Running = false; + m_running = false; } - void Application::OnEvent(Event& event) + auto Application::on_event(Event& event) -> void { EventDispatcher dispatcher(event); - dispatcher.Dispatch<WindowCloseEvent>([this, &event](WindowCloseEvent& e) + dispatcher.dispatch<WindowCloseEvent>([this, &event](WindowCloseEvent& e) { - m_Running = false; - event.Handled = true; + m_running = false; + event.handled = true; return true; }); - - dispatcher.Dispatch<WindowResizeEvent>([this, &event](WindowResizeEvent& e) + + dispatcher.dispatch<WindowResizeEvent>([this, &event](WindowResizeEvent& e) { - if (e.GetWidth() == 0 || e.GetHeight() == 0) - m_Minimized = true; + if (e.get_width() == 0 || e.get_height() == 0) + m_minimized = true; else - m_Minimized = false; + m_minimized = false; - if (m_VulkanRenderer) + if (m_vulkan_renderer) { - m_VulkanRenderer->OnResize(e.GetWidth(), e.GetHeight()); + m_vulkan_renderer->on_resize(e.get_width(), e.get_height()); } else { - Renderer::OnWindowResize(e.GetWidth(), e.GetHeight()); - if (m_Engine) m_Engine->SetWindowDimensions(e.GetWidth(), e.GetHeight()); + Renderer::on_window_resize(e.get_width(), e.get_height()); + if (m_engine) m_engine->set_window_dimensions(e.get_width(), e.get_height()); } - event.Handled = true; + event.handled = true; return true; }); - - dispatcher.Dispatch<KeyPressedEvent>([this, &event](KeyPressedEvent& e) + + dispatcher.dispatch<KeyPressedEvent>([this, &event](KeyPressedEvent& e) { - if (!m_StateManager) + if (!m_state_manager) return true; - if (e.GetKeyCode() == GLFW_KEY_1) + if (e.get_key_code() == GLFW_KEY_1) { - m_StateManager->SwitchToState("Config"); - event.Handled = true; + m_state_manager->switch_to_state("Config"); + event.handled = true; return true; } - else if (e.GetKeyCode() == GLFW_KEY_2) + else if (e.get_key_code() == GLFW_KEY_2) { - m_StateManager->SwitchToState("Simulation"); - event.Handled = true; + m_state_manager->switch_to_state("Simulation"); + event.handled = true; return true; } - else if (e.GetKeyCode() == GLFW_KEY_3) + else if (e.get_key_code() == GLFW_KEY_3) { - m_StateManager->SwitchToState("WorldBuilder"); - event.Handled = true; + m_state_manager->switch_to_state("WorldBuilder"); + event.handled = true; return true; } - + return true; }); - if (m_StateManager) - m_StateManager->OnEvent(event); + if (m_state_manager) + m_state_manager->on_event(event); } - void Application::OnInit() + auto Application::on_init() -> void { // (Logger, settings and API selection happen in the constructor.) - if (RendererAPI::GetAPI() == RendererAPI::API::Vulkan) + if (RendererAPI::get_api() == RendererAPI::API::Vulkan) { int w = 0, h = 0; - glfwGetFramebufferSize((GLFWwindow*)m_Window->GetNativeWindow(), &w, &h); - m_VulkanRenderer = CreateScope<VulkanRenderer>(); - if (!m_VulkanRenderer->Init(m_Window->GetNativeWindow(), w, h)) + glfwGetFramebufferSize((GLFWwindow*)m_window->get_native_window(), &w, &h); + m_vulkan_renderer = create_scope<VulkanRenderer>(); + if (!m_vulkan_renderer->init(m_window->get_native_window(), w, h)) DONUT_ERROR("Vulkan renderer initialization failed"); else - m_VulkanRenderer->InitImGui(); + m_vulkan_renderer->init_im_gui(); // Scene rendering hooks in here in the B-3 phase; the Vulkan path now // clears, presents, and draws the ImGui UI. return; } - Renderer::Init(); - m_Window->InitImGui(); + Renderer::init(); + m_window->init_im_gui(); - Renderer::OnWindowResize(1280, 720); - RenderCommand::SetFaceCulling(false); + Renderer::on_window_resize(1280, 720); + RenderCommand::set_face_culling(false); - m_Engine = CreateScope<Engine>(); - m_Engine->SetWindowDimensions(1280, 720); + m_engine = create_scope<Engine>(); + m_engine->set_window_dimensions(1280, 720); - m_StateManager = CreateScope<StateManager>(); - m_StateManager->RegisterState("Config", CreateScope<ConfigState>()); - m_StateManager->RegisterState("Simulation", CreateScope<SimulationState>()); - m_StateManager->RegisterState("WorldBuilder", CreateScope<WorldBuilderState>()); - m_StateManager->SwitchToState("Config"); + m_state_manager = create_scope<StateManager>(); + m_state_manager->register_state("Config", create_scope<ConfigState>()); + m_state_manager->register_state("Simulation", create_scope<SimulationState>()); + m_state_manager->register_state("WorldBuilder", create_scope<WorldBuilderState>()); + m_state_manager->switch_to_state("Config"); } - void Application::OnShutdown() + auto Application::on_shutdown() -> void { - if (m_VulkanRenderer) + if (m_vulkan_renderer) { - m_VulkanRenderer->Shutdown(); - m_VulkanRenderer.reset(); + m_vulkan_renderer->shutdown(); + m_vulkan_renderer.reset(); } else { - if (m_StateManager) - m_StateManager->Shutdown(); - Renderer::Shutdown(); + if (m_state_manager) + m_state_manager->shutdown(); + Renderer::shutdown(); } - SettingsManager::Shutdown(); - Logger::Shutdown(); + SettingsManager::shutdown(); + Logger::shutdown(); } - void Application::OnUpdate() + auto Application::on_update() -> void { - float currentFrame = (float)glfwGetTime(); - m_DeltaTime = currentFrame - m_LastFrame; - m_LastFrame = currentFrame; + float current_frame = (float)glfwGetTime(); + m_delta_time = current_frame - m_last_frame; + m_last_frame = current_frame; - m_StateManager->Update(m_DeltaTime); + m_state_manager->update(m_delta_time); } - void Application::OnRender() + auto Application::on_render() -> void { - m_StateManager->Render(); - m_Window->BeginImGuiFrame(); - + m_state_manager->render(); + m_window->begin_im_gui_frame(); + ImGuizmo::BeginFrame(); ImGuizmo::SetOrthographic(false); - - SetupDockingLayout(); - m_StateManager->OnImUIRender(); - m_Window->EndImGuiFrame(); + + setup_docking_layout(); + m_state_manager->on_im_ui_render(); + m_window->end_im_gui_frame(); } - - void Application::SetupDockingLayout() + + auto Application::setup_docking_layout() -> void { ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGui::DockSpaceOverViewport(0, viewport, ImGuiDockNodeFlags_PassthruCentralNode); diff --git a/src/Core/Application.h b/src/Core/Application.h index b715170..06c4e94 100644 --- a/src/Core/Application.h +++ b/src/Core/Application.h @@ -1,51 +1,53 @@ #pragma once -#include "StateManager.h" -#include "Memory.h" -#include "Window.h" -#include "Event.h" -#include "Log.h" +#include "state_manager.h" +#include "memory.h" +#include "window.h" +#include "event.h" +#include "log.h" -#include "Engine/Engine.h" +#include "engine/engine.h" namespace Donut { - class VulkanRenderer; // live-window Vulkan backend (Platform/Vulkan) + class VulkanRenderer; // live-window Vulkan backend (platform/vulkan) class Application { public: - Application(const std::string& name = "Donut", + Application(const std::string& name = "Donut", int width = 1280, int height = 720); ~Application(); - void Run(); - void Close(); + auto run() -> void; + auto close() -> void; + + auto get_window() -> Window& { return *m_window; } + auto get_state_manager() -> StateManager& { return *m_state_manager; } + auto get_engine() -> Engine& { return *m_engine; } + static auto get() -> Application& { return *s_instance; } - Window& GetWindow() { return *m_Window; } - StateManager& GetStateManager() { return *m_StateManager; } - Engine& GetEngine() { return *m_Engine; } - static Application& Get() { return *s_Instance; } private: - void OnInit(); - void OnShutdown(); - void OnUpdate(); - void OnRender(); - void OnEvent(Event& event); - void SetupDockingLayout(); - void BuildVulkanUI(); // ImGui UI built each frame on the Vulkan path + auto on_init() -> void; + auto on_shutdown() -> void; + auto on_update() -> void; + auto on_render() -> void; + auto on_event(Event& event) -> void; + auto setup_docking_layout() -> void; + auto build_vulkan_ui() -> void; // ImGui UI built each frame on the Vulkan path + private: - Scope<StateManager> m_StateManager; - Scope<Window> m_Window; - Scope<Engine> m_Engine; - Scope<VulkanRenderer> m_VulkanRenderer; // non-null only when the Vulkan API is selected + Scope<StateManager> m_state_manager; + Scope<Window> m_window; + Scope<Engine> m_engine; + Scope<VulkanRenderer> m_vulkan_renderer; // non-null only when the Vulkan API is selected + + bool m_running; + bool m_minimized; - bool m_Running; - bool m_Minimized; - - float m_DeltaTime = 0.0f; - float m_LastFrame = 0.0f; + float m_delta_time = 0.0f; + float m_last_frame = 0.0f; - static Application* s_Instance; + static Application* s_instance; }; -}
\ No newline at end of file +} diff --git a/src/Core/Camera.cpp b/src/Core/Camera.cpp index 028924e..35b7a2f 100644 --- a/src/Core/Camera.cpp +++ b/src/Core/Camera.cpp @@ -1,68 +1,68 @@ -#include "Camera.h" +#include "camera.h" #include <glm/gtc/quaternion.hpp> #include <GLFW/glfw3.h> namespace Donut { - Camera::Camera(float fov, float aspectRatio, float nearPlane, float farPlane) - : m_FOV(fov), m_AspectRatio(aspectRatio), m_NearPlane(nearPlane), m_FarPlane(farPlane) + Camera::Camera(float fov, float aspect_ratio, float near_plane, float far_plane) + : m_fov(fov), m_aspect_ratio(aspect_ratio), m_near_plane(near_plane), m_far_plane(far_plane) { - RecalculateProjectionMatrix(); - RecalculateViewMatrix(); + recalculate_projection_matrix(); + recalculate_view_matrix(); } - void Camera::SetProjection(float fov, float aspectRatio, float nearPlane, float farPlane) + auto Camera::set_projection(float fov, float aspect_ratio, float near_plane, float far_plane) -> void { - m_FOV = fov; - m_AspectRatio = aspectRatio; - m_NearPlane = nearPlane; - m_FarPlane = farPlane; - RecalculateProjectionMatrix(); + m_fov = fov; + m_aspect_ratio = aspect_ratio; + m_near_plane = near_plane; + m_far_plane = far_plane; + recalculate_projection_matrix(); } - void Camera::RecalculateProjectionMatrix() + auto Camera::recalculate_projection_matrix() -> void { - m_ProjectionMatrix = glm::perspective(glm::radians(m_FOV), m_AspectRatio, m_NearPlane, m_FarPlane); - m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix; + m_projection_matrix = glm::perspective(glm::radians(m_fov), m_aspect_ratio, m_near_plane, m_far_plane); + m_view_projection_matrix = m_projection_matrix * m_view_matrix; } - void Camera::RecalculateViewMatrix() + auto Camera::recalculate_view_matrix() -> void { - if (m_CameraMode == CameraMode::FPS) + if (m_camera_mode == CameraMode::FPS) { - float pitch = glm::radians(m_Rotation.x); - float yaw = glm::radians(m_Rotation.y); - float roll = glm::radians(m_Rotation.z); + float pitch = glm::radians(m_rotation.x); + float yaw = glm::radians(m_rotation.y); + float roll = glm::radians(m_rotation.z); glm::vec3 direction; direction.x = cos(yaw) * cos(pitch); direction.y = sin(pitch); direction.z = sin(yaw) * cos(pitch); - glm::vec3 worldUp(0.0f, 1.0f, 0.0f); + glm::vec3 world_up(0.0f, 1.0f, 0.0f); glm::vec3 front = glm::normalize(direction); - glm::vec3 right = glm::normalize(glm::cross(front, worldUp)); + glm::vec3 right = glm::normalize(glm::cross(front, world_up)); glm::vec3 up = glm::normalize(glm::cross(right, front)); - m_ViewMatrix = glm::lookAt(m_Position, m_Position + front, up); - m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix; + m_view_matrix = glm::lookAt(m_position, m_position + front, up); + m_view_projection_matrix = m_projection_matrix * m_view_matrix; } - else if (m_CameraMode == CameraMode::Orbital) + else if (m_camera_mode == CameraMode::Orbital) { - glm::vec3 position = GetOrbitalPosition(); - glm::vec3 target = m_OrbitalTarget; + glm::vec3 position = get_orbital_position(); + glm::vec3 target = m_orbital_target; glm::vec3 up(0.0f, 1.0f, 0.0f); - - m_ViewMatrix = glm::lookAt(position, target, up); - m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix; + + m_view_matrix = glm::lookAt(position, target, up); + m_view_projection_matrix = m_projection_matrix * m_view_matrix; } } - glm::vec3 Camera::GetForwardDirection() const + auto Camera::get_forward_direction() const -> glm::vec3 { - float pitch = glm::radians(m_Rotation.x); - float yaw = glm::radians(m_Rotation.y); + float pitch = glm::radians(m_rotation.x); + float yaw = glm::radians(m_rotation.y); glm::vec3 direction; direction.x = cos(yaw) * cos(pitch); @@ -72,154 +72,154 @@ namespace Donut return glm::normalize(direction); } - glm::vec3 Camera::GetRightDirection() const + auto Camera::get_right_direction() const -> glm::vec3 { - glm::vec3 worldUp(0.0f, 1.0f, 0.0f); - return glm::normalize(glm::cross(GetForwardDirection(), worldUp)); + glm::vec3 world_up(0.0f, 1.0f, 0.0f); + return glm::normalize(glm::cross(get_forward_direction(), world_up)); } - glm::vec3 Camera::GetUpDirection() const + auto Camera::get_up_direction() const -> glm::vec3 { - return glm::normalize(glm::cross(GetRightDirection(), GetForwardDirection())); + return glm::normalize(glm::cross(get_right_direction(), get_forward_direction())); } - void Camera::OnMouseMove(float xOffset, float yOffset, bool constrainPitch) + auto Camera::on_mouse_move(float x_offset, float y_offset, bool constrain_pitch) -> void { - if (m_CameraMode == CameraMode::FPS) + if (m_camera_mode == CameraMode::FPS) { - xOffset *= m_MouseSensitivity; - yOffset *= m_MouseSensitivity; + x_offset *= m_mouse_sensitivity; + y_offset *= m_mouse_sensitivity; - m_Rotation.y += xOffset; - m_Rotation.x += yOffset; + m_rotation.y += x_offset; + m_rotation.x += y_offset; - if (constrainPitch) + if (constrain_pitch) { - if (m_Rotation.x > 89.0f) - m_Rotation.x = 89.0f; - if (m_Rotation.x < -89.0f) - m_Rotation.x = -89.0f; + if (m_rotation.x > 89.0f) + m_rotation.x = 89.0f; + if (m_rotation.x < -89.0f) + m_rotation.x = -89.0f; } - RecalculateViewMatrix(); + recalculate_view_matrix(); } } - void Camera::MoveForward(float deltaTime) + auto Camera::move_forward(float delta_time) -> void { - if (m_CameraMode == CameraMode::FPS) + if (m_camera_mode == CameraMode::FPS) { - m_Position += GetForwardDirection() * m_MovementSpeed * deltaTime; - RecalculateViewMatrix(); + m_position += get_forward_direction() * m_movement_speed * delta_time; + recalculate_view_matrix(); } } - void Camera::MoveBackward(float deltaTime) + auto Camera::move_backward(float delta_time) -> void { - if (m_CameraMode == CameraMode::FPS) + if (m_camera_mode == CameraMode::FPS) { - m_Position -= GetForwardDirection() * m_MovementSpeed * deltaTime; - RecalculateViewMatrix(); + m_position -= get_forward_direction() * m_movement_speed * delta_time; + recalculate_view_matrix(); } } - void Camera::MoveRight(float deltaTime) + auto Camera::move_right(float delta_time) -> void { - if (m_CameraMode == CameraMode::FPS) + if (m_camera_mode == CameraMode::FPS) { - m_Position += GetRightDirection() * m_MovementSpeed * deltaTime; - RecalculateViewMatrix(); + m_position += get_right_direction() * m_movement_speed * delta_time; + recalculate_view_matrix(); } } - void Camera::MoveLeft(float deltaTime) + auto Camera::move_left(float delta_time) -> void { - if (m_CameraMode == CameraMode::FPS) + if (m_camera_mode == CameraMode::FPS) { - m_Position -= GetRightDirection() * m_MovementSpeed * deltaTime; - RecalculateViewMatrix(); + m_position -= get_right_direction() * m_movement_speed * delta_time; + recalculate_view_matrix(); } } - void Camera::MoveUp(float deltaTime) + auto Camera::move_up(float delta_time) -> void { - if (m_CameraMode == CameraMode::FPS) + if (m_camera_mode == CameraMode::FPS) { - glm::vec3 worldUp(0.0f, 1.0f, 0.0f); - m_Position += worldUp * m_MovementSpeed * deltaTime; - RecalculateViewMatrix(); + glm::vec3 world_up(0.0f, 1.0f, 0.0f); + m_position += world_up * m_movement_speed * delta_time; + recalculate_view_matrix(); } } - void Camera::MoveDown(float deltaTime) + auto Camera::move_down(float delta_time) -> void { - if (m_CameraMode == CameraMode::FPS) + if (m_camera_mode == CameraMode::FPS) { - glm::vec3 worldUp(0.0f, 1.0f, 0.0f); - m_Position -= worldUp * m_MovementSpeed * deltaTime; - RecalculateViewMatrix(); + glm::vec3 world_up(0.0f, 1.0f, 0.0f); + m_position -= world_up * m_movement_speed * delta_time; + recalculate_view_matrix(); } } - glm::vec3 Camera::GetOrbitalPosition() const + auto Camera::get_orbital_position() const -> glm::vec3 { - float clampedElevation = glm::clamp(m_Elevation, 0.01f, float(std::numbers::pi) - 0.01f); + float clamped_elevation = glm::clamp(m_elevation, 0.01f, float(std::numbers::pi) - 0.01f); return glm::vec3 ( - m_OrbitalRadius * sin(clampedElevation) * cos(m_Azimuth), - m_OrbitalRadius * cos(clampedElevation), - m_OrbitalRadius * sin(clampedElevation) * sin(m_Azimuth) + m_orbital_radius * sin(clamped_elevation) * cos(m_azimuth), + m_orbital_radius * cos(clamped_elevation), + m_orbital_radius * sin(clamped_elevation) * sin(m_azimuth) ); } - void Camera::UpdateOrbital() + auto Camera::update_orbital() -> void { - m_OrbitalTarget = glm::vec3(0.0f, 0.0f, 0.0f); - if (m_Dragging || m_Panning) - m_Moving = true; + m_orbital_target = glm::vec3(0.0f, 0.0f, 0.0f); + if (m_dragging || m_panning) + m_moving = true; else - m_Moving = false; - RecalculateViewMatrix(); + m_moving = false; + recalculate_view_matrix(); } - void Camera::ProcessOrbitalMouseMove(double x, double y) + auto Camera::process_orbital_mouse_move(double x, double y) -> void { - if (m_Dragging && !m_Panning) + if (m_dragging && !m_panning) { - float dx = float(x - m_LastX_Orbital); - float dy = float(y - m_LastY_Orbital); - - m_Azimuth += dx * m_OrbitalSpeed; - m_Elevation -= dy * m_OrbitalSpeed; - m_Elevation = glm::clamp(m_Elevation, 0.01f, float(std::numbers::pi) - 0.01f); + float dx = float(x - m_last_x_orbital); + float dy = float(y - m_last_y_orbital); + + m_azimuth += dx * m_orbital_speed; + m_elevation -= dy * m_orbital_speed; + m_elevation = glm::clamp(m_elevation, 0.01f, float(std::numbers::pi) - 0.01f); } - - m_LastX_Orbital = x; - m_LastY_Orbital = y; - UpdateOrbital(); + + m_last_x_orbital = x; + m_last_y_orbital = y; + update_orbital(); } - void Camera::ProcessOrbitalMouseButton(int button, int action, int mods) + auto Camera::process_orbital_mouse_button(int button, int action, int mods) -> void { if (button == GLFW_MOUSE_BUTTON_LEFT) { if (action == GLFW_PRESS) { - m_Dragging = true; - m_Panning = false; + m_dragging = true; + m_panning = false; } else if (action == GLFW_RELEASE) { - m_Dragging = false; - m_Panning = false; + m_dragging = false; + m_panning = false; } } } - void Camera::ProcessOrbitalScroll(double xoffset, double yoffset) + auto Camera::process_orbital_scroll(double x_offset, double y_offset) -> void { - m_OrbitalRadius -= yoffset * m_ZoomSpeed; - m_OrbitalRadius = glm::clamp(m_OrbitalRadius, m_OrbitalMinRadius, m_OrbitalMaxRadius); - UpdateOrbital(); + m_orbital_radius -= y_offset * m_zoom_speed; + m_orbital_radius = glm::clamp(m_orbital_radius, m_orbital_min_radius, m_orbital_max_radius); + update_orbital(); } } diff --git a/src/Core/Camera.h b/src/Core/Camera.h index a9aec2a..c997c35 100644 --- a/src/Core/Camera.h +++ b/src/Core/Camera.h @@ -16,115 +16,116 @@ namespace Donut class Camera { public: - Camera(float fov = 45.0f, float aspectRatio = 16.0f / 9.0f, - float nearPlane = 0.1f, float farPlane = 100.0f); + Camera(float fov = 45.0f, float aspect_ratio = 16.0f / 9.0f, + float near_plane = 0.1f, float far_plane = 100.0f); ~Camera() = default; - void SetPosition(const glm::vec3& position) { m_Position = position; RecalculateViewMatrix(); } - void SetRotation(const glm::vec3& rotation) { m_Rotation = rotation; RecalculateViewMatrix(); } - - const glm::vec3& GetPosition() const { return m_Position; } - const glm::vec3& GetRotation() const { return m_Rotation; } - - glm::vec3 GetForwardDirection() const; - glm::vec3 GetRightDirection() const; - glm::vec3 GetUpDirection() const; + auto set_position(const glm::vec3& position) -> void { m_position = position; recalculate_view_matrix(); } + auto set_rotation(const glm::vec3& rotation) -> void { m_rotation = rotation; recalculate_view_matrix(); } - const glm::mat4& GetProjectionMatrix() const { return m_ProjectionMatrix; } - const glm::mat4& GetViewMatrix() const { return m_ViewMatrix; } - const glm::mat4& GetViewProjectionMatrix() const { return m_ViewProjectionMatrix; } + auto get_position() const -> const glm::vec3& { return m_position; } + auto get_rotation() const -> const glm::vec3& { return m_rotation; } - void SetProjection(float fov, float aspectRatio, float nearPlane, float farPlane); - void OnMouseMove(float xOffset, float yOffset, bool constrainPitch = true); - - void MoveForward(float deltaTime); - void MoveBackward(float deltaTime); - void MoveRight(float deltaTime); - void MoveLeft(float deltaTime); - void MoveUp(float deltaTime); - void MoveDown(float deltaTime); + auto get_forward_direction() const -> glm::vec3; + auto get_right_direction() const -> glm::vec3; + auto get_up_direction() const -> glm::vec3; - void SetMouseSensitivity(float sensitivity) { m_MouseSensitivity = sensitivity; } - float GetMouseSensitivity() const { return m_MouseSensitivity; } + auto get_projection_matrix() const -> const glm::mat4& { return m_projection_matrix; } + auto get_view_matrix() const -> const glm::mat4& { return m_view_matrix; } + auto get_view_projection_matrix() const -> const glm::mat4& { return m_view_projection_matrix; } - void SetMovementSpeed(float speed) { m_MovementSpeed = speed; } - float GetMovementSpeed() const { return m_MovementSpeed; } + auto set_projection(float fov, float aspect_ratio, float near_plane, float far_plane) -> void; + auto on_mouse_move(float x_offset, float y_offset, bool constrain_pitch = true) -> void; - void SetOrbitalTarget(const glm::vec3& target) { m_OrbitalTarget = target; } - const glm::vec3& GetOrbitalTarget() const { return m_OrbitalTarget; } - - void SetOrbitalRadius(double radius) { m_OrbitalRadius = radius; } - double GetOrbitalRadius() const { return m_OrbitalRadius; } - - void SetOrbitalLimits(double minRadius, double maxRadius) - { - m_OrbitalMinRadius = minRadius; - m_OrbitalMaxRadius = maxRadius; + auto move_forward(float delta_time) -> void; + auto move_backward(float delta_time) -> void; + auto move_right(float delta_time) -> void; + auto move_left(float delta_time) -> void; + auto move_up(float delta_time) -> void; + auto move_down(float delta_time) -> void; + + auto set_mouse_sensitivity(float sensitivity) -> void { m_mouse_sensitivity = sensitivity; } + auto get_mouse_sensitivity() const -> float { return m_mouse_sensitivity; } + + auto set_movement_speed(float speed) -> void { m_movement_speed = speed; } + auto get_movement_speed() const -> float { return m_movement_speed; } + + auto set_orbital_target(const glm::vec3& target) -> void { m_orbital_target = target; } + auto get_orbital_target() const -> const glm::vec3& { return m_orbital_target; } + + auto set_orbital_radius(double radius) -> void { m_orbital_radius = radius; } + auto get_orbital_radius() const -> double { return m_orbital_radius; } + + auto set_orbital_limits(double min_radius, double max_radius) -> void + { + m_orbital_min_radius = min_radius; + m_orbital_max_radius = max_radius; } - - void SetOrbitalSpeed(float speed) { m_OrbitalSpeed = speed; } - float GetOrbitalSpeed() const { return m_OrbitalSpeed; } - - void SetZoomSpeed(double speed) { m_ZoomSpeed = speed; } - double GetZoomSpeed() const { return m_ZoomSpeed; } - - void SetAzimuth(float azimuth) { m_Azimuth = azimuth; } - float GetAzimuth() const { return m_Azimuth; } - - void SetElevation(float elevation) { m_Elevation = elevation; } - float GetElevation() const { return m_Elevation; } - - glm::vec3 GetOrbitalPosition() const; - void UpdateOrbital(); - void ProcessOrbitalMouseMove(double x, double y); - void ProcessOrbitalMouseButton(int button, int action, int mods); - void ProcessOrbitalScroll(double xoffset, double yoffset); - - void SetCameraMode(CameraMode mode) { m_CameraMode = mode; } - CameraMode GetCameraMode() const { return m_CameraMode; } - - bool IsDragging() const { return m_Dragging; } - bool IsPanning() const { return m_Panning; } - bool IsMoving() const { return m_Moving; } - double GetLastX() const { return m_LastX; } - double GetLastY() const { return m_LastY; } + + auto set_orbital_speed(float speed) -> void { m_orbital_speed = speed; } + auto get_orbital_speed() const -> float { return m_orbital_speed; } + + auto set_zoom_speed(double speed) -> void { m_zoom_speed = speed; } + auto get_zoom_speed() const -> double { return m_zoom_speed; } + + auto set_azimuth(float azimuth) -> void { m_azimuth = azimuth; } + auto get_azimuth() const -> float { return m_azimuth; } + + auto set_elevation(float elevation) -> void { m_elevation = elevation; } + auto get_elevation() const -> float { return m_elevation; } + + auto get_orbital_position() const -> glm::vec3; + auto update_orbital() -> void; + auto process_orbital_mouse_move(double x, double y) -> void; + auto process_orbital_mouse_button(int button, int action, int mods) -> void; + auto process_orbital_scroll(double x_offset, double y_offset) -> void; + + auto set_camera_mode(CameraMode mode) -> void { m_camera_mode = mode; } + auto get_camera_mode() const -> CameraMode { return m_camera_mode; } + + auto is_dragging() const -> bool { return m_dragging; } + auto is_panning() const -> bool { return m_panning; } + auto is_moving() const -> bool { return m_moving; } + auto get_last_x() const -> double { return m_last_x; } + auto get_last_y() const -> double { return m_last_y; } private: - void RecalculateViewMatrix(); - void RecalculateProjectionMatrix(); + auto recalculate_view_matrix() -> void; + auto recalculate_projection_matrix() -> void; + private: - CameraMode m_CameraMode = CameraMode::FPS; - - glm::mat4 m_ProjectionMatrix; - glm::mat4 m_ViewMatrix; - glm::mat4 m_ViewProjectionMatrix; + CameraMode m_camera_mode = CameraMode::FPS; + + glm::mat4 m_projection_matrix; + glm::mat4 m_view_matrix; + glm::mat4 m_view_projection_matrix; + + glm::vec3 m_position = { 0.0f, 0.0f, 3.0f }; + glm::vec3 m_rotation = { 0.0f, 0.0f, 0.0f }; - glm::vec3 m_Position = { 0.0f, 0.0f, 3.0f }; - glm::vec3 m_Rotation = { 0.0f, 0.0f, 0.0f }; + float m_fov = 45.0f; + float m_aspect_ratio = 16.0f / 9.0f; + float m_near_plane = 0.1f; + float m_far_plane = 100.0f; - float m_FOV = 45.0f; - float m_AspectRatio = 16.0f / 9.0f; - float m_NearPlane = 0.1f; - float m_FarPlane = 100.0f; + float m_mouse_sensitivity = 0.1f; + float m_movement_speed = 5.0f; + bool m_first_mouse = true; + float m_last_x = 0.0f; + float m_last_y = 0.0f; - float m_MouseSensitivity = 0.1f; - float m_MovementSpeed = 5.0f; - bool m_FirstMouse = true; - float m_LastX = 0.0f; - float m_LastY = 0.0f; - - glm::vec3 m_OrbitalTarget = glm::vec3(0.0f, 0.0f, 0.0f); - double m_OrbitalRadius = 6.34194e10; - double m_OrbitalMinRadius = 1e10; - double m_OrbitalMaxRadius = 1e12; - float m_Azimuth = 0.0f; - float m_Elevation = static_cast<float>(std::numbers::pi) / 2.0f; - float m_OrbitalSpeed = 0.01f; - double m_ZoomSpeed = 25e9f; - bool m_Dragging = false; - bool m_Panning = false; - bool m_Moving = false; - double m_LastX_Orbital = 0.0; - double m_LastY_Orbital = 0.0; + glm::vec3 m_orbital_target = glm::vec3(0.0f, 0.0f, 0.0f); + double m_orbital_radius = 6.34194e10; + double m_orbital_min_radius = 1e10; + double m_orbital_max_radius = 1e12; + float m_azimuth = 0.0f; + float m_elevation = static_cast<float>(std::numbers::pi) / 2.0f; + float m_orbital_speed = 0.01f; + double m_zoom_speed = 25e9f; + bool m_dragging = false; + bool m_panning = false; + bool m_moving = false; + double m_last_x_orbital = 0.0; + double m_last_y_orbital = 0.0; }; } diff --git a/src/Core/Event.h b/src/Core/Event.h index 23d92fd..1891206 100644 --- a/src/Core/Event.h +++ b/src/Core/Event.h @@ -46,63 +46,63 @@ namespace Donut public: virtual ~Event() = default; - bool Handled = false; + virtual auto get_event_type() const -> EventType = 0; + virtual auto get_name() const -> const char* = 0; + virtual auto get_category_flags() const -> int = 0; + virtual auto to_string() const -> std::string { return get_name(); } - virtual EventType GetEventType() const = 0; - virtual const char* GetName() const = 0; - virtual int GetCategoryFlags() const = 0; - virtual std::string ToString() const { return GetName(); } + auto is_in_category(EventCategory category) -> bool { return get_category_flags() & category; } - bool IsInCategory(EventCategory category) { return GetCategoryFlags() & category; } + bool handled = false; }; - #define EVENT_CLASS_TYPE(type) \ - static EventType GetStaticType() { return EventType::type; } \ - virtual EventType GetEventType() const override { return GetStaticType(); } \ - virtual const char* GetName() const override { return #type; } - + #define EVENT_CLASS_TYPE(type) \ + static auto get_static_type() -> EventType { return EventType::type; } \ + virtual auto get_event_type() const -> EventType override { return get_static_type(); } \ + virtual auto get_name() const -> const char* override { return #type; } + #define APPLICATION_EVENT_CLASS_TYPE(type) \ EVENT_CLASS_TYPE(type) \ - virtual int GetCategoryFlags() const override { return EventCategoryApplication; } - + virtual auto get_category_flags() const -> int override { return EventCategoryApplication; } + #define MOUSE_EVENT_CLASS_TYPE(type) \ EVENT_CLASS_TYPE(type) \ - virtual int GetCategoryFlags() const override { return EventCategoryMouse | \ - EventCategoryInput; } - + virtual auto get_category_flags() const -> int override { return EventCategoryMouse | \ + EventCategoryInput; } + #define MOUSE_BUTTON_EVENT_CLASS_TYPE(type) \ EVENT_CLASS_TYPE(type) \ - virtual int GetCategoryFlags() const override { return EventCategoryMouseButton | \ - EventCategoryMouse | \ - EventCategoryInput; } - + virtual auto get_category_flags() const -> int override { return EventCategoryMouseButton | \ + EventCategoryMouse | \ + EventCategoryInput; } + #define KEYBOARD_EVENT_CLASS_TYPE(type) \ EVENT_CLASS_TYPE(type) \ - virtual int GetCategoryFlags() const override { return EventCategoryKeyboard | \ - EventCategoryInput; } + virtual auto get_category_flags() const -> int override { return EventCategoryKeyboard | \ + EventCategoryInput; } class WindowResizeEvent : public Event { public: WindowResizeEvent(unsigned int width, unsigned int height) - : m_Width(width), m_Height(height) { } + : m_width(width), m_height(height) { } - unsigned int GetWidth() const { return m_Width; } - unsigned int GetHeight() const { return m_Height; } + auto get_width() const -> unsigned int { return m_width; } + auto get_height() const -> unsigned int { return m_height; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "WindowResizeEvent: " + std::to_string(m_Width) + ", " + std::to_string(m_Height); + return "WindowResizeEvent: " + std::to_string(m_width) + ", " + std::to_string(m_height); } APPLICATION_EVENT_CLASS_TYPE(WindowResize) private: - unsigned int m_Width, m_Height; + unsigned int m_width, m_height; }; - class WindowCloseEvent + class WindowCloseEvent : public Event { public: @@ -110,7 +110,7 @@ namespace Donut APPLICATION_EVENT_CLASS_TYPE(WindowClose) }; - class WindowFocusEvent + class WindowFocusEvent : public Event { public: @@ -118,7 +118,7 @@ namespace Donut APPLICATION_EVENT_CLASS_TYPE(WindowFocus) }; - class WindowLostFocusEvent + class WindowLostFocusEvent : public Event { public: @@ -126,175 +126,175 @@ namespace Donut APPLICATION_EVENT_CLASS_TYPE(WindowLostFocus) }; - class WindowMovedEvent + class WindowMovedEvent : public Event { public: WindowMovedEvent(int x, int y) - : m_X(x), m_Y(y) { } + : m_x(x), m_y(y) { } - int GetX() const { return m_X; } - int GetY() const { return m_Y; } + auto get_x() const -> int { return m_x; } + auto get_y() const -> int { return m_y; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "WindowMovedEvent: " + std::to_string(m_X) + ", " + std::to_string(m_Y); + return "WindowMovedEvent: " + std::to_string(m_x) + ", " + std::to_string(m_y); } APPLICATION_EVENT_CLASS_TYPE(WindowMoved) private: - int m_X, m_Y; + int m_x, m_y; }; - class KeyEvent + class KeyEvent : public Event { public: - int GetKeyCode() const { return m_KeyCode; } - virtual int GetCategoryFlags() const override { return EventCategoryKeyboard | - EventCategoryInput; } + auto get_key_code() const -> int { return m_key_code; } + virtual auto get_category_flags() const -> int override { return EventCategoryKeyboard | + EventCategoryInput; } protected: KeyEvent(int keycode) - : m_KeyCode(keycode) { } - int m_KeyCode; + : m_key_code(keycode) { } + int m_key_code; }; - class KeyPressedEvent + class KeyPressedEvent : public KeyEvent { public: - KeyPressedEvent(int keycode, bool isRepeat = false) - : KeyEvent(keycode), m_IsRepeat(isRepeat) { } + KeyPressedEvent(int keycode, bool is_repeat = false) + : KeyEvent(keycode), m_is_repeat(is_repeat) { } - bool IsRepeat() const { return m_IsRepeat; } + auto is_repeat() const -> bool { return m_is_repeat; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "KeyPressedEvent: " + std::to_string(m_KeyCode) + - " (repeat = " + std::to_string(m_IsRepeat) + ")"; + return "KeyPressedEvent: " + std::to_string(m_key_code) + + " (repeat = " + std::to_string(m_is_repeat) + ")"; } KEYBOARD_EVENT_CLASS_TYPE(KeyPressed) private: - bool m_IsRepeat; + bool m_is_repeat; }; - class KeyReleasedEvent + class KeyReleasedEvent : public KeyEvent { public: KeyReleasedEvent(int keycode) : KeyEvent(keycode) { } - std::string ToString() const override + auto to_string() const -> std::string override { - return "KeyReleasedEvent: " + std::to_string(m_KeyCode); + return "KeyReleasedEvent: " + std::to_string(m_key_code); } KEYBOARD_EVENT_CLASS_TYPE(KeyReleased) }; - class KeyTypedEvent + class KeyTypedEvent : public KeyEvent { public: KeyTypedEvent(int keycode) : KeyEvent(keycode) { } - std::string ToString() const override + auto to_string() const -> std::string override { - return "KeyTypedEvent: " + std::to_string(m_KeyCode); + return "KeyTypedEvent: " + std::to_string(m_key_code); } KEYBOARD_EVENT_CLASS_TYPE(KeyTyped) }; - class MouseMovedEvent + class MouseMovedEvent : public Event { public: MouseMovedEvent(float x, float y) - : m_MouseX(x), m_MouseY(y) { } + : m_mouse_x(x), m_mouse_y(y) { } - float GetX() const { return m_MouseX; } - float GetY() const { return m_MouseY; } + auto get_x() const -> float { return m_mouse_x; } + auto get_y() const -> float { return m_mouse_y; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "MouseMovedEvent: " + std::to_string(m_MouseX) + ", " + std::to_string(m_MouseY); + return "MouseMovedEvent: " + std::to_string(m_mouse_x) + ", " + std::to_string(m_mouse_y); } MOUSE_EVENT_CLASS_TYPE(MouseMoved) private: - float m_MouseX, m_MouseY; + float m_mouse_x, m_mouse_y; }; - class MouseScrolledEvent + class MouseScrolledEvent : public Event { public: - MouseScrolledEvent(float xOffset, float yOffset) - : m_XOffset(xOffset), m_YOffset(yOffset) { } + MouseScrolledEvent(float x_offset, float y_offset) + : m_x_offset(x_offset), m_y_offset(y_offset) { } - float GetXOffset() const { return m_XOffset; } - float GetYOffset() const { return m_YOffset; } + auto get_x_offset() const -> float { return m_x_offset; } + auto get_y_offset() const -> float { return m_y_offset; } - std::string ToString() const override + auto to_string() const -> std::string override { - return "MouseScrolledEvent: " + std::to_string(m_XOffset) + - ", " + std::to_string(m_YOffset); + return "MouseScrolledEvent: " + std::to_string(m_x_offset) + + ", " + std::to_string(m_y_offset); } MOUSE_EVENT_CLASS_TYPE(MouseScrolled) private: - float m_XOffset, m_YOffset; + float m_x_offset, m_y_offset; }; - class MouseButtonEvent + class MouseButtonEvent : public Event { public: - int GetMouseButton() const { return m_Button; } - virtual int GetCategoryFlags() const override { return EventCategoryMouseButton | - EventCategoryMouse | - EventCategoryInput; } + auto get_mouse_button() const -> int { return m_button; } + virtual auto get_category_flags() const -> int override { return EventCategoryMouseButton | + EventCategoryMouse | + EventCategoryInput; } protected: MouseButtonEvent(int button) - : m_Button(button) { } - int m_Button; + : m_button(button) { } + int m_button; }; - class MouseButtonPressedEvent + class MouseButtonPressedEvent : public MouseButtonEvent { public: MouseButtonPressedEvent(int button) : MouseButtonEvent(button) { } - std::string ToString() const override + auto to_string() const -> std::string override { - return "MouseButtonPressedEvent: " + std::to_string(m_Button); + return "MouseButtonPressedEvent: " + std::to_string(m_button); } MOUSE_BUTTON_EVENT_CLASS_TYPE(MouseButtonPressed) }; - class MouseButtonReleasedEvent + class MouseButtonReleasedEvent : public MouseButtonEvent { public: MouseButtonReleasedEvent(int button) : MouseButtonEvent(button) { } - std::string ToString() const override + auto to_string() const -> std::string override { - return "MouseButtonReleasedEvent: " + std::to_string(m_Button); + return "MouseButtonReleasedEvent: " + std::to_string(m_button); } MOUSE_BUTTON_EVENT_CLASS_TYPE(MouseButtonReleased) @@ -303,22 +303,22 @@ namespace Donut class EventDispatcher { public: - EventDispatcher(Event& event) - : m_Event(event) { } + EventDispatcher(Event& event) + : m_event(event) { } template<typename T, typename F> - bool Dispatch(const F& func) + auto dispatch(const F& func) -> bool { - if (m_Event.GetEventType() == T::GetStaticType()) + if (m_event.get_event_type() == T::get_static_type()) { - m_Event.Handled = func(static_cast<T&>(m_Event)); + m_event.handled = func(static_cast<T&>(m_event)); return true; } return false; } private: - Event& m_Event; + Event& m_event; }; class EventHandler @@ -329,29 +329,29 @@ namespace Donut EventHandler() = default; ~EventHandler() = default; - void SetEventCallback(const EventCallbackFn& callback) + auto set_event_callback(const EventCallbackFn& callback) -> void { - m_EventCallback = callback; + m_event_callback = callback; } - void OnEvent(Event& event) + auto on_event(Event& event) -> void { - if (m_EventCallback) - m_EventCallback(event); + if (m_event_callback) + m_event_callback(event); } template<typename T> - void BindEvent(const std::function<void(T&)>& callback) + auto bind_event(const std::function<void(T&)>& callback) -> void { - m_EventCallback = [callback](Event& event) + m_event_callback = [callback](Event& event) { - if (event.GetEventType() == T::GetStaticType()) + if (event.get_event_type() == T::get_static_type()) callback(static_cast<T&>(event)); }; } private: - EventCallbackFn m_EventCallback; + EventCallbackFn m_event_callback; }; #undef EVENT_CLASS_TYPE @@ -359,4 +359,4 @@ namespace Donut #undef MOUSE_EVENT_CLASS_TYPE #undef MOUSE_BUTTON_EVENT_CLASS_TYPE #undef KEYBOARD_EVENT_CLASS_TYPE -}
\ No newline at end of file +} diff --git a/src/Core/HDRIManager.cpp b/src/Core/HDRIManager.cpp deleted file mode 100644 index 6e420a6..0000000 --- a/src/Core/HDRIManager.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "HDRIManager.h" -#include <filesystem> - -namespace Donut -{ - Ref<CubemapTexture> HDRIManager::LoadHDRI(const std::string& path) - { - auto it = m_HDRICache.find(path); - if (it != m_HDRICache.end()) - { - DONUT_INFO("HDRI already cached: {}", path); - return it->second; - } - - DONUT_INFO("Loading HDRI: {}", path); - auto hdri = CubemapTexture::CreateFromHDRI(path); - - if (hdri) - { - m_HDRICache[path] = hdri; - DONUT_INFO("Successfully loaded and cached HDRI: {}", path); - } - else - DONUT_ERROR("Failed to load HDRI: {}", path); - - return hdri; - } - - void HDRIManager::SetCurrentHDRI(const std::string& path) - { - auto hdri = LoadHDRI(path); - if (hdri) - { - m_CurrentHDRI = hdri; - DONUT_INFO("Set current HDRI to: {}", path); - } - else - DONUT_ERROR("Failed to set current HDRI: {}", path); - } - - std::string HDRIManager::GetHDRIName(const std::string& path) const - { - std::filesystem::path filePath(path); - std::string filename = filePath.stem().string(); - std::string name = filename; - - for (size_t i = 0; i < name.length(); ++i) - { - if (name[i] == '_') - name[i] = ' '; - else if (i == 0 || name[i-1] == ' ') - name[i] = std::toupper(name[i]); - } - - return name; - } - - void HDRIManager::ClearCache() - { - m_HDRICache.clear(); - m_CurrentHDRI.reset(); - DONUT_INFO("HDRI cache cleared"); - } -}; diff --git a/src/Core/HDRIManager.h b/src/Core/HDRIManager.h deleted file mode 100644 index 3c1ff57..0000000 --- a/src/Core/HDRIManager.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "Core/Log.h" -#include "Rendering/Texture.h" - -#include <string> -#include <unordered_map> -#include <memory> - -namespace Donut -{ - class HDRIManager - { - public: - static HDRIManager& Get() - { - static HDRIManager instance; - return instance; - } - - Ref<CubemapTexture> LoadHDRI(const std::string& path); - Ref<CubemapTexture> GetCurrentHDRI() const { return m_CurrentHDRI; } - - void SetCurrentHDRI(const std::string& path); - const std::vector<std::string>& GetAvailableHDRI() const { return m_AvailableHDRI; } - std::string GetHDRIName(const std::string& path) const; - void ClearCache(); - private: - HDRIManager() = default; - ~HDRIManager() = default; - - HDRIManager(const HDRIManager&) = delete; - HDRIManager& operator=(const HDRIManager&) = delete; - - std::unordered_map<std::string, Ref<CubemapTexture>> m_HDRICache; - - Ref<CubemapTexture> m_CurrentHDRI; - - std::vector<std::string> m_AvailableHDRI = - { - "Assets/HDRI/HDR_blue_nebulae-1.hdr", - "Assets/HDRI/HDR_subdued_blue_nebulae.hdr", - "Assets/HDRI/HDR_subdued_multi_nebulae.hdr", - "Assets/HDRI/night_sky.hdr" - }; - }; -}; diff --git a/src/Core/Log.cpp b/src/Core/Log.cpp index f2f3e44..5a0434f 100644 --- a/src/Core/Log.cpp +++ b/src/Core/Log.cpp @@ -1,4 +1,4 @@ -#include "Log.h" +#include "log.h" #include <filesystem> @@ -6,148 +6,148 @@ #include <windows.h> #endif -namespace Donut +namespace Donut { - Ref<Logger> Logger::s_Logger; + Ref<Logger> Logger::s_logger; - void Logger::Init() + auto Logger::init() -> void { - s_Logger = CreateRef<Logger>(); - s_Logger->SetLogLevel(LogLevel::INFO); - s_Logger->EnableConsoleOutput(true); - s_Logger->EnableFileOutput(true); - s_Logger->SetLogFile("logs/donut.log"); - - s_Logger->LogMessage(LogLevel::INFO, "Logging system initialized"); + s_logger = create_ref<Logger>(); + s_logger->set_log_level(LogLevel::Info); + s_logger->enable_console_output(true); + s_logger->enable_file_output(true); + s_logger->set_log_file("logs/donut.log"); + + s_logger->log_message(LogLevel::Info, "Logging system initialized"); } - void Logger::Shutdown() + auto Logger::shutdown() -> void { - if (s_Logger) - s_Logger->LogMessage(LogLevel::INFO, "Shutting down logging system"); - s_Logger.reset(); + if (s_logger) + s_logger->log_message(LogLevel::Info, "Shutting down logging system"); + s_logger.reset(); } - Ref<Logger> Logger::GetLogger() + auto Logger::get_logger() -> Ref<Logger> { - return s_Logger; + return s_logger; } Logger::Logger() - : m_LogLevel(LogLevel::INFO), - m_ConsoleOutput(true), - m_FileOutput(false) { } + : m_log_level(LogLevel::Info), + m_console_output(true), + m_file_output(false) { } - Logger::~Logger() + Logger::~Logger() { - if (m_LogFile.is_open()) - m_LogFile.close(); + if (m_log_file.is_open()) + m_log_file.close(); } - void Logger::SetLogFile(const std::string& filename) + auto Logger::set_log_file(const std::string& filename) -> void { - std::filesystem::path logPath(filename); - std::filesystem::create_directories(logPath.parent_path()); - - m_LogFile.open(filename, std::ios::app); - if (!m_LogFile.is_open()) + std::filesystem::path log_path(filename); + std::filesystem::create_directories(log_path.parent_path()); + + m_log_file.open(filename, std::ios::app); + if (!m_log_file.is_open()) std::cerr << "Failed to open log file: " << filename << std::endl; } - std::string Logger::GetTimeStamp() + auto Logger::get_time_stamp() -> std::string { auto now = std::chrono::system_clock::now(); - auto time_t = std::chrono::system_clock::to_time_t(now); - + auto time = std::chrono::system_clock::to_time_t(now); + std::stringstream ss; - ss << std::put_time(std::localtime(&time_t), "%Y-%m-%d %H:%M:%S"); - + ss << std::put_time(std::localtime(&time), "%Y-%m-%d %H:%M:%S"); + return ss.str(); } - std::string Logger::GetLogLevelString(LogLevel level) + auto Logger::get_log_level_string(LogLevel level) -> std::string { - switch (level) + switch (level) { - case LogLevel::TRACE: return "TRACE"; - case LogLevel::INFO: return "INFO"; - case LogLevel::WARN: return "WARN"; - case LogLevel::ERR: return "ERROR"; - case LogLevel::FATAL: return "FATAL"; + case LogLevel::trace: return "TRACE"; + case LogLevel::Info: return "INFO"; + case LogLevel::Warn: return "WARN"; + case LogLevel::Err: return "ERROR"; + case LogLevel::Fatal: return "FATAL"; default: return "UNKNOWN"; } } - void Logger::SetConsoleColor(LogLevel level) + auto Logger::set_console_color(LogLevel level) -> void { #if defined(DONUT_WINDOWS) - HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE); WORD color; - + switch (level) { - case LogLevel::TRACE: + case LogLevel::trace: color = FOREGROUND_RED | - FOREGROUND_GREEN | + FOREGROUND_GREEN | FOREGROUND_BLUE; break; - case LogLevel::INFO: - color = FOREGROUND_GREEN | + case LogLevel::Info: + color = FOREGROUND_GREEN | FOREGROUND_INTENSITY; break; - case LogLevel::WARN: - color = FOREGROUND_RED | - FOREGROUND_GREEN | + case LogLevel::Warn: + color = FOREGROUND_RED | + FOREGROUND_GREEN | FOREGROUND_INTENSITY; break; - case LogLevel::ERR: - color = FOREGROUND_RED | + case LogLevel::Err: + color = FOREGROUND_RED | FOREGROUND_INTENSITY; break; - case LogLevel::FATAL: - color = FOREGROUND_RED | - FOREGROUND_BLUE | + case LogLevel::Fatal: + color = FOREGROUND_RED | + FOREGROUND_BLUE | FOREGROUND_INTENSITY; break; default: - color = FOREGROUND_RED | - FOREGROUND_GREEN | + color = FOREGROUND_RED | + FOREGROUND_GREEN | FOREGROUND_BLUE; break; } - - SetConsoleTextAttribute(hConsole, color); + + SetConsoleTextAttribute(h_console, color); #else - const char* colorCode; + const char* color_code; switch (level) { - case LogLevel::TRACE: - colorCode = "\033[37m"; + case LogLevel::trace: + color_code = "\033[37m"; break; - case LogLevel::INFO: - colorCode = "\033[32;1m"; + case LogLevel::Info: + color_code = "\033[32;1m"; break; - case LogLevel::WARN: - colorCode = "\033[33;1m"; + case LogLevel::Warn: + color_code = "\033[33;1m"; break; - case LogLevel::ERR: - colorCode = "\033[31;1m"; + case LogLevel::Err: + color_code = "\033[31;1m"; break; - case LogLevel::FATAL: - colorCode = "\033[35;1m"; + case LogLevel::Fatal: + color_code = "\033[35;1m"; break; default: - colorCode = "\033[37m"; + color_code = "\033[37m"; break; } - std::cout << colorCode; + std::cout << color_code; #endif } - void Logger::ResetConsoleColor() + auto Logger::reset_console_color() -> void { #if defined(DONUT_WINDOWS) - HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - SetConsoleTextAttribute(hConsole, FOREGROUND_RED | - FOREGROUND_GREEN | + HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(h_console, FOREGROUND_RED | + FOREGROUND_GREEN | FOREGROUND_BLUE); #else std::cout << "\033[0m"; diff --git a/src/Core/Log.h b/src/Core/Log.h index c7b2e47..db6b4b4 100644 --- a/src/Core/Log.h +++ b/src/Core/Log.h @@ -1,6 +1,6 @@ #pragma once -#include "Core/Memory.h" +#include "core/memory.h" #include <string> #include <vector> @@ -16,140 +16,141 @@ namespace Donut { enum class LogLevel { - TRACE = 0, - INFO = 2, - WARN = 3, - ERR = 4, - FATAL = 5 + trace = 0, + Info = 2, + Warn = 3, + Err = 4, + Fatal = 5 }; - class Logger + class Logger { public: - static void Init(); - static void Shutdown(); + Logger(); + ~Logger(); + + static auto init() -> void; + static auto shutdown() -> void; - static Ref<Logger> GetLogger(); + static auto get_logger() -> Ref<Logger>; template<typename... Args> - static void Trace(const std::string_view& format, const Args&... args) + static auto trace(const std::string_view& format, const Args&... args) -> void { - auto logger = GetLogger(); - if (logger) logger->LogMessage(LogLevel::TRACE, format, args...); + auto logger = get_logger(); + if (logger) logger->log_message(LogLevel::trace, format, args...); } template<typename... Args> - static void Info(const std::string_view& format, const Args&... args) + static auto info(const std::string_view& format, const Args&... args) -> void { - auto logger = GetLogger(); - if (logger) logger->LogMessage(LogLevel::INFO, format, args...); + auto logger = get_logger(); + if (logger) logger->log_message(LogLevel::Info, format, args...); } template<typename... Args> - static void Warn(const std::string_view& format, const Args&... args) + static auto warn(const std::string_view& format, const Args&... args) -> void { - auto logger = GetLogger(); - if (logger) logger->LogMessage(LogLevel::WARN, format, args...); + auto logger = get_logger(); + if (logger) logger->log_message(LogLevel::Warn, format, args...); } template<typename... Args> - static void Error(const std::string_view& format, const Args&... args) + static auto error(const std::string_view& format, const Args&... args) -> void { - auto logger = GetLogger(); - if (logger) logger->LogMessage(LogLevel::ERR, format, args...); + auto logger = get_logger(); + if (logger) logger->log_message(LogLevel::Err, format, args...); } template<typename... Args> - static void Fatal(const std::string_view& format, const Args&... args) + static auto fatal(const std::string_view& format, const Args&... args) -> void { - auto logger = GetLogger(); - if (logger) logger->LogMessage(LogLevel::FATAL, format, args...); + auto logger = get_logger(); + if (logger) logger->log_message(LogLevel::Fatal, format, args...); } template<typename... Args> - void LogMessage(LogLevel level, const std::string_view& format, const Args&... args) + auto log_message(LogLevel level, const std::string_view& format, const Args&... args) -> void { - if (level < m_LogLevel) + if (level < m_log_level) return; - std::lock_guard<std::mutex> lock(m_Mutex); - std::string message = FormatString(format, args...); - std::string fullMessage = GetTimeStamp() + " [" + GetLogLevelString(level) + "] " + message; - - if (m_ConsoleOutput) + std::lock_guard<std::mutex> lock(m_mutex); + std::string message = format_string(format, args...); + std::string full_message = get_time_stamp() + " [" + get_log_level_string(level) + "] " + message; + + if (m_console_output) { - SetConsoleColor(level); - std::cout << fullMessage << std::endl; - ResetConsoleColor(); + set_console_color(level); + std::cout << full_message << std::endl; + reset_console_color(); } - - if (m_FileOutput && m_LogFile.is_open()) + + if (m_file_output && m_log_file.is_open()) { - m_LogFile << fullMessage << std::endl; - m_LogFile.flush(); + m_log_file << full_message << std::endl; + m_log_file.flush(); } } template<typename... Args> - std::string FormatString(const std::string_view& format, const Args&... args) + auto format_string(const std::string_view& format, const Args&... args) -> std::string { std::string result = format.data(); - std::vector<std::string> argStrings = { ToString(args)... }; - - size_t argIndex = 0; + std::vector<std::string> arg_strings = { to_string(args)... }; + + size_t arg_index = 0; size_t pos = 0; - - while ((pos = result.find("{}", pos)) != std::string::npos && argIndex < argStrings.size()) + + while ((pos = result.find("{}", pos)) != std::string::npos && arg_index < arg_strings.size()) { - result.replace(pos, 2, argStrings[argIndex]); - pos += argStrings[argIndex].length(); - argIndex++; + result.replace(pos, 2, arg_strings[arg_index]); + pos += arg_strings[arg_index].length(); + arg_index++; } - + return result; } template<typename T> - std::string ToString(const T& value) + auto to_string(const T& value) -> std::string { std::stringstream ss; ss << value; return ss.str(); } - void SetLogLevel(LogLevel level) { m_LogLevel = level; } - void EnableConsoleOutput(bool enable) { m_ConsoleOutput = enable; } - void EnableFileOutput(bool enable) { m_FileOutput = enable; } - void SetLogFile(const std::string& filename); - public: - Logger(); - ~Logger(); + auto set_log_level(LogLevel level) -> void { m_log_level = level; } + auto enable_console_output(bool enable) -> void { m_console_output = enable; } + auto enable_file_output(bool enable) -> void { m_file_output = enable; } + auto set_log_file(const std::string& filename) -> void; + + auto get_time_stamp() -> std::string; + auto get_log_level_string(LogLevel level) -> std::string; + auto set_console_color(LogLevel level) -> void; + auto reset_console_color() -> void; - std::string GetTimeStamp(); - std::string GetLogLevelString(LogLevel level); - void SetConsoleColor(LogLevel level); - void ResetConsoleColor(); private: - LogLevel m_LogLevel; - bool m_ConsoleOutput; - bool m_FileOutput; - std::ofstream m_LogFile; - std::mutex m_Mutex; + LogLevel m_log_level; + bool m_console_output; + bool m_file_output; + std::ofstream m_log_file; + std::mutex m_mutex; - static Ref<Logger> s_Logger; + static Ref<Logger> s_logger; }; } #if defined(DONUT_DEBUG) - #define DONUT_TRACE(format, ...) ::Donut::Logger::Trace(format, ##__VA_ARGS__) - #define DONUT_INFO(format, ...) ::Donut::Logger::Info(format, ##__VA_ARGS__) - #define DONUT_WARN(format, ...) ::Donut::Logger::Warn(format, ##__VA_ARGS__) - #define DONUT_ERROR(format, ...) ::Donut::Logger::Error(format, ##__VA_ARGS__) - #define DONUT_FATAL(format, ...) ::Donut::Logger::Fatal(format, ##__VA_ARGS__) + #define DONUT_TRACE(format, ...) ::Donut::Logger::trace(format, ##__VA_ARGS__) + #define DONUT_INFO(format, ...) ::Donut::Logger::info(format, ##__VA_ARGS__) + #define DONUT_WARN(format, ...) ::Donut::Logger::warn(format, ##__VA_ARGS__) + #define DONUT_ERROR(format, ...) ::Donut::Logger::error(format, ##__VA_ARGS__) + #define DONUT_FATAL(format, ...) ::Donut::Logger::fatal(format, ##__VA_ARGS__) #else #define DONUT_TRACE(format, ...) {} #define DONUT_INFO(format, ...) {} #define DONUT_WARN(format, ...) {} #define DONUT_ERROR(format, ...) {} #define DONUT_FATAL(format, ...) {} -#endif
\ No newline at end of file +#endif diff --git a/src/Core/Memory.h b/src/Core/Memory.h index 0abc6b1..3240c71 100644 --- a/src/Core/Memory.h +++ b/src/Core/Memory.h @@ -2,23 +2,23 @@ #include <memory> -namespace Donut +namespace Donut { template<typename T> using Ref = std::shared_ptr<T>; - template<typename T> + template<typename T> using Scope = std::unique_ptr<T>; - - template<typename T, typename ... Args> - constexpr Scope<T> CreateScope(Args&& ... args) + + template<typename T, typename ... Args> + constexpr auto create_scope(Args&& ... args) -> Scope<T> { return std::make_unique<T>(std::forward<Args>(args)...); } - + template<typename T, typename ... Args> - constexpr Ref<T> CreateRef(Args&& ... args) + constexpr auto create_ref(Args&& ... args) -> Ref<T> { return std::make_shared<T>(std::forward<Args>(args)...); } -};
\ No newline at end of file +}; diff --git a/src/Core/SettingsManager.cpp b/src/Core/SettingsManager.cpp deleted file mode 100644 index 9543787..0000000 --- a/src/Core/SettingsManager.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include "SettingsManager.h" -#include "Log.h" -#include "ThemeManager.h" -#include "Rendering/Renderer.h" - -#include <fstream> -#include <filesystem> -#include <algorithm> - -namespace Donut -{ - Settings SettingsManager::s_Settings; - bool SettingsManager::s_Initialized = false; - - void SettingsManager::Initialize() - { - if (s_Initialized) - return; - - LoadSettings(); - s_Initialized = true; - DONUT_INFO("Settings Manager initialized"); - } - - void SettingsManager::Shutdown() - { - if (!s_Initialized) - return; - - SaveSettings(); - s_Initialized = false; - DONUT_INFO("Settings Manager shutdown"); - } - - void SettingsManager::LoadSettings() - { - std::string filePath = GetSettingsFilePath(); - - try - { - if (std::filesystem::exists(filePath)) - { - auto config = toml::parse(filePath); - - if (config.contains("simulation")) - { - auto sim = config["simulation"]; - s_Settings.simulation.targetFPS = toml::find_or(sim, "target_fps", 60); - s_Settings.simulation.computeHeight = toml::find_or(sim, "compute_height", 512); - s_Settings.simulation.maxStepsMoving = toml::find_or(sim, "max_steps_moving", 30000); - s_Settings.simulation.maxStepsStatic = toml::find_or(sim, "max_steps_static", 15000); - s_Settings.simulation.earlyExitDistance = toml::find_or(sim, "early_exit_distance", 5e12f); - s_Settings.simulation.gravityEnabled = toml::find_or(sim, "gravity_enabled", true); - s_Settings.simulation.diskThickness = toml::find_or(sim, "disk_thickness", 0.1f); - s_Settings.simulation.diskDensity = toml::find_or(sim, "disk_density", 0.1f); - s_Settings.simulation.rotationSpeed = toml::find_or(sim, "rotation_speed", 1.0f); - s_Settings.simulation.blurStrength = toml::find_or(sim, "blur_strength", 2.0f); - s_Settings.simulation.glowIntensity = toml::find_or(sim, "glow_intensity", 0.1f); - - s_Settings.simulation.targetFPS = std::max(30, std::min(120, s_Settings.simulation.targetFPS)); - s_Settings.simulation.computeHeight = std::max(64, std::min(2048, s_Settings.simulation.computeHeight)); - s_Settings.simulation.maxStepsMoving = std::max(1000, std::min(60000, s_Settings.simulation.maxStepsMoving)); - s_Settings.simulation.maxStepsStatic = std::max(1000, std::min(30000, s_Settings.simulation.maxStepsStatic)); - s_Settings.simulation.earlyExitDistance = std::max(1e11f, std::min(1e13f, s_Settings.simulation.earlyExitDistance)); - s_Settings.simulation.diskThickness = std::max(0.01f, std::min(5.0f, s_Settings.simulation.diskThickness)); - s_Settings.simulation.diskDensity = std::max(0.01f, std::min(5.0f, s_Settings.simulation.diskDensity)); - s_Settings.simulation.rotationSpeed = std::max(0.0f, std::min(5.0f, s_Settings.simulation.rotationSpeed)); - s_Settings.simulation.blurStrength = std::max(0.1f, std::min(10.0f, s_Settings.simulation.blurStrength)); - s_Settings.simulation.glowIntensity = std::max(0.01f, std::min(5.0f, s_Settings.simulation.glowIntensity)); - } - - if (config.contains("graphics")) - { - auto gfx = config["graphics"]; - s_Settings.graphics.renderAPI = toml::find_or(gfx, "render_api", std::string("OpenGL")); - s_Settings.graphics.vSyncEnabled = toml::find_or(gfx, "vsync_enabled", true); - s_Settings.graphics.showFPS = toml::find_or(gfx, "show_fps", true); - s_Settings.graphics.showPerformanceMetrics = toml::find_or(gfx, "show_performance_metrics", true); - s_Settings.graphics.showDebugInfo = toml::find_or(gfx, "show_debug_info", false); - s_Settings.graphics.enableAntiAliasing = toml::find_or(gfx, "enable_anti_aliasing", true); - s_Settings.graphics.selectedTheme = toml::find_or(gfx, "selected_theme", std::string("Dark")); - - if (s_Settings.graphics.renderAPI != "OpenGL" && - s_Settings.graphics.renderAPI != "Vulkan") - s_Settings.graphics.renderAPI = "OpenGL"; - if (s_Settings.graphics.selectedTheme != "Dark" && - s_Settings.graphics.selectedTheme != "Light" && - s_Settings.graphics.selectedTheme != "Blue") - s_Settings.graphics.selectedTheme = "Dark"; - } - - DONUT_INFO("Settings loaded from {}", filePath); - } - else - { - LoadDefaultSettings(); - SaveSettings(); - DONUT_INFO("No settings file found, created default settings"); - } - } - catch (const std::exception& e) - { - DONUT_ERROR("Failed to load settings: {}", e.what()); - LoadDefaultSettings(); - } - } - - void SettingsManager::SaveSettings() - { - std::string filePath = GetSettingsFilePath(); - - try - { - std::filesystem::path path(filePath); - std::filesystem::create_directories(path.parent_path()); - - toml::value simulation = toml::table - { - {"target_fps", s_Settings.simulation.targetFPS }, - {"compute_height", s_Settings.simulation.computeHeight }, - {"max_steps_moving", s_Settings.simulation.maxStepsMoving }, - {"max_steps_static", s_Settings.simulation.maxStepsStatic }, - {"early_exit_distance", s_Settings.simulation.earlyExitDistance}, - {"gravity_enabled", s_Settings.simulation.gravityEnabled }, - {"disk_thickness", s_Settings.simulation.diskThickness }, - {"disk_density", s_Settings.simulation.diskDensity }, - {"rotation_speed", s_Settings.simulation.rotationSpeed }, - {"blur_strength", s_Settings.simulation.blurStrength }, - {"glow_intensity", s_Settings.simulation.glowIntensity } - }; - - toml::value graphics = toml::table - { - {"render_api", s_Settings.graphics.renderAPI }, - {"vsync_enabled", s_Settings.graphics.vSyncEnabled }, - {"show_fps", s_Settings.graphics.showFPS }, - {"show_performance_metrics", s_Settings.graphics.showPerformanceMetrics}, - {"show_debug_info", s_Settings.graphics.showDebugInfo }, - {"enable_anti_aliasing", s_Settings.graphics.enableAntiAliasing }, - {"selected_theme", s_Settings.graphics.selectedTheme } - }; - - toml::value config = toml::table - { - {"simulation", simulation}, - {"graphics", graphics} - }; - - std::ofstream file(filePath); - file << config; - file.close(); - - DONUT_INFO("Settings saved to {}", filePath); - } - catch (const std::exception& e) - { - DONUT_ERROR("Failed to save settings: {}", e.what()); - } - } - - void SettingsManager::SetSimulationSettings(const SimulationSettings& settings) - { - s_Settings.simulation = settings; - SaveSettings(); - } - - void SettingsManager::SetGraphicsSettings(const GraphicsSettings& settings) - { - s_Settings.graphics = settings; - SaveSettings(); - } - - std::string SettingsManager::GetSettingsFilePath() - { - return "config/settings.toml"; - } - - void SettingsManager::LoadDefaultSettings() - { - s_Settings.simulation.targetFPS = 60; - s_Settings.simulation.computeHeight = 512; - s_Settings.simulation.maxStepsMoving = 30000; - s_Settings.simulation.maxStepsStatic = 15000; - s_Settings.simulation.earlyExitDistance = 5e12f; - s_Settings.simulation.gravityEnabled = true; - s_Settings.simulation.diskThickness = 0.1f; - s_Settings.simulation.diskDensity = 0.1f; - s_Settings.simulation.rotationSpeed = 1.0f; - s_Settings.simulation.blurStrength = 2.0f; - s_Settings.simulation.glowIntensity = 0.1f; - - s_Settings.graphics.renderAPI = "OpenGL"; - s_Settings.graphics.vSyncEnabled = true; - s_Settings.graphics.showFPS = true; - s_Settings.graphics.showPerformanceMetrics = true; - s_Settings.graphics.showDebugInfo = false; - s_Settings.graphics.enableAntiAliasing = true; - s_Settings.graphics.selectedTheme = "Dark"; - } -} diff --git a/src/Core/SettingsManager.h b/src/Core/SettingsManager.h deleted file mode 100644 index de0774b..0000000 --- a/src/Core/SettingsManager.h +++ /dev/null @@ -1,80 +0,0 @@ -#pragma once - -#include <string> -#include <toml.hpp> - -namespace Donut -{ - struct SimulationSettings - { - int targetFPS = 60; - int computeHeight = 512; - int maxStepsMoving = 30000; - int maxStepsStatic = 15000; - float earlyExitDistance = 5e12f; - bool gravityEnabled = true; - float diskThickness = 0.1f; - float diskDensity = 0.1f; - float rotationSpeed = 1.0f; - float blurStrength = 2.0f; - float glowIntensity = 0.1f; - }; - - struct GraphicsSettings - { - std::string renderAPI = "OpenGL"; - bool vSyncEnabled = true; - bool showFPS = true; - bool showPerformanceMetrics = true; - bool showDebugInfo = false; - bool enableAntiAliasing = true; - std::string selectedTheme = "Dark"; - }; - - struct Settings - { - SimulationSettings simulation; - GraphicsSettings graphics; - }; - - class SettingsManager - { - public: - static void Initialize(); - static void Shutdown(); - - static void LoadSettings(); - static void SaveSettings(); - - static Settings& GetSettings() { return s_Settings; } - static const Settings& GetSettingsConst() { return s_Settings; } - - static void SetSimulationSettings(const SimulationSettings& settings); - static void SetGraphicsSettings(const GraphicsSettings& settings); - - static int GetTargetFPS() { return s_Settings.simulation.targetFPS; } - static int GetComputeHeight() { return s_Settings.simulation.computeHeight; } - static int GetMaxStepsMoving() { return s_Settings.simulation.maxStepsMoving; } - static int GetMaxStepsStatic() { return s_Settings.simulation.maxStepsStatic; } - static float GetEarlyExitDistance() { return s_Settings.simulation.earlyExitDistance; } - static bool GetGravityEnabled() { return s_Settings.simulation.gravityEnabled; } - static float GetDiskThickness() { return s_Settings.simulation.diskThickness; } - static float GetDiskDensity() { return s_Settings.simulation.diskDensity; } - static float GetRotationSpeed() { return s_Settings.simulation.rotationSpeed; } - static float GetBlurStrength() { return s_Settings.simulation.blurStrength; } - static float GetGlowIntensity() { return s_Settings.simulation.glowIntensity; } - static std::string GetRenderAPI() { return s_Settings.graphics.renderAPI; } - static bool GetVSyncEnabled() { return s_Settings.graphics.vSyncEnabled; } - static bool GetShowFPS() { return s_Settings.graphics.showFPS; } - static bool GetShowPerformanceMetrics() { return s_Settings.graphics.showPerformanceMetrics; } - static bool GetShowDebugInfo() { return s_Settings.graphics.showDebugInfo; } - static bool GetEnableAntiAliasing() { return s_Settings.graphics.enableAntiAliasing; } - static std::string GetSelectedTheme() { return s_Settings.graphics.selectedTheme; } - private: - static std::string GetSettingsFilePath(); - static void LoadDefaultSettings(); - private: - static Settings s_Settings; - static bool s_Initialized; - }; -} diff --git a/src/Core/State.h b/src/Core/State.h index cd1b7ee..623f1c2 100644 --- a/src/Core/State.h +++ b/src/Core/State.h @@ -1,6 +1,6 @@ #pragma once -#include "Event.h" +#include "event.h" namespace Donut { @@ -8,12 +8,12 @@ namespace Donut { public: virtual ~State() = default; - - virtual void OnEnter() = 0; - virtual void OnExit() = 0; - virtual void OnUpdate(float deltaTime) = 0; - virtual void OnRender() = 0; - virtual void OnImUIRender() = 0; - virtual void OnEvent(Event& event) = 0; + + virtual auto on_enter() -> void = 0; + virtual auto on_exit() -> void = 0; + virtual auto on_update(float delta_time) -> void = 0; + virtual auto on_render() -> void = 0; + virtual auto on_im_ui_render() -> void = 0; + virtual auto on_event(Event& event) -> void = 0; }; -};
\ No newline at end of file +}; diff --git a/src/Core/StateManager.cpp b/src/Core/StateManager.cpp deleted file mode 100644 index e2aba02..0000000 --- a/src/Core/StateManager.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "StateManager.h" -#include "Log.h" - -namespace Donut -{ - void StateManager::Shutdown() - { - if (m_CurrentState) - m_CurrentState->OnExit(); - - DestroyStates(); - DONUT_INFO("StateManager shutdown"); - } - - void StateManager::DestroyStates() - { - m_States.clear(); - m_CurrentState = nullptr; - m_CurrentStateName = ""; - } - - void StateManager::RegisterState(const std::string& stateName, Scope<State> state) - { - if (m_States.find(stateName) != m_States.end()) - DONUT_WARN("State '{}' already exists, overwriting", stateName); - m_States[stateName] = std::move(state); - DONUT_INFO("Registered state: {}", stateName); - } - - void StateManager::SwitchToState(const std::string& stateName) - { - auto it = m_States.find(stateName); - if (it == m_States.end()) - { - DONUT_ERROR("Attempted to switch to unknown state: {}", stateName); - return; - } - - State* newState = it->second.get(); - if (newState == m_CurrentState) - return; - - if (m_CurrentState) - m_CurrentState->OnExit(); - - m_CurrentState = newState; - m_CurrentStateName = stateName; - m_CurrentState->OnEnter(); - DONUT_INFO("Switched to state: {}", stateName); - } - - State* StateManager::GetState(const std::string& stateName) - { - auto it = m_States.find(stateName); - if (it != m_States.end()) - return it->second.get(); - return nullptr; - } - - bool StateManager::HasState(const std::string& stateName) const - { - return m_States.find(stateName) != m_States.end(); - } - - void StateManager::Update(float deltaTime) - { - if (m_CurrentState) - m_CurrentState->OnUpdate(deltaTime); - } - - void StateManager::Render() - { - if (m_CurrentState) - m_CurrentState->OnRender(); - } - - void StateManager::OnImUIRender() - { - if (m_CurrentState) - m_CurrentState->OnImUIRender(); - } - - void StateManager::OnEvent(Event& event) - { - if (m_CurrentState) - m_CurrentState->OnEvent(event); - } -} diff --git a/src/Core/StateManager.h b/src/Core/StateManager.h deleted file mode 100644 index 4ffc86d..0000000 --- a/src/Core/StateManager.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "Memory.h" -#include "State.h" - -#include <string> -#include <unordered_map> - -namespace Donut -{ - class StateManager - { - public: - ~StateManager() = default; - void Shutdown(); - - void Update(float deltaTime); - void Render(); - void OnImUIRender(); - void OnEvent(Event& event); - - void RegisterState(const std::string& stateName, Scope<State> state); - void SwitchToState(const std::string& stateName); - - std::string GetCurrentStateName() const { return m_CurrentStateName; } - State* GetCurrentState() const { return m_CurrentState; } - - State* GetState(const std::string& stateName); - bool HasState(const std::string& stateName) const; - private: - void CreateStates(); - void DestroyStates(); - - private: - State* m_CurrentState = nullptr; - std::string m_CurrentStateName = ""; - - std::unordered_map<std::string, Scope<State>> m_States; - }; -} diff --git a/src/Core/ThemeManager.cpp b/src/Core/ThemeManager.cpp deleted file mode 100644 index e7e2f9e..0000000 --- a/src/Core/ThemeManager.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include "ThemeManager.h" - -namespace Donut -{ - Theme ThemeManager::s_CurrentTheme = Theme::Dark; - - void ThemeManager::SetTheme(Theme theme) - { - s_CurrentTheme = theme; - - switch (theme) - { - case Theme::Dark: - ApplyDarkTheme(); - break; - case Theme::Light: - ApplyLightTheme(); - break; - case Theme::Blue: - ApplyBlueTheme(); - break; - } - } - - void ThemeManager::ApplyDarkTheme() - { - ImGuiStyle& style = ImGui::GetStyle(); - ImVec4* colors = style.Colors; - - colors[ImGuiCol_Text] = ImVec4(0.95f, 0.95f, 0.95f, 1.00f); - colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.95f); - colors[ImGuiCol_ChildBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.95f); - colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.95f); - colors[ImGuiCol_Border] = ImVec4(0.25f, 0.25f, 0.25f, 0.54f); - colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_FrameBg] = ImVec4(0.12f, 0.12f, 0.12f, 0.95f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.18f, 0.18f, 0.18f, 0.95f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.22f, 0.22f, 0.22f, 0.95f); - colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f); - colors[ImGuiCol_CheckMark] = ImVec4(0.60f, 0.60f, 0.60f, 0.95f); - colors[ImGuiCol_SliderGrab] = ImVec4(0.60f, 0.60f, 0.60f, 0.95f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.70f, 0.70f, 0.70f, 0.95f); - colors[ImGuiCol_Button] = ImVec4(0.15f, 0.15f, 0.15f, 0.95f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.20f, 0.20f, 0.20f, 0.95f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.25f, 0.25f, 0.25f, 0.95f); - colors[ImGuiCol_Header] = ImVec4(0.15f, 0.15f, 0.15f, 0.95f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.20f, 0.20f, 0.20f, 0.95f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.25f, 0.25f, 0.25f, 0.95f); - colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.43f, 0.50f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); - colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.29f, 0.30f, 0.31f, 0.67f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.60f, 0.60f, 0.60f, 0.95f); - colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.08f, 0.08f, 0.83f); - colors[ImGuiCol_TabHovered] = ImVec4(0.15f, 0.15f, 0.15f, 0.83f); - colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); - colors[ImGuiCol_TabUnfocused] = ImVec4(0.08f, 0.08f, 0.08f, 0.97f); - colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f); - colors[ImGuiCol_DockingPreview] = ImVec4(0.60f, 0.60f, 0.60f, 0.70f); - colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); - colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); - colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); - colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); - colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); - colors[ImGuiCol_TextSelectedBg] = ImVec4(0.60f, 0.60f, 0.60f, 0.35f); - colors[ImGuiCol_DragDropTarget] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); - colors[ImGuiCol_NavHighlight] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); - colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); - colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); - colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); - - style.WindowPadding = ImVec2(8, 8); - style.FramePadding = ImVec2(5, 2); - style.CellPadding = ImVec2(6, 4); - style.ItemSpacing = ImVec2(6, 4); - style.ItemInnerSpacing = ImVec2(4, 4); - style.IndentSpacing = 21; - style.ScrollbarSize = 14; - style.GrabMinSize = 10; - - style.WindowBorderSize = 1; - style.ChildBorderSize = 1; - style.PopupBorderSize = 1; - style.FrameBorderSize = 0; - style.TabBorderSize = 0; - - style.WindowRounding = 8.0f; - style.ChildRounding = 6.0f; - style.FrameRounding = 4.0f; - style.PopupRounding = 4.0f; - style.ScrollbarRounding = 4.0f; - style.GrabRounding = 4.0f; - style.TabRounding = 4.0f; - - style.WindowTitleAlign = ImVec2(0.5f, 0.5f); - style.ButtonTextAlign = ImVec2(0.5f, 0.5f); - style.SelectableTextAlign = ImVec2(0.0f, 0.0f); - - style.DisplaySafeAreaPadding = ImVec2(3, 3); - - style.Alpha = 1.0f; - style.DisabledAlpha = 0.6f; - } - - void ThemeManager::ApplyLightTheme() - { - ImGuiStyle& style = ImGui::GetStyle(); - ImVec4* colors = style.Colors; - - colors[ImGuiCol_Text] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); - colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); - colors[ImGuiCol_WindowBg] = ImVec4(0.95f, 0.95f, 0.95f, 0.95f); - colors[ImGuiCol_ChildBg] = ImVec4(0.92f, 0.92f, 0.92f, 0.95f); - colors[ImGuiCol_PopupBg] = ImVec4(0.95f, 0.95f, 0.95f, 0.95f); - colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 0.54f); - colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_FrameBg] = ImVec4(0.85f, 0.85f, 0.85f, 0.95f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.80f, 0.80f, 0.80f, 0.95f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.75f, 0.75f, 0.75f, 0.95f); - colors[ImGuiCol_TitleBg] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.85f, 0.85f, 0.85f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.95f, 0.95f, 0.95f, 0.51f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.88f, 0.88f, 0.88f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.90f, 0.90f, 0.90f, 0.53f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - colors[ImGuiCol_CheckMark] = ImVec4(0.20f, 0.60f, 0.90f, 0.95f); - colors[ImGuiCol_SliderGrab] = ImVec4(0.20f, 0.60f, 0.90f, 0.95f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.15f, 0.50f, 0.80f, 0.95f); - colors[ImGuiCol_Button] = ImVec4(0.80f, 0.80f, 0.80f, 0.95f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.75f, 0.75f, 0.75f, 0.95f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 0.95f); - colors[ImGuiCol_Header] = ImVec4(0.85f, 0.85f, 0.85f, 0.95f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.80f, 0.80f, 0.80f, 0.95f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.75f, 0.75f, 0.75f, 0.95f); - colors[ImGuiCol_Separator] = ImVec4(0.70f, 0.70f, 0.70f, 0.50f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.60f, 0.60f, 0.60f, 0.67f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.20f, 0.60f, 0.90f, 0.95f); - colors[ImGuiCol_Tab] = ImVec4(0.85f, 0.85f, 0.85f, 0.83f); - colors[ImGuiCol_TabHovered] = ImVec4(0.80f, 0.80f, 0.80f, 0.83f); - colors[ImGuiCol_TabActive] = ImVec4(0.75f, 0.75f, 0.75f, 1.00f); - colors[ImGuiCol_TabUnfocused] = ImVec4(0.90f, 0.90f, 0.90f, 0.97f); - colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.85f, 0.85f, 0.85f, 1.00f); - colors[ImGuiCol_DockingPreview] = ImVec4(0.20f, 0.60f, 0.90f, 0.70f); - colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - colors[ImGuiCol_PlotLines] = ImVec4(0.40f, 0.40f, 0.40f, 1.00f); - colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.30f, 0.20f, 1.00f); - colors[ImGuiCol_PlotHistogram] = ImVec4(0.70f, 0.50f, 0.00f, 1.00f); - colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.80f, 0.40f, 0.00f, 1.00f); - colors[ImGuiCol_TextSelectedBg] = ImVec4(0.20f, 0.60f, 0.90f, 0.35f); - colors[ImGuiCol_DragDropTarget] = ImVec4(0.10f, 0.50f, 0.80f, 1.00f); - colors[ImGuiCol_NavHighlight] = ImVec4(0.20f, 0.60f, 0.90f, 1.00f); - colors[ImGuiCol_NavWindowingHighlight] = ImVec4(0.10f, 0.10f, 0.10f, 0.70f); - colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.20f); - colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); - - style.WindowPadding = ImVec2(8, 8); - style.FramePadding = ImVec2(5, 2); - style.CellPadding = ImVec2(6, 4); - style.ItemSpacing = ImVec2(6, 4); - style.ItemInnerSpacing = ImVec2(4, 4); - style.IndentSpacing = 21; - style.ScrollbarSize = 14; - style.GrabMinSize = 10; - - style.WindowBorderSize = 1; - style.ChildBorderSize = 1; - style.PopupBorderSize = 1; - style.FrameBorderSize = 0; - style.TabBorderSize = 0; - - style.WindowRounding = 8.0f; - style.ChildRounding = 6.0f; - style.FrameRounding = 4.0f; - style.PopupRounding = 4.0f; - style.ScrollbarRounding = 4.0f; - style.GrabRounding = 4.0f; - style.TabRounding = 4.0f; - - style.WindowTitleAlign = ImVec2(0.5f, 0.5f); - style.ButtonTextAlign = ImVec2(0.5f, 0.5f); - style.SelectableTextAlign = ImVec2(0.0f, 0.0f); - - style.DisplaySafeAreaPadding = ImVec2(3, 3); - - style.Alpha = 1.0f; - style.DisabledAlpha = 0.6f; - } - - void ThemeManager::ApplyBlueTheme() - { - ImGuiStyle& style = ImGui::GetStyle(); - ImVec4* colors = style.Colors; - - colors[ImGuiCol_Text] = ImVec4(0.95f, 0.95f, 0.95f, 1.00f); - colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - colors[ImGuiCol_WindowBg] = ImVec4(0.05f, 0.10f, 0.20f, 0.95f); - colors[ImGuiCol_ChildBg] = ImVec4(0.03f, 0.08f, 0.18f, 0.95f); - colors[ImGuiCol_PopupBg] = ImVec4(0.05f, 0.10f, 0.20f, 0.95f); - colors[ImGuiCol_Border] = ImVec4(0.20f, 0.30f, 0.50f, 0.54f); - colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_FrameBg] = ImVec4(0.08f, 0.15f, 0.30f, 0.95f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.12f, 0.20f, 0.40f, 0.95f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.15f, 0.25f, 0.45f, 0.95f); - colors[ImGuiCol_TitleBg] = ImVec4(0.05f, 0.10f, 0.20f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.05f, 0.10f, 0.20f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.08f, 0.15f, 0.25f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.05f, 0.10f, 0.53f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.30f, 0.40f, 0.60f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.50f, 0.70f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.50f, 0.60f, 0.80f, 1.00f); - colors[ImGuiCol_CheckMark] = ImVec4(0.20f, 0.60f, 1.00f, 0.95f); - colors[ImGuiCol_SliderGrab] = ImVec4(0.20f, 0.60f, 1.00f, 0.95f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.30f, 0.70f, 1.00f, 0.95f); - colors[ImGuiCol_Button] = ImVec4(0.10f, 0.20f, 0.40f, 0.95f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.15f, 0.25f, 0.45f, 0.95f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.30f, 0.50f, 0.95f); - colors[ImGuiCol_Header] = ImVec4(0.10f, 0.20f, 0.40f, 0.95f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.15f, 0.25f, 0.45f, 0.95f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.20f, 0.30f, 0.50f, 0.95f); - colors[ImGuiCol_Separator] = ImVec4(0.30f, 0.40f, 0.60f, 0.50f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.40f, 0.50f, 0.70f, 1.00f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.50f, 0.60f, 0.80f, 1.00f); - colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.30f, 0.40f, 0.60f, 0.67f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.20f, 0.60f, 1.00f, 0.95f); - colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.15f, 0.25f, 0.83f); - colors[ImGuiCol_TabHovered] = ImVec4(0.12f, 0.20f, 0.35f, 0.83f); - colors[ImGuiCol_TabActive] = ImVec4(0.15f, 0.25f, 0.40f, 1.00f); - colors[ImGuiCol_TabUnfocused] = ImVec4(0.05f, 0.10f, 0.20f, 0.97f); - colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.08f, 0.15f, 0.25f, 1.00f); - colors[ImGuiCol_DockingPreview] = ImVec4(0.20f, 0.60f, 1.00f, 0.70f); - colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.05f, 0.10f, 0.20f, 1.00f); - colors[ImGuiCol_PlotLines] = ImVec4(0.60f, 0.70f, 0.90f, 1.00f); - colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.60f, 0.40f, 1.00f); - colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.30f, 1.00f); - colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.80f, 0.40f, 1.00f); - colors[ImGuiCol_TextSelectedBg] = ImVec4(0.20f, 0.60f, 1.00f, 0.35f); - colors[ImGuiCol_DragDropTarget] = ImVec4(0.10f, 0.50f, 0.90f, 1.00f); - colors[ImGuiCol_NavHighlight] = ImVec4(0.20f, 0.60f, 1.00f, 1.00f); - colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); - colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); - colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); - - style.WindowPadding = ImVec2(8, 8); - style.FramePadding = ImVec2(5, 2); - style.CellPadding = ImVec2(6, 4); - style.ItemSpacing = ImVec2(6, 4); - style.ItemInnerSpacing = ImVec2(4, 4); - style.IndentSpacing = 21; - style.ScrollbarSize = 14; - style.GrabMinSize = 10; - - style.WindowBorderSize = 1; - style.ChildBorderSize = 1; - style.PopupBorderSize = 1; - style.FrameBorderSize = 0; - style.TabBorderSize = 0; - - style.WindowRounding = 8.0f; - style.ChildRounding = 6.0f; - style.FrameRounding = 4.0f; - style.PopupRounding = 4.0f; - style.ScrollbarRounding = 4.0f; - style.GrabRounding = 4.0f; - style.TabRounding = 4.0f; - - style.WindowTitleAlign = ImVec2(0.5f, 0.5f); - style.ButtonTextAlign = ImVec2(0.5f, 0.5f); - style.SelectableTextAlign = ImVec2(0.0f, 0.0f); - - style.DisplaySafeAreaPadding = ImVec2(3, 3); - - style.Alpha = 1.0f; - style.DisabledAlpha = 0.6f; - } -} diff --git a/src/Core/ThemeManager.h b/src/Core/ThemeManager.h deleted file mode 100644 index 7ff08ea..0000000 --- a/src/Core/ThemeManager.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include <imgui.h> - -namespace Donut -{ - enum class Theme - { - Dark = 0, - Light = 1, - Blue = 2 - }; - - class ThemeManager - { - public: - static void SetTheme(Theme theme); - static Theme GetCurrentTheme() { return s_CurrentTheme; } - - static void ApplyDarkTheme(); - static void ApplyLightTheme(); - static void ApplyBlueTheme(); - - private: - static Theme s_CurrentTheme; - }; -} diff --git a/src/Core/Window.cpp b/src/Core/Window.cpp index ade0c26..047ef0d 100644 --- a/src/Core/Window.cpp +++ b/src/Core/Window.cpp @@ -1,7 +1,7 @@ #include <glad/glad.h> -#include "Window.h" -#include "ThemeManager.h" -#include "Rendering/Renderer.h" // RendererAPI::GetAPI() +#include "window.h" +#include "theme_manager.h" +#include "rendering/renderer.h" // RendererAPI::get_api() #include <cstdint> @@ -11,26 +11,26 @@ namespace Donut { - static bool s_GLFWInitialized = false; - static uint32_t s_GLFWWindowCount = 0; + static bool s_glfw_initialized = false; + static uint32_t s_glfw_window_count = 0; Window::Window(const std::string& title, int width, int height) - : m_Title(title), m_Width(width), - m_Height(height), m_IsClosed(false) + : m_title(title), m_width(width), + m_height(height), m_is_closed(false) { - Init(); + init(); } Window::~Window() { - Shutdown(); + shutdown(); } - void Window::Init() + auto Window::init() -> void { - DONUT_INFO("Initializing window: ", m_Title, " (", m_Width, "x", m_Height, ")"); - - if (!s_GLFWInitialized) + DONUT_INFO("Initializing window: ", m_title, " (", m_width, "x", m_height, ")"); + + if (!s_glfw_initialized) { int success = glfwInit(); if (!success) @@ -39,11 +39,11 @@ namespace Donut return; } - s_GLFWInitialized = true; + s_glfw_initialized = true; DONUT_INFO("GLFW initialized successfully"); } - if (RendererAPI::GetAPI() == RendererAPI::API::Vulkan) + if (RendererAPI::get_api() == RendererAPI::API::Vulkan) { // Vulkan manages presentation itself; GLFW must not create a GL context. glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); @@ -62,78 +62,78 @@ namespace Donut #endif } - m_Window = glfwCreateWindow(m_Width, m_Height, m_Title.c_str(), nullptr, nullptr); - if (!m_Window) + m_window = glfwCreateWindow(m_width, m_height, m_title.c_str(), nullptr, nullptr); + if (!m_window) { DONUT_ERROR("Could not create GLFW window!"); glfwTerminate(); return; } - + DONUT_INFO("GLFW window created successfully"); - if (RendererAPI::GetAPI() != RendererAPI::API::Vulkan) - glfwMakeContextCurrent(m_Window); - glfwSetWindowUserPointer(m_Window, this); + if (RendererAPI::get_api() != RendererAPI::API::Vulkan) + glfwMakeContextCurrent(m_window); + glfwSetWindowUserPointer(m_window, this); - glfwSetErrorCallback(GLFWErrorCallback); - glfwSetWindowCloseCallback(m_Window, GLFWWindowCloseCallback); - glfwSetWindowSizeCallback(m_Window, GLFWWindowSizeCallback); - glfwSetWindowFocusCallback(m_Window, GLFWWindowFocusCallback); - glfwSetWindowPosCallback(m_Window, GLFWWindowPosCallback); - glfwSetKeyCallback(m_Window, GLFWKeyCallback); - glfwSetCharCallback(m_Window, GLFWCharCallback); - glfwSetMouseButtonCallback(m_Window, GLFWMouseButtonCallback); - glfwSetScrollCallback(m_Window, GLFWMouseScrollCallback); - glfwSetCursorPosCallback(m_Window, GLFWCursorPosCallback); + glfwSetErrorCallback(glfw_error_callback); + glfwSetWindowCloseCallback(m_window, glfw_window_close_callback); + glfwSetWindowSizeCallback(m_window, glfw_window_size_callback); + glfwSetWindowFocusCallback(m_window, glfw_window_focus_callback); + glfwSetWindowPosCallback(m_window, glfw_window_pos_callback); + glfwSetKeyCallback(m_window, glfw_key_callback); + glfwSetCharCallback(m_window, glfw_char_callback); + glfwSetMouseButtonCallback(m_window, glfw_mouse_button_callback); + glfwSetScrollCallback(m_window, glfw_mouse_scroll_callback); + glfwSetCursorPosCallback(m_window, glfw_cursor_pos_callback); - s_GLFWWindowCount++; + s_glfw_window_count++; } - void Window::Shutdown() + auto Window::shutdown() -> void { - DONUT_INFO("Shutting down window: ", m_Title); - - ShutdownImGui(); - - glfwDestroyWindow(m_Window); - s_GLFWWindowCount--; + DONUT_INFO("Shutting down window: ", m_title); + + shutdown_im_gui(); + + glfwDestroyWindow(m_window); + s_glfw_window_count--; - if (s_GLFWWindowCount == 0) + if (s_glfw_window_count == 0) { glfwTerminate(); - s_GLFWInitialized = false; + s_glfw_initialized = false; DONUT_INFO("GLFW terminated (no more windows)"); } } - void Window::OnUpdate() const + auto Window::on_update() const -> void { glfwPollEvents(); - if (RendererAPI::GetAPI() != RendererAPI::API::Vulkan) - glfwSwapBuffers(m_Window); // Vulkan presents via the swapchain instead + if (RendererAPI::get_api() != RendererAPI::API::Vulkan) + glfwSwapBuffers(m_window); // Vulkan presents via the swapchain instead } - bool Window::ShouldClose() const + auto Window::should_close() const -> bool { - return glfwWindowShouldClose(m_Window) || m_IsClosed; + return glfwWindowShouldClose(m_window) || m_is_closed; } - void Window::SetCursorLocked(bool locked) + auto Window::set_cursor_locked(bool locked) -> void { - m_CursorLocked = locked; - glfwSetInputMode(m_Window, GLFW_CURSOR, locked ? + m_cursor_locked = locked; + glfwSetInputMode(m_window, GLFW_CURSOR, locked ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL); } - void Window::SetCursorVisible(bool visible) + auto Window::set_cursor_visible(bool visible) -> void { - m_CursorVisible = visible; - glfwSetInputMode(m_Window, GLFW_CURSOR, visible ? + m_cursor_visible = visible; + glfwSetInputMode(m_window, GLFW_CURSOR, visible ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN); } - void Window::InitImGui() + auto Window::init_im_gui() -> void { IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -148,8 +148,8 @@ namespace Donut io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; #endif - SetupImGuiFonts(); - ThemeManager::SetTheme(Theme::Dark); + setup_im_gui_fonts(); + ThemeManager::set_theme(Theme::Dark); ImGuiStyle& style = ImGui::GetStyle(); if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) @@ -158,7 +158,7 @@ namespace Donut style.Colors[ImGuiCol_WindowBg].w = 1.0f; } - ImGui_ImplGlfw_InitForOpenGL(m_Window, true); + ImGui_ImplGlfw_InitForOpenGL(m_window, true); #ifdef __APPLE__ // macOS uses a core-profile context, which rejects the legacy // "#version 130" GLSL the ImGui backend defaults to. 150 is the @@ -167,53 +167,53 @@ namespace Donut #else ImGui_ImplOpenGL3_Init("#version 130"); #endif - + DONUT_INFO("ImGUI initialized successfully"); } - void Window::SetupImGuiFonts() + auto Window::setup_im_gui_fonts() -> void { ImGuiIO& io = ImGui::GetIO(); io.Fonts->Clear(); - - m_MainFont = io.Fonts->AddFontFromFileTTF("Assets/Fonts/Inter/static/Inter_18pt-Regular.ttf", 16.0f); - if (!m_MainFont) + + m_main_font = io.Fonts->AddFontFromFileTTF("assets/fonts/inter/static/Inter_18pt-Regular.ttf", 16.0f); + if (!m_main_font) { DONUT_WARN("Failed to load Inter font, falling back to default"); - m_MainFont = io.Fonts->AddFontDefault(); + m_main_font = io.Fonts->AddFontDefault(); } else DONUT_INFO("Successfully loaded Inter font"); - - m_LargeFont = io.Fonts->AddFontFromFileTTF("Assets/Fonts/Inter/static/Inter_18pt-Bold.ttf", 20.0f); - if (!m_LargeFont) - m_LargeFont = m_MainFont; - - m_SmallFont = io.Fonts->AddFontFromFileTTF("Assets/Fonts/Inter/static/Inter_18pt-Light.ttf", 12.0f); - if (!m_SmallFont) - m_SmallFont = m_MainFont; - - io.FontDefault = m_MainFont; + + m_large_font = io.Fonts->AddFontFromFileTTF("assets/fonts/inter/static/Inter_18pt-Bold.ttf", 20.0f); + if (!m_large_font) + m_large_font = m_main_font; + + m_small_font = io.Fonts->AddFontFromFileTTF("assets/fonts/inter/static/Inter_18pt-Light.ttf", 12.0f); + if (!m_small_font) + m_small_font = m_main_font; + + io.FontDefault = m_main_font; DONUT_INFO("ImGUI fonts loaded successfully"); } - void Window::ShutdownImGui() + auto Window::shutdown_im_gui() -> void { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); - + DONUT_INFO("ImGUI shutdown"); } - void Window::BeginImGuiFrame() + auto Window::begin_im_gui_frame() -> void { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); } - void Window::EndImGuiFrame() + auto Window::end_im_gui_frame() -> void { ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); @@ -228,114 +228,114 @@ namespace Donut } } - void Window::GLFWErrorCallback(int error, const char* description) + auto Window::glfw_error_callback(int error, const char* description) -> void { DONUT_ERROR("GLFW Error ({}): {}", error, description ? description : ""); } - void Window::GLFWWindowCloseCallback(GLFWwindow* window) + auto Window::glfw_window_close_callback(GLFWwindow* window) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); WindowCloseEvent event; - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } - void Window::GLFWWindowSizeCallback(GLFWwindow* window, int width, int height) + auto Window::glfw_window_size_callback(GLFWwindow* window, int width, int height) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - win->m_Width = width; - win->m_Height = height; - + win->m_width = width; + win->m_height = height; + WindowResizeEvent event(width, height); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } - void Window::GLFWWindowFocusCallback(GLFWwindow* window, int focused) + auto Window::glfw_window_focus_callback(GLFWwindow* window, int focused) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - + if (focused) { WindowFocusEvent event; - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } else { WindowLostFocusEvent event; - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } } - void Window::GLFWWindowPosCallback(GLFWwindow* window, int xpos, int ypos) + auto Window::glfw_window_pos_callback(GLFWwindow* window, int xpos, int ypos) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); WindowMovedEvent event(xpos, ypos); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } - void Window::GLFWKeyCallback(GLFWwindow* window, int key, int scancode, - int action, int mods) + auto Window::glfw_key_callback(GLFWwindow* window, int key, int scancode, + int action, int mods) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - + switch (action) { case GLFW_PRESS: { KeyPressedEvent event(key, false); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; case GLFW_RELEASE: { KeyReleasedEvent event(key); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; case GLFW_REPEAT: { KeyPressedEvent event(key, true); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; } } - void Window::GLFWCharCallback(GLFWwindow* window, unsigned int keycode) + auto Window::glfw_char_callback(GLFWwindow* window, unsigned int keycode) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); KeyTypedEvent event(keycode); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } - void Window::GLFWMouseButtonCallback(GLFWwindow* window, int button, - int action, int mods) + auto Window::glfw_mouse_button_callback(GLFWwindow* window, int button, + int action, int mods) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - + switch (action) { case GLFW_PRESS: { MouseButtonPressedEvent event(button); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; case GLFW_RELEASE: { MouseButtonReleasedEvent event(button); - win->m_EventHandler.OnEvent(event); + win->m_event_handler.on_event(event); } break; } } - void Window::GLFWMouseScrollCallback(GLFWwindow* window, double xOffset, double yOffset) + auto Window::glfw_mouse_scroll_callback(GLFWwindow* window, double x_offset, double y_offset) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - MouseScrolledEvent event((float)xOffset, (float)yOffset); - win->m_EventHandler.OnEvent(event); + MouseScrolledEvent event((float)x_offset, (float)y_offset); + win->m_event_handler.on_event(event); } - void Window::GLFWCursorPosCallback(GLFWwindow* window, double xPos, double yPos) + auto Window::glfw_cursor_pos_callback(GLFWwindow* window, double x_pos, double y_pos) -> void { Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window)); - MouseMovedEvent event((float)xPos, (float)yPos); - win->m_EventHandler.OnEvent(event); + MouseMovedEvent event((float)x_pos, (float)y_pos); + win->m_event_handler.on_event(event); } -}
\ No newline at end of file +} diff --git a/src/Core/Window.h b/src/Core/Window.h index f450bad..9b7d7b9 100644 --- a/src/Core/Window.h +++ b/src/Core/Window.h @@ -1,7 +1,7 @@ #pragma once -#include "Event.h" -#include "Log.h" +#include "event.h" +#include "log.h" #include <GLFW/glfw3.h> #include <imgui.h> @@ -18,59 +18,61 @@ namespace Donut Window(const std::string& title, int width, int height); ~Window(); - bool ShouldClose() const; - void OnUpdate() const; + auto should_close() const -> bool; + auto on_update() const -> void; - void SetEventCallback(const EventCallbackFn& callback) + auto set_event_callback(const EventCallbackFn& callback) -> void { - m_EventHandler.SetEventCallback(callback); + m_event_handler.set_event_callback(callback); } - EventHandler& GetEventHandler() { return m_EventHandler; } + auto get_event_handler() -> EventHandler& { return m_event_handler; } - unsigned int GetWidth() const { return m_Width; } - unsigned int GetHeight() const { return m_Height; } + auto get_width() const -> unsigned int { return m_width; } + auto get_height() const -> unsigned int { return m_height; } - void* GetNativeWindow() const { return m_Window; } + auto get_native_window() const -> void* { return m_window; } + + auto set_cursor_locked(bool locked) -> void; + auto set_cursor_visible(bool visible) -> void; + auto is_cursor_locked() const -> bool { return m_cursor_locked; } + auto is_cursor_visible() const -> bool { return m_cursor_visible; } + + auto init_im_gui() -> void; + auto begin_im_gui_frame() -> void; + auto end_im_gui_frame() -> void; - void SetCursorLocked(bool locked); - void SetCursorVisible(bool visible); - bool IsCursorLocked() const { return m_CursorLocked; } - bool IsCursorVisible() const { return m_CursorVisible; } - - void InitImGui(); - void BeginImGuiFrame(); - void EndImGuiFrame(); private: - void Init(); - void Shutdown(); + auto init() -> void; + auto shutdown() -> void; + + auto setup_im_gui_fonts() -> void; + auto shutdown_im_gui() -> void; + + static auto glfw_error_callback(int error, const char* description) -> void; + static auto glfw_window_close_callback(GLFWwindow* window) -> void; + static auto glfw_window_size_callback(GLFWwindow* window, int width, int height) -> void; + static auto glfw_window_focus_callback(GLFWwindow* window, int focused) -> void; + static auto glfw_window_pos_callback(GLFWwindow* window, int xpos, int ypos) -> void; + static auto glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) -> void; + static auto glfw_char_callback(GLFWwindow* window, unsigned int keycode) -> void; + static auto glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) -> void; + static auto glfw_mouse_scroll_callback(GLFWwindow* window, double x_offset, double y_offset) -> void; + static auto glfw_cursor_pos_callback(GLFWwindow* window, double x_pos, double y_pos) -> void; - void SetupImGuiFonts(); - void ShutdownImGui(); - - static void GLFWErrorCallback(int error, const char* description); - static void GLFWWindowCloseCallback(GLFWwindow* window); - static void GLFWWindowSizeCallback(GLFWwindow* window, int width, int height); - static void GLFWWindowFocusCallback(GLFWwindow* window, int focused); - static void GLFWWindowPosCallback(GLFWwindow* window, int xpos, int ypos); - static void GLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); - static void GLFWCharCallback(GLFWwindow* window, unsigned int keycode); - static void GLFWMouseButtonCallback(GLFWwindow* window, int button, int action, int mods); - static void GLFWMouseScrollCallback(GLFWwindow* window, double xOffset, double yOffset); - static void GLFWCursorPosCallback(GLFWwindow* window, double xPos, double yPos); private: - GLFWwindow* m_Window; - EventHandler m_EventHandler; + GLFWwindow* m_window; + EventHandler m_event_handler; + + std::string m_title; + unsigned int m_width; + unsigned int m_height; + bool m_is_closed; + bool m_cursor_locked = false; + bool m_cursor_visible = true; - std::string m_Title; - unsigned int m_Width; - unsigned int m_Height; - bool m_IsClosed; - bool m_CursorLocked = false; - bool m_CursorVisible = true; - - ImFont* m_MainFont = nullptr; - ImFont* m_SmallFont = nullptr; - ImFont* m_LargeFont = nullptr; + ImFont* m_main_font = nullptr; + ImFont* m_small_font = nullptr; + ImFont* m_large_font = nullptr; }; -}
\ No newline at end of file +} |
