X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FScene.cc;h=454726817a3fc9285616efbcf47e405f6fe24aa8;hp=5e44221a93391a03afacb4b4059fe30ca47ffa37;hb=1dd005530930657fd6216edc1dfcfa4c270a81c9;hpb=bfa6212d09d8735d8fd5e2638188e4a99f21ada4 diff --git a/src/Moof/Scene.cc b/src/Moof/Scene.cc index 5e44221..4547268 100644 --- a/src/Moof/Scene.cc +++ b/src/Moof/Scene.cc @@ -26,7 +26,6 @@ *******************************************************************************/ -#include #include #include @@ -34,6 +33,7 @@ #include "Camera.hh" #include "Deserializer.hh" #include "Entity.hh" +#include "Log.hh" #include "Math.hh" #include "Mippleton.hh" #include "OpenGL.hh" @@ -67,7 +67,13 @@ class Scene::Impl : public Mippleton if (!tilemap_.getTileCoords(tileIndex, texCoords_)) { - std::cerr << "no coords for tile's texture" << std::endl; + logWarning("no index %d in texture %s", tileIndex, + texture.c_str()); + + texCoords_[0] = texCoords_[1] = + texCoords_[3] = texCoords_[6] = 0.0; + texCoords_[2] = texCoords_[4] = + texCoords_[5] = texCoords_[7] = 1.0; } aabb_.encloseVertices(vertices, 4); @@ -133,13 +139,13 @@ class Scene::Impl : public Mippleton }; - static void loadBox(Aabb& theBox, SerializablePtr obj) + static void loadBox(Aabb& theBox, SerializableP obj) { - std::vector numbers; + Serializable::Array numbers; if (obj->get(numbers) && numbers.size() == 6) { - double num; + Serializable::Float num; if (numbers[0]->getNumber(num)) theBox.min[0] = Scalar(num); if (numbers[1]->getNumber(num)) theBox.min[1] = Scalar(num); @@ -158,14 +164,14 @@ public: } - void loadInstructions(SerializablePtr root) + void loadInstructions(SerializableP root) { - std::vector rootObj; - std::vector::iterator it; + Serializable::Array rootObj; + Serializable::Array::iterator it; if (!root->get(rootObj)) { - std::cerr << "error loading scene instructions" << std::endl; + logError("scene instructions must be an array"); return; } @@ -184,7 +190,7 @@ public: } else if (instruction == "translate") { - std::vector values; + Serializable::Array values; ++it; if ((*it)->get(values)) @@ -193,7 +199,7 @@ public: for (size_t i = 0; i < values.size(); ++i) { - double value; + Serializable::Float value; if (values[i]->getNumber(value)) { @@ -208,14 +214,14 @@ public: } else if (instruction == "scale") { - std::vector values; + Serializable::Array values; ++it; if ((*it)->get(values)) { if (values.size() == 1) { - double value = 1.0; + Serializable::Float value = 1.0; values[0]->getNumber(value); @@ -230,7 +236,7 @@ public: for (size_t i = 0; i < values.size(); ++i) { - double value; + Serializable::Float value; if (values[i]->getNumber(value)) { @@ -246,7 +252,7 @@ public: } else if (instruction == "rotate") { - std::vector values; + Serializable::Array values; ++it; if ((*it)->get(values)) @@ -255,7 +261,7 @@ public: { std::string axis; size_t index = 0; - double value = 0.0; + Serializable::Float value = 0.0; if (values[0]->get(axis)) { @@ -291,15 +297,15 @@ public: } - void loadTilemap(SerializablePtr root, const Matrix4& transform, + void loadTilemap(SerializableP root, const Matrix4& transform, const std::string& texture) { - std::map rootObj; - std::map::iterator it; + Serializable::Map rootObj; + Serializable::Map::iterator it; if (!root->get(rootObj)) { - std::cerr << "error loading scene tilemap object" << std::endl; + logError("invalid tilemap instruction"); return; } @@ -313,17 +319,17 @@ public: } else { - std::cerr << "width is a required field of a tilemap" << std::endl; + logError("missing required field width for tilemap instruction"); return; } - std::vector tiles; + Serializable::Array tiles; if ((it = rootObj.find("tiles")) != rootObj.end() && (*it).second->get(tiles) && tiles.size() % width == 0) { - std::vector::iterator jt; + Serializable::Array::iterator jt; int w, h; height = tiles.size() / width; @@ -339,7 +345,7 @@ public: for (w = 0; w < width && jt != tiles.end(); ++w, ++jt) { - long index; + Serializable::Integer index; if ((*jt)->get(index)) { @@ -352,7 +358,7 @@ public: } else { - std::cerr << "error loading tiles from tilemap object" << std::endl; + logError("invalid tiles in tilemap instruction"); return; } @@ -391,11 +397,11 @@ public: } } - void loadBillboard(SerializablePtr root, const Matrix4& transform, + void loadBillboard(SerializableP root, const Matrix4& transform, const std::string& texture) { - std::map rootObj; - std::map::iterator it; + Serializable::Map rootObj; + Serializable::Map::iterator it; Tilemap::Index index = 0; long width = 1; @@ -406,7 +412,7 @@ public: { if ((it = rootObj.find("tile")) != rootObj.end()) { - long value; + Serializable::Integer value; if ((*it).second->get(value)) { index = Tilemap::Index(value); @@ -473,14 +479,14 @@ public: std::string filePath = Scene::getPath(getName()); Deserializer deserializer(filePath, true); - SerializablePtr root = deserializer.deserialize(); + SerializableP root = deserializer.deserialize(); - std::map rootObj; - std::map::iterator it; + Serializable::Map rootObj; + Serializable::Map::iterator it; if (!root || !root->get(rootObj)) { - std::cerr << "error loading scene file" << std::endl; + logError("no root map in scene file"); return; } @@ -494,18 +500,20 @@ public: } else { - std::cerr << "maximum bounds required in scene" << std::endl; + logError("missing required maximum bounds"); return; } // create the tree to store the quads - octree = OctreePtr(new Octree(maximumBounds)); + octree = Octree::alloc(maximumBounds); if ((it = rootObj.find("instructions")) != rootObj.end()) { loadInstructions((*it).second); } + + octree->sort(); } @@ -535,13 +543,13 @@ public: Aabb playfieldBounds; Aabb maximumBounds; - OctreePtr octree; + OctreeP octree; }; Scene::Scene(const std::string& name) : // pass through - impl_(Scene::Impl::retain(name), &Scene::Impl::release) {} + impl_(Scene::Impl::getInstance(name)) {} void Scene::draw(Scalar alpha, const Camera& cam) const @@ -557,7 +565,7 @@ void Scene::refresh() } -OctreePtr Scene::getOctree() const +OctreeP Scene::getOctree() const { // pass through return impl_->octree;