FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

build: add clang tidy to enforce modern c++ usage by Miou-zora · Pull Request #591 · EngineSquared/EngineSquared · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5a6cd7b
build: add clang tidy config
Miou-zora May 1, 2026
9bff6f1
ci: add clang tidy check in CI
Miou-zora May 1, 2026
2004b8f
ci: add missing script execution
Miou-zora May 1, 2026
cb9d586
ci: add -y to xmake tidy to dl deps automaticaly
Miou-zora May 1, 2026
8bbb229
build: remove param in tidy config
Miou-zora May 1, 2026
df9277f
ci: split tidy+format job into two separate ones
Miou-zora May 1, 2026
cbc5bda
ci: add more details when running tidy
Miou-zora May 1, 2026
273618d
ci: remove verbosity for tidy
Miou-zora May 1, 2026
a9399f2
ci: accept apt install with -y
Miou-zora May 1, 2026
4d748db
ci: specify header filter and remove explicitely all rules except one
Miou-zora May 1, 2026
672628c
ci: add some rules to make ci fail
Miou-zora May 1, 2026
97d7bc5
refactor: fix clang tidy
Miou-zora May 1, 2026
f2c287a
refactor: make code clang format compliant
Miou-zora May 1, 2026
1d6040f
refactor: remove exception catching
Miou-zora May 2, 2026
95f7bc1
build: add more tidy rules
Miou-zora May 2, 2026
33e668b
build: add most of bugprone check in tidy
Miou-zora May 2, 2026
8a4ea29
refactor: make code clang format compliant
Miou-zora May 2, 2026
6a4ca0e
refactor(graphic): make code tidy compliant
Miou-zora May 2, 2026
1c08ec8
ci: remove version specification in ci
Miou-zora May 2, 2026
a3c4765
refactor(graphic): make code tidy compliant
Miou-zora May 2, 2026
49f8693
refactor(graphic): make code tidy compliant
Miou-zora May 2, 2026
26ef422
refactor(graphic): make code tidy compliant
Miou-zora May 2, 2026
File filter

Filter by extension

Filter by extension .cpp  (25) .hpp  (3) .ipp  (1) .yml  (1) dotfile  (1) All 5 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
26 changes: 26 additions & 0 deletions .clang-tidy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---

# bugprone-exception-escape, bugprone-throwing-static-initialization, bugprone-easily-swappable-parameters should be removed but require to modify a lot of stuff in the project
Checks: "-*, bugprone-*, -bugprone-reserved-identifier,
-bugprone-exception-escape, -bugprone-easily-swappable-parameters,
-bugprone-throwing-static-initialization"

WarningsAsErrors: "*"
HeaderFileExtensions:
- ""
- h
- hh
- hpp
- hxx
- ipp
ImplementationFileExtensions:
- c
- cc
- cpp
- cxx
HeaderFilterRegex: "^src/(?!.*/webgpu\\.hpp$).*"
FormatStyle: file
User: miouzora
CheckOptions: {}
SystemHeaders: false
...
48 changes: 40 additions & 8 deletions .github/workflows/ci.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ on:
push:
pull_request:
release:
types: [published]
types: [ published ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.base_ref }}-${{
github.head_ref }}
cancel-in-progress: true

env:
UNWANTED_REGEX: '^(?!.*tests\/).*gc(no|da|ov)$|(.*\.(a|o|so|lib))$|(.*~)$|^(#.*#)$|^tmp\/.*|.*\/tmp\/.*'
UNWANTED_REGEX: "^(?!.*tests\\/).*gc(no|da|ov)$|(.*\\.(a|o|so|lib))$|(.*~)$|^(#\
.*#)$|^tmp\\/.*|.*\\/tmp\\/.*"

jobs:
check_repository_cleanliness:
if: ${{ github.event_name != 'pull_request' || (!startsWith(github.head_ref, 'ga-ignore-') && github.head_ref != 'gh-pages') }}
name: Checks if the repository is clean and void of any unwanted files (temp files, binary files, etc.)
if: ${{ github.event_name != 'pull_request' || (!startsWith(github.head_ref,
'ga-ignore-') && github.head_ref != 'gh-pages') }}
name: Checks if the repository is clean and void of any unwanted files (temp
files, binary files, etc.)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down Expand Up @@ -66,9 +70,37 @@ jobs:
run: |
xmake format -c

tidy:
name: Run clang-tidy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Install clang-tidy
run: |
sudo apt update
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
sudo apt install -y clang-tidy

