From cd54c6eec9d3dce5fd8521429cf28616d0e9fc95 Mon Sep 17 00:00:00 2001 From: Mag1str02 Date: Tue, 19 Nov 2024 22:20:44 +0300 Subject: [PATCH 1/7] Enabled extra warnings and fixed all of them... --- CMake/Compiler.cmake | 10 +++++- DummyEditor/EditorLayer.cpp | 4 +-- DummyEditor/ImGuiUtils/ImGuiManager.cpp | 5 ++- DummyEditor/ImGuiUtils/ImGuiUtils.cpp | 6 ++-- DummyEditor/Panels/InspectorPanel.cpp | 34 +++++++++---------- DummyEditor/Panels/InspectorPanel.h | 4 +-- .../Platform/Windows/Scripting/Compiler.cpp | 2 +- DummyEditor/Scripting/ScriptManager.cpp | 4 +-- DummyEditor/Scripting/ScriptManager.h | 2 +- DummyEngine/CMakeLists.txt | 1 + DummyEngine/Core/Animations/Animator.cpp | 4 +-- DummyEngine/Core/Animations/Bone.cpp | 28 +++++++-------- DummyEngine/Core/Animations/Bone.h | 14 ++++---- DummyEngine/Core/Application/Application.cpp | 11 +++--- DummyEngine/Core/Application/Initializer.cpp | 2 +- DummyEngine/Core/Application/Input.cpp | 6 ++-- DummyEngine/Core/Application/Layer.h | 4 +-- DummyEngine/Core/Application/Window.cpp | 9 ++--- DummyEngine/Core/Application/Window.h | 2 +- DummyEngine/Core/Console/Console.cpp | 4 +-- DummyEngine/Core/Console/ConsoleLayer.cpp | 2 +- DummyEngine/Core/Console/ConsoleLayer.hpp | 2 +- DummyEngine/Core/ECS/ComponentManager.hpp | 2 +- DummyEngine/Core/ECS/Storage.hpp | 2 +- DummyEngine/Core/Physics/ConvexCollider.cpp | 10 +++--- DummyEngine/Core/Physics/ConvexCollider.hpp | 2 +- DummyEngine/Core/Physics/Solver.cpp | 3 +- DummyEngine/Core/Physics/Utils.cpp | 18 ++++------ DummyEngine/Core/Physics/Utils.hpp | 5 ++- .../Core/Rendering/Renderer/BufferLayout.cpp | 2 +- DummyEngine/Core/Rendering/Renderer/Context.h | 2 +- .../Core/Rendering/RendererOpenGL/GLContext.h | 2 -- .../Rendering/RendererOpenGL/GLShader.cpp | 24 +++++++------ .../RendererOpenGL/GLVertexBuffer.cpp | 4 +-- DummyEngine/Core/Scene/Components.h | 10 +----- DummyEngine/Core/Scene/Scene.cpp | 2 +- DummyEngine/Core/Scene/SceneHierarchy.cpp | 14 ++++---- DummyEngine/Core/Scene/SceneHierarchy.h | 2 +- DummyEngine/Core/Scene/SceneRenderer.cpp | 4 --- DummyEngine/Core/Scripting/Script.h | 4 +-- DummyEngine/Core/Scripting/ScriptEngine.cpp | 5 +-- DummyEngine/ToolBox/Loaders/SceneLoader.cpp | 22 ++++++------ 42 files changed, 145 insertions(+), 154 deletions(-) diff --git a/CMake/Compiler.cmake b/CMake/Compiler.cmake index af89dbbd..a70663f8 100644 --- a/CMake/Compiler.cmake +++ b/CMake/Compiler.cmake @@ -10,4 +10,12 @@ set(ENABLE_PRECOMPILED_HEADERS OFF) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set(ENABLE_PRECOMPILED_HEADERS ON) -endif() \ No newline at end of file +endif() + +function(add_warnings TARGET) + target_compile_options(${TARGET} PUBLIC -Wall -Wextra -Wpedantic -Wno-extra-semi -Wno-missing-field-initializers) + + if (${ENABLE_PRECOMPILED_HEADERS}) + target_compile_options(${TARGET} PUBLIC -Winvalid-pch) + endif() +endfunction(add_warnings) \ No newline at end of file diff --git a/DummyEditor/EditorLayer.cpp b/DummyEditor/EditorLayer.cpp index 068cbc38..aa9dfe2b 100644 --- a/DummyEditor/EditorLayer.cpp +++ b/DummyEditor/EditorLayer.cpp @@ -302,7 +302,7 @@ namespace DE { m_Inspector.SetActiveEntity(m_SceneHierarchy.GetActiveEntity()); } - void EditorLayer::ProcessControlls(float dt) { + void EditorLayer::ProcessControlls(float) { DE_PROFILE_SCOPE("ProcessControlls"); if (Input::KeyDown(Key::LeftControl) && Input::KeyDown(Key::LeftShift)) { @@ -367,7 +367,7 @@ namespace DE { //*___Other________________________________________________________________________________________________________________________________________________________________________________________ - void TransformSyncSystem::Update(float dt) { + void TransformSyncSystem::Update(float) { for (auto entity : View()) { entity.Get().position = entity.Get().translation; } diff --git a/DummyEditor/ImGuiUtils/ImGuiManager.cpp b/DummyEditor/ImGuiUtils/ImGuiManager.cpp index 5514638d..04e7b2d4 100644 --- a/DummyEditor/ImGuiUtils/ImGuiManager.cpp +++ b/DummyEditor/ImGuiUtils/ImGuiManager.cpp @@ -24,14 +24,13 @@ namespace DE { Path icon_font_path = Config::GetPath(DE_CFG_EXECUTABLE_PATH) / "Editor" / "Icons" / "IconsMaterialDesign.ttf"; for (const auto& entry : fs::directory_iterator(font_dir)) { // TODO: font size to settings - auto* ptr1 = io.Fonts->AddFontFromFileTTF(entry.path().string().c_str(), ImGuiUtils::Constants::BasicFontSize); + io.Fonts->AddFontFromFileTTF(entry.path().string().c_str(), ImGuiUtils::Constants::BasicFontSize); static const ImWchar icons_ranges[] = {ICON_MIN_MD, ICON_MAX_16_MD, 0}; ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true; icons_config.GlyphOffset = {0.f, 4.f}; - auto* ptr2 = - io.Fonts->AddFontFromFileTTF(icon_font_path.string().c_str(), ImGuiUtils::Constants::BasicFontSize + 1, &icons_config, icons_ranges); + io.Fonts->AddFontFromFileTTF(icon_font_path.string().c_str(), ImGuiUtils::Constants::BasicFontSize + 1, &icons_config, icons_ranges); } } void ImGuiManager::CreateDockingSpace() { diff --git a/DummyEditor/ImGuiUtils/ImGuiUtils.cpp b/DummyEditor/ImGuiUtils/ImGuiUtils.cpp index cd7b4ae6..e6df882a 100644 --- a/DummyEditor/ImGuiUtils/ImGuiUtils.cpp +++ b/DummyEditor/ImGuiUtils/ImGuiUtils.cpp @@ -76,7 +76,7 @@ namespace DE { void EditProperty(const std::string& name, S64& value) { EditProperty(name, ImGuiDataType_S64, &value); } - void EditProperty(const std::string& name, bool& value, PropertyType property_type) { + void EditProperty(const std::string& name, bool& value, PropertyType) { ImGui::SetCursorPosX(Constants::DefaultLeftPadding); ImGui::TextUnformatted(name.c_str()); ImGui::NextColumn(); @@ -84,7 +84,7 @@ namespace DE { ImGui::Checkbox(std::format("##{}", name.c_str()).c_str(), &value); ImGui::NextColumn(); } - void EditProperty(std::string name, std::string& value, PropertyType property_type) { + void EditProperty(std::string name, std::string& value, PropertyType) { ImGui::SetCursorPosX(Constants::DefaultLeftPadding); ImGui::TextUnformatted(name.c_str()); ImGui::NextColumn(); @@ -93,7 +93,7 @@ namespace DE { ImGui::InputText(name.c_str(), &value); ImGui::NextColumn(); } - void EditProperty(std::string name, Vec2& vec, PropertyType property_type) { + void EditProperty(std::string name, Vec2& vec, PropertyType) { ImGui::SetCursorPosX(Constants::DefaultLeftPadding); ImGui::TextUnformatted(name.c_str()); ImGui::NextColumn(); diff --git a/DummyEditor/Panels/InspectorPanel.cpp b/DummyEditor/Panels/InspectorPanel.cpp index 7f4401d7..47a7ff38 100644 --- a/DummyEditor/Panels/InspectorPanel.cpp +++ b/DummyEditor/Panels/InspectorPanel.cpp @@ -14,7 +14,7 @@ namespace DE { } } - template void InspectorPanel::DrawComponentWidget(Entity entity) { + template void InspectorPanel::DrawComponentWidget() { if (m_Entity.Has()) { std::string header = ICON_MD_REPORT_PROBLEM " " + DemangledName(); if (ImGui::CollapsingHeader(header.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) { @@ -24,7 +24,7 @@ namespace DE { } } - template <> void InspectorPanel::DrawComponentWidget(Entity entity) { + template <> void InspectorPanel::DrawComponentWidget() { if (m_Entity.Has()) { if (ImGui::CollapsingHeader(ICON_MD_OPEN_IN_FULL " Transformation", ImGuiTreeNodeFlags_DefaultOpen)) { auto& transform = m_Entity.Get(); @@ -36,7 +36,7 @@ namespace DE { } } } - template <> void InspectorPanel::DrawComponentWidget(Entity entity) { + template <> void InspectorPanel::DrawComponentWidget() { if (m_Entity.Has()) { auto& component = m_Entity.Get(); if (ImGui::CollapsingHeader(ICON_MD_BADGE " Tag", ImGuiTreeNodeFlags_DefaultOpen)) { @@ -46,7 +46,7 @@ namespace DE { } } } - template <> void InspectorPanel::DrawComponentWidget(Entity entity) { + template <> void InspectorPanel::DrawComponentWidget() { if (m_Entity.Has()) { auto& component = m_Entity.Get(); if (ImGui::CollapsingHeader(ICON_MD_DESCRIPTION " Script", ImGuiTreeNodeFlags_DefaultOpen)) { @@ -82,7 +82,7 @@ namespace DE { } } } - template <> void InspectorPanel::DrawComponentWidget(Entity entity) { + template <> void InspectorPanel::DrawComponentWidget() { if (m_Entity.Has()) { if (ImGui::CollapsingHeader(ICON_MD_VIDEOCAM " FPSCamera", ImGuiTreeNodeFlags_DefaultOpen)) { auto& camera = m_Entity.Get(); @@ -93,12 +93,12 @@ namespace DE { ImGuiUtils::EditProperty("FIeldOfView", camera.m_FOV); ImGui::Columns(1); if (ImGui::Button("Select as main camera", {ImGui::GetContentRegionAvail().x, 20})) { - m_Scene.lock()->SetCamera(entity); + m_Scene.lock()->SetCamera(m_Entity); } } } } - template <> void InspectorPanel::DrawComponentWidget(Entity entity) { + template <> void InspectorPanel::DrawComponentWidget() { if (m_Entity.Has()) { if (ImGui::CollapsingHeader(ICON_MD_LIGHTBULB " LightSoruce", ImGuiTreeNodeFlags_DefaultOpen)) { auto& source = m_Entity.Get(); @@ -134,7 +134,7 @@ namespace DE { } } } - template <> void InspectorPanel::DrawComponentWidget(Entity entity) { + template <> void InspectorPanel::DrawComponentWidget() { if (m_Entity.Has()) { if (ImGui::CollapsingHeader(ICON_MD_TOKEN " RenderMesh", ImGuiTreeNodeFlags_DefaultOpen)) { auto& meshes = m_Entity.Get()->GetSubMeshes(); @@ -153,7 +153,7 @@ namespace DE { } } - template <> void InspectorPanel::DrawComponentWidget(Entity entity) { + template <> void InspectorPanel::DrawComponentWidget() { if (m_Entity.Has()) { if (ImGui::CollapsingHeader(" PhysicsComponent", ImGuiTreeNodeFlags_DefaultOpen)) { auto& phys = m_Entity.Get(); @@ -176,14 +176,14 @@ namespace DE { if (ImGui::Begin(ICON_MD_INFO " Inspector")) { auto scene = m_Scene.lock(); if (scene && m_Entity.Valid()) { - DrawComponentWidget(m_Entity); - DrawComponentWidget(m_Entity); - DrawComponentWidget(m_Entity); - DrawComponentWidget(m_Entity); - DrawComponentWidget(m_Entity); - DrawComponentWidget(m_Entity); - DrawComponentWidget(m_Entity); - DrawComponentWidget(m_Entity); + DrawComponentWidget(); + DrawComponentWidget(); + DrawComponentWidget(); + DrawComponentWidget(); + DrawComponentWidget(); + DrawComponentWidget(); + DrawComponentWidget(); + DrawComponentWidget(); AddComponent(); } } diff --git a/DummyEditor/Panels/InspectorPanel.h b/DummyEditor/Panels/InspectorPanel.h index 3d2e1ab3..a22bb1e3 100644 --- a/DummyEditor/Panels/InspectorPanel.h +++ b/DummyEditor/Panels/InspectorPanel.h @@ -13,11 +13,9 @@ namespace DE { void SetScene(WeakRef scene); private: - template void DrawComponentWidget(Entity entity); + template void DrawComponentWidget(); Entity m_Entity; WeakRef m_Scene; - - float m_SliderSensitivity = 0.1; }; } // namespace DE \ No newline at end of file diff --git a/DummyEditor/Platform/Windows/Scripting/Compiler.cpp b/DummyEditor/Platform/Windows/Scripting/Compiler.cpp index fe8747bd..c8350446 100644 --- a/DummyEditor/Platform/Windows/Scripting/Compiler.cpp +++ b/DummyEditor/Platform/Windows/Scripting/Compiler.cpp @@ -76,7 +76,7 @@ namespace DE { return res; } std::string AddSourceArgument(const Path& source) { return " " + source.string(); } - std::string AddDestinationArgument(const Path& source, const Path& destination) { return " -o " + destination.string(); } + std::string AddDestinationArgument(const Path&, const Path& destination) { return " -o " + destination.string(); } std::string AddSourcesArguments(const std::vector& sources) { std::string res; diff --git a/DummyEditor/Scripting/ScriptManager.cpp b/DummyEditor/Scripting/ScriptManager.cpp index 5e1e8d87..b96fb524 100644 --- a/DummyEditor/Scripting/ScriptManager.cpp +++ b/DummyEditor/Scripting/ScriptManager.cpp @@ -85,7 +85,7 @@ namespace DE { return false; } - RestoreSciptStates(states, scene); + RestoreSciptStates(states); AttachScripts(scene); return true; @@ -116,7 +116,7 @@ namespace DE { } return states; } - void ScriptManager::RestoreSciptStates(const ScriptStates& states, Ref scene) { + void ScriptManager::RestoreSciptStates(const ScriptStates& states) { for (auto it = states.begin(); it != states.end(); ++it) { auto entity = it->first; const auto& state = it->second; diff --git a/DummyEditor/Scripting/ScriptManager.h b/DummyEditor/Scripting/ScriptManager.h index fe9d74fd..f3e018c3 100644 --- a/DummyEditor/Scripting/ScriptManager.h +++ b/DummyEditor/Scripting/ScriptManager.h @@ -15,7 +15,7 @@ namespace DE { using ScriptStates = std::unordered_map>; ScriptStates SaveSciptStates(Ref scene); - void RestoreSciptStates(const ScriptStates& states, Ref scene); + void RestoreSciptStates(const ScriptStates& states); void* Clone(const Script::Field& field) const; void Restore(ScriptComponent& script, const std::string& name, const Script::Field& field) const; diff --git a/DummyEngine/CMakeLists.txt b/DummyEngine/CMakeLists.txt index be031285..9c222ef4 100644 --- a/DummyEngine/CMakeLists.txt +++ b/DummyEngine/CMakeLists.txt @@ -15,6 +15,7 @@ target_compile_definitions(DummyEngineLib PUBLIC DE_ENABLE_LOGGING=1 ) target_include_directories(DummyEngineLib PUBLIC ../.) +add_warnings(DummyEngineLib) if (${ENABLE_PRECOMPILED_HEADERS}) target_precompile_headers(DummyEngineLib PUBLIC ${ENGINE_PRECOMPILED_HEADERS}) diff --git a/DummyEngine/Core/Animations/Animator.cpp b/DummyEngine/Core/Animations/Animator.cpp index d8b637e1..5db868fa 100644 --- a/DummyEngine/Core/Animations/Animator.cpp +++ b/DummyEngine/Core/Animations/Animator.cpp @@ -22,7 +22,7 @@ namespace DE { } void Animator::SetMatricies(Ref shader, const std::string& name) { - for (S32 i = 0; i < m_FinalBoneMatrices.size(); ++i) { + for (U32 i = 0; i < m_FinalBoneMatrices.size(); ++i) { shader->SetMat4(std::format("{}[{}]", name, i), m_FinalBoneMatrices[i]); } } @@ -38,7 +38,7 @@ namespace DE { m_FinalBoneMatrices[bone_info->bone.GetBoneID()] = parent_transform * node_transform * bone_info->offset; } Mat4 final_transform = parent_transform * node_transform; - for (S32 i = 0; i < node->childrens.size(); ++i) { + for (U32 i = 0; i < node->childrens.size(); ++i) { CalculateBoneTransform(&node->childrens[i], final_transform); } } diff --git a/DummyEngine/Core/Animations/Bone.cpp b/DummyEngine/Core/Animations/Bone.cpp index 3c0d4fee..6b3c9082 100644 --- a/DummyEngine/Core/Animations/Bone.cpp +++ b/DummyEngine/Core/Animations/Bone.cpp @@ -1,7 +1,7 @@ #include "DummyEngine/Core/Animations/Bone.h" namespace DE { - Bone::Bone(const std::string& name, S32 ID) : m_Name(name), m_ID(ID), m_LocalTransform(1.0f) {} + Bone::Bone(const std::string& name, U32 ID) : m_Name(name), m_ID(ID), m_LocalTransform(1.0f) {} Mat4 Bone::GetTransform(float animationTime) { Mat4 translation = InterpolatePosition(animationTime); @@ -12,7 +12,7 @@ namespace DE { std::string Bone::GetBoneName() const { return m_Name; } - S32 Bone::GetBoneID() const { + U32 Bone::GetBoneID() const { return m_ID; } @@ -24,24 +24,24 @@ namespace DE { return scale; } - S32 Bone::GetPositionIndex(float time) { - for (S32 i = 0; i < m_Positions.size() - 1; ++i) { + U32 Bone::GetPositionIndex(float time) { + for (U32 i = 0; i < m_Positions.size() - 1; ++i) { if (time < m_Positions[i + 1].time_stamp) { return i; } } return m_Positions.size() - 1; } - S32 Bone::GetRotationIndex(float time) { - for (S32 i = 0; i < m_Rotations.size() - 1; ++i) { + U32 Bone::GetRotationIndex(float time) { + for (U32 i = 0; i < m_Rotations.size() - 1; ++i) { if (time < m_Rotations[i + 1].time_stamp) { return i; } } return m_Rotations.size() - 1; } - S32 Bone::GetScaleIndex(float time) { - for (S32 i = 0; i < m_Scales.size() - 1; ++i) { + U32 Bone::GetScaleIndex(float time) { + for (U32 i = 0; i < m_Scales.size() - 1; ++i) { if (time < m_Scales[i + 1].time_stamp) { return i; } @@ -53,9 +53,9 @@ namespace DE { if (m_Positions.empty()) { return Mat4(1.0); } - S32 i = GetPositionIndex(time); + U32 i = GetPositionIndex(time); // printf("pos %d\n", i); - if (i == m_Positions.size() - 1) { + if (i + 1 == m_Positions.size()) { return glm::translate(Mat4(1.0f), m_Positions.back().position); } float scale = GetScaleFactor(m_Positions[i].time_stamp, m_Positions[i + 1].time_stamp, time); @@ -67,8 +67,8 @@ namespace DE { if (m_Rotations.empty()) { return Mat4(1.0); } - S32 i = GetRotationIndex(time); - if (i == m_Rotations.size() - 1) { + U32 i = GetRotationIndex(time); + if (i + 1 == m_Rotations.size()) { return glm::toMat4(glm::normalize(m_Rotations.back().orientation)); } float scale = GetScaleFactor(m_Rotations[i].time_stamp, m_Rotations[i + 1].time_stamp, time); @@ -80,9 +80,9 @@ namespace DE { if (m_Scales.empty()) { return Mat4(1.0); } - S32 i = GetScaleIndex(time); + U32 i = GetScaleIndex(time); // printf("scale %d\n", i); - if (i == m_Scales.size() - 1) { + if (i + 1 == m_Scales.size()) { return glm::scale(Mat4(1.0f), m_Scales.back().scale); } float scale = GetScaleFactor(m_Scales[i].time_stamp, m_Scales[i + 1].time_stamp, time); diff --git a/DummyEngine/Core/Animations/Bone.h b/DummyEngine/Core/Animations/Bone.h index 4573b0b3..622b221a 100644 --- a/DummyEngine/Core/Animations/Bone.h +++ b/DummyEngine/Core/Animations/Bone.h @@ -21,18 +21,18 @@ namespace DE { class Bone { public: Bone() = default; - Bone(const std::string& name, int ID); + Bone(const std::string& name, U32 ID); Mat4 GetTransform(float animationTime); std::string GetBoneName() const; - S32 GetBoneID() const; + U32 GetBoneID() const; private: float GetScaleFactor(float prev_time, float next_time, float time); - S32 GetPositionIndex(float time); - S32 GetRotationIndex(float time); - S32 GetScaleIndex(float time); + U32 GetPositionIndex(float time); + U32 GetRotationIndex(float time); + U32 GetScaleIndex(float time); Mat4 InterpolatePosition(float time); Mat4 InterpolateRotation(float time); @@ -45,9 +45,9 @@ namespace DE { std::vector m_Rotations; std::vector m_Scales; - S32 m_ID; - Mat4 m_LocalTransform; std::string m_Name; + U32 m_ID; + Mat4 m_LocalTransform; }; struct BoneInfo { Bone bone; diff --git a/DummyEngine/Core/Application/Application.cpp b/DummyEngine/Core/Application/Application.cpp index 700bfeee..858fb32b 100644 --- a/DummyEngine/Core/Application/Application.cpp +++ b/DummyEngine/Core/Application/Application.cpp @@ -8,7 +8,7 @@ namespace DE { // TODO: Customizeble name m_Window = new Window(WindowState{.mode = WindowMode::Windowed, .name = "DummyEngine", .width = 1280, .height = 720}); DE_ASSERT(m_Window, "Failed to allocate Windows"); - m_Window->SetEventCallback([this](Event& e) { OnEvent(e); }); + m_Window->SetEventCallback([](Event& e) { Application::OnEvent(e); }); m_ImGuiLayer = new ImGuiLayer(); DE_ASSERT(m_ImGuiLayer, "Failed to allocate ImGuiLayer"); @@ -33,7 +33,7 @@ namespace DE { S_METHOD_IMPL(Unit, PushLayer, (Layer * layer), (layer)) { m_Layers.push_back(layer); - layer->m_EventCallback = [this](Event& e) { OnEvent(e); }; + layer->m_EventCallback = [](Event& e) { Application::OnEvent(e); }; layer->OnAttach(); return Unit(); } @@ -45,7 +45,9 @@ namespace DE { return Unit(); } S_METHOD_IMPL(Unit, Run, (), ()) { - double frame_begin = glfwGetTime(), frame_end, prev_frame_time = 0.001, fake_time; + double frame_begin = glfwGetTime(); + double frame_end; + double prev_frame_time = 0.001; while (!m_ShouldClose) { DE_PROFILER_BEGIN_FRAME(); DE_PROFILE_SCOPE("Aplication loop"); @@ -54,7 +56,6 @@ namespace DE { prev_frame_time = frame_end - frame_begin; frame_begin = glfwGetTime(); - Renderer::BeginFrame(); Input::NewFrame(); @@ -111,7 +112,7 @@ namespace DE { void Application::OnWindowResize(WindowResizeEvent& e) { Renderer::SetViewport(e.GetWidth(), e.GetHeight()); } - void Application::OnWindowClose(WindowCloseEvent& e) { + void Application::OnWindowClose(WindowCloseEvent&) { m_ShouldClose = true; } diff --git a/DummyEngine/Core/Application/Initializer.cpp b/DummyEngine/Core/Application/Initializer.cpp index 76cee471..ea21fe3b 100644 --- a/DummyEngine/Core/Application/Initializer.cpp +++ b/DummyEngine/Core/Application/Initializer.cpp @@ -14,7 +14,7 @@ #include "DummyEngine/Utils/Base.h" namespace DE { - void error_callback(int error, const char* description) { + void error_callback(int, const char* description) { fprintf(stderr, "Error: %s\n", description); fflush(stderr); } diff --git a/DummyEngine/Core/Application/Input.cpp b/DummyEngine/Core/Application/Input.cpp index 295bc89b..144e27d0 100644 --- a/DummyEngine/Core/Application/Input.cpp +++ b/DummyEngine/Core/Application/Input.cpp @@ -18,10 +18,10 @@ namespace DE { m_CurrentFrame.key_states[event.GetKey()] = false; }); - m_EventDispatcher.AddEventListener([this](SetMouseLockEvent& event) { m_CurrentFrame.mouse_locked = true; }); - m_EventDispatcher.AddEventListener([this](SetMouseUnlockEvent& event) { m_CurrentFrame.mouse_locked = false; }); + m_EventDispatcher.AddEventListener([this](SetMouseLockEvent&) { m_CurrentFrame.mouse_locked = true; }); + m_EventDispatcher.AddEventListener([this](SetMouseUnlockEvent&) { m_CurrentFrame.mouse_locked = false; }); m_EventDispatcher.AddEventListener( - [this](SetMouseLockToggleEvent& event) { m_CurrentFrame.mouse_locked = !m_CurrentFrame.mouse_locked; }); + [this](SetMouseLockToggleEvent&) { m_CurrentFrame.mouse_locked = !m_CurrentFrame.mouse_locked; }); m_EventDispatcher.AddEventListener([this](MouseMovedCallback& event) { m_CurrentFrame.x_pos = event.GetXPos(); diff --git a/DummyEngine/Core/Application/Layer.h b/DummyEngine/Core/Application/Layer.h index d5da3d15..3f0199be 100644 --- a/DummyEngine/Core/Application/Layer.h +++ b/DummyEngine/Core/Application/Layer.h @@ -11,9 +11,9 @@ namespace DE { virtual void OnAttach() {} virtual void OnDetach() {} - virtual void OnUpdate(float dt) {} + virtual void OnUpdate(float) {} virtual void OnImGuiRender() {} - virtual void OnEvent(Event& event) {} + virtual void OnEvent(Event&) {} const std::string& GetName() const { return m_Name; } diff --git a/DummyEngine/Core/Application/Window.cpp b/DummyEngine/Core/Application/Window.cpp index 0bff77f4..69b28a74 100644 --- a/DummyEngine/Core/Application/Window.cpp +++ b/DummyEngine/Core/Application/Window.cpp @@ -8,9 +8,9 @@ namespace DE { GLFWmonitor* GetMonitor(U32 id) { - int monitors_amount; + int monitors_amount = 0; GLFWmonitor** monitors = glfwGetMonitors(&monitors_amount); - DE_ASSERT(0 <= id && id < monitors_amount, "Wrong monitor id {} should be between [0, {})", id, monitors_amount); + DE_ASSERT(0 <= id && id < U32(monitors_amount), "Wrong monitor id {} should be between [0, {})", id, monitors_amount); return monitors[id]; } @@ -44,6 +44,7 @@ namespace DE { } void Window::FullScreen(U32 id) { m_State.mode = WindowMode::FullScreen; + m_State.monitor_id = id; Invalidate(); } @@ -122,7 +123,7 @@ namespace DE { state.event_callback(event); }); - glfwSetKeyCallback(m_Window, [](GLFWwindow* window, int key, int scancode, int action, int mods) { + glfwSetKeyCallback(m_Window, [](GLFWwindow* window, int key, int, int action, int) { if (key == -1) { return; } @@ -146,7 +147,7 @@ namespace DE { } }); - glfwSetMouseButtonCallback(m_Window, [](GLFWwindow* window, int button, int action, int mods) { + glfwSetMouseButtonCallback(m_Window, [](GLFWwindow* window, int button, int action, int) { WindowState& state = *(WindowState*)glfwGetWindowUserPointer(window); switch (action) { case GLFW_PRESS: { diff --git a/DummyEngine/Core/Application/Window.h b/DummyEngine/Core/Application/Window.h index 0fbb0763..8ed37767 100644 --- a/DummyEngine/Core/Application/Window.h +++ b/DummyEngine/Core/Application/Window.h @@ -19,7 +19,7 @@ namespace DE { U32 monitor_id = 0; bool mouse_locked = false; - EventCallback event_callback; + EventCallback event_callback = {}; }; class Window { diff --git a/DummyEngine/Core/Console/Console.cpp b/DummyEngine/Core/Console/Console.cpp index 73f5ff65..7da8b789 100644 --- a/DummyEngine/Core/Console/Console.cpp +++ b/DummyEngine/Core/Console/Console.cpp @@ -26,7 +26,7 @@ namespace DE { S_METHOD_IMPL(void, ExecuteCommand, (std::string & cmd), (cmd)) { m_CmdHistory.push_back(cmd); - if (cmd.find(' ') != -1) { + if (cmd.find(' ') != std::string::npos) { size_t pos = cmd.find(' '); const auto& var_name = cmd.substr(0, pos); if (m_Variables.find(var_name) != m_Variables.end()) { @@ -153,7 +153,7 @@ namespace DE { int space_idx = cmd.find(' '); const auto& trunc_cmd = space_idx == -1 ? cmd : cmd.substr(0, space_idx); // for variables for (const auto& str : candidates) { - if (str.find(trunc_cmd) != -1) { + if (str.find(trunc_cmd) != std::string::npos) { result.push_back(str); } } diff --git a/DummyEngine/Core/Console/ConsoleLayer.cpp b/DummyEngine/Core/Console/ConsoleLayer.cpp index cbd66bef..222874d8 100644 --- a/DummyEngine/Core/Console/ConsoleLayer.cpp +++ b/DummyEngine/Core/Console/ConsoleLayer.cpp @@ -11,7 +11,7 @@ namespace DE { - void ConsoleLayer::OnUpdate(float dt) { + void ConsoleLayer::OnUpdate(float) { if (Input::KeyPressed(Key::I) && Input::KeyDown(Key::LeftShift)) { if (!m_Show) { m_JustOpened = true; diff --git a/DummyEngine/Core/Console/ConsoleLayer.hpp b/DummyEngine/Core/Console/ConsoleLayer.hpp index 323329fc..6b6e924d 100644 --- a/DummyEngine/Core/Console/ConsoleLayer.hpp +++ b/DummyEngine/Core/Console/ConsoleLayer.hpp @@ -13,7 +13,7 @@ namespace DE { private: bool m_Show = false; std::string m_Command; - int m_historyPosition = 0; + U32 m_historyPosition = 0; bool m_ScrollToBottom = true; bool m_JustOpened = false; }; diff --git a/DummyEngine/Core/ECS/ComponentManager.hpp b/DummyEngine/Core/ECS/ComponentManager.hpp index d4b5bf48..25e8cffd 100644 --- a/DummyEngine/Core/ECS/ComponentManager.hpp +++ b/DummyEngine/Core/ECS/ComponentManager.hpp @@ -124,7 +124,7 @@ namespace DE { template void ComponentManager::RegisterComponent() { if (m_ComponentId.find(INDEX(ComponentType)) == m_ComponentId.end()) { - auto default_handler = [](Entity e) {}; + auto default_handler = [](Entity) {}; m_ComponentId[INDEX(ComponentType)] = m_ComponentId.size(); m_ComponentArrays[INDEX(ComponentType)] = std::make_shared>(ComponentArray()); m_AddHandlers[INDEX(ComponentType)] = default_handler; diff --git a/DummyEngine/Core/ECS/Storage.hpp b/DummyEngine/Core/ECS/Storage.hpp index 9e37e141..17ba08be 100644 --- a/DummyEngine/Core/ECS/Storage.hpp +++ b/DummyEngine/Core/ECS/Storage.hpp @@ -3,7 +3,7 @@ namespace DE { #ifdef ECS_IMPLEMENTATION - Storage::Storage() : m_SystemManager(this), m_ComponentManager(this) {} + Storage::Storage() : m_ComponentManager(this), m_SystemManager(this){} void Storage::Destruct() { for (U32 id = m_EntityManager.BeginEntity(); id != m_EntityManager.EndEntity(); id = m_EntityManager.NextEntity(id)) { m_ComponentManager.Destroy(id); diff --git a/DummyEngine/Core/Physics/ConvexCollider.cpp b/DummyEngine/Core/Physics/ConvexCollider.cpp index ce52f3ce..cee701dc 100644 --- a/DummyEngine/Core/Physics/ConvexCollider.cpp +++ b/DummyEngine/Core/Physics/ConvexCollider.cpp @@ -83,21 +83,21 @@ DE::Vec3 DE::Physics::ConvexCollider::GetPoint(const size_t idx) const { DE::Vec3 DE::Physics::ConvexCollider::Collide(const DE::Physics::ConvexCollider& oth) const { std::vector axis; - for (int i = 1; i < DE::Physics::UNIQUE_FACES; i++) { + for (U32 i = 1; i < DE::Physics::UNIQUE_FACES; ++i) { Vec3 A = GetPoint(i) - GetPoint(0); Vec3 B = GetPoint((i + 1) % (UNIQUE_FACES - 1) + 1) - GetPoint(0); axis.push_back(glm::normalize(glm::cross(A, B))); } - for (int i = 1; i < DE::Physics::UNIQUE_FACES; i++) { + for (U32 i = 1; i < DE::Physics::UNIQUE_FACES; ++i) { Vec3 A = oth.GetPoint(i) - oth.GetPoint(0); Vec3 B = oth.GetPoint((i + 1) % (UNIQUE_FACES - 1) + 1) - oth.GetPoint(0); axis.push_back(glm::normalize(glm::cross(A, B))); } - for (int i = 1; i < DE::Physics::UNIQUE_FACES; i++) { + for (U32 i = 1; i < DE::Physics::UNIQUE_FACES; ++i) { Vec3 A = GetPoint(i) - GetPoint(0); - for (int j = 1; j < DE::Physics::UNIQUE_FACES; j++) { + for (U32 j = 1; j < DE::Physics::UNIQUE_FACES; ++j) { Vec3 B = oth.GetPoint((j + 1) % (UNIQUE_FACES - 1) + 1) - oth.GetPoint(0); Vec3 cross = glm::cross(A, B); if (glm::length(cross) == 0) { @@ -156,7 +156,7 @@ DE::Vec3 DE::Physics::ConvexCollider::GetCollisionPoint(const DE::Vec3& collisio Vec3 sum(0); cnt = 0; for (const auto& pt : _hitbox->_points) { - auto tpt = TransformPoint(pt); + TransformPoint(pt); if (std::abs(glm::dot(norm, TransformPoint(pt)) - best) < 1e-7) { cnt++; sum += TransformPoint(pt); diff --git a/DummyEngine/Core/Physics/ConvexCollider.hpp b/DummyEngine/Core/Physics/ConvexCollider.hpp index a7806ddc..89c7228c 100644 --- a/DummyEngine/Core/Physics/ConvexCollider.hpp +++ b/DummyEngine/Core/Physics/ConvexCollider.hpp @@ -43,5 +43,5 @@ namespace DE::Physics { Mat4 _transform{}; }; - const size_t UNIQUE_FACES = 4; + const U32 UNIQUE_FACES = 4; } // namespace DE::Physics \ No newline at end of file diff --git a/DummyEngine/Core/Physics/Solver.cpp b/DummyEngine/Core/Physics/Solver.cpp index 9e8cfc6a..74c454d1 100644 --- a/DummyEngine/Core/Physics/Solver.cpp +++ b/DummyEngine/Core/Physics/Solver.cpp @@ -206,9 +206,8 @@ DE::Physics::Jacobian DE::Physics::Solver::InitJacobian(DE::Physics::Collision& j.m_totalLambda = 0; return j; } -void DE::Physics::Solver::Resolve(DE::Physics::Jacobian& j, DE::Physics::Collision& collision, float dt, bool is_normal, DE::Physics::Jacobian* jn) { +void DE::Physics::Solver::Resolve(DE::Physics::Jacobian& j, DE::Physics::Collision& collision, float, bool is_normal, DE::Physics::Jacobian* jn) { auto scene = _scene.lock(); - Vec3 dir = j.m_vb; auto lhs_phys = scene->GetByID(collision.src).GetComponent(); auto rhs_phys = scene->GetByID(collision.dest).GetComponent(); diff --git a/DummyEngine/Core/Physics/Utils.cpp b/DummyEngine/Core/Physics/Utils.cpp index 3f2ee48f..648f1a43 100644 --- a/DummyEngine/Core/Physics/Utils.cpp +++ b/DummyEngine/Core/Physics/Utils.cpp @@ -2,26 +2,22 @@ namespace DE::Physics { - Plane::Plane(Vec3 normal, double_t d) : _normal(normal), _d(d) {} - Plane::Plane(Vec3 normal, Vec3 pt) : _normal(normal), _d(-glm::dot(normal, pt)) {} - Plane::Plane(Vec3 v1, Vec3 v2, Vec3 v3) : _v1(v1), _v2(v2), _v3(v3) { - _normal = glm::normalize(glm::cross(v2 - v1, v3 - v1)); - _d = -glm::dot(_normal, v1); - } + Plane::Plane(Vec3 normal, double_t d) : m_Normal(normal), m_D(d) {} + Plane::Plane(Vec3 normal, Vec3 pt) : m_Normal(normal), m_D(-glm::dot(normal, pt)) {} Vec3 Plane::intersectionPoint(Vec3 p1, Vec3 p2) const { - if (glm::dot(_normal, p2 - p1) == 0) { + if (glm::dot(m_Normal, p2 - p1) == 0) { return (p1 + p2) / 2.f; } - return p1 + (p2 - p1) * (-distance(p1) / glm::dot(_normal, p2 - p1)); + return p1 + (p2 - p1) * (-distance(p1) / glm::dot(m_Normal, p2 - p1)); }; void Plane::invert() { - _normal = -_normal; + m_Normal = -m_Normal; } Vec3 Plane::getNormal() const { - return _normal; + return m_Normal; } float Plane::distance(Vec3 q) const { - return glm::dot(_normal, q) + _d; + return glm::dot(m_Normal, q) + m_D; } } // namespace DE::Physics \ No newline at end of file diff --git a/DummyEngine/Core/Physics/Utils.hpp b/DummyEngine/Core/Physics/Utils.hpp index 552ce6a1..6a0d1c2e 100644 --- a/DummyEngine/Core/Physics/Utils.hpp +++ b/DummyEngine/Core/Physics/Utils.hpp @@ -6,7 +6,6 @@ namespace DE::Physics { public: Plane(Vec3 normal, double_t d); Plane(Vec3 normal, Vec3 pt); - Plane(Vec3 v1, Vec3 v2, Vec3 v3); Vec3 intersectionPoint(Vec3 p1, Vec3 p2) const; void invert(); @@ -14,8 +13,8 @@ namespace DE::Physics { float distance(Vec3 q) const; private: - Vec3 _normal, _v1, _v2, _v3; - float _d; + Vec3 m_Normal; + float m_D; }; } // namespace DE::Physics \ No newline at end of file diff --git a/DummyEngine/Core/Rendering/Renderer/BufferLayout.cpp b/DummyEngine/Core/Rendering/Renderer/BufferLayout.cpp index 5e8a524a..91639f5c 100644 --- a/DummyEngine/Core/Rendering/Renderer/BufferLayout.cpp +++ b/DummyEngine/Core/Rendering/Renderer/BufferLayout.cpp @@ -4,7 +4,7 @@ namespace DE { //*~~~BufferElement~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - BufferElement::BufferElement(BufferElementType type, bool normalized) : type(type), normalized(normalized), size(SizeOfElementType(type)) {} + BufferElement::BufferElement(BufferElementType type, bool normalized) : type(type), size(SizeOfElementType(type)), normalized(normalized) {} U32 BufferElement::SizeOfElementType(BufferElementType type) { switch (type) { case BufferElementType::Float: return 4; diff --git a/DummyEngine/Core/Rendering/Renderer/Context.h b/DummyEngine/Core/Rendering/Renderer/Context.h index a626e9f3..cea19f37 100644 --- a/DummyEngine/Core/Rendering/Renderer/Context.h +++ b/DummyEngine/Core/Rendering/Renderer/Context.h @@ -2,7 +2,7 @@ #include "DummyEngine/Utils/Base.h" -class GLFWwindow; +struct GLFWwindow; namespace DE { diff --git a/DummyEngine/Core/Rendering/RendererOpenGL/GLContext.h b/DummyEngine/Core/Rendering/RendererOpenGL/GLContext.h index 94e04448..004627de 100644 --- a/DummyEngine/Core/Rendering/RendererOpenGL/GLContext.h +++ b/DummyEngine/Core/Rendering/RendererOpenGL/GLContext.h @@ -2,8 +2,6 @@ #include "DummyEngine/Core/Rendering/Renderer/Context.h" -struct GLFWwindow; - namespace DE { class GLContext : public Context { diff --git a/DummyEngine/Core/Rendering/RendererOpenGL/GLShader.cpp b/DummyEngine/Core/Rendering/RendererOpenGL/GLShader.cpp index 4a710eaf..d51891c4 100644 --- a/DummyEngine/Core/Rendering/RendererOpenGL/GLShader.cpp +++ b/DummyEngine/Core/Rendering/RendererOpenGL/GLShader.cpp @@ -21,12 +21,15 @@ namespace DE { } glLinkProgram(m_ShaderId); - int success; - char info_log[Config::GetI(DE_CFG_MAX_COMPILE_ERROR_LEN)]; + int success; + std::string info_log; + info_log.resize(Config::GetI(DE_CFG_MAX_COMPILE_ERROR_LEN)); glGetProgramiv(m_ShaderId, GL_LINK_STATUS, &success); + int len = 0; if (!success) { - glGetProgramInfoLog(m_ShaderId, 512, NULL, info_log); - LOG_ERROR("Failed to link shader program {} due:\n{}", std::to_string(m_ShaderId), reinterpret_cast(&info_log)); + glGetProgramInfoLog(m_ShaderId, info_log.size(), &len, info_log.data()); + info_log.resize(len); + LOG_ERROR("Failed to link shader program {} due:\n{}", std::to_string(m_ShaderId), info_log); throw std::runtime_error("Failed to compile shader."); } LOG_INFO("GLShader program {} linked successfully", std::to_string(m_ShaderId)); @@ -123,20 +126,19 @@ namespace DE { const char* source_c_str = source.c_str(); GLuint shader_part = glCreateShader(ShaderPartTypeToGLShaderPartType(part.type)); - // if (part.type == ShaderPartType::Geometry) { - // glShaderSource(shader_part, strlen(source_c_str), &source_c_str, NULL); - // } else { glShaderSource(shader_part, 1, &source_c_str, NULL); - // } glCompileShader(shader_part); m_Parts.push_back(shader_part); int success = 1; - char infoLog[Config::GetI(DE_CFG_MAX_COMPILE_ERROR_LEN)]; + std::string info_log; + info_log.resize(Config::GetI(DE_CFG_MAX_COMPILE_ERROR_LEN)); + int len = 0; glGetShaderiv(shader_part, GL_COMPILE_STATUS, &success); if (!success) { - glGetShaderInfoLog(shader_part, Config::GetI(DE_CFG_MAX_COMPILE_ERROR_LEN), NULL, infoLog); - LOG_ERROR("Failed to compile shader {} due:\n{}", part.path, reinterpret_cast(&infoLog)); + glGetShaderInfoLog(shader_part, info_log.size(), &len, info_log.data()); + info_log.resize(len); + LOG_ERROR("Failed to compile shader {} due:\n{}", part.path, info_log); return; } LOG_INFO("File {} compiled", RelativeToExecutable(part.path)); diff --git a/DummyEngine/Core/Rendering/RendererOpenGL/GLVertexBuffer.cpp b/DummyEngine/Core/Rendering/RendererOpenGL/GLVertexBuffer.cpp index a71a48e8..47c84163 100644 --- a/DummyEngine/Core/Rendering/RendererOpenGL/GLVertexBuffer.cpp +++ b/DummyEngine/Core/Rendering/RendererOpenGL/GLVertexBuffer.cpp @@ -10,7 +10,7 @@ namespace DE { // TODO: Think about not creating LocalBuffer if BufferUsage is Static. - GLVertexBuffer::GLVertexBuffer(const BufferLayout& layout, U32 size, BufferUsage usage) : m_Layout(layout), m_Usage(usage) { + GLVertexBuffer::GLVertexBuffer(const BufferLayout& layout, U32 size, BufferUsage usage) : m_Usage(usage), m_Layout(layout) { m_Layout.SetLayoutType(BufferLayoutType::Vertex); m_Size = (size * m_Layout.GetStride()); @@ -21,7 +21,7 @@ namespace DE { glBindBuffer(GL_ARRAY_BUFFER, m_BufferId); glBufferData(GL_ARRAY_BUFFER, m_Size, nullptr, BufferUsafeToGLBufferUsage(usage)); } - GLVertexBuffer::GLVertexBuffer(const BufferLayout& layout, U32 size, const void* data, BufferUsage usage) : m_Layout(layout), m_Usage(usage) { + GLVertexBuffer::GLVertexBuffer(const BufferLayout& layout, U32 size, const void* data, BufferUsage usage) : m_Usage(usage), m_Layout(layout) { m_Layout.SetLayoutType(BufferLayoutType::Vertex); m_Size = (size * m_Layout.GetStride()); diff --git a/DummyEngine/Core/Scene/Components.h b/DummyEngine/Core/Scene/Components.h index 8796f22d..3c8df29e 100644 --- a/DummyEngine/Core/Scene/Components.h +++ b/DummyEngine/Core/Scene/Components.h @@ -4,21 +4,13 @@ #include "DummyEngine/Core/Rendering/Renderer/RenderStructs.h" #include "DummyEngine/Core/Rendering/Renderer/Shader.h" #include "DummyEngine/Core/Rendering/Renderer/SkyBox.h" -//#include "DummyEngine/Core/SoundEngine/SoundsAndFactories.h" #include "DummyEngine/Utils/Base.h" namespace DE { -// struct AudioComponent { -// AudioComponent() = default; -// -// Scope sound; -// Path path; -// }; class IDComponent { public: - IDComponent() = default; - IDComponent(const IDComponent&) = default; + IDComponent() = default; IDComponent(UUID uuid) : m_ID(uuid) {} UUID Get() const { return m_ID; } diff --git a/DummyEngine/Core/Scene/Scene.cpp b/DummyEngine/Core/Scene/Scene.cpp index 87f91e04..6088df73 100644 --- a/DummyEngine/Core/Scene/Scene.cpp +++ b/DummyEngine/Core/Scene/Scene.cpp @@ -160,7 +160,7 @@ namespace DE { } return new_entity; } - Entity Scene::CloneEntity(Entity entity) { + Entity Scene::CloneEntity(Entity) { // DE_ASSERT(false, "Clone of entity not implemented yet."); return CreateEntity("Entity", false); } diff --git a/DummyEngine/Core/Scene/SceneHierarchy.cpp b/DummyEngine/Core/Scene/SceneHierarchy.cpp index 48a54e02..0ae5203a 100644 --- a/DummyEngine/Core/Scene/SceneHierarchy.cpp +++ b/DummyEngine/Core/Scene/SceneHierarchy.cpp @@ -4,13 +4,13 @@ namespace DE { bool SceneHierarchy::Node::Valid() const { - return m_ID != -1 && m_Owner && !std::holds_alternative(m_Owner->m_Nodes[m_ID].node); + return m_ID != UINT32_MAX && m_Owner && !std::holds_alternative(m_Owner->m_Nodes[m_ID].node); } bool SceneHierarchy::Node::IsEntity() const { - return m_ID != -1 && m_Owner && std::holds_alternative(m_Owner->m_Nodes[m_ID].node); + return m_ID != UINT32_MAX && m_Owner && std::holds_alternative(m_Owner->m_Nodes[m_ID].node); } bool SceneHierarchy::Node::IsFolder() const { - return m_ID != -1 && m_Owner && std::holds_alternative(m_Owner->m_Nodes[m_ID].node); + return m_ID != UINT32_MAX && m_Owner && std::holds_alternative(m_Owner->m_Nodes[m_ID].node); } bool SceneHierarchy::Node::IsAnsestorOf(const Node& child) const { if (!Valid() || !child.Valid() || m_Owner != child.m_Owner) { @@ -22,12 +22,12 @@ namespace DE { return m_ID; } SceneHierarchy::Node SceneHierarchy::Node::GetParent() const { - DE_ASSERT(m_ID != -1 && m_Owner, "Use of GetParent on invalid SceneHierarchy::Node"); + DE_ASSERT(m_ID != UINT32_MAX && m_Owner, "Use of GetParent on invalid SceneHierarchy::Node"); return Node(m_Owner, m_Owner->m_Nodes[m_ID].parent); } bool SceneHierarchy::Node::Attach(Node other) { - DE_ASSERT(m_ID != -1 && m_Owner, "Use of Attach on invalid SceneHierarchy::Node"); + DE_ASSERT(m_ID != UINT32_MAX && m_Owner, "Use of Attach on invalid SceneHierarchy::Node"); return m_Owner->Attach(*this, other); } SceneHierarchy::Node SceneHierarchy::Node::AddEntity(Entity entity) { @@ -43,7 +43,7 @@ namespace DE { return folder; } void SceneHierarchy::Node::Delete() { - DE_ASSERT(m_ID != -1 && m_Owner, "Use of Delete on invalid SceneHierarchy::Node"); + DE_ASSERT(m_ID != UINT32_MAX && m_Owner, "Use of Delete on invalid SceneHierarchy::Node"); m_Owner->DeleteNode(*this); *this = Node(); } @@ -150,7 +150,7 @@ namespace DE { return true; } child = m_Nodes[child].parent; - } while (child != -1); + } while (child != UINT32_MAX); return false; } diff --git a/DummyEngine/Core/Scene/SceneHierarchy.h b/DummyEngine/Core/Scene/SceneHierarchy.h index 8e289da7..aa503771 100644 --- a/DummyEngine/Core/Scene/SceneHierarchy.h +++ b/DummyEngine/Core/Scene/SceneHierarchy.h @@ -35,7 +35,7 @@ namespace DE { Node(SceneHierarchy* owner, U32 id); SceneHierarchy* m_Owner = nullptr; - U32 m_ID = -1; + U32 m_ID = UINT32_MAX; }; SceneHierarchy(const std::string& name); diff --git a/DummyEngine/Core/Scene/SceneRenderer.cpp b/DummyEngine/Core/Scene/SceneRenderer.cpp index 05723bba..be2784e0 100644 --- a/DummyEngine/Core/Scene/SceneRenderer.cpp +++ b/DummyEngine/Core/Scene/SceneRenderer.cpp @@ -11,7 +11,6 @@ namespace DE { const U32 MAX_LIGHTS_IN_SCENE = 1000; - const U32 MAX_INSTANCES_PER_BUFFER = 1000; const U32 LIGHT_UB_ID = 1; @@ -172,7 +171,6 @@ namespace DE { if (skybox.Has()) { transform = skybox.Get().GetRotation(); } - static U32 cnt = 0; Renderer::Submit(skybox.Get()->GetMap(), camera, transform); } for (auto e : m_Scene->View()) { @@ -237,10 +235,8 @@ namespace DE { DE_PROFILE_SCOPE("UpdateShaders"); int cnt_light_sources = 0; - int cnt_shadowmaps = 0; for (auto enitity : m_Scene->m_Storage->View()) { auto& light_source = enitity.Get(); - auto id = enitity.Get().Get(); m_Lights->at(cnt_light_sources).Get(0) = light_source.ambient; m_Lights->at(cnt_light_sources).Get(1) = light_source.diffuse; m_Lights->at(cnt_light_sources).Get(2) = light_source.specular; diff --git a/DummyEngine/Core/Scripting/Script.h b/DummyEngine/Core/Scripting/Script.h index 878f021e..328306b3 100644 --- a/DummyEngine/Core/Scripting/Script.h +++ b/DummyEngine/Core/Scripting/Script.h @@ -73,7 +73,7 @@ namespace DE { virtual void OnAttach() {} virtual void OnRuntimeStart() {} - virtual void OnUpdate(float dt) {} + virtual void OnUpdate(float) {} virtual void OnRender() {} virtual void OnRuntimeStop() {} virtual void OnDetach() {} @@ -103,7 +103,7 @@ namespace DE { template ScriptFieldType TypeToScriptFieldType(); template constexpr U32 OffsetOf(U T::* member) { - return (char*)&((T*)nullptr->*member) - (char*)nullptr; + return (size_t)&((T*)nullptr->*member); } template T& Script::Field::Get() { diff --git a/DummyEngine/Core/Scripting/ScriptEngine.cpp b/DummyEngine/Core/Scripting/ScriptEngine.cpp index 8352a85e..76de3dae 100644 --- a/DummyEngine/Core/Scripting/ScriptEngine.cpp +++ b/DummyEngine/Core/Scripting/ScriptEngine.cpp @@ -75,7 +75,8 @@ namespace DE { } ScriptProxyManager::Iterator ScriptProxyManager::Iterator::operator++(int) { Iterator res = *this; - return ++(*this); + ++(*this); + return res; } ScriptProxy& ScriptProxyManager::Iterator::operator*() { return m_Manager->m_Proxys[m_ID]; @@ -87,7 +88,7 @@ namespace DE { ScriptProxyManager::Iterator::Iterator(ScriptProxyManager* manager, U32 id) : m_Manager(manager), m_ID(id) {} ScriptProxyManager::Iterator ScriptProxyManager::begin() { - int id = 0; + U32 id = 0; while (id < m_States.size() && !m_States[id]) { ++id; } diff --git a/DummyEngine/ToolBox/Loaders/SceneLoader.cpp b/DummyEngine/ToolBox/Loaders/SceneLoader.cpp index 0516c64f..92043364 100644 --- a/DummyEngine/ToolBox/Loaders/SceneLoader.cpp +++ b/DummyEngine/ToolBox/Loaders/SceneLoader.cpp @@ -69,7 +69,7 @@ namespace DE { } } - template void SaveComponent(YAML::Node& n_Entity, Entity entity) { + template void SaveComponent(YAML::Node&, Entity) { // TODO: Different names for different unknown components... DE_ASSERT(false, "Trying to save unknown component"); } @@ -318,17 +318,17 @@ namespace DE { } } - template void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template void LoadComponent(Ref, YAML::Node, Entity&) { LOG_WARNING("Load function of {} undefined", DemangledName()); } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { entity.AddComponent(n_Component.as()); } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { auto s = n_Component.as(); entity.AddComponent(IDComponent(UUID(n_Component.as()))); } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { TransformComponent transformation; transformation.translation = GetVec3(n_Component["Translation"]); @@ -340,7 +340,7 @@ namespace DE { entity.AddComponent(transformation); } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { UUID id = n_Component["UUID"].as(); if (!ResourceManager::HasRenderMesh(id) && !ResourceManager::LoadRenderMesh(id)) { LOG_WARNING("RenderMesh {} not found in ResourceManager", id); @@ -373,7 +373,7 @@ namespace DE { scene->GetRenderer()->RequestShader(id); } } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { FPSCamera fps_camera; fps_camera.SetFov(n_Component["FOV"].as()); @@ -385,7 +385,7 @@ namespace DE { entity.AddComponent(fps_camera); } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { LightSource light_source; light_source.type = StringToLightSourceType(n_Component["Type"].as()); @@ -400,7 +400,7 @@ namespace DE { entity.AddComponent(light_source); } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { UUID id = n_Component["UUID"].as(); SkyBoxComponent::TexType type = (n_Component["Type"].as() == "CubeMap" ? SkyBoxComponent::TexType::CubeMap : SkyBoxComponent::TexType::Equirectangular); @@ -422,7 +422,7 @@ namespace DE { } } } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { ScriptComponent script = ScriptEngine::CreateScript(n_Component["UUID"].as()); entity.AddComponent(script); if (script.Valid()) { @@ -435,7 +435,7 @@ namespace DE { LOG_INFO("Failed to create valid script: {}", script.ID()); } } - template <> void LoadComponent(Ref scene, YAML::Node n_Component, Entity& entity) { + template <> void LoadComponent(Ref, YAML::Node n_Component, Entity& entity) { Physics::PhysicsComponent component{Vec3(0, 0, 0), Vec3(0, 0, 0), n_Component["InvMass"].as(), From 32d5dce699675dbef702c0fda641f12faf6ac24f Mon Sep 17 00:00:00 2001 From: Mag1str02 Date: Tue, 19 Nov 2024 22:36:40 +0300 Subject: [PATCH 2/7] Added clang-format check workflow --- .github/workflows/code_style.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/code_style.yml diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml new file mode 100644 index 00000000..3c4bfd1a --- /dev/null +++ b/.github/workflows/code_style.yml @@ -0,0 +1,27 @@ +name: CMake on multiple platforms + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + - name: clang-format Check DummyEngine + uses: jidicula/clang-format-action@v4.13.0 + with: + clang-format-version: '18' + check-path: 'DummyEngine' + - name: clang-format Check DummyEditor + uses: jidicula/clang-format-action@v4.13.0 + with: + clang-format-version: '18' + check-path: 'DummyEditor' From 5b8e16442290ab092944a9de31b727bc61fd8b87 Mon Sep 17 00:00:00 2001 From: Mag1str02 Date: Wed, 20 Nov 2024 01:28:04 +0300 Subject: [PATCH 3/7] Updated workflows --- .clang-format | 2 +- .github/workflows/build.yml | 18 ++++++++---------- .github/workflows/code_style.yml | 8 ++++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.clang-format b/.clang-format index 95116d2f..5540b5fe 100644 --- a/.clang-format +++ b/.clang-format @@ -33,7 +33,7 @@ NamespaceIndentation: All BinPackArguments: false BinPackParameters: false ReferenceAlignment: Left -BreakTemplateDeclarations: Leave +AlwaysBreakTemplateDeclarations: MultiLine AlignArrayOfStructures: Right AllowAllArgumentsOnNextLine: true AlignConsecutiveAssignments: true diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a86126be..cd5a7d23 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: CMake on multiple platforms +name: Build Checks on: push: @@ -7,42 +7,40 @@ on: branches: [ "main" ] jobs: - build: - runs-on: ${{ matrix.os }} + BuildUbuntu: + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - os: [ubuntu-latest] build_type: [RelWithDebInfo] c_compiler: [clang-19] cpp_compiler: [clang++-19] steps: - - name: install deps + - name: Install Packages run: | sudo apt update sudo apt install libwayland-dev libxkbcommon-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libgtk-3-dev wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 19 all - - uses: actions/checkout@v4 + - name: Checkout Repository + uses: actions/checkout@v4 with: submodules: 'true' - - name: Set reusable strings id: strings shell: bash run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - - name: Configure CMake + - name: CMake Configure run: > cmake -B ${{ steps.strings.outputs.build-output-dir }} -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S ${{ github.workspace }} - - - name: Build + - name: Cmake Build run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --target DummyEditor --parallel 16 diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml index 3c4bfd1a..275dccea 100644 --- a/.github/workflows/code_style.yml +++ b/.github/workflows/code_style.yml @@ -1,4 +1,4 @@ -name: CMake on multiple platforms +name: Style Checks on: push: @@ -7,7 +7,7 @@ on: branches: [ "main" ] jobs: - build: + FormatCheck: runs-on: ubuntu-latest strategy: @@ -15,12 +15,12 @@ jobs: steps: - uses: actions/checkout@v4 - - name: clang-format Check DummyEngine + - name: Check DummyEngine Format uses: jidicula/clang-format-action@v4.13.0 with: clang-format-version: '18' check-path: 'DummyEngine' - - name: clang-format Check DummyEditor + - name: Check DummyEditor Format uses: jidicula/clang-format-action@v4.13.0 with: clang-format-version: '18' From 5f02f8d0081d4cf9099278e6bf6a38929f6322f8 Mon Sep 17 00:00:00 2001 From: Mag1str02 Date: Wed, 20 Nov 2024 02:04:24 +0300 Subject: [PATCH 4/7] Added cmake targets to format sources --- CMake/Format.py | 6 ++++++ CMake/Utils.cmake | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 CMake/Format.py diff --git a/CMake/Format.py b/CMake/Format.py new file mode 100644 index 00000000..c42c5a13 --- /dev/null +++ b/CMake/Format.py @@ -0,0 +1,6 @@ +import os +import subprocess +for root, dirs, files in os.walk("."): + for file in files: + if file.endswith(".cpp") or file.endswith(".hpp") or file.endswith(".c") or file.endswith(".h"): + subprocess.run(["clang-format", "-i", "-style=file", os.path.join(root, file)]) \ No newline at end of file diff --git a/CMake/Utils.cmake b/CMake/Utils.cmake index b768bced..5ad2bbcc 100644 --- a/CMake/Utils.cmake +++ b/CMake/Utils.cmake @@ -23,4 +23,18 @@ endmacro(save_compile_flags) macro(restore_compile_flags) set(CMAKE_CXX_FLAGS "${CXX_BUFF}") set(CMAKE_C_FLAGS "${C_BUFF}") -endmacro(restore_compile_flags) \ No newline at end of file +endmacro(restore_compile_flags) + +add_custom_target(FormatDummyEngine + COMMAND python ${CMAKE_CURRENT_LIST_DIR}/Format.py + COMMENT "Running clang-format for DummyEngine" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/DummyEngine +) +add_custom_target(FormatDummyEditor + COMMAND python ${CMAKE_CURRENT_LIST_DIR}/Format.py + COMMENT "Running clang-format for DummyEditor" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/DummyEditor +) +add_custom_target(FormatAll) +add_dependencies(FormatAll FormatDummyEditor FormatDummyEngine) + From 8963aa768c6f638ee7b1cccc70bacc0586b5e04b Mon Sep 17 00:00:00 2001 From: Mag1str02 Date: Wed, 20 Nov 2024 02:04:40 +0300 Subject: [PATCH 5/7] Formatted all sources --- DummyEditor/DummyEngineInclude.h | 2 +- DummyEditor/EditorLayer.cpp | 2 +- DummyEngine/Core/Application/EntryPoint.h | 4 ++-- DummyEngine/Core/Application/Event.h | 10 +++++++--- DummyEngine/Core/Application/Window.cpp | 4 ++-- DummyEngine/Core/Console/Console.hpp | 10 +++++----- DummyEngine/Core/ECS/Storage.hpp | 2 +- .../Core/Objects/Cameras/FPSCamera.cpp | 2 +- .../Core/Rendering/Renderer/Renderer.cpp | 9 ++++++--- .../Rendering/RendererOpenGL/GLCubeMap.cpp | 1 - .../Rendering/RendererOpenGL/GLRenderAPI.cpp | 18 +++++++++--------- .../Rendering/RendererOpenGL/GLShader.cpp | 4 ++-- .../Rendering/RendererOpenGL/GLTexture.cpp | 2 +- .../Core/ResourceManaging/ResourceManager.cpp | 2 +- DummyEngine/Core/Scene/SceneRenderer.cpp | 2 +- DummyEngine/Core/Scene/SceneRenderer.h | 16 ++++++++-------- DummyEngine/Utils/Base.h | 2 +- DummyEngine/Utils/Base/STDIncludes.h | 2 +- DummyEngine/Utils/DS/Trie.cpp | 12 ++++++------ DummyEngine/Utils/DS/Trie.hpp | 19 +++++++++---------- DummyEngine/Utils/Debug/Profiler.h | 1 - DummyEngine/Utils/Types/STDAdapters.h | 12 ++++-------- 22 files changed, 69 insertions(+), 69 deletions(-) diff --git a/DummyEditor/DummyEngineInclude.h b/DummyEditor/DummyEngineInclude.h index e1284878..24e4ed7b 100644 --- a/DummyEditor/DummyEngineInclude.h +++ b/DummyEditor/DummyEngineInclude.h @@ -1,8 +1,8 @@ #pragma once +#include #include #include -#include #include #include "DummyEngine/DummyEngine.h" diff --git a/DummyEditor/EditorLayer.cpp b/DummyEditor/EditorLayer.cpp index aa9dfe2b..6b37068a 100644 --- a/DummyEditor/EditorLayer.cpp +++ b/DummyEditor/EditorLayer.cpp @@ -223,7 +223,7 @@ namespace DE { if (!ScriptManager::LoadScripts(m_SceneFileData.assets.scripts)) { return; } - m_CurrentScene = SceneLoader::Serialize(m_SceneFileData.hierarchy); + m_CurrentScene = SceneLoader::Serialize(m_SceneFileData.hierarchy); if (m_CurrentScene == nullptr) { return; } diff --git a/DummyEngine/Core/Application/EntryPoint.h b/DummyEngine/Core/Application/EntryPoint.h index 6fca2327..8b310220 100644 --- a/DummyEngine/Core/Application/EntryPoint.h +++ b/DummyEngine/Core/Application/EntryPoint.h @@ -17,10 +17,10 @@ int main() { DE::Initializer::Terminate(); } catch (const std::exception& e) { - LOG_FATAL_AS( "EntryPoint", "Unhandled exeption occured: {}", e.what()); + LOG_FATAL_AS("EntryPoint", "Unhandled exeption occured: {}", e.what()); return -1; } catch (...) { - LOG_FATAL_AS( "EntryPoint", "Unknown error occured"); + LOG_FATAL_AS("EntryPoint", "Unknown error occured"); return -1; } return 0; diff --git a/DummyEngine/Core/Application/Event.h b/DummyEngine/Core/Application/Event.h index 7669292e..7fcfabad 100644 --- a/DummyEngine/Core/Application/Event.h +++ b/DummyEngine/Core/Application/Event.h @@ -56,9 +56,13 @@ namespace DE { std::array>, static_cast(EventType::Count)> m_EventCallbacks; }; -#define EVENT_TYPE(type) \ - virtual EventType GetType() const override { return EventType::type; } \ - static EventType Type() { return EventType::type; } +#define EVENT_TYPE(type) \ + virtual EventType GetType() const override { \ + return EventType::type; \ + } \ + static EventType Type() { \ + return EventType::type; \ + } //*Responding diff --git a/DummyEngine/Core/Application/Window.cpp b/DummyEngine/Core/Application/Window.cpp index 69b28a74..5daf9f1e 100644 --- a/DummyEngine/Core/Application/Window.cpp +++ b/DummyEngine/Core/Application/Window.cpp @@ -9,7 +9,7 @@ namespace DE { GLFWmonitor* GetMonitor(U32 id) { int monitors_amount = 0; - GLFWmonitor** monitors = glfwGetMonitors(&monitors_amount); + GLFWmonitor** monitors = glfwGetMonitors(&monitors_amount); DE_ASSERT(0 <= id && id < U32(monitors_amount), "Wrong monitor id {} should be between [0, {})", id, monitors_amount); return monitors[id]; } @@ -43,7 +43,7 @@ namespace DE { stbi_image_free(icon.pixels); } void Window::FullScreen(U32 id) { - m_State.mode = WindowMode::FullScreen; + m_State.mode = WindowMode::FullScreen; m_State.monitor_id = id; Invalidate(); diff --git a/DummyEngine/Core/Console/Console.hpp b/DummyEngine/Core/Console/Console.hpp index 1ecf6e3e..73ea6464 100644 --- a/DummyEngine/Core/Console/Console.hpp +++ b/DummyEngine/Core/Console/Console.hpp @@ -25,12 +25,12 @@ namespace DE { S_METHOD_DEF(double, GetDouble, (std::string var)) S_METHOD_DEF(bool, GetBool, (std::string var)) S_METHOD_DEF(std::string, GetString, (std::string var)) - S_METHOD_DEF(std::vector, GetHints, (std::string& cmd)) + S_METHOD_DEF(std::vector, GetHints, (std::string & cmd)) private: - std::vector m_CmdHistory; - std::vector m_LogHistory; - std::map m_Variables; + std::vector m_CmdHistory; + std::vector m_LogHistory; + std::map m_Variables; std::map> m_Callback; - std::vector m_Commands; + std::vector m_Commands; }; } // namespace DE \ No newline at end of file diff --git a/DummyEngine/Core/ECS/Storage.hpp b/DummyEngine/Core/ECS/Storage.hpp index 17ba08be..347e6315 100644 --- a/DummyEngine/Core/ECS/Storage.hpp +++ b/DummyEngine/Core/ECS/Storage.hpp @@ -3,7 +3,7 @@ namespace DE { #ifdef ECS_IMPLEMENTATION - Storage::Storage() : m_ComponentManager(this), m_SystemManager(this){} + Storage::Storage() : m_ComponentManager(this), m_SystemManager(this) {} void Storage::Destruct() { for (U32 id = m_EntityManager.BeginEntity(); id != m_EntityManager.EndEntity(); id = m_EntityManager.NextEntity(id)) { m_ComponentManager.Destroy(id); diff --git a/DummyEngine/Core/Objects/Cameras/FPSCamera.cpp b/DummyEngine/Core/Objects/Cameras/FPSCamera.cpp index 83694641..d8119e2f 100644 --- a/DummyEngine/Core/Objects/Cameras/FPSCamera.cpp +++ b/DummyEngine/Core/Objects/Cameras/FPSCamera.cpp @@ -16,7 +16,7 @@ namespace DE { m_Direction = glm::normalize(camera_direction); m_Right = glm::normalize(glm::cross(m_Direction, m_WorldUp)); m_Up = glm::normalize(glm::cross(m_Right, m_Direction)); - m_FarPlane = 100; + m_FarPlane = 100; m_NearPlane = -10; } diff --git a/DummyEngine/Core/Rendering/Renderer/Renderer.cpp b/DummyEngine/Core/Rendering/Renderer/Renderer.cpp index e2d6c714..510ecd2b 100644 --- a/DummyEngine/Core/Rendering/Renderer/Renderer.cpp +++ b/DummyEngine/Core/Rendering/Renderer/Renderer.cpp @@ -62,7 +62,10 @@ namespace DE { ++m_FrameStatistics.m_DrawnInstances; return Unit(); } - S_METHOD_IMPL(Unit, Submit, (Ref mesh, Ref shader, const Mat4& transform, const bool is_depthmap), (mesh, shader, transform, is_depthmap)) { + S_METHOD_IMPL(Unit, + Submit, + (Ref mesh, Ref shader, const Mat4& transform, const bool is_depthmap), + (mesh, shader, transform, is_depthmap)) { shader->Bind(); shader->SetMat4("u_Transform", transform); for (const auto& sub_mesh : mesh->m_SubMeshes) { @@ -517,7 +520,7 @@ namespace DE { } { std::vector parts = { - { ShaderPartType::Vertex, shaders / "Vertex/DirectionalShadowMap.vs"}, + { ShaderPartType::Vertex, shaders / "Vertex/DirectionalShadowMap.vs"}, {ShaderPartType::Fragment, shaders / "Fragment/DirectionalShadowMap.fs"} }; @@ -525,7 +528,7 @@ namespace DE { } { std::vector parts = { - {ShaderPartType::Vertex, shaders / "Vertex/OmnidirectionalShadowMap.vs"}, + { ShaderPartType::Vertex, shaders / "Vertex/OmnidirectionalShadowMap.vs"}, {ShaderPartType::Fragment, shaders / "Fragment/OmnidirectionalShadowMap.fs"}, {ShaderPartType::Geometry, shaders / "Geometry/OmnidirectionalShadowMap.gs"} }; diff --git a/DummyEngine/Core/Rendering/RendererOpenGL/GLCubeMap.cpp b/DummyEngine/Core/Rendering/RendererOpenGL/GLCubeMap.cpp index bfea50c2..61deaca4 100644 --- a/DummyEngine/Core/Rendering/RendererOpenGL/GLCubeMap.cpp +++ b/DummyEngine/Core/Rendering/RendererOpenGL/GLCubeMap.cpp @@ -70,7 +70,6 @@ namespace DE { GLTextureFormatExternal(channels), depth_map ? GL_FLOAT : GL_UNSIGNED_BYTE, nullptr); - } if (gen_mipmap) { glGenerateMipmap(GL_TEXTURE_CUBE_MAP); diff --git a/DummyEngine/Core/Rendering/RendererOpenGL/GLRenderAPI.cpp b/DummyEngine/Core/Rendering/RendererOpenGL/GLRenderAPI.cpp index 538ab543..53efab1e 100644 --- a/DummyEngine/Core/Rendering/RendererOpenGL/GLRenderAPI.cpp +++ b/DummyEngine/Core/Rendering/RendererOpenGL/GLRenderAPI.cpp @@ -9,9 +9,9 @@ namespace DE { void GLRenderAPI::SetDefaultState() { glEnable(GL_DEPTH_TEST); glEnable(GL_MULTISAMPLE); -// glEnable(GL_CULL_FACE); + // glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); -// glFrontFace(GL_CW); + // glFrontFace(GL_CW); // glDepthMask(GL_TRUE); // glDepthFunc(GL_LEQUAL); @@ -57,18 +57,18 @@ namespace DE { void GLRenderAPI::Enable(RenderSetting setting) { switch (setting) { case RenderSetting::DepthTest: glEnable(GL_DEPTH_TEST); break; - case RenderSetting::MultiSampling: glEnable(GL_MULTISAMPLE); break; - case RenderSetting::FaceCulling: glEnable(GL_CULL_FACE); break; - case RenderSetting::DepthMask: glDepthMask(GL_TRUE); break; + case RenderSetting::MultiSampling: glEnable(GL_MULTISAMPLE); break; + case RenderSetting::FaceCulling: glEnable(GL_CULL_FACE); break; + case RenderSetting::DepthMask: glDepthMask(GL_TRUE); break; default: break; } } void GLRenderAPI::Disable(RenderSetting setting) { switch (setting) { - case RenderSetting::DepthTest: glDisable(GL_DEPTH_TEST); break; - case RenderSetting::MultiSampling: glDisable(GL_MULTISAMPLE); break; - case RenderSetting::FaceCulling: glDisable(GL_CULL_FACE); break; - case RenderSetting::DepthMask: glDepthMask(GL_FALSE); break; + case RenderSetting::DepthTest: glDisable(GL_DEPTH_TEST); break; + case RenderSetting::MultiSampling: glDisable(GL_MULTISAMPLE); break; + case RenderSetting::FaceCulling: glDisable(GL_CULL_FACE); break; + case RenderSetting::DepthMask: glDepthMask(GL_FALSE); break; default: break; } } diff --git a/DummyEngine/Core/Rendering/RendererOpenGL/GLShader.cpp b/DummyEngine/Core/Rendering/RendererOpenGL/GLShader.cpp index d51891c4..642f3dc2 100644 --- a/DummyEngine/Core/Rendering/RendererOpenGL/GLShader.cpp +++ b/DummyEngine/Core/Rendering/RendererOpenGL/GLShader.cpp @@ -21,7 +21,7 @@ namespace DE { } glLinkProgram(m_ShaderId); - int success; + int success; std::string info_log; info_log.resize(Config::GetI(DE_CFG_MAX_COMPILE_ERROR_LEN)); glGetProgramiv(m_ShaderId, GL_LINK_STATUS, &success); @@ -130,7 +130,7 @@ namespace DE { glCompileShader(shader_part); m_Parts.push_back(shader_part); - int success = 1; + int success = 1; std::string info_log; info_log.resize(Config::GetI(DE_CFG_MAX_COMPILE_ERROR_LEN)); int len = 0; diff --git a/DummyEngine/Core/Rendering/RendererOpenGL/GLTexture.cpp b/DummyEngine/Core/Rendering/RendererOpenGL/GLTexture.cpp index c6dd2cab..b3f8d92e 100644 --- a/DummyEngine/Core/Rendering/RendererOpenGL/GLTexture.cpp +++ b/DummyEngine/Core/Rendering/RendererOpenGL/GLTexture.cpp @@ -24,7 +24,7 @@ namespace DE { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f }; + float borderColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); } Resize(width, height); diff --git a/DummyEngine/Core/ResourceManaging/ResourceManager.cpp b/DummyEngine/Core/ResourceManaging/ResourceManager.cpp index 0c6e6a38..dc2c4548 100644 --- a/DummyEngine/Core/ResourceManaging/ResourceManager.cpp +++ b/DummyEngine/Core/ResourceManaging/ResourceManager.cpp @@ -55,7 +55,7 @@ namespace DE { LOG_WARNING("Hitbox {} was not loaded because does not exist in AssetManager", id); return false; } - auto mesh = ModelLoader::Load(asset.value().loading_props); + auto mesh = ModelLoader::Load(asset.value().loading_props); if (mesh == nullptr) { return false; } diff --git a/DummyEngine/Core/Scene/SceneRenderer.cpp b/DummyEngine/Core/Scene/SceneRenderer.cpp index be2784e0..2b4ec801 100644 --- a/DummyEngine/Core/Scene/SceneRenderer.cpp +++ b/DummyEngine/Core/Scene/SceneRenderer.cpp @@ -10,7 +10,7 @@ #include "DummyEngine/Core/Scripting/ScriptEngine.h" namespace DE { - const U32 MAX_LIGHTS_IN_SCENE = 1000; + const U32 MAX_LIGHTS_IN_SCENE = 1000; const U32 LIGHT_UB_ID = 1; diff --git a/DummyEngine/Core/Scene/SceneRenderer.h b/DummyEngine/Core/Scene/SceneRenderer.h index dce84250..f1e13a6b 100644 --- a/DummyEngine/Core/Scene/SceneRenderer.h +++ b/DummyEngine/Core/Scene/SceneRenderer.h @@ -24,7 +24,7 @@ namespace DE { float gamma = 1; bool use_directional_shadow_map = false; - bool use_point_shadows = false; + bool use_point_shadows = false; }; Settings settings; SceneRenderer(Scene* scene); @@ -41,12 +41,12 @@ namespace DE { private: void UpdateShaders(const FPSCamera& camera, Entity skybox, const FPSCamera& lightCamera); - Scene* m_Scene; - Ref m_Lights; - Ref m_FrameBuffer; - Ref m_ShadowMap; - std::unordered_map > m_PointShadowFrameBuffers; - std::unordered_map > m_PointShadowCubemaps; - std::unordered_map> m_Shaders; + Scene* m_Scene; + Ref m_Lights; + Ref m_FrameBuffer; + Ref m_ShadowMap; + std::unordered_map> m_PointShadowFrameBuffers; + std::unordered_map> m_PointShadowCubemaps; + std::unordered_map> m_Shaders; }; } // namespace DE \ No newline at end of file diff --git a/DummyEngine/Utils/Base.h b/DummyEngine/Utils/Base.h index 443a231c..d986faf9 100644 --- a/DummyEngine/Utils/Base.h +++ b/DummyEngine/Utils/Base.h @@ -14,5 +14,5 @@ #include "DummyEngine/Utils/Helpers/Singleton.h" #include "DummyEngine/Utils/Helpers/StringOperations.h" #include "DummyEngine/Utils/Helpers/Timer.h" -#include "DummyEngine/Utils/Types/UUID.h" #include "DummyEngine/Utils/Types/STDAdapters.h" +#include "DummyEngine/Utils/Types/UUID.h" diff --git a/DummyEngine/Utils/Base/STDIncludes.h b/DummyEngine/Utils/Base/STDIncludes.h index b85426bc..b309a184 100644 --- a/DummyEngine/Utils/Base/STDIncludes.h +++ b/DummyEngine/Utils/Base/STDIncludes.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -26,4 +27,3 @@ #include #include #include -#include \ No newline at end of file diff --git a/DummyEngine/Utils/DS/Trie.cpp b/DummyEngine/Utils/DS/Trie.cpp index 0782870d..4efb0775 100644 --- a/DummyEngine/Utils/DS/Trie.cpp +++ b/DummyEngine/Utils/DS/Trie.cpp @@ -67,13 +67,13 @@ namespace DE { std::vector> Trie::Search(std::string needle) { std::vector> result; - std::set idx_found; - Ref current = m_root; - for (char c: needle) { - current = getNext(current, c); - auto &ptr = current; + std::set idx_found; + Ref current = m_root; + for (char c : needle) { + current = getNext(current, c); + auto& ptr = current; while (ptr != m_root) { - for (const auto &idx: ptr->terminal_idx) { + for (const auto& idx : ptr->terminal_idx) { if (idx_found.contains(idx)) { continue; } diff --git a/DummyEngine/Utils/DS/Trie.hpp b/DummyEngine/Utils/DS/Trie.hpp index e37e3a78..1ffbbf35 100644 --- a/DummyEngine/Utils/DS/Trie.hpp +++ b/DummyEngine/Utils/DS/Trie.hpp @@ -5,20 +5,20 @@ namespace DE { class Trie { struct Node { - Node(Ref &p, char prev) { - parent = p; + Node(Ref& p, char prev) { + parent = p; char_to_parent = prev; } std::vector terminal_idx; Ref parent; - char char_to_parent; + char char_to_parent; std::unordered_map> next; std::unordered_map> sons; - Ref suffix_link; - Ref super_suffix_link; + Ref suffix_link; + Ref super_suffix_link; }; Ref getSuffixLink(Ref v); @@ -26,13 +26,12 @@ namespace DE { Ref getUp(Ref v); public: - - void Build(std::vector &dict); - void AddWord(std::string &str); + void Build(std::vector& dict); + void AddWord(std::string& str); std::vector> Search(std::string needle); private: - Ref m_root; + Ref m_root; std::vector> m_words; }; -} \ No newline at end of file +} // namespace DE \ No newline at end of file diff --git a/DummyEngine/Utils/Debug/Profiler.h b/DummyEngine/Utils/Debug/Profiler.h index 39e7e9e0..eba14cb6 100644 --- a/DummyEngine/Utils/Debug/Profiler.h +++ b/DummyEngine/Utils/Debug/Profiler.h @@ -10,7 +10,6 @@ #include "DummyEngine/Utils/Helpers/Singleton.h" #include "DummyEngine/Utils/Types/Types.h" - namespace DE { struct TimeLapse { std::chrono::time_point m_Start; diff --git a/DummyEngine/Utils/Types/STDAdapters.h b/DummyEngine/Utils/Types/STDAdapters.h index 57e5fc3f..7e8e29b1 100644 --- a/DummyEngine/Utils/Types/STDAdapters.h +++ b/DummyEngine/Utils/Types/STDAdapters.h @@ -4,26 +4,22 @@ #include "DummyEngine/Utils/Types/UUID.h" namespace std { - template <> - struct formatter : formatter { + template <> struct formatter : formatter { auto format(const DE::Vec3& vec, format_context& ctx) const { return formatter::format(std::format("({}, {}, {})", vec.x, vec.y, vec.z), ctx); } }; - template <> - struct formatter : formatter { + template <> struct formatter : formatter { auto format(const DE::Vec4& vec, format_context& ctx) const { return formatter::format(std::format("({}, {}, {}, {})", vec.x, vec.y, vec.z, vec.w), ctx); } }; - template <> - struct formatter : formatter { + template <> struct formatter : formatter { auto format(const DE::Path& path, format_context& ctx) const { return formatter::format(path.string(), ctx); } }; - template <> - struct formatter : formatter { + template <> struct formatter : formatter { auto format(const DE::UUID& uuid, format_context& ctx) const { return formatter::format(uuid.Hex(), ctx); } }; } // namespace std \ No newline at end of file From 8b060217b772df4faed63a39a07dd089930da924 Mon Sep 17 00:00:00 2001 From: Mag1str0 Date: Wed, 20 Nov 2024 02:20:59 +0300 Subject: [PATCH 6/7] Fix clang format diffs --- .clang-format | 3 ++- DummyEngine/Core/Application/Initializer.cpp | 4 +--- DummyEngine/Core/Scripting/Script.h | 2 ++ DummyEngine/Utils/Helpers/Singleton.h | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.clang-format b/.clang-format index 5540b5fe..aed8f7cd 100644 --- a/.clang-format +++ b/.clang-format @@ -38,4 +38,5 @@ AlignArrayOfStructures: Right AllowAllArgumentsOnNextLine: true AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true -IncludeBlocks: Preserve \ No newline at end of file +IncludeBlocks: Preserve +AllowShortBlocksOnASingleLine: Empty \ No newline at end of file diff --git a/DummyEngine/Core/Application/Initializer.cpp b/DummyEngine/Core/Application/Initializer.cpp index ea21fe3b..2cfa3326 100644 --- a/DummyEngine/Core/Application/Initializer.cpp +++ b/DummyEngine/Core/Application/Initializer.cpp @@ -77,9 +77,7 @@ namespace DE { void Initializer::DepTerminate() { LOG_INFO("Terminating dependencies"); //* Terminate GLFW - { - glfwTerminate(); - } + { glfwTerminate(); } } void Initializer::PostTerminate() { LOG_INFO("PostTerminating"); diff --git a/DummyEngine/Core/Scripting/Script.h b/DummyEngine/Core/Scripting/Script.h index 328306b3..5d559e16 100644 --- a/DummyEngine/Core/Scripting/Script.h +++ b/DummyEngine/Core/Scripting/Script.h @@ -102,9 +102,11 @@ namespace DE { std::string ScriptFieldTypeToString(ScriptFieldType type); template ScriptFieldType TypeToScriptFieldType(); + // clang-format off template constexpr U32 OffsetOf(U T::* member) { return (size_t)&((T*)nullptr->*member); } + // clang-format on template T& Script::Field::Get() { DE_ASSERT(m_Type == TypeToScriptFieldType(), diff --git a/DummyEngine/Utils/Helpers/Singleton.h b/DummyEngine/Utils/Helpers/Singleton.h index 5860a251..62485060 100644 --- a/DummyEngine/Utils/Helpers/Singleton.h +++ b/DummyEngine/Utils/Helpers/Singleton.h @@ -82,8 +82,9 @@ namespace DE { protected: static T& Get(); - Singleton() {}; - virtual ~Singleton() {} + + Singleton() = default; + virtual ~Singleton() = default; static T* s_Instance; }; } // namespace DE From 83762b80932ad13b7c9be99e77c6fb6595a28787 Mon Sep 17 00:00:00 2001 From: Mag1str0 Date: Wed, 20 Nov 2024 02:53:08 +0300 Subject: [PATCH 7/7] Enabled -Werror for engine and editor --- CMake/Compiler.cmake | 2 +- DummyEditor/Platform/Linux/Scripting/Compiler.cpp | 2 +- DummyEngine/ToolBox/Loaders/ModelLoader.cpp | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CMake/Compiler.cmake b/CMake/Compiler.cmake index a70663f8..4fdb7a79 100644 --- a/CMake/Compiler.cmake +++ b/CMake/Compiler.cmake @@ -13,7 +13,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") endif() function(add_warnings TARGET) - target_compile_options(${TARGET} PUBLIC -Wall -Wextra -Wpedantic -Wno-extra-semi -Wno-missing-field-initializers) + target_compile_options(${TARGET} PUBLIC -Wall -Wextra -Wpedantic -Wno-extra-semi -Wno-missing-field-initializers -Werror) if (${ENABLE_PRECOMPILED_HEADERS}) target_compile_options(${TARGET} PUBLIC -Winvalid-pch) diff --git a/DummyEditor/Platform/Linux/Scripting/Compiler.cpp b/DummyEditor/Platform/Linux/Scripting/Compiler.cpp index 4c46fa70..c588bdfe 100644 --- a/DummyEditor/Platform/Linux/Scripting/Compiler.cpp +++ b/DummyEditor/Platform/Linux/Scripting/Compiler.cpp @@ -76,7 +76,7 @@ namespace DE { return res; } std::string AddSourceArgument(const Path& source) { return " " + source.string(); } - std::string AddDestinationArgument(const Path& source, const Path& destination) { return " -o " + destination.string(); } + std::string AddDestinationArgument(const Path&, const Path& destination) { return " -o " + destination.string(); } std::string AddSourcesArguments(const std::vector& sources) { std::string res; diff --git a/DummyEngine/ToolBox/Loaders/ModelLoader.cpp b/DummyEngine/ToolBox/Loaders/ModelLoader.cpp index 6ed6d976..ceafa7eb 100644 --- a/DummyEngine/ToolBox/Loaders/ModelLoader.cpp +++ b/DummyEngine/ToolBox/Loaders/ModelLoader.cpp @@ -28,7 +28,7 @@ namespace DE { } void ModelLoader::LoadBone(Bone& bone, aiNodeAnim* node) { - for (S32 i = 0; i < node->mNumPositionKeys; ++i) { + for (U32 i = 0; i < node->mNumPositionKeys; ++i) { auto pos = node->mPositionKeys[i].mValue; float time_stamp = node->mPositionKeys[i].mTime; KeyPosition data; @@ -39,7 +39,7 @@ namespace DE { bone.m_Positions.push_back(data); } - for (S32 i = 0; i < node->mNumRotationKeys; ++i) { + for (U32 i = 0; i < node->mNumRotationKeys; ++i) { auto rot = node->mRotationKeys[i].mValue; float time_stamp = node->mRotationKeys[i].mTime; KeyRotation data; @@ -51,7 +51,7 @@ namespace DE { bone.m_Rotations.push_back(data); } - for (S32 i = 0; i < node->mNumScalingKeys; ++i) { + for (U32 i = 0; i < node->mNumScalingKeys; ++i) { aiVector3D scale = node->mScalingKeys[i].mValue; float time_stamp = node->mScalingKeys[i].mTime; KeyScale data; @@ -77,7 +77,7 @@ namespace DE { } auto& animation = *model.animation; - for (int i = 0; i < mesh->mNumBones; ++i) { + for (U32 i = 0; i < mesh->mNumBones; ++i) { int bone_id = -1; std::string bone_name = mesh->mBones[i]->mName.C_Str(); if (!animation.m_BoneNameToID.contains(bone_name)) { @@ -100,7 +100,7 @@ namespace DE { int weights_amount = mesh->mBones[i]->mNumWeights; for (int j = 0; j < weights_amount; ++j) { - int v_id = weights[j].mVertexId; + U32 v_id = weights[j].mVertexId; float weight = weights[j].mWeight; if (v_id >= current_mesh.vertices.size()) { @@ -112,7 +112,7 @@ namespace DE { } } void ModelLoader::ReadBones(Animation& animation, const aiAnimation* anim) { - for (int i = 0; i < anim->mNumChannels; ++i) { + for (U32 i = 0; i < anim->mNumChannels; ++i) { auto channel = anim->mChannels[i]; auto bone_info = animation.GetBone(channel->mNodeName.data); if (!bone_info) { @@ -131,7 +131,7 @@ namespace DE { node.transformation = AssimpToGLM(src->mTransformation); node.childrens.resize(src->mNumChildren); - for (int i = 0; i < src->mNumChildren; i++) { + for (U32 i = 0; i < src->mNumChildren; i++) { Animation::Node& data = node.childrens[i]; ReadAnimationNode(data, src->mChildren[i]); }