From 9477099cfc95dca433f73b82f5720ec36a2770e8 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Wed, 23 Jul 2025 19:18:25 +0200 Subject: [PATCH] fix warnings + cland-tidy --- .clang-tidy | 27 +++++++++++++++++++++++ include/td/game/Team.h | 2 +- include/td/game/World.h | 2 +- include/td/game/WorldTypes.h | 3 ++- include/td/misc/Shapes.h | 4 ++-- include/td/render/loader/WorldLoader.h | 2 +- include/td/simulation/WorldTicker.h | 3 ++- src/main.cpp | 2 ++ src/td/game/World.cpp | 2 +- src/td/render/loader/WorldLoader.cpp | 4 ++-- src/td/render/renderer/EntityRenderer.cpp | 2 +- src/td/render/shader/ShaderProgram.cpp | 2 +- xmake.lua | 4 ++++ 13 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..14453e3 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,27 @@ +Checks: >- + -*, + readability-identifier-naming, + readability-redundant-string-cstr, + readability-redundant-string-init, + readability-simplify-boolean-expr, + performance-unnecessary-value-param, + performance-unnecessary-copy-initialization, + performance-for-range-copy, + performance-implicit-conversion-in-loop, +CheckOptions: +- key: readability-identifier-naming.PrivateMemberPrefix + value: 'm_' +- key: readability-identifier-naming.ClassConstantCase + value: aNy_CasE +# an empty *Prefix needs a *Case to work +- key: readability-identifier-naming.ClassConstantPrefix + value: '' +#- key: readability-identifier-naming.PrivateMemberCase +# value: CamelCase +#- key: readability-identifier-naming.FunctionCase +# value: CamelCase +#- key: readability-identifier-naming.EnumCase +# value: camelBack + +WarningsAsErrors: '*' +FormatStyle: 'file' \ No newline at end of file diff --git a/include/td/game/Team.h b/include/td/game/Team.h index 79e5547..a73fb76 100644 --- a/include/td/game/Team.h +++ b/include/td/game/Team.h @@ -17,7 +17,7 @@ class Spawn : public utils::shape::Rectangle { private: Direction m_Direction; public: - Spawn() { + Spawn() : m_Direction(Direction::PositiveX) { SetWidth(5); SetHeight(5); } diff --git a/include/td/game/World.h b/include/td/game/World.h index 410a04c..5c591bd 100644 --- a/include/td/game/World.h +++ b/include/td/game/World.h @@ -88,7 +88,7 @@ class World { return m_CurrentState.m_Mobs; } - const Color* GetTileColor(TilePtr tile) const; + const Color* GetTileColor(const TilePtr& tile) const; Team& GetRedTeam() { return m_CurrentState.m_Teams[static_cast(TeamColor::Red)]; diff --git a/include/td/game/WorldTypes.h b/include/td/game/WorldTypes.h index 4e95cd6..7bf43fb 100644 --- a/include/td/game/WorldTypes.h +++ b/include/td/game/WorldTypes.h @@ -39,6 +39,7 @@ static constexpr Color BLUE{0, 0, 255}; struct Tile { virtual TileType GetType() const = 0; + virtual ~Tile() = default; }; struct TowerTile : Tile { @@ -118,4 +119,4 @@ struct hash { return std::hash()(key.x << 16 | key.y); } }; -} // namespace std \ No newline at end of file +} // namespace std diff --git a/include/td/misc/Shapes.h b/include/td/misc/Shapes.h index 6a789f8..2367efb 100644 --- a/include/td/misc/Shapes.h +++ b/include/td/misc/Shapes.h @@ -30,7 +30,7 @@ private: Point m_Center; float m_Width, m_Height; public: - Rectangle() {} + Rectangle() : m_Center(), m_Width(0), m_Height(0) {} const Point& GetCenter() const { return m_Center; } float GetCenterX() const { return m_Center.GetX(); } @@ -92,5 +92,5 @@ public: }; } // namespace shape -} // namespace utils +} // namespace utils } // namespace td diff --git a/include/td/render/loader/WorldLoader.h b/include/td/render/loader/WorldLoader.h index b9d2482..0a5dc79 100644 --- a/include/td/render/loader/WorldLoader.h +++ b/include/td/render/loader/WorldLoader.h @@ -16,7 +16,7 @@ struct RenderData { GL::VertexArray LoadMobModel(); GL::VertexArray LoadWorldModel(const td::game::World* world); GL::VertexArray LoadTileSelectModel(); -RenderData LoadTowerModel(game::TowerPtr tower); +RenderData LoadTowerModel(const game::TowerPtr& tower); } // namespace WorldLoader diff --git a/include/td/simulation/WorldTicker.h b/include/td/simulation/WorldTicker.h index 9d6d838..6431717 100644 --- a/include/td/simulation/WorldTicker.h +++ b/include/td/simulation/WorldTicker.h @@ -13,6 +13,7 @@ namespace sim { class IWorldSystem { public: virtual void Tick(const game::World& a_World, WorldSnapshot& a_State, FpFloat a_Delta) = 0; + virtual ~IWorldSystem() = default; }; class WorldTicker { @@ -32,7 +33,7 @@ class WorldTicker { template void AddSystem() { - m_Systems.push_back(std::move(std::make_unique())); + m_Systems.push_back(std::make_unique()); } }; diff --git a/src/main.cpp b/src/main.cpp index 8b035d4..f0c9b68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ class WorldApply : public td::protocol::PacketHandler { private: td::game::World& m_World; + using td::protocol::PacketHandler::Handle; public: WorldApply(td::game::World& a_World) : m_World(a_World) {} @@ -23,6 +24,7 @@ class WorldApply : public td::protocol::PacketHandler { void Handle(const td::protocol::packets::WorldHeaderPacket& a_Header) override { m_World.LoadMap(*a_Header); } + void Handle(const td::protocol::packets::WorldDataPacket& a_Data) override { m_World.LoadMap(*a_Data); } diff --git a/src/td/game/World.cpp b/src/td/game/World.cpp index 78c515a..b4c0afc 100644 --- a/src/td/game/World.cpp +++ b/src/td/game/World.cpp @@ -7,7 +7,7 @@ namespace game { World::World() : m_CurrentState{.m_Teams{Team{TeamColor::Red}, Team{TeamColor::Blue}}}, m_NextState{.m_Teams{Team{TeamColor::Red}, Team{TeamColor::Blue}}} {} -const Color* World::GetTileColor(TilePtr tile) const { +const Color* World::GetTileColor(const TilePtr& tile) const { switch (tile->GetType()) { case TileType::Tower: { TowerTile* towerTile = dynamic_cast(tile.get()); diff --git a/src/td/render/loader/WorldLoader.cpp b/src/td/render/loader/WorldLoader.cpp index cf1beee..7f96087 100644 --- a/src/td/render/loader/WorldLoader.cpp +++ b/src/td/render/loader/WorldLoader.cpp @@ -11,7 +11,7 @@ namespace render { namespace WorldLoader { const static int POSITION_VERTEX_SIZE = 3; -const static int TEXTURE_VERTEX_SIZE = 2; +// const static int TEXTURE_VERTEX_SIZE = 2; GL::VertexArray LoadWorldModel(const td::game::World* world) { std::vector positions; @@ -173,7 +173,7 @@ GL::VertexArray LoadTileSelectModel() { return tileSelectVao; } -RenderData LoadTowerModel(game::TowerPtr tower) { +RenderData LoadTowerModel(const game::TowerPtr& tower) { RenderData renderData; float towerX, towerDX; diff --git a/src/td/render/renderer/EntityRenderer.cpp b/src/td/render/renderer/EntityRenderer.cpp index bdfa53b..9b5d189 100644 --- a/src/td/render/renderer/EntityRenderer.cpp +++ b/src/td/render/renderer/EntityRenderer.cpp @@ -6,7 +6,7 @@ namespace td { namespace render { EntityRenderer::EntityRenderer(Camera& a_Camera, const game::World& a_World) : Renderer(a_Camera), m_World(a_World) { - m_EntityVao = std::make_unique(std::move(WorldLoader::LoadMobModel())); + m_EntityVao = std::make_unique(WorldLoader::LoadMobModel()); m_Shader->Start(); m_Shader->SetColorEffect({1, 0, 1}); } diff --git a/src/td/render/shader/ShaderProgram.cpp b/src/td/render/shader/ShaderProgram.cpp index 5d89462..9406bb5 100755 --- a/src/td/render/shader/ShaderProgram.cpp +++ b/src/td/render/shader/ShaderProgram.cpp @@ -109,7 +109,7 @@ unsigned int ShaderProgram::LoadShader(const std::string& source, GLenum type) { glCompileShader(shaderID); GLint compilesuccessful; glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compilesuccessful); - if (compilesuccessful == false) { + if (!compilesuccessful) { GLsizei size; glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &size); std::vector shaderError(static_cast(size)); diff --git a/xmake.lua b/xmake.lua index 6acdb45..e92b89a 100644 --- a/xmake.lua +++ b/xmake.lua @@ -10,6 +10,10 @@ set_languages("c++17") set_warnings("all") +if is_mode("release") then + set_warnings("all", "error") +end + target("Tower-Defense2") add_includedirs("include", {public = true}) set_kind("binary")