Skip to content

Commit

Permalink
Merge pull request #9 from viniciusalmada/setup-clang-tidy
Browse files Browse the repository at this point in the history
Setup clang tidy
  • Loading branch information
viini42 authored Apr 21, 2024
2 parents 798bd7c + 7da0b95 commit b32fb7c
Show file tree
Hide file tree
Showing 48 changed files with 350 additions and 394 deletions.
51 changes: 9 additions & 42 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,24 @@
Checks: '
-*,
bugprone-*,
cert-dcl21-cpp,
cert-dcl58-cpp,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
cert-str34-c,
cert-*,
clang-analyzer-*,
cppcoreguidelines-*,
google-default-arguments,
google-explicit-constructor,
google-runtime-operator,
hicpp-exception-baseclass,
hicpp-multiway-paths-covered,
llvm-*,
misc-*,
modernize-*,
mpi-buffer-deref,
mpi-type-mismatch,
openmp-use-default-none,
performance-*,
portability-*,
readability-*,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-special-member-functions,
-llvm-header-guard,
-llvm-namespace-comment,
-misc-confusable-identifiers,
-misc-include-cleaner
-misc-non-private-member-variables-in-classes,
-misc-include-cleaner,
-modernize-use-trailing-return-type,
-readability-braces-around-statements,
-readability-identifier-length,
-readability-identifier-naming,
-readability-uppercase-literal-suffix,
-bugprone-easily-swappable-parameters
'
WarningsAsErrors: "*"
# REVISIT -cppcoreguidelines-macro-usage,
WarningsAsErrors: "*,-cppcoreguidelines-pro-type-reinterpret-cast,-*-use-default-member-init"
HeaderFileExtensions:
- ''
- h
Expand All @@ -53,23 +31,12 @@ ImplementationFileExtensions:
- cc
- cpp
- cxx
HeaderFilterRegex: 'ge_*'
#HeaderFilterRegex: 'ge_*'
AnalyzeTemporaryDtors: true
FormatStyle: file
User: vini
CheckOptions:
cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
google-readability-namespace-comments.ShortNamespaceLines: '10'
cert-err33-c.CheckedFunctions: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;'
llvm-else-after-return.WarnOnUnfixable: 'false'
cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false'
google-readability-namespace-comments.SpacesBeforeComments: '2'
llvm-else-after-return.WarnOnConditionVariables: 'false'
google-readability-braces-around-statements.ShortStatementLines: '1'
llvm-qualified-auto.AddConstToQualified: 'false'
google-readability-function-size.StatementThreshold: '800'
cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false'
cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true'
SystemHeaders: false
UseColor: true
CheckOptions:
misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
...

3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_CXX_CLANG_TIDY clang-tidy -p ${CMAKE_BINARY_DIR} --config-file=${CMAKE_SOURCE_DIR}/.clang-tidy)
message("CMAKE_CXX_CLANG_TIDY=${CMAKE_CXX_CLANG_TIDY}")

