X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FScene.cc;h=bad59bfd79c0c0103e117324f895f003720ceb66;hp=bd9c034c5f4f610ce59b80d93b328debfb71a848;hb=a31d65a998121df0651c57bfb68782e2a07d2e2f;hpb=a4debfe4a5f5d339410788971b698ba00cb7f09c diff --git a/src/Scene.cc b/src/Scene.cc index bd9c034..bad59bf 100644 --- a/src/Scene.cc +++ b/src/Scene.cc @@ -38,40 +38,30 @@ #include #include #include -#include +#include "Character.hh" #include "Scene.hh" +#include "Tilemap.hh" struct Scene::Impl : public Mf::Mippleton { - class Quad : public Mf::Entity, public Mf::OctreeInsertable + struct Quad : public Mf::Entity, public Mf::OctreeInsertable { - Mf::Scalar vertices_[12]; - Mf::Scalar texCoords_[8]; - - Mf::Tilemap tilemap_; - - bool blending_; - bool fog_; - - Mf::Aabb aabb_; - Mf::Sphere sphere_; - - public: - enum SURFACE_TYPE { + NONE = 0, LEFT = 1, RIGHT = 2, TOP = 3 }; Quad(const Mf::Vector3 vertices[4], const std::string& texture, - Mf::Tilemap::Index tileIndex) : + 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 fog_ = fog; } + void setSurfaceType(SURFACE_TYPE type) + { + surfaceType_ = type; + } + void draw(Mf::Scalar alpha = 0.0) const { if (blending_) @@ -263,17 +258,31 @@ struct Scene::Impl : public Mf::Mippleton 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_; + }; + - Mf::Script script; Mf::Matrix4 transform; std::string texture; Mf::Octree::Ptr octree; + Mf::Aabb playfieldBounds; + Mf::Aabb maximumBounds; + enum AXIS { @@ -287,10 +296,6 @@ struct Scene::Impl : public Mf::Mippleton explicit Impl(const std::string& name) : Mf::Mippleton(name) { - script.importStandardLibraries(); - importLogScript(script); - - importSceneBindings(script); loadFromFile(); } @@ -315,24 +320,29 @@ struct Scene::Impl : public Mf::Mippleton 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"); - script.push(Quad::LEFT); script.set("LEFT"); - script.push(Quad::RIGHT); script.set("RIGHT"); - script.push(Quad::TOP); script.set("TOP"); - script.push(X); script.set("X"); script.push(Y); script.set("Y"); script.push(Z); script.set("Z"); + + script.push(Quad::LEFT); script.set("LEFT"); + script.push(Quad::RIGHT); script.set("RIGHT"); + script.push(Quad::TOP); script.set("TOP"); } void loadFromFile() { + Mf::Script script; std::string filePath = Scene::getPath(getName()); + script.importStandardLibraries(); + importLogScript(script); + importSceneBindings(script); + if (script.doFile(filePath) != Mf::Script::SUCCESS) { std::string str; @@ -350,17 +360,11 @@ struct Scene::Impl : public Mf::Mippleton 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(); } } @@ -377,15 +381,13 @@ struct Scene::Impl : public Mf::Mippleton 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::alloc(bounds); + int ret = loadBox(script, maximumBounds); + octree = Mf::Octree::alloc(maximumBounds); return ret; } @@ -445,7 +447,7 @@ struct Scene::Impl : public Mf::Mippleton int rotate(Mf::Script& script) { - Mf::Script::Value axis = script[1].requireString(); + Mf::Script::Value axis = script[1].requireNumber(); Mf::Script::Value angle = script[2].requireNumber(); size_t index = 0; @@ -461,10 +463,7 @@ struct Scene::Impl : public Mf::Mippleton int setTexture(Mf::Script& script) { - Mf::Script::Value name = script[1].requireString(); - - name.get(texture); - + script[1].requireString().get(texture); return 0; } @@ -473,13 +472,17 @@ struct Scene::Impl : public Mf::Mippleton 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(); @@ -487,32 +490,31 @@ struct Scene::Impl : public Mf::Mippleton if (nTiles % width != 0) table.throwError("invalid number of tiles"); - std::vector< std::vector > indices; + std::vector< std::vector > indices; int i, w, h; height = nTiles / width; indices.resize(height); - // the indices are stored upside-down in the scene file so that they - // are easier to edit as text, so we'll need to load them last row - // first + // the indices are stored upside-down in the scene file so that they are + // easier to edit as text, so we'll need to load them last row first i = 1; for (h = height - 1; h >= 0; --h) { - std::vector row; + std::vector row; for (w = 0; w < width; ++w, ++i) { script.checkStack(2); - script.push(long(i)); + script.push(i); tiles.pushField(); - long index; + Tilemap::Index index; top.get(index); - row.push_back(Mf::Tilemap::Index(index)); + row.push_back(index); } indices[h] = row; @@ -527,8 +529,7 @@ struct Scene::Impl : public Mf::Mippleton { for (int w = 0; w <= width; ++w) { - vertices[h][w] = Mf::Vector4(Mf::Scalar(w), Mf::Scalar(h), 0.0, 1.0) * - transposedTransform; + vertices[h][w] = Mf::Vector4(w, h, 0.0, 1.0) * transposedTransform; } } @@ -536,18 +537,19 @@ struct Scene::Impl : public Mf::Mippleton { for (int w = 0; w < width; ++w) { - if (indices[h][w] == Mf::Tilemap::NO_TILE) continue; + 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 quadPtr(quad); + Quad* quad = new Quad(demotedVertices, texture, indices[h][w]); + quad->setSurfaceType(surfaceType); + boost::shared_ptr quadPtr(quad); octree->insert(quadPtr); } } @@ -560,10 +562,10 @@ struct Scene::Impl : public Mf::Mippleton 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()) { @@ -600,19 +602,18 @@ struct Scene::Impl : public Mf::Mippleton 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, Mf::Tilemap::Index(index)); + Quad* quad = new Quad(demotedVertices, texture, index); quad->setBlending(blending); quad->setFog(fog); boost::shared_ptr quadPtr(quad); - octree->insert(quadPtr); } @@ -623,17 +624,29 @@ struct Scene::Impl : public Mf::Mippleton Scene::Scene(const std::string& name) : // pass through - impl_(Scene::Impl::getInstance(name)) {} + mImpl(Scene::Impl::getInstance(name)) {} void Scene::draw(Mf::Scalar alpha) const { - impl_->octree->draw(alpha); + mImpl->octree->draw(alpha); } void Scene::drawIfVisible(Mf::Scalar alpha, const Mf::Frustum& frustum) const { - impl_->octree->drawIfVisible(alpha, frustum); + mImpl->octree->drawIfVisible(alpha, frustum); +} + + +bool Scene::checkForCollision(Character& character) +{ + std::list< boost::shared_ptr > objects; + //std::list::InsertableP> objects; + mImpl->octree->getNearbyObjects(objects, character); + mImpl->maximumBounds.draw(); + + Mf::logDebug("nearby objects: %d", objects.size()); + return false; }