Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor config and logging #10

Merged
merged 34 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
36c49dc
🚚 Move config and logging initialization to engine modules
vis4rd Sep 1, 2024
00f2d0c
🔧 Rename cebug mode to debug build
vis4rd Oct 5, 2024
8bfef02
🔧 Add some window settings to config.ini
vis4rd Oct 5, 2024
e823dcf
🚧 Experiment with new UI construct for development
vis4rd Oct 5, 2024
7e46eb2
✨ Create util module for checking which compiler is used
vis4rd Oct 26, 2024
15f2756
✨ Create separate loggers for engine and app
vis4rd Oct 26, 2024
12d9cbf
🚸 Add dedicated log functions for use by app
vis4rd Oct 26, 2024
5e1531c
🎨 Replace calls to spdlog in game directory to mono::log
vis4rd Oct 26, 2024
cb23d9c
🚚 Add mono/ prefix to logging module include paths
vis4rd Oct 26, 2024
ef6b380
🚚 Add mono/ prefix to config module include paths
vis4rd Oct 27, 2024
1519701
✨ Add ConfigItem class
vis4rd Oct 1, 2024
c396460
🚧 ✨ Add ConfigStorage class and validators
vis4rd Oct 27, 2024
c8cfb38
✨ Use ConfigStorage instead of raw ini::File in mono::config
vis4rd Oct 30, 2024
ae23500
🎨 Adapt codebase to config changes, add config converters for glm::ve…
vis4rd Oct 30, 2024
5e78975
🚚 Rename mono::config::data::configStorage to mono::config::runtime
vis4rd Nov 1, 2024
67ace52
🎨 Change ConfigStorage to return ConfigItem instead of the config val…
vis4rd Nov 1, 2024
84169d5
✨ Add getUserData() method to ConfigItem
vis4rd Nov 1, 2024
2e62d3f
✨ Add CallbackGuard class, add possibility to set callbacks for when …
vis4rd Nov 1, 2024
bbce47a
🐛 Fix callbacks being set on a copy of ConfigItem instead of actual o…
vis4rd Nov 2, 2024
a984dfe
🎨 Add possibility to specify a validator function on ConfigItem const…
vis4rd Nov 2, 2024
cb7f177
🧑‍💻 Add VSCode task to run clang-tidy on an active file
vis4rd Nov 2, 2024
4a4a7ea
💚 Fix clang-tidy check running condition wrongly triggering the job
vis4rd Nov 2, 2024
28e3ae8
♻️ Change ConfigItem to abstract base class and create derived classe…
vis4rd Nov 3, 2024
5c15d31
🎨 Change ConfigItem::getType() to return std::string instead of std::…
vis4rd Nov 3, 2024
bbc509c
✨ Add support for iterating through ConfigItems in ConfigStorage
vis4rd Nov 3, 2024
3b73d0f
✨ Add mono::ArithmeticTrait
vis4rd Nov 3, 2024
10942fc
🥅 Improve logging of configuration errors, validate all ConfigItems d…
vis4rd Nov 3, 2024
c68ea31
✨ Add mono::config::RangeNumberConfigItem
vis4rd Nov 1, 2024
412b579
💚 Fix CI build
vis4rd Nov 1, 2024
5ebba28
🐛 Add missing config fields in config.ini
vis4rd Nov 4, 2024
0765dca
🥅 Validate config fields missing in config.ini
vis4rd Nov 4, 2024
91d81ec
🧑‍💻 Buffer logs before logging is initialized and dump them as soon a…
vis4rd Nov 4, 2024
41c014e
🔥 Remove config.ini from being tracked in git
vis4rd Nov 4, 2024
fa79268
💡 Remove TODO comment in ConfigStorage
vis4rd Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
continue-on-error: true

