]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Scene.cc
dispatcher alias methods
[chaz/yoink] / src / Moof / Scene.cc
index 85e5be75d9697a315e5aded091589e6ab3c8da58..ccfd4f934060b605ad5de663c9e62bf84414c9e0 100644 (file)
@@ -36,7 +36,6 @@
 #include "Entity.hh"
 #include "Math.hh"
 #include "Mippleton.hh"
-#include "Octree.hh"
 #include "OpenGL.hh"
 #include "Scene.hh"
 #include "Serializable.hh"
@@ -46,7 +45,7 @@
 namespace Mf {
 
 
-class Scene::SceneImpl : public Mippleton<SceneImpl>
+class Scene::Impl : public Mippleton<Impl>
 {
        class Quad : public Entity
        {
@@ -99,6 +98,12 @@ class Scene::SceneImpl : public Mippleton<SceneImpl>
                                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                        }
 
+                       if (fog_)
+                       {
+                               glEnable(GL_FOG);
+                               glFogi(GL_FOG_MODE, GL_LINEAR);
+                       }
+
                        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
                        tilemap_.bind();
 
@@ -108,6 +113,7 @@ class Scene::SceneImpl : public Mippleton<SceneImpl>
                        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
                        glDisable(GL_BLEND);
+                       glDisable(GL_FOG);
                }
 
                bool isVisible(const Camera& cam) const
@@ -127,13 +133,13 @@ class Scene::SceneImpl : public Mippleton<SceneImpl>
        };
 
 
-       static void loadBox(Aabb& theBox, SerializablePtr obj)
+       static void loadBox(Aabb& theBox, SerializableP obj)
        {
-               std::vector<SerializablePtr> 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);
@@ -145,17 +151,17 @@ class Scene::SceneImpl : public Mippleton<SceneImpl>
        }
 
 public:
-       SceneImpl(const std::string& name) :
-               Mippleton<SceneImpl>(name)
+       Impl(const std::string& name) :
+               Mippleton<Impl>(name)
        {
                loadFromFile();
        }
 
 
