mirror of
https://github.com/minetest/irrlicht.git
synced 2025-02-22 05:40:26 +01:00
Now we're gonna bring back those tricks better
This commit is contained in:
parent
a8f67ace8e
commit
e4452620f0
53
.vscode/settings.json
vendored
53
.vscode/settings.json
vendored
@ -4,6 +4,57 @@
|
|||||||
"fstream": "cpp",
|
"fstream": "cpp",
|
||||||
"new": "cpp",
|
"new": "cpp",
|
||||||
"unordered_map": "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"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -191,18 +191,10 @@ void CB3DJSONMeshFileLoader::cleanUp(std::string failure) {
|
|||||||
AnimatedMesh = 0;
|
AnimatedMesh = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CB3DJSONMeshFileLoader::parseJSONFile() {
|
/**
|
||||||
|
* Returns success.
|
||||||
}
|
*/
|
||||||
|
bool CB3DJSONMeshFileLoader::parseJSONFile(io::IReadFile* file) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// So here we turn this mangled disaster into a C string.
|
// 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.
|
// Please consider this the equivalent of duct taping a chainsaw onto a car to cut your lawn.
|
||||||
auto buffer = std::make_unique<char[]>(file->getSize());
|
auto buffer = std::make_unique<char[]>(file->getSize());
|
||||||
@ -217,16 +209,30 @@ IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) {
|
|||||||
output[file->getSize()] = '\0';
|
output[file->getSize()] = '\0';
|
||||||
|
|
||||||
// We have to catch a JSON parse error or else the game will segfault.
|
// We have to catch a JSON parse error or else the game will segfault.
|
||||||
json data;
|
|
||||||
try {
|
try {
|
||||||
data = json::parse(output);
|
JSONDataContainer = json::parse(output);
|
||||||
} catch (const json::parse_error& e) {
|
} catch (const json::parse_error& e) {
|
||||||
std::cout << "message: " << e.what() << '\n'
|
std::cout << "message: " << e.what() << '\n'
|
||||||
<< "exception id: " << e.id << '\n'
|
<< "exception id: " << e.id << '\n'
|
||||||
<< "byte position of error: " << e.byte << std::endl;
|
<< "byte position of error: " << e.byte << std::endl;
|
||||||
os::Printer::log("JSON: Failed to parse!", ELL_WARNING);
|
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.
|
// Now check some real basic elements of the JSON file.
|
||||||
if (!data.contains("format") || !data["format"].is_string() || data["format"] != "BB3D") {
|
if (!data.contains("format") || !data["format"].is_string() || data["format"] != "BB3D") {
|
||||||
|
@ -17,10 +17,18 @@ class CB3DJSONMeshFileLoader : public IMeshLoader
|
|||||||
private:
|
private:
|
||||||
// Fields.
|
// Fields.
|
||||||
CSkinnedMesh* AnimatedMesh;
|
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.
|
// Methods.
|
||||||
void cleanUp(std::string);
|
void cleanUp(std::string);
|
||||||
bool parseJSONFile();
|
bool parseJSONFile(io::IReadFile* file);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user