1 #ifndef MSP_GL_SCENE_H_
2 #define MSP_GL_SCENE_H_
5 #include <msp/core/typeregistry.h>
6 #include <msp/datafile/objectloader.h>
8 #include "renderable.h"
14 Scenes are containers for other Renderables. This is a base class that can't
15 be instantiated. Examples of available Scene types are SimpleScene,
16 InstancedScene and OrderedScene.
18 class Scene: public Renderable
21 class Loader: public DataFile::CollectionObjectLoader<Scene>
24 typedef std::map<std::string, Renderable *> ContentMap;
28 unsigned inst_counter;
31 Loader(Scene &, Collection &);
32 Loader(Scene &, Collection &, ContentMap &);
36 void object(const std::string &);
37 void object_tagged(const std::string &, const std::string &);
38 void scene(const std::string &);
42 class GenericLoader: public DataFile::Loader
48 void operator()(const std::string &, GenericLoader &) const;
51 DataFile::Collection &coll;
55 static ActionMap shared_actions;
58 GenericLoader(DataFile::Collection &);
61 Scene *get_scene() { Scene *s = scene; scene = 0; return s; }
63 virtual void init_actions();
65 void type(const DataFile::Symbol &);
71 typedef TypeRegistry<GenericLoader::CreateScene, GenericLoader &> SceneRegistry;
74 mutable Matrix culling_matrix;
75 mutable Vector4 frustum_edges[6];
80 Scene &operator=(const Scene &);
84 virtual void add(Renderable &) = 0;
85 virtual void remove(Renderable &) = 0;
88 bool setup_frustum(const Renderer &) const;
89 bool frustum_cull(const Renderable &) const;
93 static void register_type(const std::string &);
95 static SceneRegistry &get_scene_registry();
99 void Scene::register_type(const std::string &kw)
101 get_scene_registry().register_type<T>(kw);
105 void Scene::GenericLoader::CreateScene<T>::operator()(const std::string &, GenericLoader &ldr) const
108 throw std::logic_error("Scene type was already specified");
112 ldr.scene_loader = new typename T::Loader(*scene, ldr.coll);
113 ldr.add_auxiliary_loader(*ldr.scene_loader);