-       void loadInstructions(SerializablePtr root)
+       void loadInstructions(SerializableP root)
        {
-               std::vector<SerializablePtr> rootObj;
-               std::vector<SerializablePtr>::iterator it;
+               Serializable::Array rootObj;
+               Serializable::Array::iterator it;
 
                if (!root->get(rootObj))
                {
@@ -178,7 +184,7 @@ public:
                                }
                                else if (instruction == "translate")
                                {
-                                       std::vector<SerializablePtr> values;
+                                       Serializable::Array values;
 
                                        ++it;
                                        if ((*it)->get(values))
@@ -187,7 +193,7 @@ public:
 
                                                for (size_t i = 0; i < values.size(); ++i)
                                                {
-                                                       double value;
+                                                       Serializable::Float value;
 
                                                        if (values[i]->getNumber(value))
                                                        {
@@ -202,14 +208,14 @@ public:
                                }
                                else if (instruction == "scale")
                                {
-                                       std::vector<SerializablePtr> 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);
 
@@ -224,7 +230,7 @@ public:
 
                                                        for (size_t i = 0; i < values.size(); ++i)
                                                        {
-                                                               double value;
+                                                               Serializable::Float value;
 
                                                                if (values[i]->getNumber(value))
                                                                {
@@ -240,7 +246,7 @@ public:
                                }
                                else if (instruction == "rotate")
                                {
-                                       std::vector<SerializablePtr> values;
+                                       Serializable::Array values;
 
                                        ++it;
                                        if ((*it)->get(values))
@@ -249,7 +255,7 @@ public:
                                                {
                                                        std::string axis;
                                                        size_t index = 0;
-                                                       double value = 0.0;
+                                                       Serializable::Float value = 0.0;
 
                                                        if (values[0]->get(axis))
                                                        {
@@ -285,11 +291,11 @@ public:
        }
 
 
-       void loadTilemap(SerializablePtr root, const Matrix4& transform,
+       void loadTilemap(SerializableP root, const Matrix4& transform,
                        const std::string& texture)
        {
-               std::map<std::string,SerializablePtr> rootObj;
-               std::map<std::string,SerializablePtr>::iterator it;
+               Serializable::Map rootObj;
+               Serializable::Map::iterator it;
 
                if (!root->get(rootObj))
                {
@@ -311,13 +317,13 @@ public:
                        return;
                }
 
-               std::vector<SerializablePtr> tiles;
+               Serializable::Array tiles;
 
                if ((it = rootObj.find("tiles")) != rootObj.end() &&
                                (*it).second->get(tiles) &&
                                tiles.size() % width == 0)
                {
-                       std::vector<SerializablePtr>::iterator jt;
+                       Serializable::Array::iterator jt;
                        int w, h;
 
                        height = tiles.size() / width;
@@ -333,7 +339,7 @@ public:
 
                                for (w = 0; w < width && jt != tiles.end(); ++w, ++jt)
                                {
-                                       long index;
+                                       Serializable::Integer index;
 
                                        if ((*jt)->get(index))
                                        {
@@ -380,51 +386,47 @@ public:
                                Quad* quad = new Quad(quadVertices, texture, indices[h][w]);
                                boost::shared_ptr<Quad> quadPtr(quad);
 
-                               //objects.push_back(quadPtr);
-                               Octree::add(octree, quadPtr);
+                               octree->insert(quadPtr);
                        }
                }
        }
 
-       void loadBillboard(SerializablePtr root, const Matrix4& transform,
+       void loadBillboard(SerializableP root, const Matrix4& transform,
                        const std::string& texture)
        {
-               std::map<std::string,SerializablePtr> rootObj;
-               std::map<std::string,SerializablePtr>::iterator it;
-
-               if (!root->get(rootObj))
-               {
-                       std::cerr << "error loading scene billboard object" << std::endl;
-                       return;
-               }
+               Serializable::Map rootObj;
+               Serializable::Map::iterator it;
 
                Tilemap::Index  index = 0;
                long                    width = 1;
                bool                    blending = false;
                bool                    fog = false;
 
-               if ((it = rootObj.find("tile")) != rootObj.end())
+               if (root->get(rootObj))
                {
-                       long value;
-                       if ((*it).second->get(value))
+                       if ((it = rootObj.find("tile")) != rootObj.end())
                        {
-                               index = Tilemap::Index(value);
+                               Serializable::Integer value;
+                               if ((*it).second->get(value))
+                               {
+                                       index = Tilemap::Index(value);
+                               }
                        }
-               }
 
-               if ((it = rootObj.find("u_scale")) != rootObj.end())
-               {
-                       (*it).second->get(width);
-               }
+                       if ((it = rootObj.find("u_scale")) != rootObj.end())
+                       {
+                               (*it).second->get(width);
+                       }
 
-               if ((it = rootObj.find("blend")) != rootObj.end())
-               {
-                       (*it).second->get(blending);
-               }
+                       if ((it = rootObj.find("blend")) != rootObj.end())
+                       {
+                               (*it).second->get(blending);
+                       }
 
-               if ((it = rootObj.find("fog")) != rootObj.end())
-               {
-                       (*it).second->get(fog);
+                       if ((it = rootObj.find("fog")) != rootObj.end())
+                       {
+                               (*it).second->get(fog);
+                       }
                }
 
 
@@ -461,21 +463,20 @@ public:
 
                        boost::shared_ptr<Quad> quadPtr(quad);
 
-                       //objects.push_back(quad_Ptr);
-                       Octree::add(octree, quadPtr);
+                       octree->insert(quadPtr);
                }
        }
 
 
        void loadFromFile()
        {
-               std::string filePath = Scene::getPathToResource(getName());
+               std::string filePath = Scene::getPath(getName());
 
                Deserializer    deserializer(filePath, true);
-               SerializablePtr root = deserializer.deserialize();
+               SerializableP   root = deserializer.deserialize();
 
-               std::map<std::string,SerializablePtr> rootObj;
-               std::map<std::string,SerializablePtr>::iterator it;
+               Serializable::Map rootObj;
+               Serializable::Map::iterator it;
 
                if (!root || !root->get(rootObj))
                {
@@ -497,67 +498,50 @@ public:
                        return;
                }
 
-               //OctreeNode rootNode(maximumBounds);
-               octree = Octree::createNewNode(maximumBounds);
+               // create the tree to store the quads
+               octree = Octree::alloc(maximumBounds);
 
                if ((it = rootObj.find("instructions")) != rootObj.end())
                {
                        loadInstructions((*it).second);
                }
+
+               octree->sort();
        }
 
 
        void draw(Scalar alpha, const Camera& cam) const
        {
-               //QuadVector::const_iterator it;
-
                glEnableClientState(GL_VERTEX_ARRAY);
                glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
                octree->drawIfVisible(alpha, cam);
 
-               //int objectsDrawn = 0;
+               //glDisableClientState(GL_VERTEX_ARRAY);
+               //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
-               //for (it = objects.begin(); it != objects.end(); ++it)
-               //{
-                       //if ((*it)->isVisible(cam))
-                       //{
-                               ////std::cout << "draw object";
-                               //(*it)->draw();
+               //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
-                               //objectsDrawn++;
-                       //}
-               //}
+               //Texture::resetBind();
+               //glColor3f(0.0f, 1.0f, 0.0f);
+               //playfieldBounds.draw();
+               //glColor3f(0.0f, 0.0f, 1.0f);
+               //maximumBounds.draw();
 
-               //std::cout << objectsDrawn << std::endl;
-
-               glDisableClientState(GL_VERTEX_ARRAY);
-               glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
-               glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
-               Texture::resetBind();
-               glColor3f(0.0f, 1.0f, 0.0f);
-               playfieldBounds.draw();
-               glColor3f(0.0f, 0.0f, 1.0f);
-               maximumBounds.draw();
-
-               glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+               //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        }
 
 
        Aabb playfieldBounds;
        Aabb maximumBounds;
 
-       //typedef std::vector< boost::shared_ptr<Quad> > QuadVector;
-       //QuadVector objects;
-       OctreePtr octree;
+       OctreeP octree;
 };
 
 
 Scene::Scene(const std::string& name) :
        // pass through
-       impl_(Scene::SceneImpl::retain(name), &Scene::SceneImpl::release) {}
+       impl_(Scene::Impl::getInstance(name)) {}
 
 
 void Scene::draw(Scalar alpha, const Camera& cam) const
@@ -573,14 +557,20 @@ void Scene::refresh()
 }
 
 
+OctreeP Scene::getOctree() const
+{
+       // pass through
+       return impl_->octree;
+}
+
 /**
  * Specialized search location for scene files.  They can be found in the
  * "scenes" subdirectory of any of the searched directories.
  */
 
-std::string Scene::getPathToResource(const std::string& name)
+std::string Scene::getPath(const std::string& name)
 {
-       return Resource::getPathToResource("scenes/" + name + ".json");
+       return Resource::getPath("scenes/" + name + ".json");
 }
 
 
This page took 0.028574 seconds and 4 git commands to generate.