Commit 6ace01af authored by Shu's avatar Shu 🍠
Browse files

clang-tidy

parent 21b95ba5
......@@ -11,6 +11,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
# set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=clang-analyzer-*,cppcoreguidelines-*,performance-*,readability-*,-readability-braces-around-statements,-readability-uppercase-literal-suffix")
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
......
......@@ -30,8 +30,8 @@
- Valgrind
- Xtree-memory
- [ ] sanitizer
- [ ] clang-tidy
- [ ] cmake
- [x] clang-tidy
- [ ] clang -fall
- [ ] Server
- [ ] ZeroMQ
- [x] Logger
......
......@@ -9,18 +9,19 @@
#include "world/Chunk.hpp"
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <ctime>
#include <filesystem>
#include <fstream>
#include <iostream>
const auto SAMPLE_SIZE = 10000;
/// Entry point
int main(int, char *[])
int main(int /*unused*/, char * /*unused*/[])
{
std::srand(std::time(nullptr));
world::Generator generator(std::rand());
std::filesystem::create_directories("samples");
for (size_t i = 0; i < 10000; i++)
for (size_t i = 0; i < SAMPLE_SIZE; i++)
{
world::Chunk chunk(chunk_pos(std::rand(), std::rand(), std::rand()), generator);
std::ofstream out("samples/" + std::to_string(i));
......
#include "AbstractFlat.hpp"
#include <imgui.h>
#include <imgui.h> // NOLINT
#include <toml.h>
#include "../world/Chunk.hpp"
......
......@@ -2,8 +2,8 @@
#include "../world/Chunk.hpp"
#include "../world/materials.hpp"
#include <Remotery.h>
#include <imgui.h>
#include <Remotery.h> // NOLINT
#include <imgui.h> // NOLINT
#include <toml.h>
#include "dualmc.h"
......
......@@ -2,8 +2,8 @@
#include "boxing.hpp"
#include "../world/Chunk.hpp"
#include <Remotery.h>
#include <imgui.h>
#include <Remotery.h> // NOLINT
#include <imgui.h> // NOLINT
using namespace geometry;
namespace contouring {
......
......@@ -22,10 +22,6 @@ public:
};
Camera(GLFWwindow*, const InputMap&, const options&);
Camera(Camera &&) = default;
Camera(const Camera &) = default;
Camera &operator=(Camera &&) = default;
Camera &operator=(const Camera &) = default;
~Camera();
void update(bool captureMouse, bool captureKeys);
......
......@@ -19,10 +19,6 @@ enum class Mouse {
class InputMap {
public:
InputMap(GLFWwindow*);
InputMap(InputMap &&) = default;
InputMap(const InputMap &) = default;
InputMap &operator=(InputMap &&) = default;
InputMap &operator=(const InputMap &) = default;
~InputMap();
void saveKeys();
......
......@@ -20,10 +20,10 @@
#include "state.h"
#include "data/math.hpp"
#include <Remotery.h>
#include <Remotery.h> // NOLINT
/// Entry point
int main(int, char *[]){
int main(int /*unused*/, char */*unused*/[]){
LOG("Univerxel");
options options;
state state;
......@@ -34,7 +34,7 @@ int main(int, char *[]){
return 1;
glClearColor(options.renderer.clear_color.x, options.renderer.clear_color.y, options.renderer.clear_color.z, options.renderer.clear_color.w);
glfwSwapInterval(options.target_fps < MIN_FPS);
glfwSwapInterval(static_cast<int>(options.target_fps < MIN_FPS));
InputMap inputs(window);
Camera camera(window, inputs, options.camera);
......@@ -113,7 +113,7 @@ int main(int, char *[]){
rmt_ScopedCPUSample(UI, 0);
const auto actions = UI::draw(options, state, reports, aimTexture);
if (actions && UI::Actions::FPS) {
glfwSwapInterval(options.target_fps < MIN_FPS);
glfwSwapInterval(static_cast<int>(options.target_fps < MIN_FPS));
}
if (actions && UI::Actions::FullScreen) {
// MAYBE: real fullscreen
......
......@@ -3,9 +3,9 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
class options;
class state;
class reports;
struct options;
struct state;
struct reports;
namespace UI {
/// Retro actions to state
enum class Actions {
......
......@@ -54,7 +54,7 @@ struct options {
culling = config["mesh"]["culling"].value_or(true);
contouring_idx = contouring::idxByName(config["mesh"]["mode"].value_or(std::string("")));
for(const auto name: contouring::names) {
for(const auto& name: contouring::names) {
contouring_data.emplace(name, config["mesh"]["options"][name].value_or(std::string("")));
}
......
......@@ -5,9 +5,9 @@
using namespace world;
#define DENSITY 0.f
#define GRANULARITY 30.f
#define RLE 1
constexpr auto DENSITY = 0.f;
constexpr auto GRANULARITY = 30.f;
constexpr auto RLE = true;
Chunk::Chunk(const chunk_pos& pos, Generator& rnd) {
const auto [densitySet, materialSet] = rnd.getChunk(pos, CHUNK_LENGTH);
......@@ -21,7 +21,7 @@ Chunk::Chunk(const chunk_pos& pos, Generator& rnd) {
FastNoiseSIMD::FreeNoiseSet(materialSet);
}
Chunk::Chunk(std::istream& str) {
#ifdef RLE
if constexpr (RLE) {
ushort i = 0;
while(!str.eof()) {
ushort count;
......@@ -36,18 +36,18 @@ Chunk::Chunk(std::istream& str) {
}
}
assert(("Mismatch data length", i == CHUNK_SIZE-1));
#else
} else {
for(auto& voxel: voxels) {
str.read(reinterpret_cast<char *>(&voxel.Density), sizeof(Voxel::Density));
str.read(reinterpret_cast<char *>(&voxel.Material), sizeof(Voxel::Material));
}
#endif
}
}
Chunk::~Chunk() { }
void Chunk::write(std::ostream& str) const {
#ifdef RLE
auto it = voxels.begin();
if constexpr (RLE) {
const auto *it = voxels.begin();
ushort counter = 1;
Voxel current = *it;
while(true) {
......@@ -66,12 +66,12 @@ void Chunk::write(std::ostream& str) const {
counter++;
}
}
#else
} else {
for(auto current: voxels) {
str.write(reinterpret_cast<char *>(&current.Density), sizeof(current.Density));
str.write(reinterpret_cast<char *>(&current.Material), sizeof(current.Material));
}
#endif
}
}
std::optional<Faces> Chunk::update() {
......@@ -94,8 +94,8 @@ void Chunk::set(ushort idx, const Voxel& val) {
((!getNeighborIdx(idx, Face::Backward).has_value()) & Faces::Backward));
}
std::optional<ushort> Chunk::getNeighborIdx(ushort idx, Face face) {
switch (face) {
std::optional<ushort> Chunk::getNeighborIdx(ushort idx, Face dir) {
switch (dir) {
case Face::Forward:
if (idx % CHUNK_LENGTH >= CHUNK_LENGTH - 1)
return {};
......
......@@ -12,7 +12,7 @@
namespace world {
using namespace geometry;
/// World part as linear 3d voxel array
struct Chunk {
class Chunk {
public:
Chunk(const chunk_pos& pos, Generator& rnd);
Chunk(std::istream& str);
......
#pragma once
#include <FastNoiseSIMD.h>
#include <FastNoiseSIMD.h> // NOLINT
#include <tuple>
#include "position.h"
......
#include "Universe.hpp"
#include <Remotery.h>
#include <Remotery.h> // NOLINT
#include <filesystem>
#include "../contouring/Dummy.hpp"
......@@ -191,7 +191,7 @@ void Universe::setOptions(const Universe::options& options) {
keepDistance = options.keepDistance;
}
void Universe::setContouring(std::shared_ptr<contouring::Abstract> ct) {
void Universe::setContouring(const std::shared_ptr<contouring::Abstract>& ct) {
contouring = ct;
last_pos = chunk_pos(INT_MAX); // trigger chunkChange on next update
}
......
......@@ -65,7 +65,7 @@ namespace world {
ItemList setCube(const voxel_pos &pos, const Voxel &val, int radius);
/// Change contouring worker
void setContouring(std::shared_ptr<contouring::Abstract>);
void setContouring(const std::shared_ptr<contouring::Abstract>& ct);
/// Get current contouring worker
std::shared_ptr<contouring::Abstract> getContouring() const {
return contouring;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment