]> Dogcows Code - chaz/yoink/commitdiff
beginning CD implementation
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 8 Nov 2009 21:42:59 +0000 (14:42 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 8 Nov 2009 21:42:59 +0000 (14:42 -0700)
13 files changed:
configure.ac
data/Makefile.am
doc/yoink.6.in
src/Character.cc
src/Character.hh
src/GameLayer.cc
src/MainLayer.cc
src/Makefile.am
src/Moof/Octree.hh
src/Moof/Sphere.hh
src/Scene.cc
src/Scene.hh
src/version.h [new file with mode: 0644]

index d591ee7af3ec31d99fe4cbc41870831b7e0d36f8..a9018e12b8b7373350d1a9fa237c8adbe738d24c 100644 (file)
@@ -125,6 +125,8 @@ if test x$profile = xyes
 then
        CFLAGS="$CFLAGS -pg"
        CXXFLAGS="$CXXFLAGS -pg"
+       AC_DEFINE([PROFILING_ENABLED], 1,
+                         [Define to 1 if profiling is built in.])
 fi
 
 if test x$extra_warnings = xyes
index 61318d22ba4d39c6adc67a0e6aafe14d1f4b453e..0ab79587e2201606825cc87b4626456c83335717 100644 (file)
@@ -1,5 +1,5 @@
 
-nobase_dist_pkgdata_DATA = @DATA_FILES@ yoinkrc
+nobase_dist_pkgdata_DATA = @DATA_FILES@
 
 appsdir=$(prefix)/share/applications
 dist_apps_DATA = yoink.desktop
index 5742a5e51963b9dcc518380c0abbb358133ad101..809faab292e91b7a0d49d1c94753424fd46ce61e 100644 (file)
@@ -28,7 +28,7 @@
 .SH NAME
 Yoink \- An alien-smashing action game.
 .SH SYNOPSIS
-.B yoink [-h|--help] [OPTION=VALUE]...
+.B yoink [-h|--help] [-i|--info] [OPTION=VALUE]...
 .br
 .SH DESCRIPTION
 .PP
@@ -42,7 +42,10 @@ arcade games like Joust, Bombjack, Rampage, and Defender--simple, fast-moving
 action.  Basic arguments include:
 .TP
 .B -h, --help
-Display this help and exit.
+Display basic usage information, and exit immediately.
+.TP
+.B -i, --info
+Display build and environment details, and exit immediately.
 .br
 .SH TIPS
 .PP
index a29e63d792fd50d17935f6dc1d3bb82067cc2903..e0ce1c05c016afa66b9ff4612f125808bc2cade4 100644 (file)
@@ -83,11 +83,11 @@ Character::Character(const std::string& name) :
        current.mass = 1.0;
        current.inverseMass = 1.0 / current.mass;
 
-       // gravity
-       current.force = Mf::Vector2(0.0, 000.0);
+       // forces
+       current.force = Mf::Vector2(0.0, 0.0);
        current.forces.push_back(SpringForce(Mf::Vector2(500.0, 200.0)));
-       current.forces.push_back(ResistanceForce(4.0));
-       current.forces.push_back(Mf::LinearState<2>::GravityForce(-2000.0));
+       current.forces.push_back(ResistanceForce(2.0));
+       current.forces.push_back(Mf::LinearState<2>::GravityForce(-1000.0));
 
        // starting position
        current.position = Mf::Vector2(64.0, 64.0);
@@ -120,6 +120,13 @@ void Character::update(Mf::Scalar t, Mf::Scalar dt)
 
        current.integrate(t, dt);
        animation.update(t, dt);
+
+       Mf::Vector3 center(current.position[0], current.position[1], z);
+       Mf::Vector3 a(current.position[0] - 16.0, current.position[1] - 16.0, z);
+       Mf::Vector3 b(current.position[0] + 16.0, current.position[1] + 16.0, z);
+
+       aabb_.init(a, b);
+       sphere_.init(center, a);
 }
 
 
@@ -165,5 +172,131 @@ void Character::draw(Mf::Scalar alpha) const
 }
 
 
