From 02448003dc0df52090c10fb1c5da56c47304f561 Mon Sep 17 00:00:00 2001 From: Ricardo Antunes Date: Tue, 24 Sep 2024 09:27:59 +0200 Subject: [PATCH] style: fix multiple clang-tidy errors --- core/include/cubos/core/memory/function.hpp | 12 +++-- .../cubos/core/reflection/type_client.hpp | 2 +- .../cubos/core/reflection/type_server.hpp | 2 +- core/src/al/oal_audio_device.cpp | 2 +- core/src/data/des/binary.cpp | 2 +- core/src/ecs/system/planner.cpp | 6 +-- core/src/ecs/system/schedule.cpp | 2 +- core/src/ecs/world.cpp | 2 +- core/src/gl/ogl_render_device.cpp | 36 +++++++-------- core/src/memory/any_vector.cpp | 5 ++- core/src/net/tcp_listener.cpp | 10 ++--- core/src/net/tcp_stream.cpp | 10 ++--- core/src/reflection/traits/mask.cpp | 12 ++--- core/src/reflection/type_client.cpp | 6 ++- .../type_client_server_defaults.cpp | 44 ++++++++++--------- core/src/reflection/type_server.cpp | 17 +++---- core/tests/ecs/cubos.cpp | 20 ++++----- core/tests/net/tcp.cpp | 3 +- core/tests/net/udp_socket.cpp | 3 +- core/tests/reflection/type_client_server.cpp | 3 +- .../cubos/engine/render/mesh/vertex.hpp | 2 +- .../include/cubos/engine/voxels/palette.hpp | 12 +++++ engine/src/imgui/imgui.cpp | 2 +- engine/src/imgui/imgui.hpp | 2 +- .../src/tesseratos/world_inspector/plugin.cpp | 10 ++--- 25 files changed, 125 insertions(+), 102 deletions(-) diff --git a/core/include/cubos/core/memory/function.hpp b/core/include/cubos/core/memory/function.hpp index 1243ac2a9..d95a645b9 100644 --- a/core/include/cubos/core/memory/function.hpp +++ b/core/include/cubos/core/memory/function.hpp @@ -160,7 +160,11 @@ namespace cubos::core::memory template static void* (*getCopier())(const void*) { - constexpr bool IsCopyable = requires(const F& f) { new F(f); }; + constexpr bool IsCopyable = requires(const F& f) + { + new F(f); + }; + if constexpr (IsCopyable) { return [](const void* function) -> void* { return new F(*static_cast(function)); }; @@ -172,9 +176,9 @@ namespace cubos::core::memory } void* mFunction{nullptr}; - I mInvoke; - void (*mFree)(void*); - void* (*mCopy)(const void*); + I mInvoke{}; + void (*mFree)(void*){}; + void* (*mCopy)(const void*){}; }; template diff --git a/core/include/cubos/core/reflection/type_client.hpp b/core/include/cubos/core/reflection/type_client.hpp index 1c29709fd..08b57d24a 100644 --- a/core/include/cubos/core/reflection/type_client.hpp +++ b/core/include/cubos/core/reflection/type_client.hpp @@ -51,7 +51,7 @@ namespace cubos::core::reflection using Deserialize = memory::Function; /// @brief Function type for discovering new types from a trait. - using DiscoverTypes = void (*)(const Type&, memory::Function); + using DiscoverTypes = void (*)(const Type&, memory::Function&); /// @brief Default constructor. TypeClient(); diff --git a/core/include/cubos/core/reflection/type_server.hpp b/core/include/cubos/core/reflection/type_server.hpp index cbde517c5..dfc064e9f 100644 --- a/core/include/cubos/core/reflection/type_server.hpp +++ b/core/include/cubos/core/reflection/type_server.hpp @@ -46,7 +46,7 @@ namespace cubos::core::reflection using Serialize = memory::Function; /// @brief Function type for discovering new types from a trait. - using DiscoverTypes = void (*)(const Type&, memory::Function); + using DiscoverTypes = void (*)(const Type&, memory::Function&); /// @brief Default constructs. TypeServer(); diff --git a/core/src/al/oal_audio_device.cpp b/core/src/al/oal_audio_device.cpp index 82072af01..e3890f3cb 100644 --- a/core/src/al/oal_audio_device.cpp +++ b/core/src/al/oal_audio_device.cpp @@ -156,7 +156,7 @@ OALAudioDevice::OALAudioDevice(const std::string& specifier) #endif // WITH_OPENAL } -OALAudioDevice::~OALAudioDevice() +OALAudioDevice::~OALAudioDevice() // NOLINT(modernize-use-equals-default) { #ifdef WITH_OPENAL auto* context = alcGetCurrentContext(); diff --git a/core/src/data/des/binary.cpp b/core/src/data/des/binary.cpp index 6950859a3..029a3b64c 100644 --- a/core/src/data/des/binary.cpp +++ b/core/src/data/des/binary.cpp @@ -158,7 +158,7 @@ bool BinaryDeserializer::decompose(const Type& type, void* value) return false; } - for (auto& bit : trait) + for (const auto& bit : trait) { bit.clear(value); } diff --git a/core/src/ecs/system/planner.cpp b/core/src/ecs/system/planner.cpp index 2611af3c0..1b29958b1 100644 --- a/core/src/ecs/system/planner.cpp +++ b/core/src/ecs/system/planner.cpp @@ -23,13 +23,13 @@ auto Planner::add() -> TagId auto Planner::add(std::string name) -> TagId { - mTags.push_back(TagData{.name = name}); + mTags.push_back(TagData{.name = memory::move(name)}); return {mTags.size() - 1}; } auto Planner::add(std::string name, SystemId systemId) -> TagId { - mTags.push_back(TagData{.name = name, .systemId = systemId}); + mTags.push_back(TagData{.name = memory::move(name), .systemId = systemId}); return {mTags.size() - 1}; } @@ -370,7 +370,7 @@ void Planner::makeSystemOrRepeatNode(TagId tagId, Schedule& schedule, const std: return; } - auto& tag = tags[tagId.inner]; + const auto& tag = tags[tagId.inner]; // Get the repeating node the new node will belong to. Opt repeatingNodeId{}; diff --git a/core/src/ecs/system/schedule.cpp b/core/src/ecs/system/schedule.cpp index 13abffbbe..a535271b4 100644 --- a/core/src/ecs/system/schedule.cpp +++ b/core/src/ecs/system/schedule.cpp @@ -120,7 +120,7 @@ bool Schedule::order(NodeId before, NodeId after) return true; } - if (this->ordered(after, before)) + if (this->ordered(after, before)) // NOLINT(readability-suspicious-call-argument) { // Would form a cycle. CUBOS_ERROR("Making node {} run before {} would form a cycle, as {} must already run before {}", before.inner, diff --git a/core/src/ecs/world.cpp b/core/src/ecs/world.cpp index d5736ef36..a388edced 100644 --- a/core/src/ecs/world.cpp +++ b/core/src/ecs/world.cpp @@ -1198,7 +1198,7 @@ void World::ConstRelations::Iterator::advance() for (; mTableIndex < tables.size(); ++mTableIndex) { mTableId = tables[mTableIndex]; - auto& table = registry.at(mTableId); + const auto& table = registry.at(mTableId); if (mRow >= table.size()) { diff --git a/core/src/gl/ogl_render_device.cpp b/core/src/gl/ogl_render_device.cpp index 564559feb..326632e58 100644 --- a/core/src/gl/ogl_render_device.cpp +++ b/core/src/gl/ogl_render_device.cpp @@ -467,7 +467,7 @@ class OGLFramebuffer : public impl::Framebuffer { public: OGLFramebuffer(std::shared_ptr destroyed, GLuint id) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) { } @@ -536,7 +536,7 @@ class OGLPixelPackBuffer : public impl::PixelPackBuffer { public: OGLPixelPackBuffer(std::shared_ptr destroyed, GLuint id) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) { } @@ -569,7 +569,7 @@ class OGLSampler : public impl::Sampler { public: OGLSampler(std::shared_ptr destroyed, GLuint id) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) { } @@ -591,7 +591,7 @@ class OGLTexture1D : public impl::Texture1D { public: OGLTexture1D(std::shared_ptr destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) , internalFormat(internalFormat) , format(format) @@ -632,7 +632,7 @@ class OGLTexture2D : public impl::Texture2D { public: OGLTexture2D(std::shared_ptr destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) , internalFormat(internalFormat) , format(format) @@ -689,7 +689,7 @@ class OGLTexture2DArray : public impl::Texture2DArray { public: OGLTexture2DArray(std::shared_ptr destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) , internalFormat(internalFormat) , format(format) @@ -732,7 +732,7 @@ class OGLTexture3D : public impl::Texture3D { public: OGLTexture3D(std::shared_ptr destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) , internalFormat(internalFormat) , format(format) @@ -775,7 +775,7 @@ class OGLCubeMap : public impl::CubeMap { public: OGLCubeMap(std::shared_ptr destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) , internalFormat(internalFormat) , format(format) @@ -820,7 +820,7 @@ class OGLCubeMapArray : public impl::CubeMapArray { public: OGLCubeMapArray(std::shared_ptr destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) , internalFormat(internalFormat) , format(format) @@ -863,7 +863,7 @@ class OGLConstantBuffer : public impl::ConstantBuffer { public: OGLConstantBuffer(std::shared_ptr destroyed, GLuint id) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) { } @@ -902,7 +902,7 @@ class OGLIndexBuffer : public impl::IndexBuffer { public: OGLIndexBuffer(std::shared_ptr destroyed, GLuint id, GLenum format, std::size_t indexSz) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) , format(format) , indexSz(indexSz) @@ -939,7 +939,7 @@ class OGLVertexBuffer : public impl::VertexBuffer { public: OGLVertexBuffer(std::shared_ptr destroyed, GLuint id) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) { } @@ -980,7 +980,7 @@ class OGLVertexArray : public impl::VertexArray { public: OGLVertexArray(std::shared_ptr destroyed, GLuint id, const VertexBuffer* buffers) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , id(id) { for (std::size_t i = 0; i < CUBOS_CORE_GL_MAX_VERTEX_ARRAY_BUFFER_COUNT; ++i) @@ -1007,7 +1007,7 @@ class OGLShaderStage : public impl::ShaderStage { public: OGLShaderStage(std::shared_ptr destroyed, Stage type, GLuint shader) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , type(type) , shader(shader) { @@ -1253,7 +1253,7 @@ class OGLShaderPipeline : public impl::ShaderPipeline { public: OGLShaderPipeline(std::shared_ptr destroyed, ShaderStage vs, ShaderStage ps, GLuint program) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , vs(std::move(vs)) , ps(std::move(ps)) , program(program) @@ -1264,13 +1264,13 @@ class OGLShaderPipeline : public impl::ShaderPipeline } OGLShaderPipeline(std::shared_ptr destroyed, ShaderStage vs, ShaderStage gs, ShaderStage ps, GLuint program) - : OGLShaderPipeline(destroyed, std::move(vs), std::move(ps), program) + : OGLShaderPipeline(std::move(destroyed), std::move(vs), std::move(ps), program) { this->gs = std::move(gs); } OGLShaderPipeline(std::shared_ptr destroyed, ShaderStage cs, GLuint program) - : destroyed(destroyed) + : destroyed(std::move(destroyed)) , cs(std::move(cs)) , program(program) { @@ -2215,7 +2215,7 @@ PixelPackBuffer OGLRenderDevice::createPixelPackBuffer(std::size_t size) GLuint id; glGenBuffers(1, &id); glBindBuffer(GL_PIXEL_PACK_BUFFER, id); - glBufferData(GL_PIXEL_PACK_BUFFER, static_cast(size), NULL, GL_STREAM_COPY); + glBufferData(GL_PIXEL_PACK_BUFFER, static_cast(size), nullptr, GL_STREAM_COPY); // Check errors GLenum glErr = glGetError(); diff --git a/core/src/memory/any_vector.cpp b/core/src/memory/any_vector.cpp index a9128e050..abd2025cd 100644 --- a/core/src/memory/any_vector.cpp +++ b/core/src/memory/any_vector.cpp @@ -65,8 +65,9 @@ void AnyVector::reserve(std::size_t capacity) } // Allocate a new buffer, move the values there and then free the old one. - void* data = operator new(capacity * mStride, static_cast(mConstructibleTrait->alignment()), - std::nothrow); + auto size = capacity * mStride; + auto alignment = static_cast(mConstructibleTrait->alignment()); + void* data = operator new(size, alignment, std::nothrow); CUBOS_ASSERT(data != nullptr, "Vector memory allocation failed"); for (std::size_t i = 0; i < mSize; ++i) { diff --git a/core/src/net/tcp_listener.cpp b/core/src/net/tcp_listener.cpp index 7b2b9f135..af72d2de8 100644 --- a/core/src/net/tcp_listener.cpp +++ b/core/src/net/tcp_listener.cpp @@ -23,7 +23,7 @@ using cubos::core::net::Address; using cubos::core::net::TcpListener; using cubos::core::net::TcpStream; -TcpListener::TcpListener() +TcpListener::TcpListener() // NOLINT(modernize-use-equals-default) { #ifdef _WIN32 WSADATA wsa; @@ -135,9 +135,7 @@ bool TcpListener::create() CUBOS_ERROR("Failed to create TCP socket, got error {}", logSystemError()); return false; } - else - { - this->setBlocking(mBlocking); - return true; - } + + this->setBlocking(mBlocking); + return true; } \ No newline at end of file diff --git a/core/src/net/tcp_stream.cpp b/core/src/net/tcp_stream.cpp index 5e84fadb9..ea44377fc 100644 --- a/core/src/net/tcp_stream.cpp +++ b/core/src/net/tcp_stream.cpp @@ -19,7 +19,7 @@ using cubos::core::net::Address; using cubos::core::net::TcpStream; -TcpStream::TcpStream() +TcpStream::TcpStream() // NOLINT(modernize-use-equals-default) { #ifdef _WIN32 WSADATA wsa; @@ -215,9 +215,7 @@ bool TcpStream::create() CUBOS_ERROR("Failed to create TCP socket, got error {}", logSystemError()); return false; } - else - { - this->setBlocking(mBlocking); - return true; - } + + this->setBlocking(mBlocking); + return true; } diff --git a/core/src/reflection/traits/mask.cpp b/core/src/reflection/traits/mask.cpp index 3aa740bf4..ee21fb69a 100644 --- a/core/src/reflection/traits/mask.cpp +++ b/core/src/reflection/traits/mask.cpp @@ -117,19 +117,19 @@ MaskTrait::Bit::Bit(std::string name, Tester tester, Setter setter, Clearer clea { } -bool MaskTrait::Bit::test(const void* instance) const +bool MaskTrait::Bit::test(const void* value) const { - return mTester(instance); + return mTester(value); } -void MaskTrait::Bit::set(void* instance) const +void MaskTrait::Bit::set(void* value) const { - mSetter(instance); + mSetter(value); } -void MaskTrait::Bit::clear(void* instance) const +void MaskTrait::Bit::clear(void* value) const { - mClearer(instance); + mClearer(value); } const std::string& MaskTrait::Bit::name() const diff --git a/core/src/reflection/type_client.cpp b/core/src/reflection/type_client.cpp index ef8e38da5..8a79cb29c 100644 --- a/core/src/reflection/type_client.cpp +++ b/core/src/reflection/type_client.cpp @@ -27,12 +27,13 @@ void TypeClient::addTrait(bool isStructural, const Type& traitType, Deserialize auto& trait = mTraits.at(traitType); // Re-discover types that are already known and have the new trait. + memory::Function addType = [this](const Type& type) { this->addType(type); }; auto oldKnownTypes = mKnownTypes; for (auto [type, _] : oldKnownTypes) { if (type->has(traitType)) { - trait.discoverTypes(*type, [this](const Type& type) { this->addType(type); }); + trait.discoverTypes(*type, addType); } } } @@ -52,11 +53,12 @@ void TypeClient::addType(const Type& type) mKnownTypes.insert(type); // Add types which can be discovered from the new type. + memory::Function addType = [this](const Type& type) { this->addType(type); }; for (const auto& [traitType, trait] : mTraits) { if (type.has(*traitType)) { - trait.discoverTypes(type, [this](const Type& type) { this->addType(type); }); + trait.discoverTypes(type, addType); } } } diff --git a/core/src/reflection/type_client_server_defaults.cpp b/core/src/reflection/type_client_server_defaults.cpp index d93555e40..0bba054e8 100644 --- a/core/src/reflection/type_client_server_defaults.cpp +++ b/core/src/reflection/type_client_server_defaults.cpp @@ -114,10 +114,10 @@ void cubos::core::reflection::setupTypeClientDefaults(TypeClient& client) return false; } - const auto& type = registry.at(typeName); - if (type.has() && type.get().hasDefaultConstruct()) + const auto& fieldType = registry.at(typeName); + if (fieldType.has() && fieldType.get().hasDefaultConstruct()) { - trait.addField(registry.at(typeName), fieldName, new FieldsTraitAddressOf(fieldName)); + trait.addField(fieldType, fieldName, new FieldsTraitAddressOf(fieldName)); } else { @@ -140,7 +140,7 @@ void cubos::core::reflection::setupTypeClientDefaults(TypeClient& client) return true; }, - [](const Type& type, memory::Function addType) { + [](const Type& type, memory::Function& addType) { for (const auto& field : type.get()) { addType(field.type()); @@ -207,7 +207,7 @@ void cubos::core::reflection::setupTypeClientDefaults(TypeClient& client) return true; }, - [](const Type& type, memory::Function addType) { + [](const Type& type, memory::Function& addType) { addType(type.get().elementType()); }); @@ -353,7 +353,7 @@ void cubos::core::reflection::setupTypeClientDefaults(TypeClient& client) return true; }, - [](const Type& type, memory::Function addType) { + [](const Type& type, memory::Function& addType) { addType(type.get().keyType()); addType(type.get().valueType()); }); @@ -381,7 +381,7 @@ void cubos::core::reflection::setupTypeClientDefaults(TypeClient& client) return true; }, - [](const Type&, memory::Function) {}); + [](const Type&, memory::Function&) {}); client.addTrait( /*isStructural=*/true, @@ -399,16 +399,20 @@ void cubos::core::reflection::setupTypeClientDefaults(TypeClient& client) for (uint64_t i = 0; i < static_cast(bits.size()); ++i) { trait.addBit( - bits[i], [i](const void* value) { return (*static_cast(value) & (1 << i)) != 0; }, - [i](void* value) { *static_cast(value) |= (1 << i); }, - [i](void* value) { *static_cast(value) &= ~(1 << i); }); + bits[i], + [i](const void* value) { + return (*static_cast(value) & (static_cast(1) << i)) != + static_cast(0); + }, + [i](void* value) { *static_cast(value) |= (static_cast(1) << i); }, + [i](void* value) { *static_cast(value) &= ~(static_cast(1) << i); }); } type.with(memory::move(trait)); type.with(TypeClient::RemoteTrait::createBasic()); return true; }, - [](const Type&, memory::Function) {}); + [](const Type&, memory::Function&) {}); client.addTrait( /*isStructural=*/true, @@ -424,7 +428,7 @@ void cubos::core::reflection::setupTypeClientDefaults(TypeClient& client) return true; }, - [](const Type&, memory::Function) {}); + [](const Type&, memory::Function&) {}); // Add non-structural traits. @@ -448,7 +452,7 @@ void cubos::core::reflection::setupTypeClientDefaults(TypeClient& client) return true; }, - [](const Type& type, memory::Function addType) { + [](const Type& type, memory::Function& addType) { addType(type.get().base()); }); } @@ -492,7 +496,7 @@ void cubos::core::reflection::setupTypeServerDefaults(TypeServer& server) return true; }, - [](const Type& type, memory::Function addType) { + [](const Type& type, memory::Function& addType) { for (const auto& field : type.get()) { addType(field.type()); @@ -501,7 +505,7 @@ void cubos::core::reflection::setupTypeServerDefaults(TypeServer& server) server.addTrait([](data::Serializer& ser, const Type& type, bool) { return ser.write(type.get().elementType().name()); }, - [](const Type& type, memory::Function addType) { + [](const Type& type, memory::Function& addType) { addType(type.get().elementType()); }); @@ -510,7 +514,7 @@ void cubos::core::reflection::setupTypeServerDefaults(TypeServer& server) const auto& trait = type.get(); return ser.write(trait.keyType().name()) && ser.write(trait.valueType().name()); }, - [](const Type& type, memory::Function addType) { + [](const Type& type, memory::Function& addType) { addType(type.get().keyType()); addType(type.get().valueType()); }); @@ -525,7 +529,7 @@ void cubos::core::reflection::setupTypeServerDefaults(TypeServer& server) } return ser.write(variants); }, - [](const Type&, memory::Function) {}); + [](const Type&, memory::Function&) {}); server.addTrait( [](data::Serializer& ser, const Type& type, bool) { @@ -537,10 +541,10 @@ void cubos::core::reflection::setupTypeServerDefaults(TypeServer& server) } return ser.write(bits); }, - [](const Type&, memory::Function) {}); + [](const Type&, memory::Function&) {}); server.addTrait([](data::Serializer&, const Type&, bool) { return true; }, - [](const Type&, memory::Function) {}); + [](const Type&, memory::Function&) {}); // Add non-structural traits. @@ -549,7 +553,7 @@ void cubos::core::reflection::setupTypeServerDefaults(TypeServer& server) const auto& trait = type.get(); return ser.write(trait.base().name()); }, - [](const Type& type, memory::Function addType) { + [](const Type& type, memory::Function& addType) { addType(type.get().base()); }); } diff --git a/core/src/reflection/type_server.cpp b/core/src/reflection/type_server.cpp index d35892b74..0325048aa 100644 --- a/core/src/reflection/type_server.cpp +++ b/core/src/reflection/type_server.cpp @@ -28,12 +28,13 @@ void TypeServer::addTrait(const Type& traitType, Serialize serialize, DiscoverTy const auto& trait = mTraits.at(traitType); // Re-discover types for all known types that have the new trait. + memory::Function recurse = [this](const Type& type) { this->addType(type); }; auto oldKnownTypes = mKnownTypes; for (auto [type, _] : oldKnownTypes) { if (type->has(traitType)) { - trait.discoverTypes(*type, [this](const Type& type) { this->addType(type); }); + trait.discoverTypes(*type, recurse); } } } @@ -49,11 +50,12 @@ void TypeServer::addType(const Type& type) mKnownTypes.insert(type); // Add types which can be discovered from the new type. + memory::Function recurse = [this](const Type& type) { this->addType(type); }; for (const auto& [traitType, trait] : mTraits) { if (type.has(*traitType)) { - trait.discoverTypes(type, [this](const Type& type) { this->addType(type); }); + trait.discoverTypes(type, recurse); } } @@ -190,10 +192,8 @@ Opt TypeServer::connect(memory::Stream& stream) CUBOS_TRACE("Skipping type {} as it is already known by the client", type->name()); continue; } - else - { - CUBOS_TRACE("Sharing type {}", type->name()); - } + + CUBOS_TRACE("Sharing type {}", type->name()); if (!ser.write(type->name())) { @@ -218,7 +218,7 @@ Opt TypeServer::connect(memory::Stream& stream) { auto& trait = mTraits.at(*structuralTraitType); - trait.discoverTypes(*type, [&](const Type& discoveredType) { + memory::Function findNonStructured = [&](const Type& discoveredType) { if (structuralTraitType != nullptr && !structuredTypes.contains(discoveredType)) { CUBOS_WARN("Type {} discovered from type {} through structural trait {} isn't structured, causing " @@ -226,7 +226,8 @@ Opt TypeServer::connect(memory::Stream& stream) discoveredType.name(), type->name(), structuralTraitType->name(), type->name()); structuralTraitType = nullptr; } - }); + }; + trait.discoverTypes(*type, findNonStructured); } // Count how many traits we'll be sending. diff --git a/core/tests/ecs/cubos.cpp b/core/tests/ecs/cubos.cpp index 94b20c035..288cee1dd 100644 --- a/core/tests/ecs/cubos.cpp +++ b/core/tests/ecs/cubos.cpp @@ -316,22 +316,22 @@ TEST_CASE("ecs::Cubos") { using cubos::core::reflection::reflect; - static constexpr auto removedPlugin = [](Cubos& cubos) { cubos.component(); }; - static constexpr auto dependencyPlugin = [](Cubos&) {}; - static constexpr auto subPlugin = [](Cubos& cubos) { cubos.component(); }; - static constexpr auto plugin = [](Cubos& cubos) { - cubos.depends(dependencyPlugin); - cubos.plugin(subPlugin); + static constexpr auto RemovedPlugin = [](Cubos& cubos) { cubos.component(); }; + static constexpr auto DependencyPlugin = [](Cubos&) {}; + static constexpr auto SubPlugin = [](Cubos& cubos) { cubos.component(); }; + static constexpr auto Plugin = [](Cubos& cubos) { + cubos.depends(DependencyPlugin); + cubos.plugin(SubPlugin); }; - cubos.plugin(removedPlugin); + cubos.plugin(RemovedPlugin); cubos.startupSystem("add plugins").call([](World& world, Plugins plugins, Commands cmds) { REQUIRE(world.types().contains(reflect())); REQUIRE_FALSE(world.types().contains(reflect())); - plugins.add(dependencyPlugin); - plugins.add(plugin); - plugins.remove(removedPlugin); + plugins.add(DependencyPlugin); + plugins.add(Plugin); + plugins.remove(RemovedPlugin); cmds.create().add(0); }); diff --git a/core/tests/net/tcp.cpp b/core/tests/net/tcp.cpp index 5f427a808..48c5361f9 100644 --- a/core/tests/net/tcp.cpp +++ b/core/tests/net/tcp.cpp @@ -22,7 +22,7 @@ TEST_CASE("net::Tcp*") uint16_t svPort = 8080; std::latch svLatch{1}; - std::jthread serverThread{[&svAddr, &svPort, &svLatch]() { + std::thread serverThread{[&svAddr, &svPort, &svLatch]() { TcpListener listener; REQUIRE(listener.listen(svAddr, svPort, 1)); REQUIRE(listener.valid()); @@ -62,6 +62,7 @@ TEST_CASE("net::Tcp*") stream.disconnect(); REQUIRE_FALSE(stream.valid()); + serverThread.join(); } SUBCASE("empty tcp stream") diff --git a/core/tests/net/udp_socket.cpp b/core/tests/net/udp_socket.cpp index b2375ecf4..ec2b2c9de 100644 --- a/core/tests/net/udp_socket.cpp +++ b/core/tests/net/udp_socket.cpp @@ -36,7 +36,8 @@ TEST_CASE("net::UdpSocket") SUBCASE("send and receive") { - UdpSocket socket1, socket2; + UdpSocket socket1; + UdpSocket socket2; REQUIRE(socket1.bind(8080)); REQUIRE(socket2.bind(8081)); diff --git a/core/tests/reflection/type_client_server.cpp b/core/tests/reflection/type_client_server.cpp index c50804644..e83859a8a 100644 --- a/core/tests/reflection/type_client_server.cpp +++ b/core/tests/reflection/type_client_server.cpp @@ -156,7 +156,7 @@ TEST_CASE("reflection::TypeClient & reflection::TypeServer") std::latch serverLatch{1}; std::latch clientLatch{1}; - std::jthread serverThread{[&]() { + std::thread serverThread{[&]() { TcpListener listener{}; REQUIRE(listener.listen(Address::LocalHost, 8888)); serverLatch.count_down(); // Notify client that server is ready. @@ -242,4 +242,5 @@ TEST_CASE("reflection::TypeClient & reflection::TypeServer") stream.disconnect(); clientLatch.count_down(); // Notify server that client is disconnected. + serverThread.join(); } diff --git a/engine/include/cubos/engine/render/mesh/vertex.hpp b/engine/include/cubos/engine/render/mesh/vertex.hpp index 4f73c2071..4a781569c 100644 --- a/engine/include/cubos/engine/render/mesh/vertex.hpp +++ b/engine/include/cubos/engine/render/mesh/vertex.hpp @@ -47,6 +47,6 @@ namespace cubos::engine /// @brief Generates a vertex mesh for the given voxel grid. /// @param grid Voxel grid. /// @param[out] vertices Vertices generated from the voxel grid. - static void generate(const VoxelGrid& grid, std::vector& facverticeses); + static void generate(const VoxelGrid& grid, std::vector& vertices); }; } // namespace cubos::engine diff --git a/engine/include/cubos/engine/voxels/palette.hpp b/engine/include/cubos/engine/voxels/palette.hpp index 1e63860f9..5c789b8bb 100644 --- a/engine/include/cubos/engine/voxels/palette.hpp +++ b/engine/include/cubos/engine/voxels/palette.hpp @@ -46,6 +46,18 @@ namespace cubos::engine /// @brief Constructs an empty palette. VoxelPalette() = default; + /// @brief Copy constructs. + VoxelPalette(const VoxelPalette&) = default; + + /// @brief Move constructs. + VoxelPalette(VoxelPalette&&) noexcept = default; + + /// @brief Copy assigns. + VoxelPalette& operator=(const VoxelPalette&) = default; + + /// @brief Move assigns. + VoxelPalette& operator=(VoxelPalette&&) noexcept = default; + /// @brief Gets a pointer to the array of materials on the palette. /// @note The first element in the array corresponds to index 1, as index 0 is reserved. /// @return Pointer to the array of materials on the palette. diff --git a/engine/src/imgui/imgui.cpp b/engine/src/imgui/imgui.cpp index c3b0c3c40..9b0e7a0aa 100644 --- a/engine/src/imgui/imgui.cpp +++ b/engine/src/imgui/imgui.cpp @@ -275,7 +275,7 @@ void main() bd->ibSize = 0; } -void cubos::engine::imguiInitialize(io::Window window, float dpiScale) +void cubos::engine::imguiInitialize(const io::Window& window, float dpiScale) { // Initialize ImGui IMGUI_CHECKVERSION(); diff --git a/engine/src/imgui/imgui.hpp b/engine/src/imgui/imgui.hpp index b8eb778fe..edea3d04f 100644 --- a/engine/src/imgui/imgui.hpp +++ b/engine/src/imgui/imgui.hpp @@ -14,7 +14,7 @@ namespace cubos::engine /// @param window The window to use. /// @param dpiScale Size factor by which to scale ImGui elements. /// @ingroup imgui-plugin - void imguiInitialize(core::io::Window window, float dpiScale); + void imguiInitialize(const core::io::Window& window, float dpiScale); /// @brief Shuts down ImGui. /// @note Should only be called once, after @ref initialize(), and no ImGui calls should be diff --git a/tools/tesseratos/src/tesseratos/world_inspector/plugin.cpp b/tools/tesseratos/src/tesseratos/world_inspector/plugin.cpp index 615ba2737..5e000e777 100644 --- a/tools/tesseratos/src/tesseratos/world_inspector/plugin.cpp +++ b/tools/tesseratos/src/tesseratos/world_inspector/plugin.cpp @@ -98,8 +98,8 @@ static void parse(World& world, const char* searchBuffer, Query