Skip to content

Commit

Permalink
Fix clang-tidy warnings
Browse files Browse the repository at this point in the history
- fix warning reported by clang-tidy
- add more exceptions to .clang-tidy
- adjust Clang warnings in CMakeLists.txt
  • Loading branch information
ducakar committed Apr 1, 2024
1 parent bfe7f17 commit 75b174d
Show file tree
Hide file tree
Showing 52 changed files with 492 additions and 496 deletions.
3 changes: 3 additions & 0 deletions .clang-tidy
Expand Up @@ -19,7 +19,10 @@ Checks: >-
-cppcoreguidelines-owning-memory, -cppcoreguidelines-owning-memory,
-cppcoreguidelines-prefer-member-initializer, -cppcoreguidelines-prefer-member-initializer,
-cppcoreguidelines-pro-*, -cppcoreguidelines-pro-*,
-cppcoreguidelines-slicing,
misc-*, misc-*,
-misc-const-correctness,
-misc-include-cleaner,
-misc-no-recursion, -misc-no-recursion,
-misc-non-private-member-variables-in-classes, -misc-non-private-member-variables-in-classes,
modernize-*, modernize-*,
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Expand Up @@ -143,10 +143,10 @@ add_compile_options(-fPIC -fsized-deallocation -fstrict-enums -fno-rtti -fno-exc


# Warnings. # Warnings.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic) add_compile_options(-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-date-time)
add_compile_options(-Wno-exit-time-destructors -Wno-global-constructors) add_compile_options(-Wno-exit-time-destructors -Wno-global-constructors -Wno-unsafe-buffer-usage)
add_compile_options(-Wno-date-time -Wno-padded -Wno-switch-enum -Wno-sign-conversion) add_compile_options(-Wno-padded -Wno-switch-enum -Wno-zero-as-null-pointer-constant)
add_compile_options(-Wno-float-equal -Wno-double-promotion -Wno-zero-as-null-pointer-constant) add_compile_options(-Wno-sign-conversion -Wno-float-equal -Wno-double-promotion )
else() else()
add_compile_options(-Wall -Wextra -Wcast-align -Winit-self -Wlogical-op -Wundef -Winvalid-pch) add_compile_options(-Wall -Wextra -Wcast-align -Winit-self -Wlogical-op -Wundef -Winvalid-pch)
add_compile_options(-Wmissing-declarations -Wnon-virtual-dtor -Woverloaded-virtual -Wformat=2) add_compile_options(-Wmissing-declarations -Wnon-virtual-dtor -Woverloaded-virtual -Wformat=2)
Expand Down
17 changes: 11 additions & 6 deletions src/builder/AssImp.cc
Expand Up @@ -29,6 +29,9 @@
namespace oz::builder namespace oz::builder
{ {


namespace
{

struct Anim struct Anim
{ {
enum Behaviour enum Behaviour
Expand All @@ -53,11 +56,11 @@ struct Anim
Mat4 interpolate(float time) const; Mat4 interpolate(float time) const;
}; };


static List<Material> materials; List<Material> materials;
static List<Anim::Key> animKeys; List<Anim::Key> animKeys;
static List<Anim> anims; List<Anim> anims;
static Assimp::Importer importer; Assimp::Importer importer;
static const aiScene* scene; const aiScene* scene;


inline Vec3 fromAiVector(const aiVector3D& aiVector) inline Vec3 fromAiVector(const aiVector3D& aiVector)
{ {
Expand All @@ -72,7 +75,7 @@ inline Mat4 fromAiMatrix(const aiMatrix4x4& aiMatrix)
aiMatrix.a4, aiMatrix.b4, aiMatrix.c4, aiMatrix.d4); aiMatrix.a4, aiMatrix.b4, aiMatrix.c4, aiMatrix.d4);
} }


static void readNode(const aiNode* node) void readNode(const aiNode* node)
{ {
if (String::equals(node->mName.C_Str(), "Armature")) { if (String::equals(node->mName.C_Str(), "Armature")) {
return; return;
Expand Down Expand Up @@ -119,6 +122,8 @@ static void readNode(const aiNode* node)
Log::unindent(); Log::unindent();
} }


}

void AssImp::build(const File& path) void AssImp::build(const File& path)
{ {
Log::println("Prebuilding Collada model '%s' {", path.c()); Log::println("Prebuilding Collada model '%s' {", path.c());
Expand Down
5 changes: 2 additions & 3 deletions src/builder/BSP.cc
Expand Up @@ -637,8 +637,8 @@ void BSP::optimise()
// collapse unnecessary nodes // collapse unnecessary nodes
Log::print("Collapsing nodes "); Log::print("Collapsing nodes ");


bool hasCollapsed = false; bool hasCollapsed = true;
do { while (hasCollapsed) {
hasCollapsed = false; hasCollapsed = false;


for (int i = 0; i < nodes.size();) { for (int i = 0; i < nodes.size();) {
Expand Down Expand Up @@ -711,7 +711,6 @@ void BSP::optimise()
hasCollapsed = true; hasCollapsed = true;
} }
} }
while (hasCollapsed);


Log::printEnd(" OK"); Log::printEnd(" OK");


Expand Down
7 changes: 6 additions & 1 deletion src/builder/Builder.cc
Expand Up @@ -35,7 +35,12 @@
namespace oz::builder namespace oz::builder
{ {


static bool skipReferences = false; namespace
{

bool skipReferences = false;

}


void Builder::printUsage() void Builder::printUsage()
{ {
Expand Down
67 changes: 36 additions & 31 deletions src/builder/Compiler.cc
Expand Up @@ -26,6 +26,9 @@ using oz::client::Animation;
namespace oz::builder namespace oz::builder
{ {


namespace
{

struct Node; struct Node;


enum Environment enum Environment
Expand Down Expand Up @@ -153,36 +156,36 @@ struct Node
OZ_STATIC_POOL_ALLOC(pool) OZ_STATIC_POOL_ALLOC(pool)
}; };


Pool<Node> Node::pool; Pool<Node> Node::pool;


static List<Point> positions; List<Point> positions;
static List<Vec3> normals; List<Vec3> normals;
static List<Vertex> vertices; List<Vertex> vertices;
static List<Mesh> meshes; List<Mesh> meshes;
static List<Light> lights; List<Light> lights;
static List<Node*> nodes; List<Node*> nodes;
static List<Animation> animations; List<Animation> animations;


static Bounds bounds; Bounds bounds;


static Vertex currentVert; Vertex currentVert;
static Mesh currentMesh; Mesh currentMesh;
static Light currentLlight; Light currentLlight;
static Node root; Node root;
static Node* currentNode; Node* currentNode;
static Animation::Channel currentChannel; Animation::Channel currentChannel;
static Animation animation; Animation animation;


static Environment environment; Environment environment;
static int caps; int caps;
static String shaderName; String shaderName;
static int nFrames; int nFrames;
static int nFramePositions; int nFramePositions;
static Compiler::PolyMode mode; Compiler::PolyMode mode;
static int vertNum; int vertNum;
static List<uint16> polyIndices; List<uint16> polyIndices;


static void calculateBounds(const Node* node, const Mat4& parentTransf) void calculateBounds(const Node* node, const Mat4& parentTransf)
{ {
Mat4 transf = parentTransf ^ node->transf; Mat4 transf = parentTransf ^ node->transf;


Expand All @@ -208,7 +211,7 @@ static void calculateBounds(const Node* node, const Mat4& parentTransf)
} }
} }


static void storeNode(Node* node, int depth) void storeNode(Node* node, int depth)
{ {
if (depth != 0) { if (depth != 0) {
for (Node* child : node->children) { for (Node* child : node->children) {
Expand All @@ -223,6 +226,8 @@ static void storeNode(Node* node, int depth)
} }
} }


}

void Compiler::enable(Capability cap) void Compiler::enable(Capability cap)
{ {
caps |= cap; caps |= cap;
Expand Down
31 changes: 18 additions & 13 deletions src/builder/Context.cc
Expand Up @@ -31,7 +31,10 @@
namespace oz::builder namespace oz::builder
{ {


const char* const IMAGE_EXTENSIONS[] = { namespace
{

static const char* const IMAGE_EXTENSIONS[] = {
".dds", ".dds",
".png", ".png",
".jpeg", ".jpeg",
Expand All @@ -41,6 +44,8 @@ const char* const IMAGE_EXTENSIONS[] = {
".tiff" ".tiff"
}; };


}

bool Context::isBaseTexture(const String& name) bool Context::isBaseTexture(const String& name)
{ {
return !name.endsWith("_d") && !name.endsWith("_m") && !name.endsWith("_s") && return !name.endsWith("_d") && !name.endsWith("_m") && !name.endsWith("_s") &&
Expand All @@ -63,18 +68,18 @@ void Context::buildTexture(const File& basePath, const File& destBasePath, bool
ImageBuilder::options |= ImageBuilder::FAST_BIT; ImageBuilder::options |= ImageBuilder::FAST_BIT;
} }


File diffuseBasePath = basePath; const File& diffuseBasePath = basePath;
File masksBasePath = basePath + "_m"; File masksBasePath = basePath + "_m";
File specular1BasePath = basePath + "_s"; File specular1BasePath = basePath + "_s";
File specular2BasePath = basePath + "_spec"; File specular2BasePath = basePath + "_spec";
File specular3BasePath = basePath + "_h"; File specular3BasePath = basePath + "_h";
File emission1BasePath = basePath + "_g"; File emission1BasePath = basePath + "_g";
File emission2BasePath = basePath + "_glow"; File emission2BasePath = basePath + "_glow";
File emission3BasePath = basePath + ".blend"; File emission3BasePath = basePath + ".blend";
File normals1BasePath = basePath + "_n"; File normals1BasePath = basePath + "_n";
File normals2BasePath = basePath + "_nm"; File normals2BasePath = basePath + "_nm";
File normals3BasePath = basePath + "_normal"; File normals3BasePath = basePath + "_normal";
File normals4BasePath = basePath + "_local"; File normals4BasePath = basePath + "_local";


File diffuse, masks, specular, emission, normals; File diffuse, masks, specular, emission, normals;


Expand Down
5 changes: 1 addition & 4 deletions src/client/CinematicProxy.cc
Expand Up @@ -88,10 +88,7 @@ void CinematicProxy::executeSequence(const File& file, const Lingua* missionLing
const Json& titleConfig = stepConfig["title"]; const Json& titleConfig = stepConfig["title"];
const String& title = titleConfig.get(String::EMPTY); const String& title = titleConfig.get(String::EMPTY);


if (titleConfig.isNull()) { if (titleConfig.isNull() || title.isEmpty()) {
step.title = "";
}
else if (title.isEmpty()) {
step.title = ""; step.title = "";
} }
else { else {
Expand Down
3 changes: 1 addition & 2 deletions src/client/Client.cc
Expand Up @@ -96,7 +96,7 @@ int Client::main()
Log::indent(); Log::indent();


// THE MAGNIFICENT MAIN LOOP // THE MAGNIFICENT MAIN LOOP
do { while (isAlive) {
// read input & events // read input & events
input.prepare(); input.prepare();


Expand Down Expand Up @@ -305,7 +305,6 @@ int Client::main()
} }
timeLast += timer.realTickDuration; timeLast += timer.realTickDuration;
} }
while (isAlive);


Log::unindent(); Log::unindent();
Log::println("}"); Log::println("}");
Expand Down
23 changes: 14 additions & 9 deletions src/client/Input.cc
Expand Up @@ -24,7 +24,10 @@
namespace oz::client namespace oz::client
{ {


static const char* const KEY_NAMES[] = { namespace
{

const char* const KEY_NAMES[] = {
"None", "None",


"Alternate UI action", "Alternate UI action",
Expand Down Expand Up @@ -97,21 +100,23 @@ static const char* const KEY_NAMES[] = {
"Quit" "Quit"
}; };


static SDL_Scancode modifier0; SDL_Scancode modifier0;
static SDL_Scancode modifier1; SDL_Scancode modifier1;


static ubyte sdlKeys[SDL_NUM_SCANCODES]; ubyte sdlKeys[SDL_NUM_SCANCODES];
static ubyte sdlOldKeys[SDL_NUM_SCANCODES]; ubyte sdlOldKeys[SDL_NUM_SCANCODES];
static ubyte sdlCurrKeys[SDL_NUM_SCANCODES]; ubyte sdlCurrKeys[SDL_NUM_SCANCODES];


static int keyMap[Input::KEY_MAX][2]; int keyMap[Input::KEY_MAX][2];
static bool configExists = false; bool configExists = false;


static int mouseEventFilter(void*, SDL_Event* event) int mouseEventFilter(void*, SDL_Event* event)
{ {
return event->type != SDL_MOUSEMOTION; return event->type != SDL_MOUSEMOTION;
} }


}

void Input::loadDefaultKeyMap() void Input::loadDefaultKeyMap()
{ {
modifier0 = SDL_SCANCODE_LALT; modifier0 = SDL_SCANCODE_LALT;
Expand Down
7 changes: 6 additions & 1 deletion src/client/LuaClient.cc
Expand Up @@ -25,7 +25,12 @@
namespace oz::client namespace oz::client
{ {


static LuaClient& lua = luaClient; namespace
{

LuaClient& lua = luaClient;

}


void LuaClient::staticCall(const char* functionName) void LuaClient::staticCall(const char* functionName)
{ {
Expand Down
3 changes: 1 addition & 2 deletions src/client/MD2.cc
Expand Up @@ -231,7 +231,7 @@ void MD2::AnimState::advance()
nextType = inferredType; nextType = inferredType;
currFrame = nextFrame; currFrame = nextFrame;


do { while (frameRatio >= 1.0f) {
frameRatio -= 1.0f; frameRatio -= 1.0f;


if (inferredType != currType) { if (inferredType != currType) {
Expand All @@ -255,7 +255,6 @@ void MD2::AnimState::advance()
} }
} }
} }
while (frameRatio >= 1.0f);
} }


OZ_ASSERT(0.0f <= frameRatio && frameRatio < 1.0f); OZ_ASSERT(0.0f <= frameRatio && frameRatio < 1.0f);
Expand Down
1 change: 0 additions & 1 deletion src/client/Profile.cc
Expand Up @@ -23,7 +23,6 @@
#include <matrix/WeaponClass.hh> #include <matrix/WeaponClass.hh>


#include <cstdlib> #include <cstdlib>
#include <cwchar>
#include <cwctype> #include <cwctype>


namespace oz::client namespace oz::client
Expand Down
10 changes: 5 additions & 5 deletions src/client/Render.cc
Expand Up @@ -671,11 +671,11 @@ void Render::init()
Log::println("Initialising Render {"); Log::println("Initialising Render {");
Log::indent(); Log::indent();


const char* vendor; const char* vendor = nullptr;
const char* renderer; const char* renderer = nullptr;
const char* version; const char* version = nullptr;
const char* glslVersion; const char* glslVersion = nullptr;
const char* sExtensions; const char* sExtensions = nullptr;


MainCall() << [&] MainCall() << [&]
{ {
Expand Down
11 changes: 8 additions & 3 deletions src/client/Shader.cc
Expand Up @@ -30,10 +30,15 @@
namespace oz::client namespace oz::client
{ {


static constexpr int LOG_BUFFER_SIZE = 8192; namespace
{

constexpr int LOG_BUFFER_SIZE = 8192;


static char logBuffer[LOG_BUFFER_SIZE]; char logBuffer[LOG_BUFFER_SIZE];
static String defines; String defines;

}


Uniform uniform; Uniform uniform;


Expand Down

0 comments on commit 75b174d

Please sign in to comment.