X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FScene.cc;fp=src%2Fscene.cc;h=f4dd1c0e3f9597bdd7505ed236bd3d91591fc40c;hp=04754ea1730e22fb24b53e19bcba976122124155;hb=c2321281bf12a7efaedde930422c7ddbc92080d4;hpb=87bc17e55b0c1dc73ecc66df856d3f08fd7a7724 diff --git a/src/scene.cc b/src/Moof/Scene.cc similarity index 70% rename from src/scene.cc rename to src/Moof/Scene.cc index 04754ea..f4dd1c0 100644 --- a/src/scene.cc +++ b/src/Moof/Scene.cc @@ -30,54 +30,53 @@ #include #include -#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 +class Scene::SceneImpl : public Mippleton { - 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 rootObj; + std::map rootObj; if (root->get(rootObj)) { - std::map::iterator it; + std::map::iterator it; if ((it = rootObj.find("width")) != rootObj.end()) { @@ -85,11 +84,11 @@ class scene::scene_impl : public mippleton } if ((it = rootObj.find("tiles")) != rootObj.end()) { - std::vector theTiles; + std::vector theTiles; if ((*it).second->get(theTiles)) { - std::vector::iterator jt; + std::vector::iterator jt; height = theTiles.size() / width; int w, h; @@ -99,7 +98,7 @@ class scene::scene_impl : public mippleton for (h = height - 1, jt = theTiles.begin(); jt != theTiles.end(); h--) { - std::vector row; + std::vector row; for (w = 0; w < width && jt != theTiles.end(); w++, jt++) @@ -108,7 +107,7 @@ class scene::scene_impl : public mippleton 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 } } - void draw(scalar alpha) + void draw(Scalar alpha) { glPushMatrix(); //std::cout << "transforming..." << std::endl; @@ -130,15 +129,15 @@ class scene::scene_impl : public mippleton 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 glPopMatrix(); } - bool isVisible(const camera& cam) + bool isVisible(const Camera& cam) { return true; } private: long width, height; - std::vector > indices; + std::vector > 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 rootObj; + std::map rootObj; if (root->get(rootObj)) { - std::map::iterator it; + std::map::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 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 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 numbers; + std::vector numbers; if (obj->get(numbers)) { @@ -250,23 +249,23 @@ class scene::scene_impl : public mippleton } public: - scene_impl(const std::string& name) : - mippleton(name) + SceneImpl(const std::string& name) : + Mippleton(name) { loadFromFile(); } - void loadInstructions(serializable_ptr root) + void loadInstructions(SerializablePtr root) { - std::vector rootObj; + std::vector rootObj; if (root->get(rootObj)) { - std::vector::iterator it; + std::vector::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 values; + std::vector 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 values; + std::vector 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 values; + std::vector 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 sceneItem(newTiles); + TilePanel* tilePanel = new TilePanel(transform, texture, + *it); + boost::shared_ptr 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 sceneItem(newBB); + boost::shared_ptr 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 rootObj; + std::map rootObj; if (root->get(rootObj)) { - std::map::iterator it; + std::map::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 > scenery_list; - scenery_list objects; + typedef std::vector > 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: *************************************************/