diff --git a/core/include/cubos/core/data/deserializer.hpp b/core/include/cubos/core/data/deserializer.hpp index 427e68022..902dd5e8d 100644 --- a/core/include/cubos/core/data/deserializer.hpp +++ b/core/include/cubos/core/data/deserializer.hpp @@ -193,21 +193,21 @@ namespace cubos::core::data /// This is a special case because std::vector are stored as arrays of bits, and therefore /// need special handling. /// @param des The deserializer. - /// @param val The value to deserialize. - void deserialize(Deserializer& des, std::vector::reference val); + /// @param obj The value to deserialize. + void deserialize(Deserializer& des, std::vector::reference obj); /// Overload for deserializing std::vector. /// @tparam T The type of the vector. /// @param des The deserializer. - /// @param vec The vector to deserialize. + /// @param obj The vector to deserialize. template - inline void deserialize(Deserializer& des, std::vector& vec) + inline void deserialize(Deserializer& des, std::vector& obj) { std::size_t length = des.beginArray(); - vec.resize(length); + obj.resize(length); for (std::size_t i = 0; i < length; ++i) { - deserialize(des, vec[i]); + deserialize(des, obj[i]); } des.endArray(); } @@ -216,20 +216,20 @@ namespace cubos::core::data /// @tparam K The key type of the map. /// @tparam V The value type of the map. /// @param des The deserializer. - /// @param map The map to deserialize. + /// @param obj The map to deserialize. template - inline void deserialize(Deserializer& des, std::unordered_map& map) + inline void deserialize(Deserializer& des, std::unordered_map& obj) { std::size_t length = des.beginDictionary(); - map.clear(); - map.reserve(length); + obj.clear(); + obj.reserve(length); for (std::size_t i = 0; i < length; ++i) { K key; V value; des.read(key); des.read(value); - map.emplace(std::move(key), std::move(value)); + obj.emplace(std::move(key), std::move(value)); } des.endDictionary(); } @@ -238,13 +238,13 @@ namespace cubos::core::data /// @tparam T The type of the first value. /// @tparam U The type of the second value. /// @param des The deserializer. - /// @param pair The pair to deserialize. + /// @param obj The pair to deserialize. template - inline void deserialize(Deserializer& des, std::pair& pair) + inline void deserialize(Deserializer& des, std::pair& obj) { des.beginObject(); - des.read(pair.first); - des.read(pair.second); + des.read(obj.first); + des.read(obj.second); des.endObject(); } } // namespace cubos::core::data diff --git a/core/include/cubos/core/data/fs/standard_archive.hpp b/core/include/cubos/core/data/fs/standard_archive.hpp index e3351c68b..3140bac3d 100644 --- a/core/include/cubos/core/data/fs/standard_archive.hpp +++ b/core/include/cubos/core/data/fs/standard_archive.hpp @@ -43,7 +43,7 @@ namespace cubos::core::data std::size_t parent(std::size_t id) const override; std::size_t sibling(std::size_t id) const override; std::size_t child(std::size_t id) const override; - std::unique_ptr open(std::size_t id, File::Handle handle, File::OpenMode mode) override; + std::unique_ptr open(std::size_t id, File::Handle file, File::OpenMode mode) override; private: /// @brief Information about a file in the directory. diff --git a/core/include/cubos/core/data/serializer.hpp b/core/include/cubos/core/data/serializer.hpp index 2c63c5fa9..cb362c72a 100644 --- a/core/include/cubos/core/data/serializer.hpp +++ b/core/include/cubos/core/data/serializer.hpp @@ -192,34 +192,34 @@ namespace cubos::core::data /// This is a special case because std::vector are stored as arrays of bits, and therefore /// need special handling. /// @param ser The serializer. - /// @param val The value to serialize. + /// @param obj The value to serialize. /// @param name The name of the value (optional). - void serialize(Serializer& ser, std::vector::const_reference val, const char* name); + void serialize(Serializer& ser, std::vector::const_reference obj, const char* name); /// Overload for serializing char arrays. /// Necessary because literal strings are treated as char arrays by the compiler. /// Without this overload, the linker would fail. /// @param ser The serializer. - /// @param str The string to serialize. + /// @param obj The string to serialize. /// @param name The name of the string (optional). template - inline void serialize(Serializer& ser, char const (&str)[N], const char* name) + inline void serialize(Serializer& ser, char const (&obj)[N], const char* name) { - ser.writeString(str, name); + ser.writeString(obj, name); } /// Overload for serializing std::vector. /// @tparam T The type of the vector. /// @param ser The serializer. - /// @param vec The vector to serialize. + /// @param obj The vector to serialize. /// @param name The name of the vector (optional). template - inline void serialize(Serializer& ser, const std::vector& vec, const char* name) + inline void serialize(Serializer& ser, const std::vector& obj, const char* name) { - ser.beginArray(vec.size(), name); - for (const auto& obj : vec) + ser.beginArray(obj.size(), name); + for (const auto& element : obj) { - ser.write(obj, nullptr); + ser.write(element, nullptr); } ser.endArray(); } @@ -228,13 +228,13 @@ namespace cubos::core::data /// @tparam K The type of the key. /// @tparam V The type of the value. /// @param ser The serializer. - /// @param map The map to serialize. + /// @param obj The map to serialize. /// @param name The name of the map (optional). template - inline void serialize(Serializer& ser, const std::unordered_map& map, const char* name) + inline void serialize(Serializer& ser, const std::unordered_map& obj, const char* name) { - ser.beginDictionary(map.size(), name); - for (const auto& pair : map) + ser.beginDictionary(obj.size(), name); + for (const auto& pair : obj) { ser.write(pair.first, nullptr); ser.write(pair.second, nullptr); @@ -246,14 +246,14 @@ namespace cubos::core::data /// @tparam T The type of the first value. /// @tparam U The type of the second value. /// @param ser The serializer. - /// @param pair The pair to serialize. + /// @param obj The pair to serialize. /// @param name The name of the pair (optional). template - inline void serialize(Serializer& ser, const std::pair& pair, const char* name) + inline void serialize(Serializer& ser, const std::pair& obj, const char* name) { ser.beginObject(name); - ser.write(pair.first, "first"); - ser.write(pair.second, "second"); + ser.write(obj.first, "first"); + ser.write(obj.second, "second"); ser.endObject(); } } // namespace cubos::core::data diff --git a/core/include/cubos/core/ecs/event_pipe.hpp b/core/include/cubos/core/ecs/event_pipe.hpp index ccad42923..3b5372167 100644 --- a/core/include/cubos/core/ecs/event_pipe.hpp +++ b/core/include/cubos/core/ecs/event_pipe.hpp @@ -67,7 +67,7 @@ namespace cubos::core::ecs mutable std::atomic_size_t readCount{0}; Event(T e, unsigned int m) - : event(e) + : event(std::move(e)) , mask(m) { } diff --git a/core/include/cubos/core/ecs/world.hpp b/core/include/cubos/core/ecs/world.hpp index 0ba9ffba5..6b3d63144 100644 --- a/core/include/cubos/core/ecs/world.hpp +++ b/core/include/cubos/core/ecs/world.hpp @@ -185,11 +185,11 @@ namespace cubos::core::ecs #if CUBOS_LOG_LEVEL <= CUBOS_LOG_LEVEL_DEBUG // Get the number of components being added. - constexpr std::size_t componentCount = sizeof...(ComponentTypes); + constexpr std::size_t ComponentCount = sizeof...(ComponentTypes); std::string componentNames[] = {"", "'" + std::string{getComponentName().value()} + "'" ...}; CUBOS_DEBUG("Created entity {} with components {}", entity.index, - fmt::join(componentNames + 1, componentNames + componentCount + 1, ", ")); + fmt::join(componentNames + 1, componentNames + ComponentCount + 1, ", ")); #endif return entity; } diff --git a/core/include/cubos/core/geom/box.hpp b/core/include/cubos/core/geom/box.hpp index e723a61dd..9da96350a 100644 --- a/core/include/cubos/core/geom/box.hpp +++ b/core/include/cubos/core/geom/box.hpp @@ -15,7 +15,7 @@ namespace cubos::core::geom /// @ingroup core-geom struct Box { - glm::vec3 halfSize{0.5f}; ///< Half size of the box. + glm::vec3 halfSize{0.5F}; ///< Half size of the box. /// @brief Computes two opposite corners of the box on the major diagonal. /// @param corners Array to store the two corners in. diff --git a/core/include/cubos/core/geom/capsule.hpp b/core/include/cubos/core/geom/capsule.hpp index 69ae9a72f..71b8586c2 100644 --- a/core/include/cubos/core/geom/capsule.hpp +++ b/core/include/cubos/core/geom/capsule.hpp @@ -13,22 +13,22 @@ namespace cubos::core::geom /// @ingroup core-geom struct Capsule { - float radius = 1.0f; ///< Radius of the capsule. - float length = 0.0f; ///< Length of the capsule. + float radius = 1.0F; ///< Radius of the capsule. + float length = 0.0F; ///< Length of the capsule. /// @brief Constructs a sphere. /// @param radius Sphere radius. /// @return Sphere shape. static Capsule sphere(float radius) { - return {radius, 0.0f}; + return {radius, 0.0F}; } /// @brief Gets the height of the capsule. /// @return Height of the capsule. float height() const { - return length + 2.0f * radius; + return length + 2.0F * radius; } }; } // namespace cubos::core::geom diff --git a/core/include/cubos/core/geom/plane.hpp b/core/include/cubos/core/geom/plane.hpp index 0ce8c13b6..f355f8bb5 100644 --- a/core/include/cubos/core/geom/plane.hpp +++ b/core/include/cubos/core/geom/plane.hpp @@ -15,7 +15,7 @@ namespace cubos::core::geom /// @ingroup core-geom struct Plane { - glm::vec3 normal{0.0f, 1.0f, 0.0f}; ///< Normal of the plane. + glm::vec3 normal{0.0F, 1.0F, 0.0F}; ///< Normal of the plane. }; } // namespace cubos::core::geom diff --git a/core/include/cubos/core/reflection/traits/constructible.hpp b/core/include/cubos/core/reflection/traits/constructible.hpp index a46fde7da..a269bf1fe 100644 --- a/core/include/cubos/core/reflection/traits/constructible.hpp +++ b/core/include/cubos/core/reflection/traits/constructible.hpp @@ -108,9 +108,9 @@ namespace cubos::core::reflection std::size_t mSize; std::size_t mAlignment; Destructor mDestructor; - DefaultConstructor mDefaultConstructor; - CopyConstructor mCopyConstructor; - MoveConstructor mMoveConstructor; + DefaultConstructor mDefaultConstructor{nullptr}; + CopyConstructor mCopyConstructor{nullptr}; + MoveConstructor mMoveConstructor{nullptr}; }; template diff --git a/core/include/cubos/core/reflection/type.hpp b/core/include/cubos/core/reflection/type.hpp index cf127dfd8..8516b219f 100644 --- a/core/include/cubos/core/reflection/type.hpp +++ b/core/include/cubos/core/reflection/type.hpp @@ -117,8 +117,8 @@ namespace cubos::core::reflection { // This variable is unused, but since there is one for each type, its address is // guaranteed to be unique for each type. - static const bool var = false; - return reinterpret_cast(&var); + static const bool Var = false; + return reinterpret_cast(&Var); } /// @brief %Trait entry in the type. diff --git a/core/samples/data/fs/embedded_archive/embed.cpp b/core/samples/data/fs/embedded_archive/embed.cpp index 1a4194034..1fb151d19 100644 --- a/core/samples/data/fs/embedded_archive/embed.cpp +++ b/core/samples/data/fs/embedded_archive/embed.cpp @@ -10,27 +10,27 @@ using cubos::core::data::EmbeddedArchive; -static const uint8_t fileData3[] = { +static const uint8_t FileData3[] = { 0x62, 0x61, 0x7a, }; -static const uint8_t fileData4[] = { +static const uint8_t FileData4[] = { 0x66, 0x6f, 0x6f, }; -static const EmbeddedArchive::Data::Entry entries[] = { +static const EmbeddedArchive::Data::Entry Entries[] = { {"", true, 0, 0, 2, nullptr, 0}, {"bar", true, 1, 4, 3, nullptr, 0}, - {"baz.txt", false, 2, 0, 0, fileData3, sizeof(fileData3)}, - {"foo.txt", false, 1, 0, 0, fileData4, sizeof(fileData4)}, + {"baz.txt", false, 2, 0, 0, FileData3, sizeof(FileData3)}, + {"foo.txt", false, 1, 0, 0, FileData4, sizeof(FileData4)}, }; -static const EmbeddedArchive::Data embeddedArchiveData = { - entries, - sizeof(entries) / sizeof(entries[0]), +static const EmbeddedArchive::Data EmbeddedArchiveData = { + Entries, + sizeof(Entries) / sizeof(Entries[0]), }; class DataRegister @@ -38,7 +38,7 @@ class DataRegister public: DataRegister() { - EmbeddedArchive::registerData("assets", embeddedArchiveData); + EmbeddedArchive::registerData("assets", EmbeddedArchiveData); } }; diff --git a/core/src/cubos/core/data/deserializer.cpp b/core/src/cubos/core/data/deserializer.cpp index 15c52fde3..e3f099ed3 100644 --- a/core/src/cubos/core/data/deserializer.cpp +++ b/core/src/cubos/core/data/deserializer.cpp @@ -96,11 +96,11 @@ void cubos::core::data::deserialize(Deserializer& des, std::string& des.readString(obj); } -void cubos::core::data::deserialize(Deserializer& des, std::vector::reference val) +void cubos::core::data::deserialize(Deserializer& des, std::vector::reference obj) { bool boolean; des.readBool(boolean); - val = boolean; + obj = boolean; } // Implementation of deserialize() for GLM types. diff --git a/core/src/cubos/core/data/fs/file_system.cpp b/core/src/cubos/core/data/fs/file_system.cpp index a4a08c3fe..53480a53b 100644 --- a/core/src/cubos/core/data/fs/file_system.cpp +++ b/core/src/cubos/core/data/fs/file_system.cpp @@ -99,14 +99,12 @@ std::unique_ptr FileSystem::open(std::string_view path, File::Op CUBOS_ERROR("Could not open file for reading at path '{}': the file does not exist", path); return nullptr; } - else - { - if (auto file = FileSystem::root()->create(path)) - { - return file->open(mode); - } - CUBOS_ERROR("Could not open file for writing at path '{}': the file could not be created", path); - return nullptr; + if (auto file = FileSystem::root()->create(path)) + { + return file->open(mode); } + + CUBOS_ERROR("Could not open file for writing at path '{}': the file could not be created", path); + return nullptr; } diff --git a/core/src/cubos/core/data/fs/standard_archive.cpp b/core/src/cubos/core/data/fs/standard_archive.cpp index ee60d7481..aa41c1c46 100644 --- a/core/src/cubos/core/data/fs/standard_archive.cpp +++ b/core/src/cubos/core/data/fs/standard_archive.cpp @@ -28,32 +28,30 @@ StandardArchive::StandardArchive(const std::filesystem::path& osPath, bool isDir CUBOS_ERROR("File/directory '{}' does not exist on the host file system", osPath.string()); return; } - else + + // Create the file/directory. + if (isDirectory) { - // Create the file/directory. - if (isDirectory) + std::error_code err; + if (!std::filesystem::create_directory(osPath, err)) { - std::error_code err; - if (!std::filesystem::create_directory(osPath, err)) - { - CUBOS_ERROR("std::filesystem::create_directory() failed: {}", err.message()); - CUBOS_ERROR("Could not create root directory '{}' on the host file system", osPath.string()); - return; - } + CUBOS_ERROR("std::filesystem::create_directory() failed: {}", err.message()); + CUBOS_ERROR("Could not create root directory '{}' on the host file system", osPath.string()); + return; } - else + } + else + { + // Write an empty file. + std::string path = osPath.string(); + FILE* file = fopen(path.c_str(), "w"); + if (file == nullptr) { - // Write an empty file. - std::string path = osPath.string(); - FILE* file = fopen(path.c_str(), "w"); - if (file == nullptr) - { - CUBOS_ERROR("fopen() failed: {}", strerror(errno)); - CUBOS_ERROR("Could not create root file '{}' on the host file system", path); - return; - } - fclose(file); + CUBOS_ERROR("fopen() failed: {}", strerror(errno)); + CUBOS_ERROR("Could not create root file '{}' on the host file system", path); + return; } + fclose(file); } } @@ -264,7 +262,7 @@ std::unique_ptr StandardArchive::open(std::size_t id, File::Handle file, } std::string path = it->second.osPath.string(); - auto fd = fopen(path.c_str(), stdMode); + auto* fd = fopen(path.c_str(), stdMode); if (fd == nullptr) { CUBOS_ERROR("fopen() failed: {}", strerror(errno)); diff --git a/core/src/cubos/core/data/serializer.cpp b/core/src/cubos/core/data/serializer.cpp index 987c1af43..88ee6e3c5 100644 --- a/core/src/cubos/core/data/serializer.cpp +++ b/core/src/cubos/core/data/serializer.cpp @@ -104,9 +104,9 @@ void cubos::core::data::serialize(Serializer& ser, const std::strin ser.writeString(obj.c_str(), name); } -void cubos::core::data::serialize(Serializer& ser, std::vector::const_reference val, const char* name) +void cubos::core::data::serialize(Serializer& ser, std::vector::const_reference obj, const char* name) { - ser.writeBool(val, name); + ser.writeBool(obj, name); } // Implementation of serialize() for GLM types. diff --git a/core/src/cubos/core/io/gamepad.cpp b/core/src/cubos/core/io/gamepad.cpp index 24df311ed..bfae92224 100644 --- a/core/src/cubos/core/io/gamepad.cpp +++ b/core/src/cubos/core/io/gamepad.cpp @@ -45,7 +45,7 @@ void data::serialize(Serializer& ser, const GamepadButton& obj, c GamepadButton io::stringToGamepadButton(const std::string& str) { #define MAP_STRING_TO_BUTTON(string, button) \ - if (str == string) \ + if (str == (string)) \ return GamepadButton::button; MAP_STRING_TO_BUTTON("A", A) MAP_STRING_TO_BUTTON("B", B) @@ -103,7 +103,7 @@ void data::serialize(Serializer& ser, const GamepadAxis& obj, const GamepadAxis io::stringToGamepadAxis(const std::string& str) { #define MAP_STRING_TO_AXIS(string, axis) \ - if (str == string) \ + if (str == (string)) \ return GamepadAxis::axis; MAP_STRING_TO_AXIS("LX", LX) MAP_STRING_TO_AXIS("LY", LY) diff --git a/core/src/cubos/core/io/glfw_window.cpp b/core/src/cubos/core/io/glfw_window.cpp index 1a180a0d8..79f350038 100644 --- a/core/src/cubos/core/io/glfw_window.cpp +++ b/core/src/cubos/core/io/glfw_window.cpp @@ -15,7 +15,7 @@ static void mouseButtonCallback(GLFWwindow* window, int button, int action, int static void scrollCallback(GLFWwindow* window, double xoffset, double yoffset); static void framebufferSizeCallback(GLFWwindow* window, int width, int height); static void charCallback(GLFWwindow* window, unsigned int codepoint); -static void joystickCallback(int jid, int event); +static void joystickCallback(int id, int event); static void updateMods(GLFWWindow* handler, int glfwMods); static MouseButton glfwToCubosMouseButton(int button); static Key glfwToCubosKey(int key); @@ -87,7 +87,7 @@ GLFWWindow::GLFWWindow(const std::string& title, const glm::ivec2& size) for (int i = GLFW_JOYSTICK_1; i < GLFW_JOYSTICK_LAST; ++i) { - if (glfwJoystickIsGamepad(i)) + if (glfwJoystickIsGamepad(i) != GLFW_FALSE) { this->pushEvent(GamepadConnectionEvent{.gamepad = i, .connected = true}); } @@ -310,9 +310,9 @@ Modifiers GLFWWindow::modifiers() const #endif } -void GLFWWindow::modifiers(Modifiers mods) +void GLFWWindow::modifiers(Modifiers modifiers) { - mModifiers = mods; + mModifiers = modifiers; } bool GLFWWindow::gamepadState(int gamepad, GamepadState& state) const diff --git a/core/src/cubos/core/io/keyboard.cpp b/core/src/cubos/core/io/keyboard.cpp index d61b26c51..472a9b3de 100644 --- a/core/src/cubos/core/io/keyboard.cpp +++ b/core/src/cubos/core/io/keyboard.cpp @@ -13,13 +13,24 @@ std::string io::modifiersToString(Modifiers modifiers) std::string result; if ((modifiers & Modifiers::Control) != Modifiers::None) + { result += "C-"; + } + if ((modifiers & Modifiers::Shift) != Modifiers::None) + { result += "S-"; + } + if ((modifiers & Modifiers::Alt) != Modifiers::None) + { result += "M-"; + } + if ((modifiers & Modifiers::System) != Modifiers::None) + { result += "D-"; + } return result; } @@ -35,13 +46,24 @@ Modifiers io::stringToModifiers(const std::string& str) Modifiers result = Modifiers::None; if (str.find("C-") != std::string::npos) + { result |= Modifiers::Control; + } + if (str.find("S-") != std::string::npos) + { result |= Modifiers::Shift; + } + if (str.find("M-") != std::string::npos) + { result |= Modifiers::Alt; + } + if (str.find("D-") != std::string::npos) + { result |= Modifiers::System; + } return result; } @@ -58,7 +80,7 @@ std::string io::keyToString(Key key) { #define MAP_KEY_TO_STRING(key, string) \ case Key::key: \ - return string; + return (string); switch (key) { MAP_KEY_TO_STRING(A, "a") @@ -174,9 +196,8 @@ void data::serialize(Serializer& ser, const Key& obj, const char* name) Key io::stringToKey(const std::string& str) { #define MAP_STRING_TO_KEY(string, key) \ - if (str == string) \ - return Key::key; \ - else + if (str == (string)) \ + return Key::key; MAP_STRING_TO_KEY("a", A) MAP_STRING_TO_KEY("b", B) MAP_STRING_TO_KEY("c", C) diff --git a/core/src/cubos/core/reflection/traits/constructible.cpp b/core/src/cubos/core/reflection/traits/constructible.cpp index 17fd8b4ca..dbb136366 100644 --- a/core/src/cubos/core/reflection/traits/constructible.cpp +++ b/core/src/cubos/core/reflection/traits/constructible.cpp @@ -8,9 +8,6 @@ ConstructibleTrait::ConstructibleTrait(std::size_t size, std::size_t alignment, : mSize(size) , mAlignment(alignment) , mDestructor(destructor) - , mDefaultConstructor(nullptr) - , mCopyConstructor(nullptr) - , mMoveConstructor(nullptr) { CUBOS_ASSERT(mAlignment > 0, "Alignment must be positive"); CUBOS_ASSERT((mAlignment & (mAlignment - 1)) == 0, "Alignment must be a power of two"); @@ -55,7 +52,7 @@ void ConstructibleTrait::destruct(void* instance) const bool ConstructibleTrait::defaultConstruct(void* instance) const { - if (mDefaultConstructor) + if (mDefaultConstructor != nullptr) { mDefaultConstructor(instance); return true; @@ -66,7 +63,7 @@ bool ConstructibleTrait::defaultConstruct(void* instance) const bool ConstructibleTrait::copyConstruct(void* instance, const void* other) const { - if (mCopyConstructor) + if (mCopyConstructor != nullptr) { mCopyConstructor(instance, other); return true; @@ -77,7 +74,7 @@ bool ConstructibleTrait::copyConstruct(void* instance, const void* other) const bool ConstructibleTrait::moveConstruct(void* instance, void* other) const { - if (mMoveConstructor) + if (mMoveConstructor != nullptr) { mMoveConstructor(instance, other); return true; diff --git a/core/src/cubos/core/reflection/type.cpp b/core/src/cubos/core/reflection/type.cpp index 2e770a738..c224ca935 100644 --- a/core/src/cubos/core/reflection/type.cpp +++ b/core/src/cubos/core/reflection/type.cpp @@ -5,7 +5,7 @@ using namespace cubos::core::reflection; Type& Type::create(std::string name) { - return *(new Type(name)); + return *(new Type(std::move(name))); } void Type::destroy(Type& type) diff --git a/core/tests/data/fs/embedded_archive.cpp b/core/tests/data/fs/embedded_archive.cpp index abd591389..e7907f6c8 100644 --- a/core/tests/data/fs/embedded_archive.cpp +++ b/core/tests/data/fs/embedded_archive.cpp @@ -13,22 +13,22 @@ using cubos::core::memory::Stream; // Fear not - we aren't supposed do this manually - usually quadrados would do this for us. // Embedded data with a single regular file which has the data "ab". -static const EmbeddedArchive::Data::Entry singleEntry{"root", false, 0, 0, 0, "ab", 2}; -static const EmbeddedArchive::Data singleData = {&singleEntry, 1}; +static const EmbeddedArchive::Data::Entry SingleEntry{"root", false, 0, 0, 0, "ab", 2}; +static const EmbeddedArchive::Data SingleData = {&SingleEntry, 1}; // Embedded data with four files: // - root directory // - foo "foo" // - bar directory // - baz "" (empty file) -static const EmbeddedArchive::Data::Entry multipleEntries[] = { +static const EmbeddedArchive::Data::Entry MultipleEntries[] = { {"root", true, 0, 0, 2, nullptr, 0}, {"foo", false, 1, 3, 0, "foo", 3}, {"bar", true, 1, 0, 4, nullptr, 0}, {"baz", false, 3, 0, 0, nullptr, 0}, }; -static const EmbeddedArchive::Data multipleData = {multipleEntries, - sizeof(multipleEntries) / sizeof(multipleEntries[0])}; +static const EmbeddedArchive::Data MultipleData = {MultipleEntries, + sizeof(MultipleEntries) / sizeof(MultipleEntries[0])}; TEST_CASE("data::EmbeddedArchive") { @@ -40,8 +40,8 @@ TEST_CASE("data::EmbeddedArchive") { // Register embedded data so that we can mount it later. registered = true; - EmbeddedArchive::registerData("single", singleData); - EmbeddedArchive::registerData("multiple", multipleData); + EmbeddedArchive::registerData("single", SingleData); + EmbeddedArchive::registerData("multiple", MultipleData); } SUBCASE("single file") diff --git a/core/tests/data/fs/file_system.cpp b/core/tests/data/fs/file_system.cpp index a626417f6..5cc13e41d 100644 --- a/core/tests/data/fs/file_system.cpp +++ b/core/tests/data/fs/file_system.cpp @@ -44,7 +44,7 @@ inline auto mockArchive(bool readOnly) } /// Resets the file system to its initial state. -inline void unmountAll(File::Handle handle) +inline void unmountAll(const File::Handle& handle) { while (handle->child() != nullptr) { @@ -59,7 +59,7 @@ inline void unmountAll(File::Handle handle) } } -TEST_CASE("data::FileSystem") +TEST_CASE("data::FileSystem") // NOLINT(readability-function-size) { cubos::core::disableLogging(); unmountAll(FileSystem::root()); diff --git a/core/tests/data/fs/standard_archive.cpp b/core/tests/data/fs/standard_archive.cpp index 459f478d3..e2ec5abf7 100644 --- a/core/tests/data/fs/standard_archive.cpp +++ b/core/tests/data/fs/standard_archive.cpp @@ -22,7 +22,7 @@ static void assertInitializationFailed(StandardArchive& archive) REQUIRE(archive.open(1, nullptr, File::OpenMode::Read) == nullptr); } -TEST_CASE("data::StandardArchive") +TEST_CASE("data::StandardArchive") // NOLINT(readability-function-size) { auto path = genTempPath(); @@ -214,6 +214,7 @@ TEST_CASE("data::StandardArchive") std::filesystem::create_directory(path); std::filesystem::create_directory(path / "bar"); std::ofstream{path / "foo"} << "foo"; + // NOLINTNEXTLINE(bugprone-unused-raii) std::ofstream{path / "bar" / "baz"}; // Don't write anything to "baz", but create it. // Create a read-only archive on the generated directory. diff --git a/core/tests/ecs/system.cpp b/core/tests/ecs/system.cpp index 246096f26..e01a7e258 100644 --- a/core/tests/ecs/system.cpp +++ b/core/tests/ecs/system.cpp @@ -197,23 +197,23 @@ static void accessNothing() { } -static void accessResources(Read, Write, Read) +static void accessResources(Read /*unused*/, Write /*unused*/, Read /*unused*/) { } -static void accessComponents(Query, Write>, Query, Read>) +static void accessComponents(Query, Write> /*unused*/, Query, Read> /*unused*/) { } -static void accessCommands(Commands) +static void accessCommands(Commands /*unused*/) { } -static void accessWriteWorld(Write) +static void accessWriteWorld(Write /*unused*/) { } -static void accessReadWorld(Read) +static void accessReadWorld(Read /*unused*/) { } diff --git a/core/tests/geom/box.cpp b/core/tests/geom/box.cpp index e6f81afc4..c34c88d78 100644 --- a/core/tests/geom/box.cpp +++ b/core/tests/geom/box.cpp @@ -8,9 +8,9 @@ using cubos::core::geom::Box; TEST_CASE("geom::Box") { - auto x = 1.0f; - auto y = 2.0f; - auto z = 3.0f; + auto x = 1.0F; + auto y = 2.0F; + auto z = 3.0F; Box box{{x, y, z}}; SUBCASE("diagonal") diff --git a/core/tests/geom/capsule.cpp b/core/tests/geom/capsule.cpp index 1b62cd32b..6c8aeb74f 100644 --- a/core/tests/geom/capsule.cpp +++ b/core/tests/geom/capsule.cpp @@ -6,8 +6,8 @@ using cubos::core::geom::Capsule; TEST_CASE("geom::Capsule") { - auto r = 1.0f; - auto l = 2.0f; + auto r = 1.0F; + auto l = 2.0F; Capsule capsule{r, l}; SUBCASE("height") @@ -17,7 +17,7 @@ TEST_CASE("geom::Capsule") SUBCASE("sphere") { - auto sphere = Capsule::sphere(1.0f); + auto sphere = Capsule::sphere(1.0F); CHECK_EQ(sphere.height(), 2 * r); } } diff --git a/core/tests/geom/simplex.cpp b/core/tests/geom/simplex.cpp index d4d8f8964..91d1ccbf6 100644 --- a/core/tests/geom/simplex.cpp +++ b/core/tests/geom/simplex.cpp @@ -6,10 +6,10 @@ using cubos::core::geom::Simplex; TEST_CASE("geom::Simplex") { - auto p1 = glm::vec3{1.0f}; - auto p2 = glm::vec3{2.0f}; - auto p3 = glm::vec3{3.0f}; - auto p4 = glm::vec3{4.0f}; + auto p1 = glm::vec3{1.0F}; + auto p2 = glm::vec3{2.0F}; + auto p3 = glm::vec3{3.0F}; + auto p4 = glm::vec3{4.0F}; SUBCASE("empty") { diff --git a/core/tests/reflection/traits/constructible.cpp b/core/tests/reflection/traits/constructible.cpp index c04101b16..22e048501 100644 --- a/core/tests/reflection/traits/constructible.cpp +++ b/core/tests/reflection/traits/constructible.cpp @@ -29,11 +29,11 @@ TEST_CASE("reflection::ConstructibleTrait") SUBCASE("destructor works") { - auto ptr = operator new(sizeof(DetectDestructor)); + auto* ptr = operator new(sizeof(DetectDestructor)); auto trait = ConstructibleTrait::typed().build(); bool destroyed = false; - auto detector = new (ptr) DetectDestructor(&destroyed); + auto* detector = new (ptr) DetectDestructor(&destroyed); REQUIRE_FALSE(destroyed); trait.destruct(detector); @@ -44,7 +44,7 @@ TEST_CASE("reflection::ConstructibleTrait") SUBCASE("non-assigned constructors work as expected") { - auto ptr = operator new(sizeof(DetectDestructor)); + auto* ptr = operator new(sizeof(DetectDestructor)); auto trait = ConstructibleTrait::typed().build(); DetectDestructor detector{}; @@ -58,12 +58,12 @@ TEST_CASE("reflection::ConstructibleTrait") SUBCASE("default constructor works") { - auto ptr = operator new(sizeof(SimpleConstructible)); + auto* ptr = operator new(sizeof(SimpleConstructible)); auto trait = ConstructibleTrait::typed().withDefaultConstructor().build(); REQUIRE(trait.defaultConstruct(ptr)); - auto simple = static_cast(ptr); + auto* simple = static_cast(ptr); CHECK(simple->value == SimpleConstructible::DEFAULT); trait.destruct(ptr); @@ -72,14 +72,14 @@ TEST_CASE("reflection::ConstructibleTrait") SUBCASE("copy constructor works") { - auto ptr = operator new(sizeof(SimpleConstructible)); + auto* ptr = operator new(sizeof(SimpleConstructible)); auto trait = ConstructibleTrait::typed().withCopyConstructor().build(); SimpleConstructible copied{}; copied.value = 1; REQUIRE(trait.copyConstruct(ptr, &copied)); - auto simple = static_cast(ptr); + auto* simple = static_cast(ptr); CHECK(simple->value == copied.value); trait.destruct(ptr); @@ -88,7 +88,7 @@ TEST_CASE("reflection::ConstructibleTrait") SUBCASE("move constructor works") { - auto ptr = operator new(sizeof(DetectDestructor)); + auto* ptr = operator new(sizeof(DetectDestructor)); auto trait = ConstructibleTrait::typed().withMoveConstructor().build(); bool destroyed = false; diff --git a/core/tests/utils.hpp b/core/tests/utils.hpp index c6fd5fc71..df2e35882 100644 --- a/core/tests/utils.hpp +++ b/core/tests/utils.hpp @@ -22,6 +22,7 @@ /// Turns a list of argument types into a list of argument declarations. /// For example, DEFINE_MOCK_IMPL_DECL(int, float) becomes int _0, float _1. +// NOLINTBEGIN(readability-identifier-naming) #define MAKE_DECLARATIONS(...) __VA_OPT__(MAKE_DECLARATIONS_N(COUNT_ARGS(__VA_ARGS__), __VA_ARGS__)) #define MAKE_DECLARATIONS_N(n, ...) MAKE_DECLARATIONS_N_IMPL(n, __VA_ARGS__) #define MAKE_DECLARATIONS_N_IMPL(n, ...) MAKE_DECLARATIONS_##n(__VA_ARGS__) @@ -29,6 +30,7 @@ #define MAKE_DECLARATIONS_2(a, b) a _0, b _1 #define MAKE_DECLARATIONS_3(a, b, c) a _0, b _1, c _2 #define MAKE_DECLARATIONS_4(a, b, c, d) a _0, b _1, c _2, d _3 +// NOLINTEND(readability-identifier-naming) /// Turns a list of argument types into a list of argument names. /// For example, DEFINE_MOCK_IMPL_NAME(int, float) becomes _0, _1. diff --git a/engine/include/cubos/engine/collisions/colliders/box.hpp b/engine/include/cubos/engine/collisions/colliders/box.hpp index 1d84db964..24fce6a97 100644 --- a/engine/include/cubos/engine/collisions/colliders/box.hpp +++ b/engine/include/cubos/engine/collisions/colliders/box.hpp @@ -18,7 +18,7 @@ namespace cubos::engine /// @ingroup collisions-plugin struct [[cubos::component("cubos/box_collider", VecStorage)]] BoxCollider { - glm::mat4 transform{1.0f}; ///< Transform of the collider. + glm::mat4 transform{1.0F}; ///< Transform of the collider. cubos::core::geom::Box shape; ///< Box shape of the collider. /// @brief Margin of the collider. Needed for collision stability. @@ -26,6 +26,6 @@ namespace cubos::engine /// The collider margin avoids collision errors by rounding off sharp corners. It is /// absolute so the collider's transform won't affect it. Shouldn't be changed without good /// reason, as it's preferable to scale down the collider to account for it. - float margin = 0.04f; + float margin = 0.04F; }; } // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/colliders/capsule.hpp b/engine/include/cubos/engine/collisions/colliders/capsule.hpp index 65355f008..a8a696ab8 100644 --- a/engine/include/cubos/engine/collisions/colliders/capsule.hpp +++ b/engine/include/cubos/engine/collisions/colliders/capsule.hpp @@ -19,7 +19,7 @@ namespace cubos::engine /// @ingroup collisions-plugin struct [[cubos::component("cubos/capsule_collider", VecStorage)]] CapsuleCollider { - glm::mat4 transform{1.0f}; ///< Transform of the collider. + glm::mat4 transform{1.0F}; ///< Transform of the collider. cubos::core::geom::Capsule shape; ///< Capsule shape of the collider. }; } // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/colliders/plane.hpp b/engine/include/cubos/engine/collisions/colliders/plane.hpp index 6afaa0ee5..1f8377e28 100644 --- a/engine/include/cubos/engine/collisions/colliders/plane.hpp +++ b/engine/include/cubos/engine/collisions/colliders/plane.hpp @@ -16,13 +16,13 @@ namespace cubos::engine /// @ingroup collisions-plugin struct [[cubos::component("cubos/plane_collider", VecStorage)]] PlaneCollider { - glm::vec3 offset{0.0f}; ///< Offset of the collider. + glm::vec3 offset{0.0F}; ///< Offset of the collider. cubos::core::geom::Plane shape; ///< Plane shape of the collider. /// @brief Margin of the collider. Needed for creating the AABB. /// /// The collider margin is absolute so the collider's transform won't affect it. Shouldn't /// be changed without good reason. - float margin = 0.04f; + float margin = 0.04F; }; } // namespace cubos::engine diff --git a/engine/include/cubos/engine/collisions/colliders/simplex.hpp b/engine/include/cubos/engine/collisions/colliders/simplex.hpp index 617a726b0..022d1e3f8 100644 --- a/engine/include/cubos/engine/collisions/colliders/simplex.hpp +++ b/engine/include/cubos/engine/collisions/colliders/simplex.hpp @@ -20,7 +20,7 @@ namespace cubos::engine /// @ingroup collisions-plugin struct [[cubos::component("cubos/simplex", VecStorage)]] SimplexCollider { - glm::vec3 offset{0.0f}; ///< Offset of the collider. + glm::vec3 offset{0.0F}; ///< Offset of the collider. cubos::core::geom::Simplex shape; ///< Simplex shape of the collider. /// @brief Margin of the collider. Needed for collision stability. @@ -28,6 +28,6 @@ namespace cubos::engine /// The collider margin avoids collision errors by rounding off sharp corners. Shouldn't be /// changed without good reason, it's preferable to move the simplex corners to account for /// it. - float margin = 0.04f; + float margin = 0.04F; }; } // namespace cubos::engine diff --git a/engine/include/cubos/engine/input/action.hpp b/engine/include/cubos/engine/input/action.hpp index 590419c2c..0e27d56aa 100644 --- a/engine/include/cubos/engine/input/action.hpp +++ b/engine/include/cubos/engine/input/action.hpp @@ -29,8 +29,8 @@ namespace cubos::engine /// @param gamepadButtons Gamepad button bindings. InputAction(std::vector> keys, std::vector gamepadButtons) - : mKeys(keys) - , mGamepadButtons(gamepadButtons) + : mKeys(std::move(keys)) + , mGamepadButtons(std::move(gamepadButtons)) { } diff --git a/engine/include/cubos/engine/input/axis.hpp b/engine/include/cubos/engine/input/axis.hpp index 6889304c0..cf3ea0007 100644 --- a/engine/include/cubos/engine/input/axis.hpp +++ b/engine/include/cubos/engine/input/axis.hpp @@ -32,9 +32,9 @@ namespace cubos::engine InputAxis(std::vector> positive, std::vector> negative, std::vector gamepadAxes) - : mPositive(positive) - , mNegative(negative) - , mGamepadAxes(gamepadAxes) + : mPositive(std::move(positive)) + , mNegative(std::move(negative)) + , mGamepadAxes(std::move(gamepadAxes)) { } diff --git a/engine/include/cubos/engine/input/input.hpp b/engine/include/cubos/engine/input/input.hpp index 0800fa000..71db18da4 100644 --- a/engine/include/cubos/engine/input/input.hpp +++ b/engine/include/cubos/engine/input/input.hpp @@ -84,7 +84,7 @@ namespace cubos::engine /// /// @param window Window that received the event. /// @param event Event to discard. - inline void handle(const core::io::Window& window, const core::io::WindowEvent& event) + static void handle(const core::io::Window& window, const core::io::WindowEvent& event) { (void)window; (void)event; @@ -106,7 +106,8 @@ namespace cubos::engine bool negative = false; ///< Whether the pressed key is a negative axis key. }; - bool anyPressed(const core::io::Window& window, const std::vector>& keys) const; + static bool anyPressed(const core::io::Window& window, + const std::vector>& keys); bool anyPressed(int player, const std::vector& buttons) const; void handleActions(const core::io::Window& window, const std::vector& boundActions); void handleAxes(const core::io::Window& window, const std::vector& boundAxes); diff --git a/engine/samples/collisions/main.cpp b/engine/samples/collisions/main.cpp index 593cf6854..222b498be 100644 --- a/engine/samples/collisions/main.cpp +++ b/engine/samples/collisions/main.cpp @@ -44,7 +44,7 @@ static void init(Commands commands, Write input, Write cam { // Add procedural asset for detecting a reset action on a space key press. auto bindings = InputBindings{}; - bindings.actions()["reset"].keys().push_back({Key::Space, Modifiers::None}); + bindings.actions()["reset"].keys().emplace_back(Key::Space, Modifiers::None); input->bind(bindings); // Spawn the camera. @@ -109,7 +109,7 @@ static void updateCollided(Query> query, Write state, R { for (auto [entity, collider] : query) { - for (auto& [collider1, collider2] : collisions->candidates(BroadPhaseCollisions::CollisionType::BoxBox)) + for (const auto& [collider1, collider2] : collisions->candidates(BroadPhaseCollisions::CollisionType::BoxBox)) { if (collider1 == entity || collider2 == entity) { diff --git a/engine/samples/input/main.cpp b/engine/samples/input/main.cpp index bfdf270b5..a843ae05a 100644 --- a/engine/samples/input/main.cpp +++ b/engine/samples/input/main.cpp @@ -12,7 +12,7 @@ using cubos::core::io::Window; using namespace cubos::engine; -static const Asset bindingsAsset = AnyAsset("bf49ba61-5103-41bc-92e0-8a442d7842c3"); +static const Asset BindingsAsset = AnyAsset("bf49ba61-5103-41bc-92e0-8a442d7842c3"); struct State { @@ -122,7 +122,7 @@ static void showcaseAxis(const Input& input, bool& explained) explained = true; } - if (input.axis("horizontal") != 0.0f || input.axis("vertical") != 0.0f) + if (input.axis("horizontal") != 0.0F || input.axis("vertical") != 0.0F) { CUBOS_INFO("horizontal: {}, vertical: {}", input.axis("horizontal"), input.axis("vertical")); } @@ -138,7 +138,7 @@ static void showcaseModifierAxis(const Input& input, bool& explained) explained = true; } - if (input.axis("shift-vertical") != 0.0f) + if (input.axis("shift-vertical") != 0.0F) { CUBOS_INFO("shift-vertical: {}", input.axis("shift-vertical")); } @@ -204,7 +204,7 @@ static void config(Write settings) static void init(Read assets, Write input) { - auto bindings = assets->read(bindingsAsset); + auto bindings = assets->read(BindingsAsset); input->bind(*bindings); CUBOS_INFO("Loaded bindings: {}", Debug(input->bindings().at(0))); } diff --git a/engine/src/cubos/engine/collisions/broad_phase.cpp b/engine/src/cubos/engine/collisions/broad_phase.cpp index 71cd6411f..47a7a3990 100644 --- a/engine/src/cubos/engine/collisions/broad_phase.cpp +++ b/engine/src/cubos/engine/collisions/broad_phase.cpp @@ -19,7 +19,7 @@ void updateBoxAABBs(Query, Read, Write collisions) { if (marker.isMin) { - for (auto& other : collisions->activePerAxis[axis]) + for (const auto& other : collisions->activePerAxis[axis]) { collisions->sweepOverlapMaps[axis][marker.entity].push_back(other); } @@ -101,23 +101,50 @@ void sweep(Write collisions) CollisionType getCollisionType(bool box, bool capsule, bool plane, bool simplex) { if (box && capsule) + { return CollisionType::BoxCapsule; + } + if (box && plane) + { return CollisionType::BoxPlane; + } + if (box && simplex) + { return CollisionType::BoxSimplex; + } + if (box) + { return CollisionType::BoxBox; + } + if (capsule && plane) + { return CollisionType::CapsulePlane; + } + if (capsule && simplex) + { return CollisionType::CapsuleSimplex; + } + if (capsule) + { return CollisionType::CapsuleCapsule; + } + if (plane && simplex) + { return CollisionType::PlaneSimplex; + } + if (plane) + { return CollisionType::PlanePlane; + } + return CollisionType::SimplexSimplex; } @@ -145,15 +172,21 @@ void findPairs(Query, OptRead, OptReadoverlapsY(*otherAabb) && aabb->overlapsZ(*otherAabb)) + { collisions->addCandidate(type, {entity, other}); + } break; case 1: // Y if (aabb->overlapsX(*otherAabb) && aabb->overlapsZ(*otherAabb)) + { collisions->addCandidate(type, {entity, other}); + } break; case 2: // Z if (aabb->overlapsX(*otherAabb) && aabb->overlapsY(*otherAabb)) + { collisions->addCandidate(type, {entity, other}); + } break; } } diff --git a/engine/src/cubos/engine/collisions/broad_phase_collisions.cpp b/engine/src/cubos/engine/collisions/broad_phase_collisions.cpp index ef88dfac7..c7597de53 100644 --- a/engine/src/cubos/engine/collisions/broad_phase_collisions.cpp +++ b/engine/src/cubos/engine/collisions/broad_phase_collisions.cpp @@ -11,18 +11,17 @@ using SweepMarker = BroadPhaseCollisions::SweepMarker; void BroadPhaseCollisions::addEntity(Entity entity) { - for (std::size_t axis = 0; axis < 3; axis++) + for (auto& markers : markersPerAxis) { - markersPerAxis[axis].push_back({entity, true}); - markersPerAxis[axis].push_back({entity, false}); + markers.push_back({entity, true}); + markers.push_back({entity, false}); } } void BroadPhaseCollisions::removeEntity(Entity entity) { - for (std::size_t axis = 0; axis < 3; axis++) + for (auto& markers : markersPerAxis) { - auto& markers = markersPerAxis[axis]; markers.erase(std::remove_if(markers.begin(), markers.end(), [entity](const SweepMarker& m) { return m.entity == entity; }), markers.end()); @@ -31,9 +30,9 @@ void BroadPhaseCollisions::removeEntity(Entity entity) void BroadPhaseCollisions::clearEntities() { - for (std::size_t axis = 0; axis < 3; axis++) + for (auto& markers : markersPerAxis) { - markersPerAxis[axis].clear(); + markers.clear(); } } @@ -49,8 +48,8 @@ const std::unordered_set& BroadPhaseCollisions::candid void BroadPhaseCollisions::clearCandidates() { - for (std::size_t i = 0; i < static_cast(CollisionType::Count); i++) + for (auto& candidates : candidatesPerType) { - candidatesPerType[i].clear(); + candidates.clear(); } } diff --git a/engine/src/cubos/engine/input/axis.cpp b/engine/src/cubos/engine/input/axis.cpp index 8b38286c2..14b6d28a4 100644 --- a/engine/src/cubos/engine/input/axis.cpp +++ b/engine/src/cubos/engine/input/axis.cpp @@ -45,9 +45,9 @@ float InputAxis::value() const void InputAxis::value(float value) { - if (std::abs(value) > 1.0f) + if (std::abs(value) > 1.0F) { CUBOS_WARN("Axis value out of range: {}", value); } - mValue = std::clamp(value, -1.0f, 1.0f); + mValue = std::clamp(value, -1.0F, 1.0F); } diff --git a/engine/src/cubos/engine/input/bindings.cpp b/engine/src/cubos/engine/input/bindings.cpp index 6666ed03d..c01d85139 100644 --- a/engine/src/cubos/engine/input/bindings.cpp +++ b/engine/src/cubos/engine/input/bindings.cpp @@ -64,8 +64,8 @@ void cubos::core::data::deserialize(Deserializer& des, InputBindi { des.beginObject(); - std::size_t actions_sz = des.beginDictionary(); - for (std::size_t i = 0; i < actions_sz; ++i) + std::size_t actionsSz = des.beginDictionary(); + for (std::size_t i = 0; i < actionsSz; ++i) { std::string action; des.read(action); @@ -76,8 +76,8 @@ void cubos::core::data::deserialize(Deserializer& des, InputBindi } des.endDictionary(); - std::size_t axes_sz = des.beginDictionary(); - for (std::size_t i = 0; i < axes_sz; ++i) + std::size_t axesSz = des.beginDictionary(); + for (std::size_t i = 0; i < axesSz; ++i) { std::string axis; des.read(axis); diff --git a/engine/src/cubos/engine/input/input.cpp b/engine/src/cubos/engine/input/input.cpp index 8d6454416..eb4e8c660 100644 --- a/engine/src/cubos/engine/input/input.cpp +++ b/engine/src/cubos/engine/input/input.cpp @@ -142,22 +142,22 @@ float Input::axis(const char* axisName, int player) const if (pIt == mPlayerBindings.end()) { CUBOS_WARN("Player {} does not have any associated input bindings", player); - return 0.0f; + return 0.0F; } auto aIt = pIt->second.axes().find(axisName); if (aIt == pIt->second.axes().end()) { CUBOS_WARN("Axis {} is not bound to any input for player {}", axisName, player); - return 0.0f; + return 0.0F; } return aIt->second.value(); } -bool Input::anyPressed(const Window& window, const std::vector>& keys) const +bool Input::anyPressed(const Window& window, const std::vector>& keys) { - for (auto& key : keys) + for (const auto& key : keys) { // window->pressed() returns true when more modifiers than the specified are active, so we need to check that // the modifiers are exactly the same as the ones specified in the binding. @@ -177,9 +177,9 @@ bool Input::anyPressed(int player, const std::vector& buttons) co { return false; } - auto& state = mGamepadStates.at(it->second); + const auto& state = mGamepadStates.at(it->second); - for (auto& button : buttons) + for (const auto& button : buttons) { if (state.pressed(button)) { @@ -210,14 +210,14 @@ void Input::handleAxes(const Window& window, const std::vector& bo { auto& axis = mPlayerBindings[boundAxis.player].axes()[boundAxis.name]; - float value = 0.0f; + float value = 0.0F; if (anyPressed(window, axis.negative())) { - value -= 1.0f; + value -= 1.0F; } if (anyPressed(window, axis.positive())) { - value += 1.0f; + value += 1.0F; } if (auto it = mPlayerGamepads.find(boundAxis.player); it != mPlayerGamepads.end()) { @@ -241,7 +241,7 @@ void Input::handle(const Window& window, const KeyEvent& event) this->handleAxes(window, mBoundAxes[event.key]); } -void Input::handle(const Window&, const GamepadConnectionEvent& event) +void Input::handle(const Window& /*unused*/, const GamepadConnectionEvent& event) { if (event.connected) { @@ -259,11 +259,11 @@ void Input::handle(const Window&, const GamepadConnectionEvent& event) else { mGamepadStates.erase(event.gamepad); - for (auto it = mPlayerGamepads.begin(); it != mPlayerGamepads.end(); ++it) + for (const auto& playerGamepad : mPlayerGamepads) { - if (it->second == event.gamepad) + if (playerGamepad.second == event.gamepad) { - this->gamepad(it->first, -1); + this->gamepad(playerGamepad.first, -1); break; } } diff --git a/engine/src/cubos/engine/renderer/frame.cpp b/engine/src/cubos/engine/renderer/frame.cpp index ebd630743..a6678906b 100644 --- a/engine/src/cubos/engine/renderer/frame.cpp +++ b/engine/src/cubos/engine/renderer/frame.cpp @@ -4,7 +4,7 @@ using namespace cubos::engine; void RendererFrame::draw(RendererGrid grid, glm::mat4 modelMat) { - mDrawCmds.push_back(DrawCmd{grid, modelMat}); + mDrawCmds.push_back(DrawCmd{std::move(grid), modelMat}); } void RendererFrame::ambient(const glm::vec3& color) diff --git a/engine/src/cubos/engine/renderer/plugin.cpp b/engine/src/cubos/engine/renderer/plugin.cpp index 564e123dc..456b5bf70 100644 --- a/engine/src/cubos/engine/renderer/plugin.cpp +++ b/engine/src/cubos/engine/renderer/plugin.cpp @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include #include #include @@ -132,7 +132,7 @@ static void draw(Write renderer, Read activeCameras, Wr cubos::core::gl::Camera cameras[4]{}; int cameraCount = 0; - for (int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) // NOLINT(modernize-loop-convert) { if (activeCameras->entities[i].isNull()) { diff --git a/engine/src/cubos/engine/tools/asset_explorer/plugin.cpp b/engine/src/cubos/engine/tools/asset_explorer/plugin.cpp index 3a0139a56..c35cd783c 100644 --- a/engine/src/cubos/engine/tools/asset_explorer/plugin.cpp +++ b/engine/src/cubos/engine/tools/asset_explorer/plugin.cpp @@ -22,8 +22,8 @@ static bool assetsCompare(AnyAsset const& a, AnyAsset const& b, Assets const& as std::string aDir = aPath; std::string bDir = bPath; - aDir.erase(aDir.rfind("/")); - bDir.erase(bDir.rfind("/")); + aDir.erase(aDir.rfind('/')); + bDir.erase(bDir.rfind('/')); if (aCount != bCount) { @@ -31,7 +31,8 @@ static bool assetsCompare(AnyAsset const& a, AnyAsset const& b, Assets const& as { return true; } - else if (bDir.find(aDir + "/") != std::string::npos) + + if (bDir.find(aDir + "/") != std::string::npos) { return false; } @@ -44,7 +45,7 @@ static void showAsset(Assets const& assets, AnyAsset const& asset, EventWriterget("path").value(); ImGui::PushID(path.c_str()); - ImGui::BulletText("%s", path.erase(0, path.rfind("/") + 1).c_str()); + ImGui::BulletText("%s", path.erase(0, path.rfind('/') + 1).c_str()); ImGui::SameLine(); if (ImGui::Button("Select")) { @@ -59,7 +60,7 @@ static std::vector::iterator showFolder(Assets const& assets, std::str EventWriter events) { std::string displayName = folder; - displayName.erase(0, displayName.rfind("/")); + displayName.erase(0, displayName.rfind('/')); ImGui::PushStyleColor(ImGuiCol_Text, (ImVec4)ImColor(149, 252, 75)); if (ImGui::TreeNode(displayName.c_str())) @@ -111,7 +112,7 @@ static void showAssets(Read assets, Write settings, EventWrite std::string folder = settings->getString("assets.io.path", ""); - folder.erase(0, folder.rfind("/")); + folder.erase(0, folder.rfind('/')); std::vector assetsVector; for (auto const& a : assets->listAll()) diff --git a/engine/src/cubos/engine/tools/scene_editor/plugin.cpp b/engine/src/cubos/engine/tools/scene_editor/plugin.cpp index 09a419694..938fb08e9 100644 --- a/engine/src/cubos/engine/tools/scene_editor/plugin.cpp +++ b/engine/src/cubos/engine/tools/scene_editor/plugin.cpp @@ -48,9 +48,9 @@ static void closeScene(Commands& commands, SceneInfo& scene) scene.scenes.clear(); } -static void placeEntity(std::string name, Entity handle, SceneInfo& scene) +static void placeEntity(const std::string& name, Entity handle, SceneInfo& scene) { - auto split = name.find("."); + auto split = name.find('.'); if (split == std::string::npos) { scene.entities.emplace_back(name, handle); @@ -60,7 +60,7 @@ static void placeEntity(std::string name, Entity handle, SceneInfo& scene) auto subsceneName = name.substr(0, split - 1); for (auto& [sname, subscene] : scene.scenes) { - if (sname.compare(subsceneName) == 0) + if (sname == subsceneName) { placeEntity(name.substr(split + 1), handle, subscene); return; @@ -101,7 +101,9 @@ static void checkAssetEventSystem(cubos::core::ecs::EventReaderEventChar == '.') + { return 1; + } return 0; } @@ -130,7 +132,7 @@ static void showSceneEntities(std::vector>& entit ImGui::InputText("", &name, ImGuiInputTextFlags_CallbackCharFilter, entityNameFilter); - if (name.compare(buff)) + if (name != buff) { entities[i].first = buff; } @@ -197,7 +199,7 @@ static void showSceneHierarchy(SceneInfo& scene, Commands& cmds, cubos::engine:: ImGui::InputText("", &buff, ImGuiInputTextFlags_CallbackCharFilter, entityNameFilter); ImGui::PopID(); - if (scene.name.compare(buff)) + if (scene.name != buff) { scene.name = buff; } diff --git a/engine/tests/collisions/aabb.cpp b/engine/tests/collisions/aabb.cpp index b0251b016..a9f346a65 100644 --- a/engine/tests/collisions/aabb.cpp +++ b/engine/tests/collisions/aabb.cpp @@ -21,10 +21,10 @@ using namespace cubos::engine; static void setup(Commands commands) { - commands.create(BoxCollider{glm::mat4{1.0f}, Box{glm::vec3{1.0f}}}); - commands.create(CapsuleCollider{glm::mat4{1.0f}, Capsule{1.0f, 1.0f}}); - commands.create(SimplexCollider{glm::vec3{0.0f}, Simplex{{glm::vec3{1.0f}, glm::vec3{2.0f}, glm::vec3{3.0f}}}}); - commands.create(PlaneCollider{glm::vec3{0.0f}, Plane{glm::vec3{1.0f}}}); + commands.create(BoxCollider{glm::mat4{1.0F}, Box{glm::vec3{1.0F}}}); + commands.create(CapsuleCollider{glm::mat4{1.0F}, Capsule{1.0F, 1.0F}}); + commands.create(SimplexCollider{glm::vec3{0.0F}, Simplex{{glm::vec3{1.0F}, glm::vec3{2.0F}, glm::vec3{3.0F}}}}); + commands.create(PlaneCollider{glm::vec3{0.0F}, Plane{glm::vec3{1.0F}}}); } template @@ -41,14 +41,14 @@ TEST_CASE("collisions.aabb") auto cubos = Cubos{}; cubos.addPlugin(collisionsPlugin); - cubos.system(setup).beforeTag("cubos.collisions.aabb.missing"); + cubos.system(setup).before("cubos.collisions.aabb.missing"); SUBCASE("collisions.aabb.missing: missing aabbs were added") { - cubos.system(testAddMissingAABBs).afterTag("cubos.collisions.aabb.missing"); - cubos.system(testAddMissingAABBs).afterTag("cubos.collisions.aabb.missing"); - cubos.system(testAddMissingAABBs).afterTag("cubos.collisions.aabb.missing"); - cubos.system(testAddMissingAABBs).afterTag("cubos.collisions.aabb.missing"); + cubos.system(testAddMissingAABBs).after("cubos.collisions.aabb.missing"); + cubos.system(testAddMissingAABBs).after("cubos.collisions.aabb.missing"); + cubos.system(testAddMissingAABBs).after("cubos.collisions.aabb.missing"); + cubos.system(testAddMissingAABBs).after("cubos.collisions.aabb.missing"); } cubos.run(); diff --git a/tools/quadrados-gen/src/main.cpp b/tools/quadrados-gen/src/main.cpp index bd08cab24..6c67c0318 100644 --- a/tools/quadrados-gen/src/main.cpp +++ b/tools/quadrados-gen/src/main.cpp @@ -833,7 +833,7 @@ static bool generate(const GenerateOptions& options) else { file << " ser.beginObject(name);" << std::endl; - if (component.fields.size() == 0) + if (component.fields.empty()) { file << " (void)obj;" << std::endl; } @@ -858,7 +858,7 @@ static bool generate(const GenerateOptions& options) else { file << " des.beginObject();" << std::endl; - if (component.fields.size() == 0) + if (component.fields.empty()) { file << " (void)obj;" << std::endl; }