]> Dogcows Code - chaz/yoink/blobdiff - src/Scene.cc
beginning CD implementation
[chaz/yoink] / src / Scene.cc
index 59ece168a4167089f4f9e056122115fa2f485ae9..cffd382b1a7aaa62a0e1da42e592b6fea83421bf 100644 (file)
 #include <Moof/Script.hh>
 #include <Moof/Settings.hh>
 
+#include "Character.hh"
 #include "Scene.hh"
 #include "Tilemap.hh"
 
 
 struct Scene::Impl : public Mf::Mippleton<Impl>
 {
-       class Quad : public Mf::Entity, public Mf::OctreeInsertable
+       struct Quad : public Mf::Entity, public Mf::OctreeInsertable
        {
-               Mf::Scalar              vertices_[12];
-               Mf::Scalar              texCoords_[8];
-               
-               Tilemap                 tilemap_;
-
-               bool                    blending_;
-               bool                    fog_;
-
-               Mf::Aabb                aabb_;
-               Mf::Sphere              sphere_;
-
-       public:
-
                enum SURFACE_TYPE
                {
+                       NONE    = 0,
                        LEFT    = 1,
                        RIGHT   = 2,
                        TOP             = 3
@@ -71,7 +60,8 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
                                Tilemap::Index tileIndex) :
                        tilemap_(texture),
                        blending_(false),
-                       fog_(false)
+                       fog_(false),
+                       surfaceType_(NONE)
                {
                        for (int i = 0, num = 0; i < 4; ++i)
                        {
@@ -107,6 +97,11 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
                        fog_ = fog;
                }
 
+               void setSurfaceType(SURFACE_TYPE type)
+               {
+                       surfaceType_ = type;
+               }
+
                void draw(Mf::Scalar alpha = 0.0) const
                {
                        if (blending_)
@@ -263,6 +258,19 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
 
                        return octantNum;
                }
+
+
+               Mf::Scalar              vertices_[12];
+               Mf::Scalar              texCoords_[8];
+               
+               Tilemap                 tilemap_;
+
+               bool                    blending_;
+               bool                    fog_;
+               SURFACE_TYPE    surfaceType_;
+
+               Mf::Aabb                aabb_;
+               Mf::Sphere              sphere_;
        };
 
 
@@ -272,6 +280,9 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
 
        Mf::Octree<Quad>::Ptr   octree;
 
+       Mf::Aabb                                playfieldBounds;
+       Mf::Aabb                                maximumBounds;
+
 
        enum AXIS
        {
@@ -309,7 +320,7 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
                script.importFunction("MakeBillboard",
                                boost::bind(&Impl::makeBillboard, this, _1));
 
-               long detail = 3;
+               int detail = 3;
                Mf::Settings::getInstance().get("detail", detail);
                script.push(detail); script.set("detail");
 
@@ -349,17 +360,11 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
                        script[2].requireTable()
                };
 
-               if (!table[0].isTable() || !table[1].isTable())
-               {
-                       Mf::logWarning("wrong arguments to setPlayfieldBounds; ignoring...");
-                       return 0;
-               }
-
                for (int i = 0; i <= 1; ++i)
                {
                        for (int j = 1; j <= 3; ++j)
                        {
-                               script.push((long)j);
+                               script.push(j);
                                table[i].pushField();
                        }
                }
@@ -376,15 +381,13 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
 
        int setPlayfieldBounds(Mf::Script& script)
        {
-               Mf::Aabb bounds;
-               return loadBox(script, bounds);
+               return loadBox(script, playfieldBounds);
        }
 
        int setMaximumBounds(Mf::Script& script)
        {
-               Mf::Aabb bounds;
-               int ret = loadBox(script, bounds);
-               octree = Mf::Octree<Quad>::alloc(bounds);
+               int ret = loadBox(script, maximumBounds);
+               octree = Mf::Octree<Quad>::alloc(maximumBounds);
                return ret;
        }
 
@@ -472,13 +475,17 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
                Mf::Script::Value table = script[1].requireTable();
                Mf::Script::Value top = script[-1];
 
-               long width = 1;
-               long height = 1;
+               Quad::SURFACE_TYPE surfaceType;
+               table.pushField("surface_type");
+               top.get(surfaceType);
+
+               int width = 1;
+               int height = 1;
 
                table.pushField("width");
                top.get(width);
 
-               long nTiles = 0;
+               int nTiles = 0;
 
                table.pushField("tiles");
                Mf::Script::Value tiles = script.getTop();
@@ -505,7 +512,7 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
                        for (w = 0; w < width; ++w, ++i)
                        {
                                script.checkStack(2);
-                               script.push(long(i));
+                               script.push(i);
                                tiles.pushField();
 
                                Tilemap::Index index;
@@ -536,16 +543,17 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
                        {
                                if (indices[h][w] == Tilemap::NO_TILE) continue;
 
-                               Mf::Vector3 quadVertices[4];
+                               Mf::Vector3 demotedVertices[4];
 
-                               quadVertices[0] = Mf::demote(vertices[h][w]);
-                               quadVertices[1] = Mf::demote(vertices[h][w+1]);
-                               quadVertices[2] = Mf::demote(vertices[h+1][w+1]);
-                               quadVertices[3] = Mf::demote(vertices[h+1][w]);
+                               demotedVertices[0] = Mf::demote(vertices[h][w]);
+                               demotedVertices[1] = Mf::demote(vertices[h][w+1]);
+                               demotedVertices[2] = Mf::demote(vertices[h+1][w+1]);
+                               demotedVertices[3] = Mf::demote(vertices[h+1][w]);
 
-                               Quad* quad = new Quad(quadVertices, texture, indices[h][w]);
-                               boost::shared_ptr<Quad> quadPtr(quad);
+                               Quad* quad = new Quad(demotedVertices, texture, indices[h][w]);
+                               quad->setSurfaceType(surfaceType);
 
+                               boost::shared_ptr<Quad> quadPtr(quad);
                                octree->insert(quadPtr);
                        }
                }
@@ -558,10 +566,10 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
                Mf::Script::Value table = script[1];
                Mf::Script::Value top = script[-1];
 
-               long    index = 0;
-               long    width = 1;
-               bool    blending = false;
-               bool    fog = false;
+               Tilemap::Index  index = 0;
+               int                             width = 1;
+               bool                    blending = false;
+               bool                    fog = false;
 
                if (table.isTable())
                {
@@ -598,19 +606,18 @@ struct Scene::Impl : public Mf::Mippleton<Impl>
 
                for (int w = 0; w < width; ++w)
                {
-                       Mf::Vector3 quadVertices[4];
+                       Mf::Vector3 demotedVertices[4];
 
-                       quadVertices[0] = Mf::demote(vertices[0][w]);
-                       quadVertices[1] = Mf::demote(vertices[0][w+1]);
-                       quadVertices[2] = Mf::demote(vertices[1][w+1]);
-                       quadVertices[3] = Mf::demote(vertices[1][w]);
+                       demotedVertices[0] = Mf::demote(vertices[0][w]);
+                       demotedVertices[1] = Mf::demote(vertices[0][w+1]);
+                       demotedVertices[2] = Mf::demote(vertices[1][w+1]);
+                       demotedVertices[3] = Mf::demote(vertices[1][w]);
 
-                       Quad* quad = new Quad(quadVertices, texture, Tilemap::Index(index));
+                       Quad* quad = new Quad(demotedVertices, texture, index);
                        quad->setBlending(blending);
                        quad->setFog(fog);
 
                        boost::shared_ptr<Quad> quadPtr(quad);
-
                        octree->insert(quadPtr);
                }
 
@@ -635,6 +642,18 @@ void Scene::drawIfVisible(Mf::Scalar alpha, const Mf::Frustum& frustum) const
 }
 
 
+bool Scene::checkForCollision(Character& character)
+{
+       std::list< boost::shared_ptr<Impl::Quad> > objects;
+       //std::list<Mf::Octree<Impl::Quad>::InsertableP> objects;
+       impl_->octree->getNearbyObjects(objects, character);
+       impl_->maximumBounds.draw();
+
+       Mf::logDebug("nearby objects: %d", objects.size());
+       return false;
+}
+
+
 std::string Scene::getPath(const std::string& name)
 {
        return Mf::Resource::getPath("scenes/" + name + ".lua");
This page took 0.026244 seconds and 4 git commands to generate.