Skip to content

Commit

Permalink
Enabled warnings and added style check action
Browse files Browse the repository at this point in the history
Environment changes
  • Loading branch information
Mag1str02 authored Nov 19, 2024
2 parents cf48d33 + 83762b8 commit e9274d1
Show file tree
Hide file tree
Showing 67 changed files with 285 additions and 247 deletions.
5 changes: 3 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ NamespaceIndentation: All
BinPackArguments: false
BinPackParameters: false
ReferenceAlignment: Left
BreakTemplateDeclarations: Leave
AlwaysBreakTemplateDeclarations: MultiLine
AlignArrayOfStructures: Right
AllowAllArgumentsOnNextLine: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
IncludeBlocks: Preserve
IncludeBlocks: Preserve
AllowShortBlocksOnASingleLine: Empty
18 changes: 8 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake on multiple platforms
name: Build Checks

on:
push:
Expand All @@ -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
27 changes: 27 additions & 0 deletions .github/workflows/code_style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Style Checks

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
FormatCheck:
runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4
- name: Check DummyEngine Format
uses: jidicula/[email protected]
with:
clang-format-version: '18'
check-path: 'DummyEngine'
- name: Check DummyEditor Format
uses: jidicula/[email protected]
with:
clang-format-version: '18'
check-path: 'DummyEditor'
10 changes: 9 additions & 1 deletion CMake/Compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
endif()

function(add_warnings TARGET)
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)
endif()
endfunction(add_warnings)
6 changes: 6 additions & 0 deletions CMake/Format.py
Original file line number Diff line number Diff line change
@@ -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)])
16 changes: 15 additions & 1 deletion CMake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)

2 changes: 1 addition & 1 deletion DummyEditor/DummyEngineInclude.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#include <imgui.h>
#include <imgui_stdlib.h>