+bool Character::isInsideAabb(const Mf::Aabb& aabb) const
+{
+       // make sure the entity is fully inside the volume
+       if (!(aabb_.max[0] < aabb.max[0] &&
+                 aabb_.min[0] > aabb.min[0] &&
+                 aabb_.max[1] < aabb.max[1] &&
+                 aabb_.min[1] > aabb.min[1] &&
+                 aabb_.max[2] < aabb.max[2] &&
+                 aabb_.min[2] > aabb.min[2]))
+       {
+               return false;
+       }
+
+       return true;
+}
+
+int Character::getOctant(const Mf::Aabb& aabb) const
+{
+       int octantNum = -1;
+
+       Mf::Plane::Halfspace halfspace;
+
+       Mf::Plane xy = aabb.getPlaneXY();
+       halfspace = xy.intersects(sphere_);
+       if (halfspace == Mf::Plane::INTERSECT)
+       {
+               halfspace = xy.intersects(aabb_);
+       }
+
+       if (halfspace == Mf::Plane::POSITIVE)
+       {
+               Mf::Plane xz = aabb.getPlaneXZ();
+               halfspace = xz.intersects(sphere_);
+               if (halfspace == Mf::Plane::INTERSECT)
+               {
+                       halfspace = xz.intersects(aabb_);
+               }
+
+               if (halfspace == Mf::Plane::POSITIVE)
+               {
+                       Mf::Plane yz = aabb.getPlaneYZ();
+                       halfspace = yz.intersects(sphere_);
+                       if (halfspace == Mf::Plane::INTERSECT)
+                       {
+                               halfspace = yz.intersects(aabb_);
+                       }
+
+                       if (halfspace == Mf::Plane::POSITIVE)
+                       {
+                               octantNum = 2;
+                       }
+                       else if (halfspace == Mf::Plane::NEGATIVE)
+                       {
+                               octantNum = 3;
+                       }
+               }
+               else if (halfspace == Mf::Plane::NEGATIVE)
+               {
+                       Mf::Plane yz = aabb.getPlaneYZ();
+                       halfspace = yz.intersects(sphere_);
+                       if (halfspace == Mf::Plane::INTERSECT)
+                       {
+                               halfspace = yz.intersects(aabb_);
+                       }
+
+                       if (halfspace == Mf::Plane::POSITIVE)
+                       {
+                               octantNum = 1;
+                       }
+                       else if (halfspace == Mf::Plane::NEGATIVE)
+                       {
+                               octantNum = 0;
+                       }
+               }
+       }
+       else if (halfspace == Mf::Plane::NEGATIVE)
+       {
+               Mf::Plane xz = aabb.getPlaneXZ();
+               halfspace = xz.intersects(sphere_);
+               if (halfspace == Mf::Plane::INTERSECT)
+               {
+                       halfspace = xz.intersects(aabb_);
+               }
+
+               if (halfspace == Mf::Plane::POSITIVE)
+               {
+                       Mf::Plane yz = aabb.getPlaneYZ();
+                       halfspace = yz.intersects(sphere_);
+                       if (halfspace == Mf::Plane::INTERSECT)
+                       {
+                               halfspace = yz.intersects(aabb_);
+                       }
+
+                       if (halfspace == Mf::Plane::POSITIVE)
+                       {
+                               octantNum = 6;
+                       }
+                       else if (halfspace == Mf::Plane::NEGATIVE)
+                       {
+                               octantNum = 7;
+                       }
+               }
+               else if (halfspace == Mf::Plane::NEGATIVE)
+               {
+                       Mf::Plane yz = aabb.getPlaneYZ();
+                       halfspace = yz.intersects(sphere_);
+                       if (halfspace == Mf::Plane::INTERSECT)
+                       {
+                               halfspace = yz.intersects(aabb_);
+                       }
+
+                       if (halfspace == Mf::Plane::POSITIVE)
+                       {
+                               octantNum = 5;
+                       }
+                       else if (halfspace == Mf::Plane::NEGATIVE)
+                       {
+                               octantNum = 4;
+                       }
+               }
+       }
+
+       return octantNum;
+}
+
+
 /** vim: set ts=4 sw=4 tw=80: *************************************************/
 
index 19559f38b0f54be1643f31fc29f2949323be977b..50c3da51a6418582569a88145be462acc5b017d6 100644 (file)
 
 #include <boost/shared_ptr.hpp>
 
+#include <Moof/Aabb.hh>
 #include <Moof/Entity.hh>
 #include <Moof/Math.hh>
