*/
class OccludedScene: public Scene
{
+public:
+ using Scene::Loader;
+
private:
struct OccludedRenderable
{
*/
class OrderedScene: public Scene
{
+public:
+ using Scene::Loader;
+
private:
typedef std::list<Renderable *> RenderableList;
#include <msp/datafile/collection.h>
#include "animatedobject.h"
#include "camera.h"
+#include "orderedscene.h"
#include "renderer.h"
#include "scene.h"
+#include "simplescene.h"
+#include "zsortedscene.h"
using namespace std;
return false;
}
+Scene::SceneRegistry &Scene::get_scene_registry()
+{
+ static SceneRegistry registry;
+ static bool initialized = false;
+ if(!initialized)
+ {
+ initialized = true;
+ register_type<SimpleScene>("simple");
+ register_type<ZSortedScene>("zsorted");
+ register_type<OrderedScene>("ordered");
+ // TODO OccludedScene requires a collection as a constructor parameter
+ //register_type<OccludedScene>("occluded");
+ }
+ return registry;
+}
+
Scene::Loader::Loader(Scene &s, Collection &c):
DataFile::CollectionObjectLoader<Scene>(s, &c),
obj.owned_data.push_back(anob.release());
}
+
+DataFile::Loader::ActionMap Scene::GenericLoader::shared_actions;
+
+Scene::GenericLoader::GenericLoader(DataFile::Collection &c):
+ coll(c),
+ scene(0),
+ scene_loader(0)
+{
+ set_actions(shared_actions);
+}
+
+Scene::GenericLoader::~GenericLoader()
+{
+ delete scene;
+ delete scene_loader;
+}
+
+void Scene::GenericLoader::init_actions()
+{
+ add("type", &GenericLoader::type);
+}
+
+void Scene::GenericLoader::type(const DataFile::Symbol &sym)
+{
+ get_scene_registry().invoke(sym.name, *this);
+}
+
} // namespace GL
} // namespace Msp
#define MSP_GL_SCENE_H_
#include <vector>
+#include <msp/core/typeregistry.h>
#include <msp/datafile/objectloader.h>
#include "matrix.h"
#include "renderable.h"
*/
class Scene: public Renderable
{
-public:
+protected:
class Loader: public DataFile::CollectionObjectLoader<Scene>
{
public:
void object_tagged(const std::string &, const std::string &);
};
+public:
+ class GenericLoader: public DataFile::Loader
+ {
+ private:
+ template<typename T>
+ struct CreateScene
+ {
+ void operator()(const std::string &, GenericLoader &) const;
+ };
+
+ DataFile::Collection &coll;
+ Scene *scene;
+ Loader *scene_loader;
+
+ static ActionMap shared_actions;
+
+ public:
+ GenericLoader(DataFile::Collection &);
+ ~GenericLoader();
+
+ Scene *get_scene() { Scene *s = scene; scene = 0; return s; }
+ private:
+ virtual void init_actions();
+
+ void type(const DataFile::Symbol &);
+
+ friend class Scene;
+ };
+
+private:
+ typedef TypeRegistry<GenericLoader::CreateScene, GenericLoader &> SceneRegistry;
+
protected:
// XXX If a loaded renderable is removed from the scene it needs to be removed from here as well
std::vector<Renderable *> owned_data;
protected:
bool setup_frustum(const Renderer &) const;
bool frustum_cull(const Renderable &) const;
+
+public:
+ template<typename T>
+ static void register_type(const std::string &);
+private:
+ static SceneRegistry &get_scene_registry();
};
+template<typename T>
+void Scene::register_type(const std::string &kw)
+{
+ get_scene_registry().register_type<T>(kw);
+}
+
+template<typename T>
+void Scene::GenericLoader::CreateScene<T>::operator()(const std::string &, GenericLoader &ldr) const
+{
+ if(ldr.scene)
+ throw std::logic_error("Scene type was already specified");
+
+ T *scene = new T;
+ ldr.scene = scene;
+ ldr.scene_loader = new typename T::Loader(*scene, ldr.coll);
+ ldr.add_auxiliary_loader(*ldr.scene_loader);
+}
+
} // namespace GL
} // namespace Msp
*/
class SimpleScene: public Scene
{
+public:
+ using Scene::Loader;
+
private:
typedef std::set<Renderable *> RenderableSet;
typedef std::vector<Renderable *> RenderableArray;
*/
class ZSortedScene: public Scene
{
+public:
+ using Scene::Loader;
+
private:
struct SortedRenderable
{