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/Engine/Engine.h | |
| parent | e3abaaf59777258ba06705135a0cafcb5918ad12 (diff) | |
[chore]: MASSIVE refactor + more vulkan bs
Diffstat (limited to 'src/Engine/Engine.h')
| -rw-r--r-- | src/Engine/Engine.h | 210 |
1 files changed, 105 insertions, 105 deletions
diff --git a/src/Engine/Engine.h b/src/Engine/Engine.h index a4cbdc7..c7d02b5 100644 --- a/src/Engine/Engine.h +++ b/src/Engine/Engine.h @@ -8,15 +8,15 @@ #include <chrono> #include <cmath> -#include "Core/Camera.h" -#include "Object.h" +#include "core/camera.h" +#include "object.h" -#include "Rendering/Renderer.h" -#include "Rendering/Shader.h" -#include "Rendering/VertexArray.h" -#include "Rendering/Texture.h" -#include "Rendering/UniformBuffer.h" -#include "Rendering/TextureManager.h" +#include "rendering/renderer.h" +#include "rendering/shader.h" +#include "rendering/vertex_array.h" +#include "rendering/texture.h" +#include "rendering/uniform_buffer.h" +#include "rendering/texture_manager.h" #include <GLFW/glfw3.h> #include <glm/glm.hpp> @@ -30,33 +30,33 @@ namespace Donut struct BlackHole { - glm::vec3 m_Position; - double m_Mass; - double m_Radius; - double m_Rs; + glm::vec3 m_position; + double m_mass; + double m_radius; + double m_rs; BlackHole(glm::vec3 pos, float mass) - : m_Position(pos), m_Mass(mass) + : m_position(pos), m_mass(mass) { - m_Rs = 2.0 * G * m_Mass / (c * c); + m_rs = 2.0 * G * m_mass / (c * c); } - bool Intercept(float px, float py, float pz) const + bool intercept(float px, float py, float pz) const { - double dx = double(px) - double(m_Position.x); - double dy = double(py) - double(m_Position.y); - double dz = double(pz) - double(m_Position.z); + double dx = double(px) - double(m_position.x); + double dy = double(py) - double(m_position.y); + double dz = double(pz) - double(m_position.z); double dist2 = dx * dx + dy * dy + dz * dz; - return dist2 < m_Rs * m_Rs; + return dist2 < m_rs * m_rs; } }; struct ObjectData { - glm::vec4 m_PosRadius; - glm::vec4 m_Color; - float m_Mass; - glm::vec3 m_Velocity = glm::vec3(0.0f, 0.0f, 0.0f); + glm::vec4 m_pos_radius; + glm::vec4 m_color; + float m_mass; + glm::vec3 m_velocity = glm::vec3(0.0f, 0.0f, 0.0f); }; class Engine @@ -65,120 +65,120 @@ namespace Donut Engine(); ~Engine() = default; - void DrawFullScreenQuad(); - void DrawBlurPass(); - void DispatchCompute(const Camera& cam); - void UploadCameraUBO(const Camera& cam); - void UploadObjectsUBO(const std::vector<ObjectData>& objs); - void UploadDiskUBO(); - void UploadSimulationUBO(); - void RenderScene(); - void UpdatePhysics(float deltaTime); - void UpdateWindowDimensions(); - void SetWindowDimensions(int width, int height); + auto draw_full_screen_quad() -> void; + auto draw_blur_pass() -> void; + auto dispatch_compute(const Camera& cam) -> void; + auto upload_camera_ubo(const Camera& cam) -> void; + auto upload_objects_ubo(const std::vector<ObjectData>& objs) -> void; + auto upload_disk_ubo() -> void; + auto upload_simulation_ubo() -> void; + auto render_scene() -> void; + auto update_physics(float delta_time) -> void; + auto update_window_dimensions() -> void; + auto set_window_dimensions(int width, int height) -> void; - int GetWidth() const { return m_Width; } - int GetHeight() const { return m_Height; } + auto get_width() const -> int { return m_width; } + auto get_height() const -> int { return m_height; } - std::vector<ObjectData>& GetObjects() { return m_Objects; } - BlackHole& GetSagA() { return m_SagA; } - Camera& GetCamera() { return m_Camera; } - bool& GetGravity() { return m_Gravity; } + auto get_objects() -> std::vector<ObjectData>& { return m_objects; } + auto get_sag_a() -> BlackHole& { return m_sag_a; } + auto get_camera() -> Camera& { return m_camera; } + auto get_gravity() -> bool& { return m_gravity; } - void UpdatePerformance(float deltaTime); - void SetTargetFPS(int fps) { m_TargetFPS = fps; } - int GetTargetFPS() const { return m_TargetFPS; } - float GetCurrentFPS() const { return m_CurrentFPS; } - void SetComputeHeight(int height) + auto update_performance(float delta_time) -> void; + auto set_target_fps(int fps) -> void { m_target_fps = fps; } + auto get_target_fps() const -> int { return m_target_fps; } + auto get_current_fps() const -> float { return m_current_fps; } + void set_compute_height(int height) { #ifdef __APPLE__ // Without compute shaders the geodesic pass runs as a tiled - // fragment shader (see DrawGeodesicPass), so very high working + // fragment shader (see draw_geodesic_pass), so very high working // resolutions make each frame take many seconds. Cap it on macOS. if (height > 256) height = 256; #endif - m_ComputeHeight = height; + m_compute_height = height; } - int GetComputeHeight() const { return m_ComputeHeight; } - int GetComputeWidth() const { return (m_Width * m_ComputeHeight) / m_Height; } - void UpdateComputeDimensions(); + auto get_compute_height() const -> int { return m_compute_height; } + auto get_compute_width() const -> int { return (m_width * m_compute_height) / m_height; } + auto update_compute_dimensions() -> void; - int GetMaxStepsMoving() const { return m_MaxStepsMoving; } - int GetMaxStepsStatic() const { return m_MaxStepsStatic; } - float GetEarlyExitDistance() const { return m_EarlyExitDistance; } - void SetMaxStepsMoving(int steps) { m_MaxStepsMoving = steps; } - void SetMaxStepsStatic(int steps) { m_MaxStepsStatic = steps; } - void SetEarlyExitDistance(float distance) { m_EarlyExitDistance = distance; } + auto get_max_steps_moving() const -> int { return m_max_steps_moving; } + auto get_max_steps_static() const -> int { return m_max_steps_static; } + auto get_early_exit_distance() const -> float { return m_early_exit_distance; } + auto set_max_steps_moving(int steps) -> void { m_max_steps_moving = steps; } + auto set_max_steps_static(int steps) -> void { m_max_steps_static = steps; } + auto set_early_exit_distance(float distance) -> void { m_early_exit_distance = distance; } - float GetDiskThickness() const { return m_DiskThickness; } - void SetDiskThickness(float thickness) { m_DiskThickness = thickness; } + auto get_disk_thickness() const -> float { return m_disk_thickness; } + auto set_disk_thickness(float thickness) -> void { m_disk_thickness = thickness; } - float GetDiskDensity() const { return m_DiskDensity; } - void SetDiskDensity(float density) { m_DiskDensity = density; } + auto get_disk_density() const -> float { return m_disk_density; } + auto set_disk_density(float density) -> void { m_disk_density = density; } - float GetRotationSpeed() const { return m_RotationSpeed; } - void SetRotationSpeed(float speed) { m_RotationSpeed = speed; } + auto get_rotation_speed() const -> float { return m_rotation_speed; } + auto set_rotation_speed(float speed) -> void { m_rotation_speed = speed; } - float GetBlurStrength() const { return m_BlurStrength; } - void SetBlurStrength(float strength) { m_BlurStrength = strength; } + auto get_blur_strength() const -> float { return m_blur_strength; } + auto set_blur_strength(float strength) -> void { m_blur_strength = strength; } - float GetGlowIntensity() const { return m_GlowIntensity; } - void SetGlowIntensity(float intensity) { m_GlowIntensity = intensity; } + auto get_glow_intensity() const -> float { return m_glow_intensity; } + auto set_glow_intensity(float intensity) -> void { m_glow_intensity = intensity; } - void LoadObjectsFromScene(const std::vector<Donut::Object>& objects); - void ExportHighResFrame(const std::string& filename, int width = 4096, int height = 3072); - void PrintObjectInfo() const; + auto load_objects_from_scene(const std::vector<Donut::Object>& objects) -> void; + auto export_high_res_frame(const std::string& filename, int width = 4096, int height = 3072) -> void; + auto print_object_info() const -> void; - void SetHDRIEnvironment(Ref<CubemapTexture> hdri) { m_HDRIEnvironment = hdri; } - Ref<CubemapTexture> GetHDRIEnvironment() const { return m_HDRIEnvironment; } + auto set_hdri_environment(Ref<CubemapTexture> hdri) -> void { m_hdri_environment = hdri; } + auto get_hdri_environment() const -> Ref<CubemapTexture> { return m_hdri_environment; } private: - Ref<Shader> CreateComputeProgram(const char* path); + auto create_compute_program(const char* path) -> Ref<Shader>; std::pair<Ref<VertexArray>, Ref<Texture2D>> QuadVAO(); // Draws the bound geodesic shader over a cw x ch target. On macOS this // is split into scissored tiles (with a flush each) so no single GPU // submission trips the OS watchdog; elsewhere it is one fast draw. - void DrawGeodesicPass(int cw, int ch); + auto draw_geodesic_pass(int cw, int ch) -> void; private: - Ref<VertexArray> m_QuadVAO; - Ref<Texture2D> m_Texture; - Ref<CubemapTexture> m_HDRIEnvironment; - Ref<Shader> m_ShaderProgram; - Ref<Shader> m_ComputeProgram; - Ref<Shader> m_BlurShader; - Ref<UniformBuffer> m_CameraUBO; - Ref<UniformBuffer> m_DiskUBO; - Ref<UniformBuffer> m_ObjectsUBO; - Ref<UniformBuffer> m_SimulationUBO; + Ref<VertexArray> m_quad_vao; + Ref<Texture2D> m_texture; + Ref<CubemapTexture> m_hdri_environment; + Ref<Shader> m_shader_program; + Ref<Shader> m_compute_program; + Ref<Shader> m_blur_shader; + Ref<UniformBuffer> m_camera_ubo; + Ref<UniformBuffer> m_disk_ubo; + Ref<UniformBuffer> m_objects_ubo; + Ref<UniformBuffer> m_simulation_ubo; - // FBO used to render the geodesic pass into m_Texture. The geodesic + // FBO used to render the geodesic pass into m_texture. The geodesic // shader is a fragment shader (macOS has no compute), so it draws a // fullscreen quad into this framebuffer instead of dispatching compute. - uint32_t m_GeodesicFBO = 0; + uint32_t m_geodesic_fbo = 0; - int m_Width; - int m_Height; - float m_Width_f = 100.0f*1e10f; - float m_Height_f = 75.0f*1e10f; + int m_width; + int m_height; + float m_width_f = 100.0f*1e10f; + float m_height_f = 75.0f*1e10f; - int m_TargetFPS = 60; - float m_CurrentFPS = 60.0f; - float m_LastFrameTime = 0.0f; - int m_ComputeHeight = 150; + int m_target_fps = 60; + float m_current_fps = 60.0f; + float m_last_frame_time = 0.0f; + int m_compute_height = 150; - std::vector<ObjectData> m_Objects; - BlackHole m_SagA; - Camera m_Camera; - bool m_Gravity = false; + std::vector<ObjectData> m_objects; + BlackHole m_sag_a; + Camera m_camera; + bool m_gravity = false; - int m_MaxStepsMoving = 60000; - int m_MaxStepsStatic = 30000; - float m_EarlyExitDistance = 5.0e11f; + int m_max_steps_moving = 60000; + int m_max_steps_static = 30000; + float m_early_exit_distance = 5.0e11f; - float m_DiskThickness = 0.1f; - float m_DiskDensity = 0.1f; - float m_RotationSpeed = 1.0f; - float m_BlurStrength = 2.0f; - float m_GlowIntensity = 0.1f; + float m_disk_thickness = 0.1f; + float m_disk_density = 0.1f; + float m_rotation_speed = 1.0f; + float m_blur_strength = 2.0f; + float m_glow_intensity = 0.1f; }; }; |