-#include <Moof/RK4.hh>
+#include <Moof/Octree.hh>
+#include <Moof/Physics.hh>
+#include <Moof/Sphere.hh>
 
 #include "Animation.hh"
 #include "Tilemap.hh"
@@ -49,7 +52,7 @@ typedef boost::shared_ptr<Character> CharacterP;
  * includes the heroine herself and the bad guys.
  */
 
-struct Character : public Mf::Entity
+struct Character : public Mf::Entity, public Mf::OctreeInsertable
 {
 protected:
 
@@ -63,9 +66,21 @@ public:
        virtual void update(Mf::Scalar t, Mf::Scalar dt);
        virtual void draw(Mf::Scalar alpha) const;
 
+       virtual bool isInsideAabb(const Mf::Aabb& aabb) const;
+       virtual int getOctant(const Mf::Aabb& aabb) const;
 
-       Tilemap         tilemap;
-       Animation       animation;
+       Mf::State2              previous;
+       Mf::State2              current;
+
+       Tilemap                 tilemap;
+       Animation               animation;
+
+       Mf::Aabb                aabb_;
+       Mf::Sphere              sphere_;
+
+private:
+
+       static const Mf::Scalar z = 96.0;
 };
 
 
index 2035248115869afdb4a42cb16647be34f29014d0..e7ab9e849a4b100773e7c550bf7ab7280d4dc737 100644 (file)
@@ -72,6 +72,8 @@ void GameLayer::update(Mf::Scalar t, Mf::Scalar dt)
        camera.update(t, dt);
        heroine->update(t, dt);
 
+       scene->checkForCollision(*heroine);
+
        //camera.lookAt(heroine->getSphere().point);
        camera.setPosition(Mf::Vector3(-heroine->current.position[0],
                                -heroine->current.position[1], -256));
index 2266326402f89b475df8c1a57b3f4abd3dba9d37..4975e17f1b28db30e9df1d95a73469a9f6a85456 100644 (file)
@@ -27,7 +27,6 @@
 *******************************************************************************/
 
 #include <cstdlib>             // atexit, getenv
-#include <cstring>
 #include <iostream>
 #include <string>
 
@@ -46,6 +45,7 @@
 #if HAVE_CONFIG_H
 #include "config.h"
 #endif
+#include "version.h"
 
 
 MainLayer::MainLayer()
@@ -171,12 +171,14 @@ void MainLayer::contextRecreated(const Mf::Notification* note)
 
 void printUsage()
 {
-       std::cout << "Usage: "PACKAGE" [-h|--help] [OPTION=VALUE]..." << std::endl
+       std::cout << "Usage: "PACKAGE" [-h|--help] [-i|--info] [OPTION=VALUE]..." << std::endl
                          << "The alien-smashing action game." << std::endl
                          << std::endl
                          << "Options:" << std::endl
                          << "  -h, --help" << std::endl
                          << "      show this help and exit" << std::endl
+                         << "  -i, --info" << std::endl
+                         << "      show version and build information" << std::endl
                          << "  detail=1|2|3" << std::endl
                          << "      the level of detail of game scenes" << std::endl
                          << "  fullscreen=true|false" << std::endl
@@ -187,18 +189,55 @@ void printUsage()
                          << "See documentation for more options." << std::endl;
 }
 
+void printInfo()
+{
+       std::cout << PACKAGE_STRING << std::endl
+#ifdef __DATE__
+                         << "When compiled: "__DATE__" "__TIME__ << std::endl
+#endif
+                         << "Compiler: "COMPILER_STRING << std::endl
+                         << "Asset directory: "YOINK_DATADIR << std::endl
+                         << "Build options: "
+#ifdef NDEBUG
+                         << "-"
+#endif
+                         << "debug "
+#ifndef USE_DOUBLE_PRECISION
+                         << "-"
+#endif
+                         << "double "
+#ifndef PROFILING_ENABLED
+                         << "-"
+#endif
+                         << "profile "
+                         << std::endl;
+#if !defined (_WIN32) && !defined(__WIN32__)
+       system("uname -a");
+#endif
+}
+
 void goodbye()
 {
        std::cout << std::endl << "Goodbye..." << std::endl << std::endl;
 }
 
+
+
 int main(int argc, char* argv[])
 {
-       if (argc > 1 &&
-                       (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0))
+       if (argc > 1)
        {
-               printUsage();
-               return 0;
+               std::string arg(argv[1]);
+               if (arg == "-h" || arg == "--help")
+               {
+                       printUsage();
+                       return 0;
+               }
+               else if (arg == "-i" || arg == "--info")
+               {
+                       printInfo();
+                       return 0;
+               }
        }
 
        std::cout << std::endl << PACKAGE_STRING << std::endl
index a7598d40e740b65482534a8c936e59edd1cfd2e3..7c4e61c83cbd7bbf095f9e67c6d44030a165d675 100644 (file)
@@ -103,6 +103,7 @@ yoink_SOURCES = \
                                TitleLayer.hh \
                                Typesetter.cc \
                                Typesetter.hh \
+                               version.h \
                                $(ENDLIST)
 
 if WIN32
index cdac62a29071f4eeaeb51c48c055e84db1a029dc..88dae7ac6492e587d1bb133516a27b4343d98735 100644 (file)
 namespace Mf {
 
 
-//class Octree;
-//typedef boost::shared_ptr<Octree> OctreeP;
-
-//class Octree::Node;
-//typedef stlplus::ntree<Octree::Node>::iterator OctreeNodeP;
-
-
 struct OctreeInsertable
 {
        virtual ~OctreeInsertable() {}
@@ -85,30 +78,36 @@ class Octree : public Entity
 
                void draw(Scalar alpha) const
                {
-                       typename std::list<InsertableP>::const_iterator it;
+                       aabb.draw(alpha);
+               }
 
-                       for (it = objects.begin(); it != objects.end(); ++it)
+               void drawIfVisible(Scalar alpha, const Frustum& frustum) const
+               {
+                       if (isVisible(frustum))
                        {
-                               (*it)->draw(alpha);
+                               aabb.draw(alpha);
                        }
+               }
 
-                       if (!objects.empty())
-                               aabb.draw(); // temporary
+               void printSize()
+               {
+                       logDebug("size of node %d", objects.size());
                }
 
-               void drawIfVisible(Scalar alpha, const Frustum& frustum) const
+               void getAll(std::list<InsertableP>& insertables) const
+               {
+                       insertables.insert(insertables.end(), objects.begin(),
+                                       objects.end());
+               }
+
+               void getIfVisible(std::list<InsertableP>& insertables,
+                               const Frustum& frustum) const
                {
                        typename std::list<InsertableP>::const_iterator it;
 
                        for (it = objects.begin(); it != objects.end(); ++it)
                        {
-                               (*it)->drawIfVisible(alpha, frustum);
-                       }
-
-                       if (!objects.empty())
-                       {
-                               //aabb.draw();
-                               //sphere.draw();
+                               if ((*it)->isVisible(frustum)) insertables.push_back(*it);
                        }
                }
 
@@ -170,7 +169,7 @@ private:
                        NodeP child = tree_.child(node, octantNum);
                        ASSERT(child.valid() && "expected valid child node");
 
-                       return insert(entity, child);
+                       return insert_recurse(entity, child);
                }
        }
 
@@ -188,22 +187,51 @@ private:
        }
 
 
-       void draw(Scalar alpha, NodeP node) const
+       void getNearbyObjects(std::list<InsertableP>& insertables,
+                       const OctreeInsertable& entity, NodeP node) const
        {
                ASSERT(node.valid() && "invalid node passed");
 
-               node->draw(alpha);
+               node->printSize();
+
+               int octantNum = entity.getOctant(node->aabb);
+               if (octantNum != -1)
+               {
+                       node->getAll(insertables);
+
+                       if (octantNum < (int)tree_.children(node))
+                       {
+                               NodeP child = tree_.child(node, octantNum);
+                               ASSERT(child.valid() && "expected valid child node");
+
+                               getNearbyObjects(insertables, entity, child);
+                       }
+               }
+               else
+               {
+                       logDebug("getting all the rest...");
+                       getAll(insertables, node);
+               }
+       }
+
+
+       void getAll(std::list<InsertableP>& insertables, NodeP node) const
+       {
+               ASSERT(node.valid() && "invalid node passed");
+
+               node->getAll(insertables);
 
                for (unsigned i = 0; i < tree_.children(node); ++i)
                {
                        NodeP child = tree_.child(node, i);
                        ASSERT(child.valid() && "expected valid child node");
 
-                       draw(alpha, child);
+                       getAll(insertables, child);
                }
        }
 
-       void drawIfVisible(Scalar alpha, const Frustum& frustum, NodeP node) const
+       void getIfVisible(std::list<InsertableP>& insertables,
+                       const Frustum& frustum, NodeP node) const
        {
                ASSERT(node.valid() && "invalid node passed");
 
@@ -218,11 +246,11 @@ private:
 
                if (collision == Frustum::INSIDE)
                {
-                       node->draw(alpha);
+                       node->getAll(insertables);
                }
                else // collision == Frustum::INTERSECT
                {
-                       node->drawIfVisible(alpha, frustum);
+                       node->getIfVisible(insertables, frustum);
                }
 
                if (tree_.children(node) > 0)
@@ -234,7 +262,7 @@ private:
                                        NodeP child = tree_.child(node, i);
                                        ASSERT(child.valid() && "expected valid child node");
 
-                                       draw(alpha, child);
+                                       getAll(insertables, child);
                                }
                        }
                        else // collision == Frustum::INTERSECT
@@ -244,12 +272,13 @@ private:
                                        NodeP child = tree_.child(node, i);
                                        ASSERT(child.valid() && "expected valid child node");
 
-                                       drawIfVisible(alpha, frustum, child);
+                                       getIfVisible(insertables, frustum, child);
                                }
                        }
                }
        }
 
+
        mutable stlplus::ntree<Node> tree_;
 
 
@@ -257,9 +286,9 @@ public:
 
        void print(NodeP node)
        {
-               //logDebug("-----");
-               //logDebug("depth to node: %d", tree_.depth(node));
-               //logDebug("size of node: %d", tree_.size(node));
+               logInfo("-----");
+               logInfo("depth to node: %d", tree_.depth(node));
+               logInfo("size of node: %d", tree_.size(node));
        }
 
        static Ptr alloc(const Node& rootNode)
@@ -272,12 +301,13 @@ public:
                tree_.insert(rootNode);
        }
 
+
        NodeP insert(InsertableP entity)
        {
                return insert(entity, tree_.root());
        }
 
-       NodeP reinsert(InsertableP entity, NodeP node)
+       void remove(InsertableP entity, NodeP node)
        {
                ASSERT(entity && "null entity passed");
                ASSERT(node.valid() && "invalid node passed");
@@ -289,18 +319,63 @@ public:
                {
                        node->objects.erase(it);
                }
+       }
 
+
+       NodeP reinsert(InsertableP entity, NodeP node)
+       {
+               remove(entity, node);
                return insert(entity);
        }
 
+
        void draw(Scalar alpha) const
        {
-               draw(alpha, tree_.root());
+               std::list<InsertableP> objects;
+               getAll(objects);
+
+               typename std::list<InsertableP>::const_iterator it;
+               for (it = objects.begin(); it != objects.end(); ++it)
+               {
+                       (*it)->draw(alpha);
+               }
        }
 
        void drawIfVisible(Scalar alpha, const Frustum& frustum) const
        {
-               drawIfVisible(alpha, frustum, tree_.root());
+               std::list<InsertableP> objects;
+               //getIfVisible(objects, frustum);
+               getNearbyObjects(objects, *savedObj);
+
+               typename std::list<InsertableP>::const_iterator it;
+               for (it = objects.begin(); it != objects.end(); ++it)
+               {
+                       (*it)->draw(alpha);
+               }
+       }
+
+
+       void getAll(std::list<InsertableP>& insertables) const
+       {
+               getAll(insertables, tree_.root());
+       }
+
+       void getIfVisible(std::list<InsertableP>& insertables,
+                       const Frustum& frustum) const
+       {
+               getIfVisible(insertables, frustum, tree_.root());
+       }
+
+       mutable const OctreeInsertable* savedObj;
+
+
+       void getNearbyObjects(std::list<InsertableP>& insertables,
+                       const OctreeInsertable& entity) const
+       {
+               logDebug("--- GETTING NEARBY");
+               getNearbyObjects(insertables, entity, tree_.root());
+               logDebug("---");
+               savedObj = &entity;
        }
 };
 
index 7f7a76373dfd7f0d228f33c9c36379c25a57959c..d6903564eac5309c59f6f793eef60e8ea0c0844b 100644 (file)
@@ -62,6 +62,12 @@ struct Sphere : public Cullable, public Drawable
                radius = r;
        }
 
