Browse Source

confirming rapidjson schmea validation doesn't work with arrays of items

master
cinnaboot 8 years ago
parent
commit
8bd1218e9f
  1. 3
      .gitmodules
  2. 2
      Makefile
  3. 1
      TODO.md
  4. 9
      data/hashmap_scene.json
  5. 6
      data/scene_schema.json
  6. 1
      ext/rapidjson
  7. 11
      src/scene_loader.cpp

3
.gitmodules vendored

@ -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

2
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

1
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

9
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",

6
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": {

1
ext/rapidjson

@ -0,0 +1 @@
Subproject commit bfdcf4911047688fec49014d575433e2e5eb05be

11
src/scene_loader.cpp

@ -2,6 +2,7 @@
#include <string>
#include <glm/glm.hpp>
#include <rapidjson/cursorstreamwrapper.h>
#include <rapidjson/document.h>
#include <rapidjson/schema.h>
#include <rapidjson/stringbuffer.h>
@ -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<rapidjson::StringStream> 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;

Loading…
Cancel
Save