From e4452620f08d87de2d627966a205469769097a3d Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Tue, 28 Nov 2023 05:06:58 -0500 Subject: [PATCH] Now we're gonna bring back those tricks better --- .vscode/settings.json | 53 +++++++++++++++++++++- source/Irrlicht/CB3DJSONMeshFileLoader.cpp | 36 +++++++++------ source/Irrlicht/CB3DJSONMeshFileLoader.h | 10 +++- 3 files changed, 82 insertions(+), 17 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 18dbb4a4..cd3e9066 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,57 @@ "fstream": "cpp", "new": "cpp", "unordered_map": "cpp", - "unordered_set": "cpp" + "unordered_set": "cpp", + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "filesystem": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "ratio": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "valarray": "cpp" } } \ No newline at end of file diff --git a/source/Irrlicht/CB3DJSONMeshFileLoader.cpp b/source/Irrlicht/CB3DJSONMeshFileLoader.cpp index 2458c099..5dc3db3c 100644 --- a/source/Irrlicht/CB3DJSONMeshFileLoader.cpp +++ b/source/Irrlicht/CB3DJSONMeshFileLoader.cpp @@ -191,18 +191,10 @@ void CB3DJSONMeshFileLoader::cleanUp(std::string failure) { AnimatedMesh = 0; } -bool CB3DJSONMeshFileLoader::parseJSONFile() { - -} - -IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) { - - // Less than zero? What is this file a black hole? - if (file->getSize() <= 0) { - this->cleanUp("B3D JSON severe error! File size is 0!"); - return AnimatedMesh; - } - +/** + * Returns success. +*/ +bool CB3DJSONMeshFileLoader::parseJSONFile(io::IReadFile* file) { // So here we turn this mangled disaster into a C string. // Please consider this the equivalent of duct taping a chainsaw onto a car to cut your lawn. auto buffer = std::make_unique(file->getSize()); @@ -217,16 +209,30 @@ IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) { output[file->getSize()] = '\0'; // We have to catch a JSON parse error or else the game will segfault. - json data; try { - data = json::parse(output); + JSONDataContainer = json::parse(output); } catch (const json::parse_error& e) { std::cout << "message: " << e.what() << '\n' << "exception id: " << e.id << '\n' << "byte position of error: " << e.byte << std::endl; os::Printer::log("JSON: Failed to parse!", ELL_WARNING); - return nullptr; + return false; } + return true; +} + +IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) { + + // Less than zero? What is this file a black hole? + if (file->getSize() <= 0) { + this->cleanUp("B3D JSON severe error! File size is 0!"); + return AnimatedMesh; + } + + if (!this->parseJSONFile(file)) { + + } + // Now check some real basic elements of the JSON file. if (!data.contains("format") || !data["format"].is_string() || data["format"] != "BB3D") { diff --git a/source/Irrlicht/CB3DJSONMeshFileLoader.h b/source/Irrlicht/CB3DJSONMeshFileLoader.h index c383f03b..693b690e 100644 --- a/source/Irrlicht/CB3DJSONMeshFileLoader.h +++ b/source/Irrlicht/CB3DJSONMeshFileLoader.h @@ -17,10 +17,18 @@ class CB3DJSONMeshFileLoader : public IMeshLoader private: // Fields. CSkinnedMesh* AnimatedMesh; + /* + Quick note about JSON. + This is static memory, it's a static memory address so I do not think + that this needs to be freed. + So once this model goes out of scope, I'm pretty sure that this will + be pointing to the next model. Or maybe the last model loaded. + */ + json JSONDataContainer; // Methods. void cleanUp(std::string); - bool parseJSONFile(); + bool parseJSONFile(io::IReadFile* file); public: