Skip to content

Commit

Permalink
Add clang-tidy modernize checks to the project
Browse files Browse the repository at this point in the history
This commit also fixes all warnings caught by clang-tidy
-checks="modernize-*". Most of the fixes were applied automatically.
  • Loading branch information
kantoniak committed Dec 1, 2018
1 parent 4bf0885 commit 486ded1
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 106 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ifeq ($(OS), Windows_NT)
RELEASE_DLLS += libwinpthread-1.dll
endif

CXX=clang++ -target x86_64-w64-pc-windows-gnu
CPPFLAGS := -target x86_64-w64-pc-windows-gnu $(CPPFLAGS)
OBJ_FILES += $(OBJDIR)/windows.rc.o
endif

Expand Down Expand Up @@ -124,6 +124,9 @@ run:
format-all:
clang-format -i -style=file -fallback-style=llvm -sort-includes $(CPP_FILES) $(HPP_FILES)

modernize-all:
clang-tidy -checks="modernize-*" -fix $(CPP_FILES) $(HPP_FILES) -- $(CPPFLAGS) $(DEFINES)

todos:
@grep -norwP src/ -e '(TODO|FIXME).*$''

Expand All @@ -142,16 +145,19 @@ release-zip: rebuild $(RELEASE_DLLS)

help:
@echo $(PROJECT_NAME) $(PROJECT_VERSION)-$(PROJECT_LAST_COMMIT)
@echo -e "\nTargets:"
@echo ""
@echo "Targets:"
@echo " clean"
@echo " format-all"
@echo " modernize-all"
@echo " build"
@echo " rebuild (clean + build)"
@echo " run"
@echo " all"
@echo " todos"
@echo " release-zip"
@echo " help"
@echo ""
@echo "Flags:"
@echo " CONFIG=[DEBUG|RELEASE]"
@echo " HIDE_CONSOLE=[TRUE|FALSE] (Windows)"
6 changes: 3 additions & 3 deletions src/data/Chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace data {

class Chunk {
typedef const std::vector<data::Lot> lotList;
typedef const std::vector<data::buildings::Building> residentialList;
typedef std::vector<data::buildings::Building>::const_iterator residentialListIter;
using lotList = const std::vector<data::Lot>;
using residentialList = const std::vector<data::buildings::Building>;
using residentialListIter = std::vector<data::buildings::Building>::const_iterator;

public:
constexpr unsigned static int SIDE_LENGTH = 64;
Expand Down
19 changes: 9 additions & 10 deletions src/data/Position.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "Position.hpp"

namespace data {
Position::Position() {
}
Position::Position() = default;

Position::Position(glm::ivec2 global) : global(global) {
}
Expand Down Expand Up @@ -45,14 +44,14 @@ glm::ivec2 Position::getChunk() const {

std::vector<Position> Position::getNeighbors() const {
std::vector<Position> result;
result.push_back(Position(global + glm::ivec2(1, -1)));
result.push_back(Position(global + glm::ivec2(1, 0)));
result.push_back(Position(global + glm::ivec2(1, 1)));
result.push_back(Position(global + glm::ivec2(0, -1)));
result.push_back(Position(global + glm::ivec2(0, +1)));
result.push_back(Position(global + glm::ivec2(-1, -1)));
result.push_back(Position(global + glm::ivec2(-1, 0)));
result.push_back(Position(global + glm::ivec2(-1, +1)));
result.emplace_back(global + glm::ivec2(1, -1));
result.emplace_back(global + glm::ivec2(1, 0));
result.emplace_back(global + glm::ivec2(1, 1));
result.emplace_back(global + glm::ivec2(0, -1));
result.emplace_back(global + glm::ivec2(0, +1));
result.emplace_back(global + glm::ivec2(-1, -1));
result.emplace_back(global + glm::ivec2(-1, 0));
result.emplace_back(global + glm::ivec2(-1, +1));
return result;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/data/Road.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "Road.hpp"

#include <utility>

namespace data {
Road::Road(const std::vector<Position>& tiles) : tiles(tiles) {
Road::Road(std::vector<Position> tiles) : tiles(std::move(tiles)) {
}

const std::vector<Position> Road::getTiles() const {
Expand Down
2 changes: 1 addition & 1 deletion src/data/Road.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace data {
class Road {

public:
explicit Road(const std::vector<Position>& tiles);
explicit Road(std::vector<Position> tiles);
const std::vector<Position> getTiles() const;

private:
Expand Down
4 changes: 2 additions & 2 deletions src/engine/DebugInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace engine {

class DebugInfo {
typedef std::chrono::steady_clock Clock;
typedef std::chrono::time_point<std::chrono::steady_clock> TimePoint;
using Clock = std::chrono::steady_clock;
using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;

public:
DebugInfo();
Expand Down
3 changes: 1 addition & 2 deletions src/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Engine::Engine(settings& gameSettings, Logger& logger)
ui(nullptr) {
}

Engine::~Engine() {
}
Engine::~Engine() = default;

bool Engine::running() {
return isRunning;
Expand Down
9 changes: 4 additions & 5 deletions src/engine/GameState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class GameState {

public:
GameState(Engine& engine) : engine(engine){};
virtual ~GameState(){};
GameState(const GameState&) = delete;
GameState& operator=(const GameState&) = delete;
virtual ~GameState() = default;
;
virtual void init(){};
virtual void cleanup(){};

Expand All @@ -36,11 +39,7 @@ class GameState {

protected:
bool suspended;

Engine& engine;

GameState(const GameState&) = delete;
GameState& operator=(const GameState&) = delete;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/input/LineSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const std::vector<data::Position> LineSelection::getSelected() const {
std::vector<data::Position> result;
for (int i = 0; i < length; i++) {
const glm::ivec2 toAdd = goesNorth ? glm::ivec2(0, i) : glm::ivec2(i, 0);
result.push_back(data::Position(start + toAdd));
result.emplace_back(start + toAdd);
}

return result;
Expand Down
6 changes: 3 additions & 3 deletions src/input/LineSelection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class LineSelection : public Selection {
public:
explicit LineSelection(unsigned short lineWidth);

virtual glm::ivec2 getFrom() const;
virtual glm::ivec2 getTo() const;
glm::ivec2 getFrom() const override;
glm::ivec2 getTo() const override;

virtual const std::vector<data::Position> getSelected() const;
const std::vector<data::Position> getSelected() const override;
const std::vector<LineSelection> divideByChunk() const;

private:
Expand Down
13 changes: 1 addition & 12 deletions src/input/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@ Selection::Selection() : selecting(false), valid(true) {
invalidColor = glm::vec4();
}

Selection& Selection::operator=(const Selection& other) {
selecting = other.selecting;
valid = other.valid;
fromPoint = other.fromPoint;
toPoint = other.toPoint;

startColor = other.startColor;
selectionColor = other.selectionColor;
invalidColor = other.invalidColor;

return *this;
}
Selection& Selection::operator=(const Selection& other) = default;

void Selection::setColors(glm::vec4 startColor, glm::vec4 selectionColor, glm::vec4 invalidColor) {
this->startColor = startColor;
Expand Down
12 changes: 6 additions & 6 deletions src/input/callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
namespace callbacks {

void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {
input::WindowHandler* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
auto* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
windowHandler->onKey(key, scancode, action, mods);
}

void onMouseButton(GLFWwindow* window, int button, int action, int mods) {
input::WindowHandler* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
auto* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
windowHandler->onMouseButton(button, action, mods);
}

void onMouseMove(GLFWwindow* window, double xpos, double ypos) {
input::WindowHandler* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
auto* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
windowHandler->onMouseMove(xpos, ypos);
}

void onScroll(GLFWwindow* window, double xoffset, double yoffset) {
input::WindowHandler* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
auto* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
windowHandler->onScroll(xoffset, yoffset);
}

void onWindowResize(GLFWwindow* window, int width, int height) {
input::WindowHandler* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
auto* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
windowHandler->onWindowResize(width, height);
}

void onWindowFocusChange(GLFWwindow* window, int focused) {
input::WindowHandler* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
auto* windowHandler = (input::WindowHandler*)glfwGetWindowUserPointer(window);
windowHandler->onWindowFocusChange(focused);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/io/serializers.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef IO_SERIALIZERS_HPP
#define IO_SERIALIZERS_HPP

#include <cereal/cereal.hpp>
#include <glm/glm.hpp>

namespace glm {
Expand Down
6 changes: 3 additions & 3 deletions src/rendering/ShaderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ GLuint ShaderManager::compileShader(GLenum shaderType, std::string filename, eng
const char* shaderSource = shaderSourceString.c_str();

GLuint shader = glCreateShader(shaderType);
glShaderSource(shader, 1, &shaderSource, NULL);
glShaderSource(shader, 1, &shaderSource, nullptr);
glCompileShader(shader);

GLint success;
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if (!success) {
GLchar errorMessage[512];
glGetShaderInfoLog(shader, 512, NULL, errorMessage);
glGetShaderInfoLog(shader, 512, nullptr, errorMessage);
log.error("Shader compilation failed for \"%s\": %s", filename.c_str(), errorMessage);
return 0;
}
Expand All @@ -55,7 +55,7 @@ GLuint ShaderManager::linkProgram(GLuint vertexShader, GLuint geomShader, GLuint
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success) {
GLchar errorMessage[512];
glGetProgramInfoLog(shaderProgram, 512, NULL, errorMessage);
glGetProgramInfoLog(shaderProgram, 512, nullptr, errorMessage);
log.error("Shader linking failed: %s", errorMessage);
return 0;
}
Expand Down
16 changes: 8 additions & 8 deletions src/rendering/WorldRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ bool WorldRenderer::setupBuildings() {
glBindBuffer(GL_ARRAY_BUFFER, buildingsVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(building), building, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)nullptr);

glGenBuffers(1, &buildingsInstanceVBO);
glBindBuffer(GL_ARRAY_BUFFER, buildingsInstanceVBO);

glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)nullptr);
glVertexAttribDivisor(1, 1);

glEnableVertexAttribArray(2);
Expand All @@ -151,8 +151,8 @@ void WorldRenderer::cleanup() {
glDeleteBuffers(1, &terrainPositionVBO);
glDeleteProgram(this->shaderProgram);

for (auto it = chunks.begin(); it != chunks.end(); it++) {
glDeleteBuffers(1, &(it->second));
for (auto& chunk : chunks) {
glDeleteBuffers(1, &(chunk.second));
}

glDeleteVertexArrays(1, &buildingsVAO);
Expand Down Expand Up @@ -207,7 +207,7 @@ void WorldRenderer::renderWorld(const input::Selection& selection) {
glEnableVertexAttribArray(1);
for (data::Chunk* chunk : world.getMap().getChunks()) {
glBindBuffer(GL_ARRAY_BUFFER, chunks[std::make_pair(chunk->getPosition().x, chunk->getPosition().y)]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)nullptr);
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));

glDrawArrays(GL_TRIANGLES, 0, data::Chunk::SIDE_LENGTH * data::Chunk::SIDE_LENGTH * 2 * 3);
Expand Down Expand Up @@ -414,9 +414,9 @@ void WorldRenderer::sendBuildingData() {
constexpr float buildingMargin = 0.2f;
for (data::Chunk* chunk : world.getMap().getChunks()) {
for (data::buildings::Building building : chunk->getResidentials()) {
buildingPositions.push_back(glm::vec3(building.x + buildingMargin, 0, building.y + buildingMargin));
buildingPositions.push_back(
glm::vec3(building.width - 2 * buildingMargin, building.level, building.length - 2 * buildingMargin));
buildingPositions.emplace_back(building.x + buildingMargin, 0, building.y + buildingMargin);
buildingPositions.emplace_back(building.width - 2 * buildingMargin, building.level,
building.length - 2 * buildingMargin);
}
}
glBindVertexArray(buildingsVAO);
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/WorldRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class WorldRenderer : public Renderer {
public:
WorldRenderer(engine::Engine& engine, world::World& world);

virtual bool init();
bool init() override;
bool setupShaders();
bool setupTextures();
bool setupTerrain();
bool setupBuildings();
virtual void cleanup();
void cleanup() override;

void markBuildingDataForUpdate();
void markTileDataForUpdate();
Expand Down
16 changes: 8 additions & 8 deletions src/states/MainMenuState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class MainMenuState : public engine::GameState {
public:
MainMenuState(engine::Engine& engine, MapState& mapState);

void init();
void init() override;

void update(std::chrono::milliseconds delta);
void render();
void update(std::chrono::milliseconds delta) override;
void render() override;

void onKey(int key, int scancode, int action, int mods);
void onMouseButton(int button, int action, int mods);
void onScroll(double xoffset, double yoffset);
void onWindowFocusChange(int focused);
void onWindowResize(int width, int height);
void onKey(int key, int scancode, int action, int mods) override;
void onMouseButton(int button, int action, int mods) override;
void onScroll(double xoffset, double yoffset) override;
void onWindowFocusChange(int focused) override;
void onWindowResize(int width, int height) override;

private:
// FIXME(kantoniak): MainMenuState::renderButton() should not be there
Expand Down
16 changes: 8 additions & 8 deletions src/states/MapPauseState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class MapPauseState : public engine::GameState {
public:
MapPauseState(engine::Engine& engine, world::World& world, rendering::WorldRenderer& worldRenderer);

void init();
void init() override;

void update(std::chrono::milliseconds delta);
void render();
void update(std::chrono::milliseconds delta) override;
void render() override;

void onKey(int key, int scancode, int action, int mods);
void onMouseButton(int button, int action, int mods);
void onScroll(double xoffset, double yoffset);
void onWindowFocusChange(int focused);
void onWindowResize(int width, int height);
void onKey(int key, int scancode, int action, int mods) override;
void onMouseButton(int button, int action, int mods) override;
void onScroll(double xoffset, double yoffset) override;
void onWindowFocusChange(int focused) override;
void onWindowResize(int width, int height) override;

private:
world::World& world;
Expand Down

0 comments on commit 486ded1

Please sign in to comment.