From 8bd1218e9fcda8009b7b217e8807d9f62969e07f Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Thu, 24 Jan 2019 22:37:59 -0500 Subject: [PATCH] confirming rapidjson schmea validation doesn't work with arrays of items --- .gitmodules | 3 +++ Makefile | 2 +- TODO.md | 1 - data/hashmap_scene.json | 9 ++++++--- data/scene_schema.json | 6 ++++-- ext/rapidjson | 1 + src/scene_loader.cpp | 11 ++++++++--- 7 files changed, 23 insertions(+), 10 deletions(-) create mode 160000 ext/rapidjson diff --git a/.gitmodules b/.gitmodules index d26cc89..234adc5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "ext/stb_libs"] path = ext/stb_libs url = https://github.com/nothings/stb.git +[submodule "ext/rapidjson"] + path = ext/rapidjson + url = https://github.com/Tencent/rapidjson.git diff --git a/Makefile b/Makefile index eef3363..90510d5 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CXX = g++ -CXXFLAGS = -std=c++11 -g -ggdb3 -Wall -I/usr/include/SDL2 -Iext/aixlog/include -Iext/stb_libs +CXXFLAGS = -std=c++11 -g -ggdb3 -Wall -I/usr/include/SDL2 -Iext/aixlog/include -Iext/stb_libs -Iext/rapidjson/include SRC_DIR = src OBJ_DIR = build diff --git a/TODO.md b/TODO.md index 1a21dc7..ed4cef2 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ ## TODO: -- allocate meMeshGroup->meshes as single chunk of mem instead of p2p - position entities on grid hexes - pathfinding - assimp animation diff --git a/data/hashmap_scene.json b/data/hashmap_scene.json index 19e79a1..c622864 100644 --- a/data/hashmap_scene.json +++ b/data/hashmap_scene.json @@ -22,21 +22,24 @@ "model_file" : "catepillar.dae", "position" : {"x":-140,"y":50,"z":0}, "rotation" : {"x":0,"y":0,"z":0,"w":0}, - "scale" : {"x":10,"y":10,"z":10} + "scale" : {"x":10,"y":10,"z":10}, + "grid_pos": {"x":10,"y":10,"z":10} }, { "name" : "catepillar 2", "model_file" : "catepillar.dae", "position" : {"x" :140,"y":0,"z":0}, "rotation" : {"x":0,"y":0,"z":0,"w":0}, - "scale" : {"x":10,"y":10,"z":10} + "scale" : {"x":10,"y":10,"z":10}, + "grid_pos": {"q":10,"r":10,"s":10} }, { "name" : "box", "model_file" : "block2.dae", "position" : {"x":140,"y":-100,"z":0}, "rotation" : {"x":0,"y":0,"z":0,"w":0}, - "scale" : {"x":10,"y":10,"z":10} + "scale" : {"x":10,"y":10,"z":10}, + "potato": 2 }, { "name" : "ground", diff --git a/data/scene_schema.json b/data/scene_schema.json index 1e80095..577ed37 100644 --- a/data/scene_schema.json +++ b/data/scene_schema.json @@ -79,9 +79,11 @@ "model_file": { "type": "string" }, "position": { "$ref": "#/definitions/vector3" }, "rotation": { "$ref": "#/definitions/vector4" }, - "scale": { "$ref": "#/definitions/vector3" } + "scale": { "$ref": "#/definitions/vector3" }, + "grid_pos": { "$ref": "#/definitions/vector3" } }, - "required" : ["name", "model_file", "position", "rotation", "scale"] + "additionalItems": false, + "required" : ["name", "model_file", "position", "rotation", "scale", "grid_pos"] }, "lights": { diff --git a/ext/rapidjson b/ext/rapidjson new file mode 160000 index 0000000..bfdcf49 --- /dev/null +++ b/ext/rapidjson @@ -0,0 +1 @@ +Subproject commit bfdcf4911047688fec49014d575433e2e5eb05be diff --git a/src/scene_loader.cpp b/src/scene_loader.cpp index 2bab987..7264c74 100644 --- a/src/scene_loader.cpp +++ b/src/scene_loader.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -69,7 +70,7 @@ slLoadFile(const char* data_dir, const char* scene_file, const char* schema_file void slFreeSceneDoc(slSceneDoc* sd) { - if (sd->doc != nullptr) { + if (sd != nullptr && sd->doc != nullptr) { delete sd->doc; sd->doc = nullptr; } @@ -324,9 +325,13 @@ loadTextFile(char*& output, const char* data_dir, const char* file_name) bool parseFile(rapidjson::Document* doc, const char* file_contents, const char* file_name) { - rapidjson::ParseResult pr = doc->Parse(file_contents); + rapidjson::StringStream ss(file_contents); + rapidjson::CursorStreamWrapper csw(ss); + rapidjson::ParseResult pr = doc->ParseStream(csw); + if (!pr || !doc->IsObject()) { - LOG(ERROR) << "Error parrsing json file: " << file_name << "\n"; + LOG(ERROR) << "Error parrsing json file: " << file_name; + LOG(ERROR) << " at line " << csw.GetLine() << ", col " << csw.GetColumn() << "\n"; LOG(ERROR) << "Error desscription: " << rapidjson::GetParseError_En(pr.Code()) << " (" << pr.Offset() << ")\n"; return false;