hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-08-13 18:39:13 +0200
committerhachem <im@hachem.wtf>2025-08-13 18:39:13 +0200
commit23086a5d33acc66414f1169bf22abe78b3383f94 (patch)
treea895c3e3ab8074118a84aada97ea990b60fba556 /src/core
parent2d8f706efe6e0a02b3238c2f22e7cdce620e9807 (diff)
fix: more consistent formatting
Diffstat (limited to 'src/core')
-rw-r--r--src/core/application.h41
-rw-r--r--src/core/camera.cpp16
-rw-r--r--src/core/camera.h22
-rw-r--r--src/core/event.h26
-rw-r--r--src/core/window.cpp44
-rw-r--r--src/core/window.h10
6 files changed, 74 insertions, 85 deletions
diff --git a/src/core/application.h b/src/core/application.h
index 713ecba..e5a983a 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -6,14 +6,11 @@
#include <memory>
#include <functional>
-namespace Donut
-{
- class VertexArray;
- class VertexBuffer;
- class IndexBuffer;
- class Shader;
- class Texture2D;
-};
+#include "rendering/vertex_array.h"
+#include "rendering/vertex_buffer.h"
+#include "rendering/index_buffer.h"
+#include "rendering/shader.h"
+#include "rendering/texture.h"
namespace Donut
{
@@ -41,29 +38,29 @@ namespace Donut
bool m_running;
bool m_minimized;
- std::shared_ptr<VertexArray> m_vertex_array;
+ std::shared_ptr<VertexArray> m_vertex_array;
std::shared_ptr<VertexBuffer> m_vertex_buffer;
- std::shared_ptr<IndexBuffer> m_index_buffer;
- std::shared_ptr<Shader> m_shader;
- std::shared_ptr<Texture2D> m_texture;
+ std::shared_ptr<IndexBuffer> m_index_buffer;
+ std::shared_ptr<Shader> m_shader;
+ std::shared_ptr<Texture2D> m_texture;
- std::shared_ptr<Shader> m_compute_shader;
+ std::shared_ptr<Shader> m_compute_shader;
std::shared_ptr<Texture2D> m_processed_texture;
float m_compute_brightness;
float m_compute_contrast;
float m_compute_saturation;
- bool m_use_compute_shader;
+ bool m_use_compute_shader;
std::unique_ptr<Camera> m_camera;
- bool m_keys[1024] = { false };
- bool m_first_mouse = true;
- float m_last_x = 0.0f;
- float m_last_y = 0.0f;
- float m_delta_time = 0.0f;
- float m_last_frame = 0.0f;
- bool m_mouse_dragging = false;
- float m_texture_time = 0.0f;
+ bool m_keys[1024] = { false };
+ bool m_first_mouse = true;
+ float m_last_x = 0.0f;
+ float m_last_y = 0.0f;
+ float m_delta_time = 0.0f;
+ float m_last_frame = 0.0f;
+ bool m_mouse_dragging = false;
+ float m_texture_time = 0.0f;
static Application* s_instance;
};
diff --git a/src/core/camera.cpp b/src/core/camera.cpp
index bad2919..06866e4 100644
--- a/src/core/camera.cpp
+++ b/src/core/camera.cpp
@@ -28,27 +28,27 @@ namespace Donut
void Camera::recalculate_view_matrix()
{
float pitch = glm::radians(m_rotation.x);
- float yaw = glm::radians(m_rotation.y);
- float roll = glm::radians(m_rotation.z);
+ 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 front = glm::normalize(direction);
glm::vec3 world_up(0.0f, 1.0f, 0.0f);
+ glm::vec3 front = glm::normalize(direction);
glm::vec3 right = glm::normalize(glm::cross(front, world_up));
- glm::vec3 up = glm::normalize(glm::cross(right, front));
+ glm::vec3 up = glm::normalize(glm::cross(right, front));
- m_view_matrix = glm::lookAt(m_position, m_position + front, up);
+ m_view_matrix = glm::lookAt(m_position, m_position + front, up);
m_view_projection_matrix = m_projection_matrix * m_view_matrix;
}
glm::vec3 Camera::get_forward_direction() const
{
float pitch = glm::radians(m_rotation.x);
- float yaw = glm::radians(m_rotation.y);
+ float yaw = glm::radians(m_rotation.y);
glm::vec3 direction;
direction.x = cos(yaw) * cos(pitch);
@@ -69,10 +69,6 @@ namespace Donut
return glm::normalize(glm::cross(get_right_direction(), get_forward_direction()));
}
- void Camera::on_update(float delta_time)
- {
- }
-
void Camera::on_mouse_move(float x_offset, float y_offset, bool constrain_pitch)
{
x_offset *= m_mouse_sensitivity;
diff --git a/src/core/camera.h b/src/core/camera.h
index 200c4b0..25f7e2a 100644
--- a/src/core/camera.h
+++ b/src/core/camera.h
@@ -27,8 +27,6 @@ namespace Donut
const glm::mat4& get_view_projection_matrix() const { return m_view_projection_matrix; }
void set_projection(float fov, float aspect_ratio, float near_plane, float far_plane);
-
- void on_update(float delta_time);
void on_mouse_move(float x_offset, float y_offset, bool constrain_pitch = true);
void move_forward(float delta_time);
@@ -39,10 +37,10 @@ namespace Donut
void move_down(float delta_time);
void set_mouse_sensitivity(float sensitivity) { m_mouse_sensitivity = sensitivity; }
- float get_mouse_sensitivity() const { return m_mouse_sensitivity; }
+ float get_mouse_sensitivity() const { return m_mouse_sensitivity; }
- void set_movement_speed(float speed) { m_movement_speed = speed; }
- float get_movement_speed() const { return m_movement_speed; }
+ void set_movement_speed(float speed) { m_movement_speed = speed; }
+ float get_movement_speed() const { return m_movement_speed; }
private:
void recalculate_view_matrix();
@@ -55,15 +53,15 @@ namespace Donut
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_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_near_plane = 0.1f;
+ float m_far_plane = 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_movement_speed = 5.0f;
+ bool m_first_mouse = true;
+ float m_last_x = 0.0f;
+ float m_last_y = 0.0f;
};
}
diff --git a/src/core/event.h b/src/core/event.h
index e4d1be1..a1e30e9 100644
--- a/src/core/event.h
+++ b/src/core/event.h
@@ -156,7 +156,8 @@ namespace Donut
EventCategoryInput; }
protected:
- KeyEvent(int keycode) : m_key_code(keycode) { }
+ KeyEvent(int keycode)
+ : m_key_code(keycode) { }
int m_key_code;
};
@@ -185,7 +186,8 @@ namespace Donut
: public KeyEvent
{
public:
- KeyReleasedEvent(int keycode) : KeyEvent(keycode) { }
+ KeyReleasedEvent(int keycode)
+ : KeyEvent(keycode) { }
std::string to_string() const override
{
@@ -199,7 +201,8 @@ namespace Donut
: public KeyEvent
{
public:
- KeyTypedEvent(int keycode) : KeyEvent(keycode) { }
+ KeyTypedEvent(int keycode)
+ : KeyEvent(keycode) { }
std::string to_string() const override
{
@@ -262,7 +265,8 @@ namespace Donut
EventCategoryInput; }
protected:
- MouseButtonEvent(int button) : m_button(button) { }
+ MouseButtonEvent(int button)
+ : m_button(button) { }
int m_button;
};
@@ -270,7 +274,8 @@ namespace Donut
: public MouseButtonEvent
{
public:
- MouseButtonPressedEvent(int button) : MouseButtonEvent(button) { }
+ MouseButtonPressedEvent(int button)
+ : MouseButtonEvent(button) { }
std::string to_string() const override
{
@@ -284,7 +289,8 @@ namespace Donut
: public MouseButtonEvent
{
public:
- MouseButtonReleasedEvent(int button) : MouseButtonEvent(button) { }
+ MouseButtonReleasedEvent(int button)
+ : MouseButtonEvent(button) { }
std::string to_string() const override
{
@@ -297,7 +303,8 @@ 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)
@@ -322,7 +329,10 @@ namespace Donut
EventHandler() = default;
~EventHandler() = default;
- void set_event_callback(const EventCallbackFn& callback) { m_event_callback = callback; }
+ void set_event_callback(const EventCallbackFn& callback)
+ {
+ m_event_callback = callback;
+ }
void on_event(Event& event)
{
diff --git a/src/core/window.cpp b/src/core/window.cpp
index 26c134c..9605f8c 100644
--- a/src/core/window.cpp
+++ b/src/core/window.cpp
@@ -1,11 +1,10 @@
#include "window.h"
#include <cstdint>
#include <iostream>
-#include <glad/glad.h>
namespace Donut
{
- static bool s_glfw_initialized = false;
+ static bool s_glfw_initialized = false;
static uint32_t s_glfw_window_count = 0;
Window::Window(const std::string& title, int width, int height)
@@ -43,26 +42,18 @@ namespace Donut
}
glfwMakeContextCurrent(m_window);
-
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
- {
- std::cout << "Failed to initialize GLAD!" << std::endl;
- glfwTerminate();
- return;
- }
-
glfwSetWindowUserPointer(m_window, this);
glfwSetErrorCallback(glfw_error_callback);
glfwSetWindowCloseCallback(m_window, glfw_window_close_callback);
- glfwSetWindowSizeCallback(m_window, glfw_window_size_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);
+ 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);
+ glfwSetScrollCallback(m_window, glfw_mouse_scroll_callback);
+ glfwSetCursorPosCallback(m_window, glfw_cursor_pos_callback);
s_glfw_window_count++;
}
@@ -93,19 +84,15 @@ namespace Donut
void Window::set_cursor_locked(bool locked)
{
m_cursor_locked = locked;
- if (locked)
- glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
- else
- glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+ glfwSetInputMode(m_window, GLFW_CURSOR, locked ?
+ GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
}
void Window::set_cursor_visible(bool visible)
{
m_cursor_visible = visible;
- if (visible)
- glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
- else
- glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+ glfwSetInputMode(m_window, GLFW_CURSOR, visible ?
+ GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN);
}
void Window::glfw_error_callback(int error, const char* description)
@@ -153,7 +140,8 @@ namespace Donut
win->m_event_handler.on_event(event);
}
- void Window::glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
+ void Window::glfw_key_callback(GLFWwindow* window, int key, int scancode,
+ int action, int mods)
{
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
@@ -184,7 +172,8 @@ namespace Donut
win->m_event_handler.on_event(event);
}
- void Window::glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
+ void Window::glfw_mouse_button_callback(GLFWwindow* window, int button,
+ int action, int mods)
{
Window* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
@@ -199,8 +188,7 @@ namespace Donut
{
MouseButtonReleasedEvent event(button);
win->m_event_handler.on_event(event);
- break;
- }
+ } break;
}
}
diff --git a/src/core/window.h b/src/core/window.h
index d541b54..cf80cac 100644
--- a/src/core/window.h
+++ b/src/core/window.h
@@ -24,14 +24,14 @@ namespace Donut
EventHandler& get_event_handler() { return m_event_handler; }
- unsigned int get_width() const { return m_width; }
+ unsigned int get_width() const { return m_width; }
unsigned int get_height() const { return m_height; }
- void* get_native_window() const { return m_window; }
+ void* get_native_window() const { return m_window; }
void set_cursor_locked(bool locked);
void set_cursor_visible(bool visible);
- bool is_cursor_locked() const { return m_cursor_locked; }
+ bool is_cursor_locked() const { return m_cursor_locked; }
bool is_cursor_visible() const { return m_cursor_visible; }
private:
void init();
@@ -48,10 +48,10 @@ namespace Donut
static void glfw_mouse_scroll_callback(GLFWwindow* window, double x_offset, double y_offset);
static void glfw_cursor_pos_callback(GLFWwindow* window, double x_pos, double y_pos);
private:
- GLFWwindow* m_window;
+ GLFWwindow* m_window;
EventHandler m_event_handler;
- std::string m_title;
+ std::string m_title;
unsigned int m_width;
unsigned int m_height;
bool m_is_closed;