mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-01 15:50:27 +02:00
Now we're gonna bring back those tricks better
This commit is contained in:
@ -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<char[]>(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") {
|
||||
|
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user