if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always -fansi-escape-codes)
Expand Down
88 changes: 41 additions & 47 deletions Grapengine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,37 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# #############################################################################
# Engine
add_library(Grapengine STATIC
controllers/ge_app_controller.cpp
core/ge_application.cpp
core/ge_platform.cpp
core/ge_window.cpp
drawables/ge_canvas.cpp
drawables/ge_cube.cpp
drawables/ge_cylinder.cpp
drawables/ge_drawing_object.cpp
drawables/ge_mesh.cpp
drawables/ge_world_reference.cpp
events/ge_event.cpp
input/ge_input.cpp
input/ge_key_codes.cpp
layer/ge_imgui_layer.cpp
layer/ge_layer.cpp
log/ge_logger.cpp
math/ge_arithmetic.cpp
math/ge_geometry.cpp
math/ge_quaternions.cpp
math/ge_transformations.cpp
math/ge_vector.cpp
profiling/ge_time.cpp
renderer/ge_buffer_layout.cpp
renderer/ge_camera.cpp
renderer/ge_editor_camera.cpp
renderer/ge_framebuffer.cpp
renderer/ge_gl_checkers.cpp
renderer/ge_index_buffer.cpp
renderer/ge_ishader_program.hpp
renderer/ge_renderer.cpp
renderer/ge_shader.cpp
renderer/ge_texture_2d.cpp
renderer/ge_vertex_array.cpp
renderer/ge_vertex_buffer.cpp
renderer/shader_programs/ge_material_shader.cpp
renderer/shader_programs/ge_pos_tex_shader.cpp
utils/ge_io.cpp
utils/ge_random.cpp
scene/ge_scene.cpp
scene/ge_scene.hpp
scene/ge_components.hpp
scene/ge_ec_registry.cpp
scene/ge_ec_registry.hpp
scene/ge_entity.hpp
core/ge_context.cpp
core/ge_context.hpp
file(GLOB_RECURSE GRAPES_SOURCES
controllers/*.cpp
core/*.cpp
drawables/*.cpp
events/*.cpp
input/*.cpp
layer/*.cpp
log/*.cpp
math/*.cpp
profiling/*.cpp
renderer/*.cpp
scene/*.cpp
utils/*.cpp
)

file(GLOB_RECURSE GRAPES_HEADERS
controllers/*.hpp
core/*.hpp
drawables/*.hpp
events/*.hpp
input/*.hpp
layer/*.hpp
log/*.hpp
math/*.hpp
profiling/*.hpp
renderer/*.hpp
scene/*.hpp
utils/*.hpp
)

add_library(Grapengine STATIC ${GRAPES_HEADERS} ${GRAPES_SOURCES})
target_precompile_headers(Grapengine PRIVATE ${CMAKE_SOURCE_DIR}/Grapengine/grapengine_pch.hpp)
target_include_directories(Grapengine
PUBLIC ${CMAKE_SOURCE_DIR}/Grapengine
Expand All @@ -71,6 +54,17 @@ endif ()

target_link_libraries(Grapengine PRIVATE GrapengineCompileOptions)

##############################################################################
#
if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
add_custom_target(
GrapeTidy
DEPENDS Grapengine
COMMAND clang-tidy --config-file=${CMAKE_SOURCE_DIR}/.clang-tidy -p ${CMAKE_BINARY_DIR} --quiet --export-fixes=${CMAKE_SOURCE_DIR}/fixes.yaml --header-filter='^ge_.*?\.hpp$$'
${GRAPES_SOURCES}
)
endif ()

# ############################################################################
# imgui
file(GLOB IMGUI_SRC ${CMAKE_SOURCE_DIR}/vendor/imgui/*.cpp ${CMAKE_SOURCE_DIR}/imgui/*.h)
Expand Down
14 changes: 6 additions & 8 deletions Grapengine/controllers/ge_app_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using namespace GE;

GE::Ctrl::App::App() {}

void Ctrl::App::Init(const Ref<Application>& app)
{
Get().m_application = app;
Expand All @@ -18,17 +16,17 @@ void GE::Ctrl::App::Shutdown()

void GE::Ctrl::App::Close()
{
GE::Assert(Get().m_application.has_value(), "Controller not initialized");
GE::Assert(Get().m_application != nullptr, "Application destroyed");
const auto app = Get().m_application;
GE_ASSERT(app != nullptr, "Application destroyed")

Get().m_application.value()->Close();
app->Close();
}
void GE::Ctrl::App::AllowImGuiEvents(bool value)
{
GE::Assert(Get().m_application.has_value(), "Controller not initialized");
GE::Assert(Get().m_application != nullptr, "Application destroyed");
const auto app = Get().m_application;
GE_ASSERT(app != nullptr, "Application destroyed")

Get().m_application.value()->GetImGuiLayer()->AllowMouseAndKeyboardEvents(value);
app->GetImGuiLayer()->AllowMouseAndKeyboardEvents(value);
}

Ctrl::App& Ctrl::App::Get()
Expand Down
6 changes: 3 additions & 3 deletions Grapengine/controllers/ge_app_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ namespace GE::Ctrl
class App
{
public:
static void Init(const Ref<GE::Application>& app);
static void Init(const Ref<Application>& app);
static void Shutdown();

static void Close();

static void AllowImGuiEvents(bool value);

private:
App();
App() = default;

static App& Get();

std::optional<Ref<Application>> m_application = std::nullopt;
Ref<Application> m_application = nullptr;
};
}
#endif // GRAPENGINE_GE_APP_CONTROLLER_HPP
13 changes: 6 additions & 7 deletions Grapengine/core/ge_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

using namespace GE;

Application::Application(std::string_view title, u32 width, u32 height, std::string_view icon)
Application::Application(std::string_view title, Dimension dim, std::string_view icon)
{
GE_INFO("Application creation")

Init(title, width, height, icon, [this](auto&& e) { OnEvent(e); });
Init(title, dim, icon, [this](auto&& e) { OnEvent(e); });

Renderer::Init();
Renderer::SetViewport(0, 0, width, height);
Renderer::SetViewport(0, 0, dim);
}

Application::~Application()
Expand All @@ -30,12 +30,11 @@ Application::~Application()
}

void Application::Init(std::string_view title,
u32 width,
u32 height,
Dimension dim,
std::string_view icon,
const EventCallbackFn& cb)
{
m_window = MakeScope<Window>(WindowProps{ title, width, height, icon }, cb);
m_window = MakeScope<Window>(WindowProps{ title, dim, icon }, cb);
Input::Initialize(m_window);
m_imgui_layer = ImGuiLayer::Make(m_window);
m_imgui_layer->OnAttach();
Expand All @@ -57,7 +56,7 @@ void Application::Run()
{
while (m_running)
{
u64 time_ms = Platform::GetCurrentTimeMS();
const u64 time_ms = Platform::GetCurrentTimeMS();
TimeStep step{ time_ms - m_last_frame_time };
m_last_frame_time = time_ms;

Expand Down
9 changes: 3 additions & 6 deletions Grapengine/core/ge_application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace GE
class Application
{
public:
Application(std::string_view title, u32 width, u32 height, std::string_view icon);
Application(std::string_view title, Dimension dim, std::string_view icon);
virtual ~Application();

void AddLayer(const Ref<Layer>& layer);
Expand All @@ -32,11 +32,8 @@ namespace GE
[[nodiscard]] Ref<ImGuiLayer> GetImGuiLayer() const;

private:
void Init(std::string_view title,
u32 width,
u32 height,
std::string_view icon,
const EventCallbackFn& cb);
void
Init(std::string_view title, Dimension dim, std::string_view icon, const EventCallbackFn& cb);

void OnDestroy();

Expand Down
25 changes: 14 additions & 11 deletions Grapengine/core/ge_assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
#endif
#endif

namespace GE
{
template <typename... Args>
void Assert(bool condition, Args... args)
{
if (condition)
return;

GE_ERROR(std::forward<Args>(args)...)
}
}
#ifndef GE_ASSERT
#if defined(GE_DIST)
#define GE_ASSERT(...)
#else
#define GE_ASSERT(cond, ...) \
{ \
if (!(cond)) \
{ \
GE_ERROR("Assertion failed: {0}", __VA_ARGS__) \
BREAKPOINT \
} \
}
#endif
#endif

#endif // GRAPENGINE_ASSERT_HPP
7 changes: 7 additions & 0 deletions Grapengine/core/ge_type_aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cstdint>
#include <memory>
#include <optional>

using i8 [[maybe_unused]] = std::int8_t;
using i16 [[maybe_unused]] = std::int16_t;
Expand All @@ -17,6 +18,12 @@ using f64 [[maybe_unused]] = double;

namespace GE
{
/**
* Pointer that acts as reference
*/
template <class T>
using Opt = std::optional<T>;

/**
* Pointer that acts as reference
*/
Expand Down
Loading

0 comments on commit b32fb7c

Please sign in to comment.