- name: Run clang-tidy
if: ${{ steps.check-compile-commands.outcome == 'success' }} && ${{ steps.list-files.outcome == 'success' }}
if: ${{ steps.check-compile-commands.outcome == 'success' && steps.list-files.outcome == 'success' }}
shell: bash
run: |
cat files.txt | xargs clang-tidy --quiet --config-file=.clang-tidy -p=${{ github.workspace }}/build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ dev/
# Logging
logs/
*.log

# Configuration
config/config.ini
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"C_Cpp.loggingLevel": "Debug",
//
"clangd.arguments": [
"-log=verbose",
"--log=verbose",
"--clang-tidy",
],
//
Expand Down
61 changes: 46 additions & 15 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
//! Executing tasks on Windows requires Git Bash (or other unix-like shell) to be installed.
// Default shell on Windows is either Powershell or CMD, which do not support grep or xargs.
// Basically it is easier to require specific shell than to maintain multiplatform tasks.
"version": "2.0.0",
"tasks": [
{
Expand All @@ -17,17 +14,17 @@
"clear": true,
"panel": "dedicated",
"reveal": "silent",
"showReuseMessage": false,
},
"showReuseMessage": false
}
},
{
"label": "Run clang-tidy",
"label": "Run clang-tidy (all files)",
"detail": "Run clang-tidy on all C++ files in src/ directory.",
"type": "shell",
"command": "cmake -P ./cmake/clang-tidy.cmake",
"icon": {
"color": "terminal.ansiCyan",
"id": "sparkle",
"id": "sparkle"
},
"problemMatcher": {
"source": "clang-tidy",
Expand All @@ -42,26 +39,60 @@
"column": 3,
"severity": 4,
"message": 5,
"code": 6,
"code": 6
}
],
]
},
"presentation": {
"clear": true,
"panel": "dedicated",
"reveal": "silent",
"showReuseMessage": false,
"showReuseMessage": false
}
},
{
"label": "Run clang-tidy (current file)",
"detail": "Run clang-tidy on the currently active open file.",
"type": "shell",
"command": "clang-tidy --quiet --config-file=.clang-tidy -p=build/ ${file}",
"icon": {
"color": "terminal.ansiWhite",
"id": "sparkle"
},
"problemMatcher": {
"source": "clang-tidy",
"owner": "clang-tidy",
"applyTo": "openDocuments",
"fileLocation": "absolute",
"pattern": [
{
"regexp": "^(.*):([0-9]{1,6}):([0-9]{1,6}):\\s([a-z]+):\\s(.*)\\[(.*)\\]$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
]
},
"presentation": {
"clear": true,
"echo": true,
"panel": "dedicated",
"reveal": "silent",
"showReuseMessage": false
}
},
{
"label": "Setup hooks",
"detail": "Copy git hooks to .git/hooks/ directory.",
"type": "shell",
"linux": {
"command": "cp -r .githooks/* .git/hooks/",
"command": "cp -r .githooks/* .git/hooks/"
},
"windows": {
"command": "Copy-Item -Path '.githooks/*' -Destination '.git/hooks/' -Exclude '.*'",
"command": "Copy-Item -Path '.githooks/*' -Destination '.git/hooks/' -Exclude '.*'"
},
"icon": {
"color": "terminal.ansiYellow",
Expand All @@ -70,7 +101,7 @@
"presentation": {
"clear": true,
"reveal": "silent",
"showReuseMessage": false,
"showReuseMessage": false
},
"hide": true,
"runOptions": {
Expand All @@ -95,7 +126,7 @@
"clear": true,
"panel": "dedicated",
"reveal": "silent",
"showReuseMessage": false,
"showReuseMessage": false
}
},
{
Expand All @@ -116,7 +147,7 @@
"clear": true,
"panel": "dedicated",
"reveal": "silent",
"showReuseMessage": false,
"showReuseMessage": false
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endif()
if(CMAKE_BUILD_TYPE EQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
string(COMPARE EQUAL "${CMAKE_BUILD_TYPE}" "Debug" DEBUG_MODE)
string(COMPARE EQUAL "${CMAKE_BUILD_TYPE}" "Debug" DEBUG_BUILD)

include(${PROJECT_SOURCE_DIR}/cmake/version.cmake)

Expand Down
2 changes: 0 additions & 2 deletions config/config.ini

This file was deleted.

3 changes: 2 additions & 1 deletion src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(MONOENGINE LANGUAGES CXX C)
if(CMAKE_BUILD_TYPE EQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
string(COMPARE EQUAL "${CMAKE_BUILD_TYPE}" "Debug" DEBUG_MODE)
string(COMPARE EQUAL "${CMAKE_BUILD_TYPE}" "Debug" DEBUG_BUILD)

option(MOLD_LINKER_PATH "Path to the mold linker executable (Unix only)" "")

Expand Down Expand Up @@ -70,6 +70,7 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/module/resource")
add_subdirectory("${PROJECT_SOURCE_DIR}/module/time")
add_subdirectory("${PROJECT_SOURCE_DIR}/module/config")
add_subdirectory("${PROJECT_SOURCE_DIR}/module/util")
add_subdirectory("${PROJECT_SOURCE_DIR}/module/dev_ui")


# Use mold linker if present in the system (to speed up linking time)
Expand Down
4 changes: 2 additions & 2 deletions src/engine/module/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ include_guard()
add_library(mono_module_audio)
add_library(mono::audio ALIAS mono_module_audio)

if(DEBUG_MODE)
if(DEBUG_BUILD)
target_compile_definitions(mono_module_audio
PRIVATE "DEBUG_MODE"
PRIVATE "DEBUG_BUILD"
)
endif()

Expand Down
5 changes: 2 additions & 3 deletions src/engine/module/camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ include_guard()
add_library(mono_module_camera)
add_library(mono::camera ALIAS mono_module_camera)

if(DEBUG_MODE)
if(DEBUG_BUILD)
target_compile_definitions(mono_module_camera

PRIVATE "DEBUG_MODE"
PRIVATE "DEBUG_BUILD"
)
endif()

Expand Down
9 changes: 8 additions & 1 deletion src/engine/module/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ target_compile_features(mono_module_config

target_sources(mono_module_config
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src/ConfigLoader.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Config.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ConfigItem.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ConfigStorage.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/CallbackGuard.cpp"
)

target_include_directories(mono_module_config
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include/mono"
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include"
)

target_link_libraries(mono_module_config
PUBLIC inifile::inifile
spdlog::spdlog
glm::glm
mono::traits
mono::log
)
33 changes: 0 additions & 33 deletions src/engine/module/config/include/config/ConfigLoader.hpp

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions src/engine/module/config/include/config/StaticConfiguration.hpp

This file was deleted.

23 changes: 23 additions & 0 deletions src/engine/module/config/include/mono/config/CallbackGuard.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

namespace mono::config
{

class ConfigItem;

class CallbackGuard
{
public:
explicit CallbackGuard(ConfigItem& config_item);
~CallbackGuard() noexcept;

CallbackGuard(const CallbackGuard& other) = delete;
CallbackGuard(CallbackGuard&& other) noexcept = delete;
CallbackGuard& operator=(const CallbackGuard& other) = delete;
CallbackGuard& operator=(CallbackGuard&& other) noexcept = delete;

private:
ConfigItem& m_configItem;
};

} // namespace mono::config
28 changes: 28 additions & 0 deletions src/engine/module/config/include/mono/config/Config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <inicpp.h>

#include "ConfigStorage.hpp"
#include "mono/log/priv/BufferedSink.hpp"
#include "priv/StaticConfiguration.hpp" // IWYU pragma: export
#include "priv/converters/GlmVec2Converter.hpp" // IWYU pragma: export
#include "priv/converters/SpdlogLevelConverter.hpp" // IWYU pragma: export

namespace mono::config
{


namespace priv
{

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
inline std::shared_ptr<log::priv::BufferedSink> buffered_sink;

} // namespace priv

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
inline ConfigStorage runtime;

void initialize();

} // namespace mono::config
Loading
Loading