#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())
{
}
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;
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++)
if ((*jt)->get(index))
{
- row.push_back(unsigned(index));
+ row.push_back(Tilemap::Index(index));
}
}
}
}
- void draw(scalar alpha)
+ void draw(Scalar alpha)
{
glPushMatrix();
//std::cout << "transforming..." << std::endl;
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))
{
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);
}
}
}
image.getTileCoords(index, texCoords);
}
- void draw(scalar alpha)
+ void draw(Scalar alpha)
{
glPushMatrix();
glMultMatrixf(transformation.data());
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))
{
}
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++)
{
}
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;
}
}
- matrix4 translation;
+ Matrix4 translation;
cml::matrix_translation(translation, vec);
transform = translation * transform;
//std::cout << "TRANSLATE\t" << vec << std::endl
}
else if (instruction == "scale")
{
- std::vector<serializable_ptr> values;
+ std::vector<SerializablePtr> values;
it++;
if ((*it)->get(values))
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;
}
}
- matrix4 scaling;
+ Matrix4 scaling;
cml::matrix_scale(scaling, vec);
transform = scaling * transform;
//std::cout << "SCALE\t\t" << vec << std::endl
}
else if (instruction == "rotate")
{
- std::vector<serializable_ptr> values;
+ std::vector<SerializablePtr> values;
it++;
if ((*it)->get(values))
}
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;
}
//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")
//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);
}
}
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())
{
}
- void draw(scalar alpha)
+ void draw(Scalar alpha)
{
- scenery_list::iterator it;
+ SceneryVector::iterator it;
for (it = objects.begin(); it != objects.end(); it++)
{
}
- 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);
}
* "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: *************************************************/