diff --git a/examples/ExampleApps/TextExampleApp.cpp b/examples/ExampleApps/TextExampleApp.cpp index ddbaebb..bc363b0 100644 --- a/examples/ExampleApps/TextExampleApp.cpp +++ b/examples/ExampleApps/TextExampleApp.cpp @@ -81,7 +81,7 @@ namespace OpenVulkano for (int i = 0, xOffset = -5; i < atlasesCount; i++, xOffset += 20) { float totalH = 0; - for (int j = 0; j < texts.size(); j++) + for (size_t j = 0; j < texts.size(); j++) { TextDrawable* t = nullptr; #if defined(MSDFGEN_AVAILABLE) && defined(CREATE_NEW_ATLAS) diff --git a/examples/main.cpp b/examples/main.cpp index 263c96f..b5640c7 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -42,7 +42,7 @@ int main(int argc, char** argv) if (shouldExit) return 0; - if (selectedExample >= examples.size()) + if (static_cast(selectedExample) >= examples.size()) { throw std::runtime_error("Invalid menu selection!"); } diff --git a/openVulkanoCpp/Data/Containers/StableVector.hpp b/openVulkanoCpp/Data/Containers/StableVector.hpp index 0685f32..38f8f9b 100644 --- a/openVulkanoCpp/Data/Containers/StableVector.hpp +++ b/openVulkanoCpp/Data/Containers/StableVector.hpp @@ -178,11 +178,11 @@ namespace OpenVulkano } } - std::streamsize GetIteratorIndex() const { return m_chunk->GetRealIndex(m_index); } + size_t GetIteratorIndex() const { return m_chunk->GetRealIndex(m_index); } private: VectorChunk* m_chunk; - std::streamsize m_index; + size_t m_index; }; public: @@ -266,15 +266,6 @@ namespace OpenVulkano return; // return? or make } - if (m_lastChunk->m_nextIndex == -1) - { - VectorChunk* temp = m_lastChunk; - m_lastChunk = m_lastChunk->m_prev; - m_lastChunk->m_next = nullptr; - temp->~VectorChunk(); - ::operator delete(temp); - } - m_lastChunk->m_data[m_lastChunk->m_nextIndex - 1].~T(); m_lastChunk->m_occupiedIndices[m_lastChunk->m_nextIndex - 1] = false; m_lastChunk->m_size--; @@ -378,10 +369,24 @@ namespace OpenVulkano bool Empty() const noexcept { return m_size == 0; } RegIterator begin() { return RegIterator(m_firstChunk, 0); } - RegIterator end() { return RegIterator(m_lastChunk, m_lastChunk->m_nextIndex - 1); } + RegIterator end() + { + if (Empty()) [[unlikely]] + { + return begin(); + } + return RegIterator(m_lastChunk, m_lastChunk->m_nextIndex - 1); + } ConstIterator cbegin() const { return ConstIterator(m_firstChunk, 0); } - ConstIterator cend() const { return ConstIterator(m_lastChunk, m_lastChunk->m_nextIndex - 1); } + ConstIterator cend() const + { + if (Empty()) [[unlikely]] + { + return cbegin(); + } + return ConstIterator(m_lastChunk, m_lastChunk->m_nextIndex - 1); + } //region std aliases void push_back(const T& value) { PushBack(value); } diff --git a/openVulkanoCpp/Image/ImageLoaderPfm.cpp b/openVulkanoCpp/Image/ImageLoaderPfm.cpp index 8c4931b..9ae1e2e 100644 --- a/openVulkanoCpp/Image/ImageLoaderPfm.cpp +++ b/openVulkanoCpp/Image/ImageLoaderPfm.cpp @@ -61,9 +61,8 @@ namespace OpenVulkano::Image PfmImageHeader header = ParseHeader(stream); size_t numChannels = header.isColor ? 3 : 1; - size_t dataSize = header.width * header.height * numChannels * sizeof(float); Array data(header.width * header.height * numChannels); - size_t rowSize = header.width * numChannels * sizeof(float); + size_t rowSize = header.width * numChannels * sizeof(float); for (int y = header.height - 1; y >= 0; --y) { diff --git a/openVulkanoCpp/Image/YuvUtils.hpp b/openVulkanoCpp/Image/YuvUtils.hpp index 9dd1aca..fd40985 100644 --- a/openVulkanoCpp/Image/YuvUtils.hpp +++ b/openVulkanoCpp/Image/YuvUtils.hpp @@ -27,7 +27,7 @@ namespace OpenVulkano uint8_t* dest2 = dest + chromaChannelWidth * chromaChannelHeight; for (uint32_t row = 0; row < chromaChannelHeight; row++) { - for (int col = 0; col < chromaChannelWidth; col++, dest++, dest2++, src += 2) + for (uint32_t col = 0; col < chromaChannelWidth; col++, dest++, dest2++, src += 2) { *dest = src[0]; *dest2 = src[1]; diff --git a/openVulkanoCpp/Input/InputDeviceKeyboard.hpp b/openVulkanoCpp/Input/InputDeviceKeyboard.hpp index 4e55752..13f0051 100644 --- a/openVulkanoCpp/Input/InputDeviceKeyboard.hpp +++ b/openVulkanoCpp/Input/InputDeviceKeyboard.hpp @@ -67,7 +67,7 @@ namespace OpenVulkano public: [[nodiscard]] bool GetButton(const InputKey::Keyboard::Key button) const { - return keyState[button] > 0; + return keyState[button]; } [[nodiscard]] bool GetButtonUp(const InputKey::Keyboard::Key button) const diff --git a/openVulkanoCpp/Math/RGB10A2.hpp b/openVulkanoCpp/Math/RGB10A2.hpp index 27dd1bc..fad4e7d 100644 --- a/openVulkanoCpp/Math/RGB10A2.hpp +++ b/openVulkanoCpp/Math/RGB10A2.hpp @@ -51,7 +51,7 @@ namespace OpenVulkano::Math template>> void Set(Vector4 vec4) { - vec4 &= VALUE_BITMASK; + static_cast(vec4 &= VALUE_BITMASK); SetUnchecked(vec4); } #pragma GCC diagnostic pop diff --git a/openVulkanoCpp/Scene/Export/MeshWriter.cpp b/openVulkanoCpp/Scene/Export/MeshWriter.cpp index d7c0601..d42ce03 100644 --- a/openVulkanoCpp/Scene/Export/MeshWriter.cpp +++ b/openVulkanoCpp/Scene/Export/MeshWriter.cpp @@ -63,7 +63,7 @@ namespace mesh.mTextureCoords[0] = new aiVector3D[geometry->vertexCount]; } - for (int i = 0; i < geometry->vertexCount; ++i) + for (uint32_t i = 0; i < geometry->vertexCount; ++i) { const OpenVulkano::Vertex& vertex = geometry->vertices[i]; mesh.mVertices[i] = aiVector3D(vertex.position.x, vertex.position.y, vertex.position.z) * scaling; @@ -78,7 +78,7 @@ namespace mesh.mFaces = new aiFace[mesh.mNumFaces]; indices = std::make_unique(geometry->indexCount); - for (unsigned int i = 0; i < geometry->indexCount; ++i) + for (uint32_t i = 0; i < geometry->indexCount; ++i) { indices[i] = geometry->GetIndex(i); } diff --git a/openVulkanoCpp/Scene/Export/ObjEncoder.hpp b/openVulkanoCpp/Scene/Export/ObjEncoder.hpp index 5118ad3..c9f16d2 100644 --- a/openVulkanoCpp/Scene/Export/ObjEncoder.hpp +++ b/openVulkanoCpp/Scene/Export/ObjEncoder.hpp @@ -38,25 +38,25 @@ map_Kd texture.png objContent.write("\n", 1); } - for (int i = 0; i < geometry->vertexCount; ++i) + for (uint32_t i = 0; i < geometry->vertexCount; ++i) { const auto& v = geometry->vertices[i]; const std::string content = fmt::format("v {} {} {}\n", v.position.x, v.position.y, v.position.z); objContent.write(content.data(), content.size()); } - for (int i = 0; i < geometry->vertexCount; ++i) + for (uint32_t i = 0; i < geometry->vertexCount; ++i) { const auto& v = geometry->vertices[i]; const std::string content = fmt::format("vn {} {} {}\n", v.normal.x, v.normal.y, v.normal.z); objContent.write(content.data(), content.size()); } - for (int i = 0; i < geometry->vertexCount; ++i) + for (uint32_t i = 0; i < geometry->vertexCount; ++i) { const auto& v = geometry->vertices[i]; const std::string content = fmt::format("vt {} {}\n", v.textureCoordinates.x, v.textureCoordinates.y); objContent.write(content.data(), content.size()); } - for (int i = 0; i < geometry->indexCount; i += 3) + for (uint32_t i = 0; i < geometry->indexCount; i += 3) { uint32_t i0 = geometry->GetIndex(i + 0) + 1; uint32_t i1 = geometry->GetIndex(i + 1) + 1; diff --git a/openVulkanoCpp/Scene/Geometry.cpp b/openVulkanoCpp/Scene/Geometry.cpp index cfd5414..a1a6d53 100644 --- a/openVulkanoCpp/Scene/Geometry.cpp +++ b/openVulkanoCpp/Scene/Geometry.cpp @@ -89,7 +89,7 @@ namespace OpenVulkano::Scene { return; } - for (int i = 0; i < vertexCount; i++) + for (uint32_t i = 0; i < vertexCount; i++) { aabb.Grow(vertices[i].position); } diff --git a/openVulkanoCpp/Scene/GeometryFactory.cpp b/openVulkanoCpp/Scene/GeometryFactory.cpp index 137e97f..a9a6f97 100644 --- a/openVulkanoCpp/Scene/GeometryFactory.cpp +++ b/openVulkanoCpp/Scene/GeometryFactory.cpp @@ -308,16 +308,16 @@ namespace OpenVulkano::Scene return result; } - Geometry GeometryFactory::MakeArchStrip(float radius, float width, float endRadius, int segments, const Math::Vector4f& color, float endVCoord, bool indexBuffer) + Geometry GeometryFactory::MakeArchStrip(float radius, float width, float endRadius, uint32_t segments, const Math::Vector4f& color, float endVCoord, bool indexBuffer) { Geometry result; - segments = std::max(2, segments); + segments = std::max(2u, segments); result.Init(2 * segments, indexBuffer ? 6 * segments : 0); const float segmentAngle = endRadius / static_cast(segments - 1); width /= 2; const float segmentV = endVCoord / (segments - 1); float segV = 0; - for(int i = 0, seg = 0; seg < segments; seg++) + for(uint32_t i = 0, seg = 0; seg < segments; seg++) { float angle = seg * segmentAngle; float z = std::cos(angle) * radius; diff --git a/openVulkanoCpp/Scene/GeometryFactory.hpp b/openVulkanoCpp/Scene/GeometryFactory.hpp index 45e383d..972bdac 100644 --- a/openVulkanoCpp/Scene/GeometryFactory.hpp +++ b/openVulkanoCpp/Scene/GeometryFactory.hpp @@ -20,6 +20,6 @@ namespace OpenVulkano::Scene static Geometry MakeTriangle(const Math::Vector3f& p1, const Math::Vector3f& p2, const Math::Vector3f& p3, const Math::Vector4f& color = Math::Vector4f(1)); static Geometry MakeCylinder(float radius, float height, uint32_t segments, const Math::Vector4f& color = Math::Vector4f(1)); static Geometry MakePyramid(float baseLength = 1, float height = 1, const Math::Vector4f& color = Math::Vector4f(1)); - static Geometry MakeArchStrip(float radius = 1, float width = 0.2, float endRadius = std::numbers::pi, int segments = 16, const Math::Vector4f& color = Math::Vector4f(1), float endVCoord = 1, bool indexBuffer = true); + static Geometry MakeArchStrip(float radius = 1, float width = 0.2, float endRadius = std::numbers::pi, uint32_t segments = 16, const Math::Vector4f& color = Math::Vector4f(1), float endVCoord = 1, bool indexBuffer = true); }; } diff --git a/openVulkanoCpp/Scene/Prefabs/LabelDrawable.cpp b/openVulkanoCpp/Scene/Prefabs/LabelDrawable.cpp index eeb5201..c7987a7 100644 --- a/openVulkanoCpp/Scene/Prefabs/LabelDrawable.cpp +++ b/openVulkanoCpp/Scene/Prefabs/LabelDrawable.cpp @@ -65,7 +65,7 @@ namespace OpenVulkano::Scene Shader* GetTextShader(const FontAtlasType type, const bool billboard) { - return &TEXT_SHADERS[static_cast(type) << 1 | billboard]; + return &TEXT_SHADERS[(static_cast(type) << 1) + billboard]; } } diff --git a/openVulkanoCpp/Scene/SimpleDrawable.cpp b/openVulkanoCpp/Scene/SimpleDrawable.cpp index 2d8aa99..68fe4cc 100644 --- a/openVulkanoCpp/Scene/SimpleDrawable.cpp +++ b/openVulkanoCpp/Scene/SimpleDrawable.cpp @@ -52,7 +52,7 @@ namespace OpenVulkano::Scene if (m_mesh->indexCount != 0) { assert(m_mesh->indexCount % 3 == 0 && "Topology is TRIANGLE_LIST but index count is not divisible by 3"); - for (int i = 0; i < m_mesh->indexCount; i += 3) + for (uint32_t i = 0; i < m_mesh->indexCount; i += 3) { if (m_mesh->indexType == VertexIndexType::UINT16) { @@ -79,7 +79,7 @@ namespace OpenVulkano::Scene else { assert(m_mesh->indexCount % 3 == 0 && "Topology is TRIANGLE_LIST but vertex count is not divisible by 3"); - for (int i = 0; i < m_mesh->vertexCount; i += 3) + for (uint32_t i = 0; i < m_mesh->vertexCount; i += 3) { if (auto hit = ray.IntersectTriangle(m_mesh->vertices[i].position, m_mesh->vertices[i + 1].position, diff --git a/openVulkanoCpp/Scene/Text/BitmapFontAtlasGenerator.cpp b/openVulkanoCpp/Scene/Text/BitmapFontAtlasGenerator.cpp index 94842aa..bf1daae 100644 --- a/openVulkanoCpp/Scene/Text/BitmapFontAtlasGenerator.cpp +++ b/openVulkanoCpp/Scene/Text/BitmapFontAtlasGenerator.cpp @@ -148,7 +148,7 @@ namespace OpenVulkano::Scene { char* baseAddress = static_cast(m_atlasData->GetTexture()->textureBuffer) + glyph.firstGlyphByteInAtlas; - for (int row = 0; row < slot->bitmap.rows; row++) + for (unsigned int row = 0; row < slot->bitmap.rows; row++) { std::memcpy(baseAddress - row * m_atlasData->GetTexture()->resolution.x, &slot->bitmap.buffer[row * slot->bitmap.pitch], slot->bitmap.width); @@ -181,9 +181,9 @@ namespace OpenVulkano::Scene { // RGB RGB RGB assert(bitmap.width % 3 == 0); - for (int row = 0; row < bitmap.rows; row++) + for (unsigned int row = 0; row < bitmap.rows; row++) { - for (int col = 0, atlasPos = 0; col < bitmap.width; col += 3, atlasPos += 4) + for (unsigned int col = 0, atlasPos = 0; col < bitmap.width; col += 3, atlasPos += 4) { const size_t bitmapPos = row * bitmap.pitch + col; const size_t texturePos = (glyph.firstGlyphByteInAtlas - row * tex->resolution.x * m_channelsCount) + atlasPos; @@ -200,9 +200,9 @@ namespace OpenVulkano::Scene // GGG // BBB assert(bitmap.rows % 3 == 0); - for (int row = 0; row < bitmap.rows; row += 3) + for (unsigned int row = 0; row < bitmap.rows; row += 3) { - for (int col = 0; col < bitmap.width; col++) + for (unsigned int col = 0; col < bitmap.width; col++) { const size_t bitmapPos = col + (bitmap.pitch * row); const size_t texturePos = (glyph.firstGlyphByteInAtlas + col * m_channelsCount) diff --git a/openVulkanoCpp/Scene/Text/SdfFontAtlasGenerator.cpp b/openVulkanoCpp/Scene/Text/SdfFontAtlasGenerator.cpp index de76dd2..77884f5 100644 --- a/openVulkanoCpp/Scene/Text/SdfFontAtlasGenerator.cpp +++ b/openVulkanoCpp/Scene/Text/SdfFontAtlasGenerator.cpp @@ -124,7 +124,7 @@ namespace OpenVulkano::Scene // store RGB as RGBA const msdfgen::BitmapConstRef storage = generator.atlasStorage(); msdfgen::byte* data = static_cast(m_atlasData->GetTexture()->textureBuffer); - for (size_t srcPos = 0, dstPos = 0; srcPos < width * height * 3; srcPos += 3, dstPos += 4) + for (size_t srcPos = 0, dstPos = 0; srcPos < static_cast(width * height * 3); srcPos += 3, dstPos += 4) { data[dstPos] = storage.pixels[srcPos]; data[dstPos + 1] = storage.pixels[srcPos + 1]; diff --git a/openVulkanoCpp/Scene/UI/PerformanceInfo.cpp b/openVulkanoCpp/Scene/UI/PerformanceInfo.cpp index 10e1399..13c7c82 100644 --- a/openVulkanoCpp/Scene/UI/PerformanceInfo.cpp +++ b/openVulkanoCpp/Scene/UI/PerformanceInfo.cpp @@ -35,7 +35,7 @@ namespace OpenVulkano::Scene::UI m_frames.m_values.push_back(newFrameTime); - while(m_frames.m_values.size() > m_windowSize) + while(static_cast(m_frames.m_values.size()) > m_windowSize) { float poppedFrameTime = m_frames.m_values.front(); m_frames.m_values.pop_front(); @@ -51,7 +51,7 @@ namespace OpenVulkano::Scene::UI } m_ramUsed.m_values.push_back(static_cast(SystemInfo::GetAppRamUsed())); - while(m_ramUsed.m_values.size() > m_windowSize) + while(static_cast(m_ramUsed.m_values.size()) > m_windowSize) m_ramUsed.m_values.pop_front(); m_ramUsed.m_maxValue = SystemInfo::GetAppRamMax(); diff --git a/openVulkanoCpp/Vulkan/Device.cpp b/openVulkanoCpp/Vulkan/Device.cpp index 76d22d4..102a3b0 100644 --- a/openVulkanoCpp/Vulkan/Device.cpp +++ b/openVulkanoCpp/Vulkan/Device.cpp @@ -23,7 +23,7 @@ namespace OpenVulkano::Vulkan void AddQueueFamily(const uint32_t queueFamilyIndex, const std::vector& priorities) { prioritiesVector.push_back(priorities); - createInfos.emplace_back(vk::DeviceQueueCreateFlags(), queueFamilyIndex, priorities.size(), prioritiesVector[prioritiesVector.size()-1].data()); + createInfos.emplace_back(vk::DeviceQueueCreateFlags(), queueFamilyIndex, static_cast(priorities.size()), prioritiesVector[prioritiesVector.size()-1].data()); } void AddQueueFamily(uint32_t queueFamilyIndex, uint32_t count = 1) diff --git a/openVulkanoCpp/Vulkan/RenderPass.cpp b/openVulkanoCpp/Vulkan/RenderPass.cpp index 979ed5f..a055706 100644 --- a/openVulkanoCpp/Vulkan/RenderPass.cpp +++ b/openVulkanoCpp/Vulkan/RenderPass.cpp @@ -67,7 +67,7 @@ namespace OpenVulkano::Vulkan std::vector subPasses; subPasses.emplace_back(vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 0, nullptr, - colorAttachmentReferences.size(), colorAttachmentReferences.data(), nullptr, depthReference, 0, nullptr); + static_cast(colorAttachmentReferences.size()), colorAttachmentReferences.data(), nullptr, depthReference, 0, nullptr); std::vector subPassDependencies; subPassDependencies.emplace_back(0, VK_SUBPASS_EXTERNAL, vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eBottomOfPipe, vk::AccessFlagBits::eColorAttachmentRead | vk::AccessFlagBits::eColorAttachmentWrite, diff --git a/openVulkanoCpp/Vulkan/Renderer.cpp b/openVulkanoCpp/Vulkan/Renderer.cpp index 4aa56f1..d80435a 100644 --- a/openVulkanoCpp/Vulkan/Renderer.cpp +++ b/openVulkanoCpp/Vulkan/Renderer.cpp @@ -34,7 +34,7 @@ namespace OpenVulkano::Vulkan throw std::runtime_error("The provided window is not compatible with Vulkan."); } context.Init(graphicsAppManager, vulkanWindow); - for (int i = 0; i < context.swapChain.GetImageCount(); i++) + for (uint32_t i = 0; i < context.swapChain.GetImageCount(); i++) { waitSemaphores.emplace_back(); vk::Semaphore sema = context.device->device.createSemaphore({}); diff --git a/tests/Data/Containers/ArrayTest.cpp b/tests/Data/Containers/ArrayTest.cpp index 1388a7a..1c14931 100644 --- a/tests/Data/Containers/ArrayTest.cpp +++ b/tests/Data/Containers/ArrayTest.cpp @@ -245,7 +245,7 @@ TEST_CASE("Iterator constructor", "[Array]") char data[] = "Hello world"; Array arr(data, data + sizeof(data)); REQUIRE(arr.Data() != data); - for (int i = 0; i < sizeof(data); i++) + for (size_t i = 0; i < sizeof(data); i++) { REQUIRE(data[i] == arr[i]); } @@ -254,7 +254,7 @@ TEST_CASE("Iterator constructor", "[Array]") { Array arr = { 1, 2, 3, 4, 5 }; Array arr2(arr.begin(), arr.end()); - for (int i = 0; i < arr.Size(); i++) + for (size_t i = 0; i < arr.Size(); i++) { REQUIRE(arr[i] == arr2[i]); } diff --git a/tests/Data/Containers/StableVectorTest.cpp b/tests/Data/Containers/StableVectorTest.cpp index d0efb35..edef5a8 100644 --- a/tests/Data/Containers/StableVectorTest.cpp +++ b/tests/Data/Containers/StableVectorTest.cpp @@ -101,6 +101,12 @@ TEST_CASE("ChunkVector") REQUIRE(vec.Capacity() == tempVal); } + SECTION("Iterators with empty vector") + { + StableVector vec; + REQUIRE(vec.begin() == vec.end()); + } + SECTION("Clear") { StableVector vec; diff --git a/tests/Scene/RayTest.cpp b/tests/Scene/RayTest.cpp index 73a6eca..f26f5aa 100644 --- a/tests/Scene/RayTest.cpp +++ b/tests/Scene/RayTest.cpp @@ -42,7 +42,6 @@ TEST_CASE("RaySphereIntersection") // this returns just closest point if (auto opt = ray.IntersectSphere(Vector3f(0), 1)) { - opt->GetDistance(); REQUIRE(opt.value() == h1); } }