]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Scene.cc
extreme refactoring
[chaz/yoink] / src / Moof / Scene.cc
similarity index 70%
rename from src/scene.cc
rename to src/Moof/Scene.cc
index 04754ea1730e22fb24b53e19bcba976122124155..f4dd1c0e3f9597bdd7505ed236bd3d91591fc40c 100644 (file)
 #include <map>
 #include <vector>
 
-#include "aabb.hh"
-#include "camera.hh"
-#include "cullable.hh"
-#include "deserializer.hh"
-#include "drawable.hh"
-#include "math.hh"
-#include "mippleton.hh"
-#include "opengl.hh"
-#include "serializable.hh"
-#include "tilemap.hh"
+#include "Aabb.hh"
+#include "Camera.hh"
+#include "Cullable.hh"
+#include "Deserializer.hh"
+#include "Drawable.hh"
+#include "Math.hh"
+#include "Mippleton.hh"
+#include "OpenGL.hh"
+#include "Scene.hh"
+#include "Serializable.hh"
+#include "Tilemap.hh"
 
-#include "scene.hh"
 
+namespace Mf {
 
-namespace dc {
 
-
-class scene::scene_impl : public mippleton<scene_impl>
+class Scene::SceneImpl : public Mippleton<SceneImpl>
 {
-       class scenery : public drawable, public cullable
+       class Scenery : public Drawable, public Cullable
        {
        public:
-               scenery(const matrix4& transform, const std::string& textureName) :
+               Scenery(const Matrix4& transform, const std::string& textureName) :
                        transformation(transform),
                        image(textureName) {}
 
        protected:
-               matrix4         transformation;
-               tilemap         image;
+               Matrix4         transformation;
+               Tilemap         image;
                bool            blending;
                long            detail;
                bool            fog;
        };
 
-       class tiles : public scenery
+       class TilePanel : public Scenery
        {
        public:
-               tiles(const matrix4& transform, const std::string& textureName,
-                               serializable_ptr root) :
-                       scenery(transform, textureName),
+               TilePanel(const Matrix4& transform, const std::string& textureName,
+                               SerializablePtr root) :
+                       Scenery(transform, textureName),
                        width(1),
                        height(1)
                {
-                       std::map<std::string,serializable_ptr> rootObj;
+                       std::map<std::string,SerializablePtr> rootObj;
 
                        if (root->get(rootObj))
                        {
-                               std::map<std::string,serializable_ptr>::iterator it;
+                               std::map<std::string,SerializablePtr>::iterator it;
 
                                if ((it = rootObj.find("width")) != rootObj.end())
                                {
@@ -85,11 +84,11 @@ class scene::scene_impl : public mippleton<scene_impl>
                                }
                                if ((it = rootObj.find("tiles")) != rootObj.end())
                                {
-                                       std::vector<serializable_ptr> theTiles;
+                                       std::vector<SerializablePtr> theTiles;
 
                                        if ((*it).second->get(theTiles))
                                        {
-                                               std::vector<serializable_ptr>::iterator jt;
+                                               std::vector<SerializablePtr>::iterator jt;
 
                                                height = theTiles.size() / width;
                                                int w, h;
@@ -99,7 +98,7 @@ class scene::scene_impl : public mippleton<scene_impl>
                                                for (h = height - 1, jt = theTiles.begin();
                                                                jt != theTiles.end(); h--)
                                                {
-                                                       std::vector<unsigned> row;
+                                                       std::vector<Tilemap::Index> row;
 
                                                        for (w = 0; w < width && jt != theTiles.end();
                                                                        w++, jt++)
@@ -108,7 +107,7 @@ class scene::scene_impl : public mippleton<scene_impl>
 
                                                                if ((*jt)->get(index))
                                                                {
-                                                                       row.push_back(unsigned(index));
+                                                                       row.push_back(Tilemap::Index(index));
                                                                }
                                                        }
 
@@ -119,7 +118,7 @@ class scene::scene_impl : public mippleton<scene_impl>
                        }
                }
 
-               void draw(scalar alpha)
+               void draw(Scalar alpha)
                {
                        glPushMatrix();
                        //std::cout << "transforming..." << std::endl;
@@ -130,15 +129,15 @@ class scene::scene_impl : public mippleton<scene_impl>
                        image.bind();
 
                        long x, y;
-                       scalar xf, yf;
+                       Scalar xf, yf;
 
                        for (y = 0, yf = 0.0; y < height; y++, yf += 1.0)
                        {
                                for (x = 0, xf = 0.0; x < width; x++, xf += 1.0)
                                {
-                                       scalar texCoords[8];
+                                       Scalar texCoords[8];
 
-                                       unsigned index = indices[y][x];
+                                       Tilemap::Index index = indices[y][x];
 
                                        if (image.getTileCoords(index, texCoords))
                                        {
@@ -159,36 +158,36 @@ class scene::scene_impl : public mippleton<scene_impl>
                        glPopMatrix();
                }
 
-               bool isVisible(const camera& cam)
+               bool isVisible(const Camera& cam)
                {
                        return true;
                }
 
        private:
                long width, height;
-               std::vector<std::vector<unsigned> > indices;
+               std::vector<std::vector<Tilemap::Index> > indices;
        };
 
-       class billboard : public scenery
+       class Billboard : public Scenery
        {
        public:
-               billboard(const matrix4& transform, const std::string& textureName,
-                               serializable_ptr root) :
-                       scenery(transform, textureName),
+               Billboard(const Matrix4& transform, const std::string& textureName,
+                               SerializablePtr root) :
+                       Scenery(transform, textureName),
                        index(0)
                {
-                       std::map<std::string,serializable_ptr> rootObj;
+                       std::map<std::string,SerializablePtr> rootObj;
 
                        if (root->get(rootObj))
                        {
-                               std::map<std::string,serializable_ptr>::iterator it;
+                               std::map<std::string,SerializablePtr>::iterator it;
 
                                if ((it = rootObj.find("tile")) != rootObj.end())
                                {
                                        long value;
                                        if ((*it).second->get(value))
                                        {
-                                               index = unsigned(value);
+                                               index = Tilemap::Index(value);
                                        }
                                }
                        }
@@ -196,7 +195,7 @@ class scene::scene_impl : public mippleton<scene_impl>
                        image.getTileCoords(index, texCoords);
                }
 
-               void draw(scalar alpha)
+               void draw(Scalar alpha)
                {
                        glPushMatrix();
                        glMultMatrixf(transformation.data());
@@ -218,20 +217,20 @@ class scene::scene_impl : public mippleton<scene_impl>
                        glPopMatrix();
                }
 
-               bool isVisible(const camera& cam)
+               bool isVisible(const Camera& cam)
                {
                        return false;
                }
 
        private:
-               unsigned index;
-               scalar texCoords[8];
+               Tilemap::Index  index;
+               Scalar                  texCoords[8];
        };
 
 
-       static bool loadBox(aabb& theBox, serializable_ptr obj)
+       static bool loadBox(Aabb& theBox, SerializablePtr obj)
        {
-               std::vector<serializable_ptr> numbers;
+               std::vector<SerializablePtr> numbers;
 
                if (obj->get(numbers))
                {
@@ -250,23 +249,23 @@ class scene::scene_impl : public mippleton<scene_impl>
        }
 
 public:
-       scene_impl(const std::string& name) :
-               mippleton<scene_impl>(name)
+       SceneImpl(const std::string& name) :
+               Mippleton<SceneImpl>(name)
        {
                loadFromFile();
        }
 
 
-       void loadInstructions(serializable_ptr root)
+       void loadInstructions(SerializablePtr root)
        {
-               std::vector<serializable_ptr> rootObj;
+               std::vector<SerializablePtr> rootObj;
 
                if (root->get(rootObj))
                {
-                       std::vector<serializable_ptr>::iterator it;
+                       std::vector<SerializablePtr>::iterator it;
 
-                       matrix4 transform;
-                       std::string texture;
+                       Matrix4         transform;
+                       std::string     texture;
 
                        for (it = rootObj.begin(); it != rootObj.end(); it++)
                        {
@@ -281,14 +280,14 @@ public:
                                        }
                                        else if (instruction == "translate")
                                        {
-                                               std::vector<serializable_ptr> values;
+                                               std::vector<SerializablePtr> values;
 
                                                it++;
                                                if ((*it)->get(values))
                                                {
-                                                       vector3 vec;
+                                                       Vector3 vec;
 
-                                                       for (unsigned i = 0; i < values.size(); i++)
+                                                       for (size_t i = 0; i < values.size(); i++)
                                                        {
                                                                double value;
 
@@ -298,7 +297,7 @@ public:
                                                                }
                                                        }
 
-                                                       matrix4 translation;
+                                                       Matrix4 translation;
                                                        cml::matrix_translation(translation, vec);
                                                        transform = translation * transform;
                                                        //std::cout << "TRANSLATE\t" << vec << std::endl
@@ -307,7 +306,7 @@ public:
                                        }
                                        else if (instruction == "scale")
                                        {
-                                               std::vector<serializable_ptr> values;
+                                               std::vector<SerializablePtr> values;
 
                                                it++;
                                                if ((*it)->get(values))
@@ -318,17 +317,17 @@ public:
 
                                                                values[0]->getNumber(value);
 
-                                                               matrix4 scaling;
-                                                               cml::matrix_uniform_scale(scaling, scalar(value));
+                                                               Matrix4 scaling;
+                                                               cml::matrix_uniform_scale(scaling, Scalar(value));
                                                                transform = scaling * transform;
                                                                //std::cout << "SCALE\t\t" << value << std::endl
                                                                        //<< transform << std::endl;
                                                        }
                                                        else if (values.size() == 3)
                                                        {
-                                                               vector3 vec;
+                                                               Vector3 vec;
 
-                                                               for (unsigned i = 0; i < values.size(); i++)
+                                                               for (size_t i = 0; i < values.size(); i++)
                                                                {
                                                                        double value;
 
@@ -338,7 +337,7 @@ public:
                                                                        }
                                                                }
 
-                                                               matrix4 scaling;
+                                                               Matrix4 scaling;
                                                                cml::matrix_scale(scaling, vec);
                                                                transform = scaling * transform;
                                                                //std::cout << "SCALE\t\t" << vec << std::endl
@@ -348,7 +347,7 @@ public:
                                        }
                                        else if (instruction == "rotate")
                                        {
-                                               std::vector<serializable_ptr> values;
+                                               std::vector<SerializablePtr> values;
 
                                                it++;
                                                if ((*it)->get(values))
@@ -377,7 +376,7 @@ public:
                                                                }
 
                                                                cml::matrix_rotate_about_local_axis(transform,
-                                                                               axisIndex, scalar(value * cml::constantsd::rad_per_deg()));
+                                                                               axisIndex, Scalar(value * cml::constantsd::rad_per_deg()));
                                                                //std::cout << "ROTATE\t" << axis << " " << value << std::endl
                                                                        //<< transform << std::endl;
                                                        }
@@ -394,8 +393,9 @@ public:
                                                //std::cout << transform << std::endl;
 
                                                it++;
-                                               tiles* newTiles = new tiles(transform, texture, *it);
-                                               boost::shared_ptr<scenery> sceneItem(newTiles);
+                                               TilePanel* tilePanel = new TilePanel(transform, texture,
+                                                               *it);
+                                               boost::shared_ptr<Scenery> sceneItem(tilePanel);
                                                objects.push_back(sceneItem);
                                        }
                                        else if (instruction == "billboard")
@@ -404,9 +404,9 @@ public:
                                                //std::cout << transform << std::endl;
 
                                                it++;
-                                               billboard* newBB = new billboard(transform, texture,
+                                               Billboard* billboard = new Billboard(transform, texture,
                                                                *it);
-                                               boost::shared_ptr<scenery> sceneItem(newBB);
+                                               boost::shared_ptr<Scenery> sceneItem(billboard);
                                                objects.push_back(sceneItem);
                                        }
                                }
@@ -417,19 +417,19 @@ public:
 
        void loadFromFile()
        {
-               std::string filePath = scene::getPathToResource(getName());
+               std::string filePath = Scene::getPathToResource(getName());
 
-               deserializer in(filePath, true);
+               Deserializer deserializer(filePath, true);
 
-               serializable_ptr root = in.deserialize();
+               SerializablePtr root = deserializer.deserialize();
 
                if (root)
                {
-                       std::map<std::string,serializable_ptr> rootObj;
+                       std::map<std::string,SerializablePtr> rootObj;
 
                        if (root->get(rootObj))
                        {
-                               std::map<std::string,serializable_ptr>::iterator it;
+                               std::map<std::string,SerializablePtr>::iterator it;
 
                                if ((it = rootObj.find("playfield_bounds")) != rootObj.end())
                                {
@@ -448,9 +448,9 @@ public:
        }
 
 
-       void draw(scalar alpha)
+       void draw(Scalar alpha)
        {
-               scenery_list::iterator it;
+               SceneryVector::iterator it;
 
                for (it = objects.begin(); it != objects.end(); it++)
                {
@@ -460,23 +460,23 @@ public:
        }
 
 
-       aabb playfieldBounds;
-       aabb maximumBounds;
+       Aabb playfieldBounds;
+       Aabb maximumBounds;
 
-       typedef std::vector<boost::shared_ptr<scenery> > scenery_list;
-       scenery_list objects;
+       typedef std::vector<boost::shared_ptr<Scenery> > SceneryVector;
+       SceneryVector objects;
 };
 
 
-scene::scene(const std::string& name) :
+Scene::Scene(const std::string& name) :
        // pass through
-       impl(scene::scene_impl::retain(name), &scene::scene_impl::release) {}
+       impl_(Scene::SceneImpl::retain(name), &Scene::SceneImpl::release) {}
 
 
-void scene::draw(scalar alpha)
+void Scene::draw(Scalar alpha)
 {
        // pass through
-       impl->draw(alpha);
+       impl_->draw(alpha);
 }
 
 
@@ -485,13 +485,13 @@ void scene::draw(scalar alpha)
  * "scenes" subdirectory of any of the searched directories.
  */
 
-std::string scene::getPathToResource(const std::string& name)
+std::string Scene::getPathToResource(const std::string& name)
 {
-       return resource::getPathToResource("scenes/" + name + ".json");
+       return Resource::getPathToResource("scenes/" + name + ".json");
 }
 
 
-} // namespace dc
+} // namespace Mf
 
 /** vim: set ts=4 sw=4 tw=80: *************************************************/
 
This page took 0.043572 seconds and 4 git commands to generate.