#include "DummyEngine/DummyEngine.h"
6 changes: 3 additions & 3 deletions DummyEditor/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -367,7 +367,7 @@ namespace DE {

//*___Other________________________________________________________________________________________________________________________________________________________________________________________

void TransformSyncSystem::Update(float dt) {
void TransformSyncSystem::Update(float) {
for (auto entity : View<LightSource, TransformComponent>()) {
entity.Get<LightSource>().position = entity.Get<TransformComponent>().translation;
}
Expand Down
5 changes: 2 additions & 3 deletions DummyEditor/ImGuiUtils/ImGuiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions DummyEditor/ImGuiUtils/ImGuiUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ 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();
ImGui::SetNextItemWidth(-1);
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();
Expand All @@ -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();
Expand Down
34 changes: 17 additions & 17 deletions DummyEditor/Panels/InspectorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace DE {
}
}

template <typename Component> void InspectorPanel::DrawComponentWidget(Entity entity) {
template <typename Component> void InspectorPanel::DrawComponentWidget() {
if (m_Entity.Has<Component>()) {
std::string header = ICON_MD_REPORT_PROBLEM " " + DemangledName<Component>();
if (ImGui::CollapsingHeader(header.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
Expand All @@ -24,7 +24,7 @@ namespace DE {
}
}

template <> void InspectorPanel::DrawComponentWidget<TransformComponent>(Entity entity) {
template <> void InspectorPanel::DrawComponentWidget<TransformComponent>() {
if (m_Entity.Has<TransformComponent>()) {
if (ImGui::CollapsingHeader(ICON_MD_OPEN_IN_FULL " Transformation", ImGuiTreeNodeFlags_DefaultOpen)) {
auto& transform = m_Entity.Get<TransformComponent>();
Expand All @@ -36,7 +36,7 @@ namespace DE {
}
}
}
template <> void InspectorPanel::DrawComponentWidget<TagComponent>(Entity entity) {
template <> void InspectorPanel::DrawComponentWidget<TagComponent>() {
if (m_Entity.Has<TagComponent>()) {
auto& component = m_Entity.Get<TagComponent>();
if (ImGui::CollapsingHeader(ICON_MD_BADGE " Tag", ImGuiTreeNodeFlags_DefaultOpen)) {
Expand All @@ -46,7 +46,7 @@ namespace DE {
}
}
}
template <> void InspectorPanel::DrawComponentWidget<ScriptComponent>(Entity entity) {
template <> void InspectorPanel::DrawComponentWidget<ScriptComponent>() {
if (m_Entity.Has<ScriptComponent>()) {
auto& component = m_Entity.Get<ScriptComponent>();
if (ImGui::CollapsingHeader(ICON_MD_DESCRIPTION " Script", ImGuiTreeNodeFlags_DefaultOpen)) {
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace DE {
}
}
}
template <> void InspectorPanel::DrawComponentWidget<FPSCamera>(Entity entity) {
template <> void InspectorPanel::DrawComponentWidget<FPSCamera>() {
if (m_Entity.Has<FPSCamera>()) {
if (ImGui::CollapsingHeader(ICON_MD_VIDEOCAM " FPSCamera", ImGuiTreeNodeFlags_DefaultOpen)) {
auto& camera = m_Entity.Get<FPSCamera>();
Expand All @@ -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<LightSource>(Entity entity) {
template <> void InspectorPanel::DrawComponentWidget<LightSource>() {
if (m_Entity.Has<LightSource>()) {
if (ImGui::CollapsingHeader(ICON_MD_LIGHTBULB " LightSoruce", ImGuiTreeNodeFlags_DefaultOpen)) {
auto& source = m_Entity.Get<LightSource>();
Expand Down Expand Up @@ -134,7 +134,7 @@ namespace DE {
}
}
}
template <> void InspectorPanel::DrawComponentWidget<RenderMeshComponent>(Entity entity) {
template <> void InspectorPanel::DrawComponentWidget<RenderMeshComponent>() {
if (m_Entity.Has<RenderMeshComponent>()) {
if (ImGui::CollapsingHeader(ICON_MD_TOKEN " RenderMesh", ImGuiTreeNodeFlags_DefaultOpen)) {
auto& meshes = m_Entity.Get<RenderMeshComponent>()->GetSubMeshes();
Expand All @@ -153,7 +153,7 @@ namespace DE {
}
}

template <> void InspectorPanel::DrawComponentWidget<Physics::PhysicsComponent>(Entity entity) {
template <> void InspectorPanel::DrawComponentWidget<Physics::PhysicsComponent>() {
if (m_Entity.Has<Physics::PhysicsComponent>()) {
if (ImGui::CollapsingHeader(" PhysicsComponent", ImGuiTreeNodeFlags_DefaultOpen)) {
auto& phys = m_Entity.Get<Physics::PhysicsComponent>();
Expand All @@ -176,14 +176,14 @@ namespace DE {
if (ImGui::Begin(ICON_MD_INFO " Inspector")) {
auto scene = m_Scene.lock();
if (scene && m_Entity.Valid()) {
DrawComponentWidget<TagComponent>(m_Entity);
DrawComponentWidget<ScriptComponent>(m_Entity);
DrawComponentWidget<TransformComponent>(m_Entity);
DrawComponentWidget<FPSCamera>(m_Entity);
DrawComponentWidget<LightSource>(m_Entity);
DrawComponentWidget<RenderMeshComponent>(m_Entity);
DrawComponentWidget<SkyBoxComponent>(m_Entity);
DrawComponentWidget<Physics::PhysicsComponent>(m_Entity);
DrawComponentWidget<TagComponent>();
DrawComponentWidget<ScriptComponent>();
DrawComponentWidget<TransformComponent>();
DrawComponentWidget<FPSCamera>();
DrawComponentWidget<LightSource>();
DrawComponentWidget<RenderMeshComponent>();
DrawComponentWidget<SkyBoxComponent>();
DrawComponentWidget<Physics::PhysicsComponent>();
AddComponent();
}
}
Expand Down
4 changes: 1 addition & 3 deletions DummyEditor/Panels/InspectorPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ namespace DE {
void SetScene(WeakRef<Scene> scene);

private:
template <typename Component> void DrawComponentWidget(Entity entity);
template <typename Component> void DrawComponentWidget();

Entity m_Entity;
WeakRef<Scene> m_Scene;

float m_SliderSensitivity = 0.1;
};
} // namespace DE
2 changes: 1 addition & 1 deletion DummyEditor/Platform/Linux/Scripting/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>& sources) {
std::string res;
Expand Down
2 changes: 1 addition & 1 deletion DummyEditor/Platform/Windows/Scripting/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>& sources) {
std::string res;
Expand Down
4 changes: 2 additions & 2 deletions DummyEditor/Scripting/ScriptManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace DE {
return false;
}

RestoreSciptStates(states, scene);
RestoreSciptStates(states);
AttachScripts(scene);

return true;
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace DE {
}
return states;
}
void ScriptManager::RestoreSciptStates(const ScriptStates& states, Ref<Scene> 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;
Expand Down
2 changes: 1 addition & 1 deletion DummyEditor/Scripting/ScriptManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace DE {
using ScriptStates = std::unordered_map<Entity, std::unordered_map<std::string, Script::Field>>;

ScriptStates SaveSciptStates(Ref<Scene> scene);
void RestoreSciptStates(const ScriptStates& states, Ref<Scene> 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;
Expand Down
1 change: 1 addition & 0 deletions DummyEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Loading

0 comments on commit e9274d1

Please sign in to comment.