diff --git a/src/fastgltf.cpp b/src/fastgltf.cpp index 20617c0e9..105a5a61e 100644 --- a/src/fastgltf.cpp +++ b/src/fastgltf.cpp @@ -3910,33 +3910,33 @@ fg::Parser& fg::Parser::operator=(Parser&& other) noexcept { fg::Parser::~Parser() = default; -fg::Expected fg::Parser::loadGltf(GltfDataBuffer* buffer, fs::path directory, Options options, Category categories) { +fg::Expected fg::Parser::loadGltf(GltfDataBuffer* buffer, fs::path _directory, Options _options, Category categories) { auto type = fastgltf::determineGltfFileType(buffer); if (type == fastgltf::GltfType::glTF) { - return loadGltfJson(buffer, std::move(directory), options, categories); + return loadGltfJson(buffer, std::move(_directory), _options, categories); } if (type == fastgltf::GltfType::GLB) { - return loadGltfBinary(buffer, std::move(directory), options, categories); + return loadGltfBinary(buffer, std::move(_directory), _options, categories); } return Error::InvalidFileData; } -fg::Expected fg::Parser::loadGltfJson(GltfDataBuffer* buffer, fs::path directory, Options options, Category categories) { +fg::Expected fg::Parser::loadGltfJson(GltfDataBuffer* buffer, fs::path _directory, Options _options, Category categories) { using namespace simdjson; + options = _options; + directory = std::move(_directory); + #if !defined(__ANDROID__) // If we never have to load the files ourselves, we're fine with the directory being invalid/blank. - if (std::error_code ec; hasBit(options, Options::LoadExternalBuffers) && (!fs::is_directory(directory, ec) || ec)) { + if (std::error_code ec; hasBit(_options, Options::LoadExternalBuffers) && (!fs::is_directory(directory, ec) || ec)) { return Error::InvalidPath; } #endif - this->options = options; - this->directory = std::move(directory); - // If we own the allocation of the JSON data, we'll try to minify the JSON, which, in most cases, // will speed up the parsing by a small amount. std::size_t jsonLength = buffer->getBufferSize(); @@ -3959,17 +3959,17 @@ fg::Expected fg::Parser::loadGltfJson(GltfDataBuffer* buffer, fs::pat return parse(root, categories); } -fg::Expected fg::Parser::loadGltfBinary(GltfDataBuffer* buffer, fs::path directory, Options options, Category categories) { +fg::Expected fg::Parser::loadGltfBinary(GltfDataBuffer* buffer, fs::path _directory, Options _options, Category categories) { using namespace simdjson; + options = _options; + directory = std::move(_directory); + // If we never have to load the files ourselves, we're fine with the directory being invalid/blank. if (std::error_code ec; hasBit(options, Options::LoadExternalBuffers) && (!fs::is_directory(directory, ec) || ec)) { return Error::InvalidPath; } - this->options = options; - this->directory = std::move(directory); - std::size_t offset = 0UL; auto read = [&buffer, &offset](void* dst, std::size_t size) mutable { std::memcpy(dst, buffer->bufferPointer + offset, size); @@ -5422,10 +5422,10 @@ std::string fg::Exporter::writeJson(const fastgltf::Asset &asset) { return outputString; } -fg::Expected> fg::Exporter::writeGltfJson(const Asset& asset, ExportOptions nOptions) { +fg::Expected> fg::Exporter::writeGltfJson(const Asset& asset, ExportOptions _options) { bufferPaths.clear(); imagePaths.clear(); - options = nOptions; + options = _options; exportingBinary = false; if (hasBit(options, ExportOptions::ValidateAsset)) { @@ -5448,10 +5448,10 @@ fg::Expected> fg::Exporter::writeGltfJson(const As return std::move(result); } -fg::Expected>> fg::Exporter::writeGltfBinary(const Asset& asset, ExportOptions nOptions) { +fg::Expected>> fg::Exporter::writeGltfBinary(const Asset& asset, ExportOptions _options) { bufferPaths.clear(); imagePaths.clear(); - options = nOptions; + options = _options; exportingBinary = true; options &= (~ExportOptions::PrettyPrintJson); @@ -5609,7 +5609,7 @@ namespace fastgltf { } } // namespace fastgltf -fg::Error fg::FileExporter::writeGltfJson(const Asset& asset, fs::path target, ExportOptions options) { +fg::Error fg::FileExporter::writeGltfJson(const Asset& asset, fs::path target, ExportOptions _options) { if (std::error_code ec; !fs::exists(target.parent_path(), ec) || ec) { fs::create_directory(target.parent_path(), ec); if (ec) { @@ -5617,7 +5617,7 @@ fg::Error fg::FileExporter::writeGltfJson(const Asset& asset, fs::path target, E } } - auto expected = Exporter::writeGltfJson(asset, options); + auto expected = Exporter::writeGltfJson(asset, _options); if (!expected) { return expected.error(); @@ -5638,7 +5638,7 @@ fg::Error fg::FileExporter::writeGltfJson(const Asset& asset, fs::path target, E return Error::None; } -fg::Error fg::FileExporter::writeGltfBinary(const Asset& asset, fs::path target, ExportOptions options) { +fg::Error fg::FileExporter::writeGltfBinary(const Asset& asset, fs::path target, ExportOptions _options) { if (std::error_code ec; !fs::exists(target.parent_path(), ec) || ec) { fs::create_directory(target.parent_path(), ec); if (ec) { @@ -5646,7 +5646,7 @@ fg::Error fg::FileExporter::writeGltfBinary(const Asset& asset, fs::path target, } } - auto expected = Exporter::writeGltfBinary(asset, options); + auto expected = Exporter::writeGltfBinary(asset, _options); if (!expected) { return expected.error(); diff --git a/tests/benchmarks.cpp b/tests/benchmarks.cpp index dc67ee446..0145e41f8 100644 --- a/tests/benchmarks.cpp +++ b/tests/benchmarks.cpp @@ -4,7 +4,7 @@ #include #include -#include "simdjson.h" +#include #include #include @@ -32,8 +32,8 @@ bool tinygltf_FileExistsFunction([[maybe_unused]] const std::string& filename, [ return true; } -std::string tinygltf_ExpandFilePathFunction(const std::string& path, [[maybe_unused]] void* user) { - return path; +std::string tinygltf_ExpandFilePathFunction(const std::string& filePath, [[maybe_unused]] void* user) { + return filePath; } bool tinygltf_ReadWholeFileFunction(std::vector* data, std::string*, const std::string&, void*) { @@ -76,10 +76,10 @@ void setTinyGLTFCallbacks(tinygltf::TinyGLTF& gltf) { #include #endif -fastgltf::StaticVector readFileAsBytes(const std::filesystem::path& path) { - std::ifstream file(path, std::ios::ate | std::ios::binary); +fastgltf::StaticVector readFileAsBytes(const std::filesystem::path& filePath) { + std::ifstream file(filePath, std::ios::ate | std::ios::binary); if (!file.is_open()) - throw std::runtime_error(std::string { "Failed to open file: " } + path.string()); + throw std::runtime_error(std::string { "Failed to open file: " } + filePath.string()); auto fileSize = file.tellg(); fastgltf::StaticVector bytes(static_cast(fileSize) + fastgltf::getGltfBufferPadding()); diff --git a/tests/uri_tests.cpp b/tests/uri_tests.cpp index 740466424..8e8dee4be 100644 --- a/tests/uri_tests.cpp +++ b/tests/uri_tests.cpp @@ -10,13 +10,13 @@ TEST_CASE("Test basic URIs", "[uri-tests]") { REQUIRE(uri1.scheme().empty()); REQUIRE(uri1.path().empty()); - std::string_view path = "path/somewhere.xyz"; + std::string_view relpath = "path/somewhere.xyz"; SECTION("Basic local path") { - const fastgltf::URI uri2(path); + const fastgltf::URI uri2(relpath); REQUIRE(uri2.scheme().empty()); - REQUIRE(uri2.path() == path); + REQUIRE(uri2.path() == relpath); REQUIRE(uri2.isLocalPath()); - REQUIRE(uri2.fspath() == path); + REQUIRE(uri2.fspath() == relpath); } std::string_view abspath = "/path/somewhere.xyz";