- name: Install xmake
uses: xmake-io/github-action-setup-xmake@fadadea1162ec75ce1541d5bb68226fb147c221e
with:
xmake-version: latest
actions-cache-folder: ".xmake-cache"
actions-cache-key: "clang-tidy"
build-cache: true
build-cache-key: "clang-tidy"
- name: Run clang-tidy
run: |
xmake check -y clang.tidy --configfile=./.clang-tidy

check_program_compilation:
name: Build and verify binaries
needs: [check_repository_cleanliness, lint_code]
needs: [ check_repository_cleanliness, lint_code ]
strategy:
matrix:
include:
Expand Down Expand Up @@ -105,7 +137,7 @@ jobs:

run_tests:
name: Run tests
needs: [check_repository_cleanliness, lint_code]
needs: [ check_repository_cleanliness, lint_code ]
strategy:
matrix:
include:
Expand Down Expand Up @@ -163,7 +195,7 @@ jobs:

check_examples:
name: Build and test examples
needs: [check_repository_cleanliness, lint_code]
needs: [ check_repository_cleanliness, lint_code ]
strategy:
matrix:
include:
Expand Down
14 changes: 8 additions & 6 deletions src/engine/src/Id.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ template <typename TDerived, typename TValue> struct BasicId {
/// @brief The underlying value of the ID.
TValue value;

/// @brief Constructor for BasicId. Allows implicit construction from the underlying value type, defaulting to the
/// null value.
/// @param value_ The value to initialize the ID with. Defaults to the null value defined by the derived class.
/// @return An instance of the derived ID type initialized with the given value.
constexpr explicit(false) BasicId(TValue value_ = TDerived::NullValue());

/// @brief Get the null value for this ID type. This should be defined by the derived class to specify what
/// constitutes a null/invalid ID.
/// @return The value representing a null/invalid ID for this type.
Expand All @@ -33,6 +27,14 @@ template <typename TDerived, typename TValue> struct BasicId {
/// @brief Checks if the ID is null/invalid by comparing its value to the null value defined by the derived class.
/// @return True if the ID is null/invalid, false otherwise.
constexpr bool IsNull(void) const;

private:
/// @brief Constructor for BasicId. Allows implicit construction from the underlying value type, defaulting to the
/// null value.
/// @param value_ The value to initialize the ID with. Defaults to the null value defined by the derived class.
/// @return An instance of the derived ID type initialized with the given value.
constexpr explicit(false) BasicId(TValue value_ = TDerived::NullValue());
friend TDerived;
};

/// @struct Id
Expand Down
4 changes: 0 additions & 4 deletions src/engine/src/entity/EntityId.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ struct EntityId : Id {
/// @param id The Engine::Id to convert.
constexpr EntityId(Id id);

/// @brief Implicit conversion operator to the underlying ValueType. This allows for seamless use of EntityId where
/// a ValueType is expected.
constexpr operator ValueType() const;

/// @brief Returns a null EntityId. A null EntityId is an EntityId that does not correspond to any valid entity in
/// the registry.
/// @return A null EntityId.
Expand Down
2 changes: 0 additions & 2 deletions src/engine/src/entity/EntityId.ipp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ constexpr EntityId::EntityId(ValueType v) : Id{v} {}

constexpr EntityId::EntityId(Id id) : Id{id} {}

constexpr EntityId::operator ValueType() const { return value; }

constexpr EntityId EntityId::Null() { return EntityId{NullValue()}; }

inline bool EntityId::IsValid(const Engine::Core &core) const { return core.IsEntityValid(value); }
Expand Down
2 changes: 1 addition & 1 deletion src/engine/src/scheduler/FixedTimeUpdate.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void Engine::Scheduler::FixedTimeUpdate::RunSystems()
{
_bufferedTime += this->_core.GetResource<Engine::Resource::Time>()._elapsedTime;
auto ticks = static_cast<unsigned int>(_bufferedTime / _tickRate);
_bufferedTime -= ticks * _tickRate;
_bufferedTime -= static_cast<float>(ticks) * _tickRate;

for (unsigned int i = 0; i < ticks; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/engine/src/scheduler/RelativeTimeUpdate.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void Engine::Scheduler::RelativeTimeUpdate::RunSystems()
{
_bufferedTime += this->_core.GetResource<Engine::Resource::Time>()._elapsedTime;
auto ticks = static_cast<unsigned int>(_bufferedTime / _tickRate);
float remainder = _bufferedTime - ticks * _tickRate;
_bufferedTime -= ticks * _tickRate;
float remainder = _bufferedTime - static_cast<float>(ticks) * _tickRate;
_bufferedTime -= static_cast<float>(ticks) * _tickRate;

for (unsigned int i = 0; i < ticks; i++)
{
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ void DefaultPipeline::System::OnMaterialCreation(Engine::Core &core, Engine::Ent
auto &textureContainer = core.GetResource<Graphic::Resource::TextureContainer>();
auto &samplerContainer = core.GetResource<Graphic::Resource::SamplerContainer>();
const auto &context = core.GetResource<Graphic::Resource::Context>();
const auto &device = context.deviceContext.GetDevice();

if (!device.has_value())
{
Log::Error("DefaultPipeline::System::OnMaterialCreation: device is empty");
return;
}

auto &GPUMaterial = entity.AddComponent<Component::GPUMaterial>();

Expand All @@ -46,7 +53,7 @@ void DefaultPipeline::System::OnMaterialCreation(Engine::Core &core, Engine::Ent

if (!samplerContainer.Contains(samplerId))
{
Graphic::Resource::Sampler sampler{context.deviceContext.GetDevice().value()};
Graphic::Resource::Sampler sampler{device.value()};
samplerContainer.Add(samplerId, std::move(sampler));
}
GPUMaterial.sampler = samplerId;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ static void CreateDirectionalLightsShadowTextures(Engine::Core &core)
auto &textureContainer = core.GetResource<Graphic::Resource::TextureContainer>();
auto &samplerContainer = core.GetResource<Graphic::Resource::SamplerContainer>();
const auto &context = core.GetResource<Graphic::Resource::Context>();
const auto &device = context.deviceContext.GetDevice();

if (!device.has_value())
{
Log::Error("CreateLights::CreateDirectionalLightsShadowTextures: device is empty");
return;
}

wgpu::TextureDescriptor textureDescriptor(wgpu::Default);
textureDescriptor.label = wgpu::StringView("DIRECTIONAL_LIGHTS_SHADOW_TEXTURE");
Expand All @@ -34,7 +41,7 @@ static void CreateDirectionalLightsShadowTextures(Engine::Core &core)
samplerDescriptor.addressModeV = wgpu::AddressMode::ClampToEdge;
samplerDescriptor.minFilter = wgpu::FilterMode::Linear;
samplerDescriptor.magFilter = wgpu::FilterMode::Linear;
Graphic::Resource::Sampler shadowSampler(context.deviceContext.GetDevice().value(), samplerDescriptor);
Graphic::Resource::Sampler shadowSampler(device.value(), samplerDescriptor);
samplerContainer.Add(Utils::DIRECTIONAL_LIGHTS_SHADOW_SAMPLER_ID, std::move(shadowSampler));
}

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ void Graphic::System::ConfigureSurface(Engine::Core &core)
if (config.height == 0)
config.height = 1;

auto &optDevice = context.deviceContext.GetDevice();
if (!context.surface.has_value() || !context.surface.value().capabilities.has_value() || !optDevice.has_value() ||
!context.surface.value().value.has_value())
{
return;
}

config.usage = wgpu::TextureUsage::RenderAttachment;
config.format = context.surface->capabilities->formats[0];
config.device = context.deviceContext.GetDevice().value();
config.device = optDevice.value();
config.presentMode = wgpu::PresentMode::Fifo;
config.alphaMode = wgpu::CompositeAlphaMode::Auto;

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ static std::optional<wgpu::BackendType> getBackendType(const wgpu::Adapter &adap

static std::optional<wgpu::Adapter> findVulkanAdapter(const Graphic::Resource::Context &context)
{
if (!context.instance.has_value())
return std::nullopt;
wgpu::InstanceEnumerateAdapterOptions enumOpts(wgpu::Default);
size_t count = context.instance->enumerateAdapters(enumOpts, nullptr);
if (count == 0)
Expand Down Expand Up @@ -67,6 +69,12 @@ void Graphic::System::CreateAdapter(Engine::Core &core)
auto &context = core.GetResource<Resource::Context>();
const auto &graphicSettings = core.GetResource<Resource::GraphicSettings>();

if (!context.instance.has_value())
{
Log::Error("Graphic::System::CreateAdapter: context.instance has no value");
return;
}

wgpu::RequestAdapterOptions adapterOpts(wgpu::Default);

if (graphicSettings.GetPowerPreference() == Resource::PowerPreference::LowPower)
Expand All @@ -78,7 +86,7 @@ void Graphic::System::CreateAdapter(Engine::Core &core)
adapterOpts.powerPreference = wgpu::PowerPreference::HighPerformance;
}

if (context.surface.has_value())
if (context.surface.has_value() && context.surface->value.has_value())
adapterOpts.compatibleSurface = context.surface->value.value();

wgpu::Adapter adapter = context.instance->requestAdapter(adapterOpts);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ void CreateDefaultSampler(Engine::Core &core)
samplerDesc.addressModeV = wgpu::AddressMode::ClampToEdge;
samplerDesc.addressModeW = wgpu::AddressMode::ClampToEdge;

Resource::Sampler defaultSampler(context.deviceContext.GetDevice().value(), samplerDesc);

const auto &optDevice = context.deviceContext.GetDevice();
if (!optDevice.has_value())
{
Log::Error("Graphic::System::CreateDefaultSampler: Graphic device not found");
return;
}
Resource::Sampler defaultSampler(optDevice.value(), samplerDesc);
samplerContainer.Add(Utils::DEFAULT_SAMPLER_ID, std::move(defaultSampler));
}
} // namespace Graphic::System
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ static void SetupDeviceDescriptor(wgpu::DeviceDescriptor &deviceDesc, Graphic::R
deviceDesc.requiredLimits = dynamic_cast<wgpu::Limits *>(&settings.GetWantedLimits());
deviceDesc.defaultQueue.nextInChain = nullptr;
deviceDesc.defaultQueue.label = wgpu::StringView("The default queue");
deviceDesc.deviceLostCallbackInfo = {};
deviceDesc.deviceLostCallbackInfo.nextInChain = nullptr;
deviceDesc.deviceLostCallbackInfo.mode = wgpu::CallbackMode::AllowProcessEvents;
deviceDesc.deviceLostCallbackInfo.callback = [](WGPUDevice const *device, WGPUDeviceLostReason reason,
Expand All @@ -21,7 +20,6 @@ static void SetupDeviceDescriptor(wgpu::DeviceDescriptor &deviceDesc, Graphic::R
Log::Error(fmt::format("Device lost: reason {:x} ({})", static_cast<uint32_t>(reason),
std::string(message.data, message.length)));
};
deviceDesc.uncapturedErrorCallbackInfo = {};
deviceDesc.uncapturedErrorCallbackInfo.nextInChain = nullptr;
deviceDesc.uncapturedErrorCallbackInfo.callback = settings.GetOnErrorCallback();
}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ void Graphic::System::CreateQueue(Engine::Core &core)
{
auto &context = core.GetResource<Resource::Context>();
const auto &settings = core.GetResource<Resource::GraphicSettings>();
auto &device = context.deviceContext.GetDevice();

auto queue = context.deviceContext.GetDevice()->getQueue();
if (!device.has_value())
return;

auto queue = device->getQueue();

if (queue == nullptr)
throw Exception::QueueCreationError("Could not create WebGPU queue");
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ void Graphic::System::CreateSurface(Engine::Core &core)
{
auto &context = core.GetResource<Resource::Context>();
auto &graphicSettings = core.GetResource<Resource::GraphicSettings>();
auto &instance = context.instance.value();
auto &instance = context.instance;

if (!instance.has_value())
{
Log::Error("Graphic::System::CreateSurface: context.instance has no value");
return;
}
wgpu::Surface surface = nullptr;

if (graphicSettings.GetWindowSystem() == Resource::WindowSystem::None)
return;
else if (graphicSettings.GetWindowSystem() == Resource::WindowSystem::GLFW)
{
auto glfwWindow = core.GetResource<Window::Resource::Window>().GetGLFWWindow();
surface = glfwCreateWindowWGPUSurface(instance, glfwWindow);
surface = glfwCreateWindowWGPUSurface(instance.value(), glfwWindow);
}
else
{
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
void Graphic::System::ReleaseAdapter(Engine::Core &core)
{
auto &context = core.GetResource<Resource::Context>();
context.adapter->release();
context.adapter.reset();
if (context.adapter.has_value())
{
context.adapter->release();
context.adapter.reset();
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void RequestCapabilities(Engine::Core &core)
{
auto &context = core.GetResource<Resource::Context>();

if (context.surface == std::nullopt)
if (context.surface == std::nullopt || !context.adapter.has_value())
return;
if (context.surface->updateCapabilities(context.adapter.value()) == wgpu::Status::Error)
{
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ void Graphic::System::SetupQueue(Engine::Core &core)
return;

auto &context = core.GetResource<Resource::Context>();
if (!context.queue.has_value())
return;

auto onQueueWorkDone = [](WGPUQueueWorkDoneStatus status, [[maybe_unused]] WGPU_NULLABLE void *userdata1,
[[maybe_unused]] WGPU_NULLABLE void *userdata2) {
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void Graphic::System::Present(Engine::Core &core)
{
auto &context = core.GetResource<Resource::Context>();

if (!context.surface.has_value() || !context.surface->configured)
if (!context.surface.has_value() || !context.surface->value.has_value() || !context.surface->configured)
return;

context.surface->value->present();
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL