From 2a331011d5ad295288d0d4f44447fa60f593b9b6 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Fri, 22 Nov 2024 16:36:41 +0200 Subject: [PATCH] Changed order of includes, uint32_t as index for Geometry::GetIndex(), minor changes --- openVulkanoCpp/IO/Archive/ZipWriter.hpp | 6 +++--- openVulkanoCpp/Scene/Geometry.cpp | 8 ++------ openVulkanoCpp/Scene/Geometry.hpp | 2 +- openVulkanoCpp/Scene/MeshWriter.cpp | 15 +++------------ openVulkanoCpp/Scene/MeshWriter.hpp | 4 ++-- openVulkanoCpp/Scene/ObjEncoder.hpp | 3 ++- openVulkanoCpp/Scene/UsdEncoder.hpp | 4 ++-- tests/IO/Archive/ZipWriterTest.cpp | 8 ++++---- 8 files changed, 19 insertions(+), 31 deletions(-) diff --git a/openVulkanoCpp/IO/Archive/ZipWriter.hpp b/openVulkanoCpp/IO/Archive/ZipWriter.hpp index 722a9de..7b25be8 100644 --- a/openVulkanoCpp/IO/Archive/ZipWriter.hpp +++ b/openVulkanoCpp/IO/Archive/ZipWriter.hpp @@ -5,19 +5,19 @@ */ #pragma once +#include "IO/FileDescription.hpp" + #include #include #include -#include "IO/FileDescription.hpp" - namespace OpenVulkano { class ZipWriter { std::vector m_centralDirs; int m_numFiles = 0; - FILE *m_file; + FILE* m_file; public: ZipWriter(const std::filesystem::path& filePath); diff --git a/openVulkanoCpp/Scene/Geometry.cpp b/openVulkanoCpp/Scene/Geometry.cpp index 7a780f5..4fa4c9f 100644 --- a/openVulkanoCpp/Scene/Geometry.cpp +++ b/openVulkanoCpp/Scene/Geometry.cpp @@ -154,11 +154,11 @@ namespace OpenVulkano::Scene indices = nullptr; } - uint32_t Geometry::GetIndex(int index) const + uint32_t Geometry::GetIndex(uint32_t index) const { uint32_t result = 0; - if (index >= indexCount) + if (index >= indexCount) [[unlikely]] throw std::out_of_range("Index is out of range"); if (indexType == OpenVulkano::Scene::VertexIndexType::UINT16) @@ -171,10 +171,6 @@ namespace OpenVulkano::Scene uint32_t* indices = GetIndices32(); result = indices[index]; } - else - { - throw std::runtime_error("Invalid geometry index type"); - } return result; } diff --git a/openVulkanoCpp/Scene/Geometry.hpp b/openVulkanoCpp/Scene/Geometry.hpp index 8653a52..5522ac5 100644 --- a/openVulkanoCpp/Scene/Geometry.hpp +++ b/openVulkanoCpp/Scene/Geometry.hpp @@ -57,7 +57,7 @@ namespace OpenVulkano Vertex* GetVertices() const { return vertices; } void* GetIndices() const { return indices; } - uint32_t GetIndex(int index) const; + uint32_t GetIndex(uint32_t index) const; uint16_t* GetIndices16() const { return static_cast(indices); } uint32_t* GetIndices32() const { return static_cast(indices); } uint32_t GetIndexCount() const { return indexCount; } diff --git a/openVulkanoCpp/Scene/MeshWriter.cpp b/openVulkanoCpp/Scene/MeshWriter.cpp index afa03c0..28a7277 100644 --- a/openVulkanoCpp/Scene/MeshWriter.cpp +++ b/openVulkanoCpp/Scene/MeshWriter.cpp @@ -11,18 +11,9 @@ #include "Scene/ObjEncoder.hpp" #include "IO/Archive/ArchiveWriter.hpp" #include "IO/Archive/ZipWriter.hpp" + #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include namespace OpenVulkano::Scene { @@ -48,7 +39,7 @@ namespace OpenVulkano::Scene file.close(); } - void MeshWriter::WriteObjAsZip(Geometry* geometry, const std::string& zipPath, const std::string& texturePath) + void MeshWriter::WriteObjAsZip(Geometry* geometry, const std::string& texturePath, const std::string& zipPath) { OpenVulkano::ArchiveWriter zipWriter(zipPath.c_str()); @@ -68,7 +59,7 @@ namespace OpenVulkano::Scene } } - void MeshWriter::WriteAsUSDZ(Geometry* geometry, const std::string& usdzPath, const std::string& texturePath) + void MeshWriter::WriteAsUSDZ(Geometry* geometry, const std::string& texturePath, const std::string& usdzPath) { OpenVulkano::ZipWriter zipWriter(usdzPath); diff --git a/openVulkanoCpp/Scene/MeshWriter.hpp b/openVulkanoCpp/Scene/MeshWriter.hpp index 2c8176b..c484bee 100644 --- a/openVulkanoCpp/Scene/MeshWriter.hpp +++ b/openVulkanoCpp/Scene/MeshWriter.hpp @@ -16,7 +16,7 @@ namespace OpenVulkano::Scene public: static void WriteAsOBJ(Geometry* geometry, const std::string& filePath); static void WriteAsUSD(Geometry* geometry, const std::string& filePath); - static void WriteObjAsZip(Geometry* geometry, const std::string& zipPath, const std::string& texturePath); - static void WriteAsUSDZ(Geometry* geometry, const std::string& usdzPath, const std::string& texturePath); + static void WriteObjAsZip(Geometry* geometry, const std::string& texturePath, const std::string& zipPath); + static void WriteAsUSDZ(Geometry* geometry, const std::string& texturePath, const std::string& usdzPath); }; } \ No newline at end of file diff --git a/openVulkanoCpp/Scene/ObjEncoder.hpp b/openVulkanoCpp/Scene/ObjEncoder.hpp index 0b7b660..8bd6311 100644 --- a/openVulkanoCpp/Scene/ObjEncoder.hpp +++ b/openVulkanoCpp/Scene/ObjEncoder.hpp @@ -5,11 +5,12 @@ */ #pragma once +#include "Scene/Geometry.hpp" + #include #include #include #include -#include "Scene/Geometry.hpp" namespace OpenVulkano::Scene { diff --git a/openVulkanoCpp/Scene/UsdEncoder.hpp b/openVulkanoCpp/Scene/UsdEncoder.hpp index 6f7effc..429ceed 100644 --- a/openVulkanoCpp/Scene/UsdEncoder.hpp +++ b/openVulkanoCpp/Scene/UsdEncoder.hpp @@ -5,10 +5,10 @@ */ #pragma once -#include - #include "Scene/Geometry.hpp" +#include + namespace OpenVulkano::Scene { std::string GetUsdContents(OpenVulkano::Scene::Geometry* geometry, const std::string texturePath = "") diff --git a/tests/IO/Archive/ZipWriterTest.cpp b/tests/IO/Archive/ZipWriterTest.cpp index 9fa99e8..fffa270 100644 --- a/tests/IO/Archive/ZipWriterTest.cpp +++ b/tests/IO/Archive/ZipWriterTest.cpp @@ -6,14 +6,14 @@ #include -#include -#include -#include - #include "Base/Utils.hpp" #include "IO/Archive/ZipWriter.hpp" #include "IO/AppFolders.hpp" +#include +#include +#include + using namespace OpenVulkano; TEST_CASE("Empty zip file", "[ZipWriter]")