From a504b5c8a6b6687864234f79e6e03586b90d0ecd Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 18 Aug 2026 15:32:46 +0200 Subject: chore: clangd --- compile_flags.txt | 15 ++++++++ src/engine/engine.cpp | 104 +++++++++++++++++++++++++------------------------- 2 files changed, 67 insertions(+), 52 deletions(-) create mode 100644 compile_flags.txt diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..b39cf53 --- /dev/null +++ b/compile_flags.txt @@ -0,0 +1,15 @@ +-std=c++20 +-Isrc +-IVendor/glm +-IVendor/glfw/include +-IVendor/glad/include +-IVendor/imgui +-IVendor/imgui/backends +-IVendor/ImGuizmo +-IVendor/toml11/include +-IVendor/json/single_include +-IVendor/stb +-DDONUT_MACOS +-D_CRT_SECURE_NO_WARNINGS +-DGLFW_INCLUDE_NONE +-DDONUT_DEBUG diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index bdd468b..d6e2723 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -21,14 +21,14 @@ namespace Donut { m_width = 1280; m_height = 720; - + m_camera.set_camera_mode(CameraMode::Orbital); m_camera.set_orbital_radius(1e11); m_camera.set_orbital_limits(1e9, 1e13); m_camera.set_orbital_speed(0.01f); m_camera.set_zoom_speed(1e10f); - - m_objects = + + m_objects = { { glm::vec4(0.00f, 0.00f, 0.00f, m_sag_a.m_rs), glm::vec4(0, 0, 0, 1), static_cast(m_sag_a.m_mass) } }; @@ -36,7 +36,7 @@ namespace Donut m_compute_program = Ref(Shader::create("assets/shaders/geodesic.glsl")); m_shader_program = Ref(Shader::create("assets/shaders/textured_quad.glsl")); m_blur_shader = Ref(Shader::create("assets/shaders/blur.glsl")); - + auto& hdri_manager = HDRIManager::get(); m_hdri_environment = hdri_manager.get_current_hdri(); if (!m_hdri_environment) @@ -46,15 +46,15 @@ namespace Donut if (!m_hdri_environment) DONUT_WARN("Failed to load default HDRI, using fallback"); } - + m_camera_ubo = UniformBuffer::create(128, 1); m_disk_ubo = UniformBuffer::create(sizeof(float) * 5, 2); - + uint32_t obj_ubo_size = sizeof(int) + 3 * sizeof(float) + 16 * (sizeof(glm::vec4) + sizeof(glm::vec4)) + 16 * sizeof(float); m_objects_ubo = UniformBuffer::create(obj_ubo_size, 3); - + m_simulation_ubo = UniformBuffer::create(sizeof(int) * 2 + sizeof(float) * 2, 4); auto result = quad_vao(); @@ -83,18 +83,18 @@ namespace Donut { update_compute_dimensions(); } - + void Engine::set_window_dimensions(int width, int height) { int old_width = m_width; int old_height = m_height; int old_compute_height = m_compute_height; - + m_width = width; m_height = height; - - if (old_width != m_width || - old_height != m_height || + + if (old_width != m_width || + old_height != m_height || old_compute_height != m_compute_height) update_compute_dimensions(); } @@ -113,7 +113,7 @@ namespace Donut void Engine::draw_full_screen_quad() { RenderCommand::set_viewport(0, 0, m_width, m_height); - + m_shader_program->bind(); m_quad_vao->bind(); @@ -128,7 +128,7 @@ namespace Donut void Engine::draw_blur_pass() { RenderCommand::set_viewport(0, 0, m_width, m_height); - + m_blur_shader->bind(); m_quad_vao->bind(); @@ -309,7 +309,7 @@ namespace Donut double Gforce = (G * obj.m_mass * obj2.m_mass) / (distance * distance); double acc1 = Gforce / obj.m_mass; std::vector acc = {direction[0] * acc1, direction[1] * acc1, direction[2] * acc1}; - + if (m_gravity) { obj.m_velocity.x += static_cast(acc[0]); @@ -350,7 +350,7 @@ namespace Donut std::pair, Ref> Engine::quad_vao() { - float quad_vertices[] = + float quad_vertices[] = { -1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, @@ -369,24 +369,24 @@ namespace Donut auto vertex_array = Ref(VertexArray::create()); vertex_array->add_vertex_buffer(vertex_buffer); auto texture = Texture2D::create(get_compute_width(), m_compute_height); - + return { vertex_array, texture }; } - + void Engine::load_objects_from_scene(const std::vector& objects) { m_objects.clear(); m_objects.push_back( - { - glm::vec4(0.00f, 0.00f, 0.00f, m_sag_a.m_rs), - glm::vec4(0, 0, 0, 1), - static_cast(m_sag_a.m_mass) + { + glm::vec4(0.00f, 0.00f, 0.00f, m_sag_a.m_rs), + glm::vec4(0, 0, 0, 1), + static_cast(m_sag_a.m_mass) }); - + for (const auto& obj : objects) { ObjectData engine_obj; - + float scale_factor = 1e10f; engine_obj.m_pos_radius = glm::vec4 ( @@ -395,30 +395,30 @@ namespace Donut obj.m_centre.z * scale_factor, obj.m_radius * scale_factor ); - + engine_obj.m_color = glm::vec4(obj.m_material.m_color, 1.0f); - + float volume = (4.0f / 3.0f) * 3.14159f * engine_obj.m_pos_radius.w * engine_obj.m_pos_radius.w * engine_obj.m_pos_radius.w; float density = 1e12f; engine_obj.m_mass = volume * density; engine_obj.m_velocity = glm::vec3(0.0f, 0.0f, 0.0f); - + m_objects.push_back(engine_obj); } - + DONUT_INFO("Loaded {} objects from WorldBuilder scene (scaled up by {})", objects.size(), 1e10f); print_object_info(); } - + void Engine::print_object_info() const { DONUT_INFO("=== Object Information ==="); DONUT_INFO("Total objects: {}", m_objects.size()); - + for (size_t i = 0; i < m_objects.size(); ++i) { const auto& obj = m_objects[i]; - DONUT_INFO("Object {}: Pos=({}, {}, {}), Radius={}, Mass={}, Color=({}, {}, {})", + DONUT_INFO("Object {}: Pos=({}, {}, {}), Radius={}, Mass={}, Color=({}, {}, {})", i, obj.m_pos_radius.x, obj.m_pos_radius.y, obj.m_pos_radius.z, obj.m_pos_radius.w, @@ -426,7 +426,7 @@ namespace Donut obj.m_color.x, obj.m_color.y, obj.m_color.z ); } - DONUT_INFO("Camera position: ({}, {}, {})", + DONUT_INFO("Camera position: ({}, {}, {})", m_camera.get_orbital_position().x, m_camera.get_orbital_position().y, m_camera.get_orbital_position().z @@ -434,52 +434,52 @@ namespace Donut DONUT_INFO("Camera radius: {}", m_camera.get_orbital_radius()); DONUT_INFO("========================"); } - + void Engine::export_high_res_frame(const std::string& filename, int width, int height) { DONUT_INFO("Exporting high-resolution frame: {}x{} to {}", width, height, filename); - + if (width <= 0 || height <= 0) { DONUT_ERROR("Invalid dimensions for export: {}x{}", width, height); return; } - + if (filename.empty()) { DONUT_ERROR("Invalid filename for export"); return; } - + int original_width = m_width; int original_height = m_height; int original_compute_height = m_compute_height; - + m_width = width; m_height = height; m_compute_height = height; - + int compute_height = height; int compute_width = (width * compute_height) / height; - + if (compute_width <= 0 || compute_height <= 0) { DONUT_ERROR("Invalid compute dimensions: {}x{}", compute_width, compute_height); return; } - + FramebufferSpecification fb_spec; fb_spec.Width = width; fb_spec.Height = height; fb_spec.attachments = { FramebufferTextureFormat::RGBA8 }; - + auto high_res_framebuffer = Framebuffer::create(fb_spec); if (!high_res_framebuffer) { DONUT_ERROR("Failed to create high-resolution framebuffer"); return; } - + auto high_res_texture = Texture2D::create(compute_width, compute_height); if (!high_res_texture) { @@ -540,18 +540,18 @@ namespace Donut m_shader_program->bind(); m_quad_vao->bind(); - + high_res_texture->bind(0); m_shader_program->set_int("u_ScreenTexture", 0); - + RenderCommand::disable_depth_test(); RenderCommand::draw_arrays(6); RenderCommand::enable_depth_test(); - + std::vector pixels(width * height * 4); DONUT_INFO("Reading {} pixels from framebuffer...", width * height); RenderCommand::read_pixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data()); - + DONUT_INFO("Flipping image vertically..."); std::vector flipped_pixels(width * height * 4); for (int y = 0; y < height; ++y) @@ -566,22 +566,22 @@ namespace Donut flipped_pixels[dst_index + 3] = pixels[src_index + 3]; } } - + DONUT_INFO("Saving PNG file: {}...", filename); int result = stbi_write_png(filename.c_str(), width, height, 4, flipped_pixels.data(), width * 4); - + if (result) DONUT_INFO("Successfully exported high-resolution frame to: {}", filename); else DONUT_ERROR("Failed to export high-resolution frame to: {}", filename); - + high_res_framebuffer->unbind(); - + m_width = original_width; m_height = original_height; m_compute_height = original_compute_height; - + RenderCommand::set_viewport(0, 0, original_width, original_height); } - + } -- cgit v1.3