+       void init(const Vector3& p, const Vector3& o)
+       {
+               point = p;
+               radius = (o - p).length();
+       }
+
        void encloseVertices(const Vector3 vertices[], unsigned count);
 
        void draw(Scalar alpha = 0.0) const;
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");
index ca96aeaca15d93d5053919afa98d5cbd5b38822b..24a790f26490a7cd2edc0da1fe798aaca19200ef 100644 (file)
@@ -38,6 +38,9 @@
 #include <Moof/Resource.hh>
 
 
+class Character;
+
+
 class Scene;
 typedef boost::shared_ptr<Scene> SceneP;
 
@@ -58,6 +61,8 @@ public:
        void draw(Mf::Scalar alpha) const;
        void drawIfVisible(Mf::Scalar alpha, const Mf::Frustum& frustum) const;
 
+       bool checkForCollision(Character& character);
+
        static std::string getPath(const std::string& name);
 };
 
diff --git a/src/version.h b/src/version.h
new file mode 100644 (file)
index 0000000..5937771
--- /dev/null
@@ -0,0 +1,84 @@
+
+/*******************************************************************************
+
+ Copyright (c) 2009, Charles McGarvey
+ All rights reserved.
+ Redistribution   and   use  in  source  and  binary  forms,  with  or  without
+ modification, are permitted provided that the following conditions are met:
+   * Redistributions  of  source  code  must retain the above copyright notice,
+     this list of conditions and the following disclaimer.
+   * Redistributions  in binary form must reproduce the above copyright notice,
+     this  list of conditions and the following disclaimer in the documentation
+     and/or other materials provided with the distribution.
+ THIS  SOFTWARE  IS  PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND  ANY  EXPRESS  OR  IMPLIED  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED.  IN  NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES  (INCLUDING,  BUT  NOT  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES;  LOSS  OF  USE,  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ CAUSED  AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ OR  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+#ifndef _VERSION_H_
+#define _VERSION_H_
+
+
+// yoinked from fluxbox
+
+#ifdef __VERSION__
+#define COMPILER_VERSION __VERSION__
+
+#ifdef __GNUG__
+#define COMPILER_NAME "GCC"
+#endif  // __GNUG__
+
+#elif (defined(__sgi) || defined(sgi)) && __COMPILER_VERSION
+#define COMPILER_NAME "SGI"
+#define COMPILER_VERSION __COMPILER_VERSION
+#elif defined(__MWERKS__)
+#define COMPILER_NAME "MWERKS"
+#define COMPILER_VERSION __MWERKS__
+#elif defined(__INTEL_COMPILER) || defined(__ICC)
+#define COMPILER_NAME "ICC"
+#define COMPILER_VERSION __INTEL_COMPILER
+#elif defined(__SUNPRO_CC)
+#define COMPILER_NAME "SUNPRO_CC"
+#define COMPILER_VERSION __SUNPRO_CC
+#elif defined(__COMO__) && defined(__COMO_VERSION__)
+#define COMPILER_NAME "COMO"
+#define COMPILER_VERSION __COMO_VERSION__
+#elif defined(_CRAYC) && defined(_REVISION)
+#define COMPILER_NAME "GRAYC"
+#define COMPILER_VERSION _REVISION
+#elif defined(__DECCXX) && defined(__DECCXX)
+#define COMPILER_NAME "DECCXX"
+#define COMPILER_VERSION __DECCXX
+#elif defined(__DCC__)
+#define COMPILER_NAME "DCC"
+#define COMPILER_VERSION __VERSION_NUMBER__
+#endif // __VERSION__
+
+#ifdef COMPILER_NAME
+#ifdef COMPILER_VERSION
+#define COMPILER_STRING COMPILER_NAME" "COMPILER_VERSION
+#else
+#define COMPILER_STRING COMPILER_NAME" (unknown version)"
+#define COMPILER_VERSION "Unknown"
+#endif // COMPILER_VERSION
+#else
+#define COMPILER_STRING "Unknown"
+#define COMPILER_NAME "Unknown"
+#endif // COMPILER_NAME
+
+
+#endif // _VERSION_H_
+
+/** vim: set ts=4 sw=4 tw=80: *************************************************/
+
This page took 0.047525 seconds and 4 git commands to generate.