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"
15 Scenes are containers for other Renderables. This is a base class that can't
16 be instantiated. Examples of available Scene types are SimpleScene,
17 InstancedScene and OrderedScene.
19 class Scene: public Renderable
22 class Loader: public DataFile::CollectionObjectLoader<Scene>
25 typedef std::map<std::string, Renderable *> ContentMap;
29 unsigned inst_counter;
32 Loader(Scene &, Collection &);
33 Loader(Scene &, Collection &, ContentMap &);
37 void object(const std::string &);
38 void object_tagged(const std::string &, const std::string &);
39 void scene(const std::string &);
43 class GenericLoader: public DataFile::Loader
49 void operator()(const std::string &, GenericLoader &) const;
52 DataFile::Collection &coll;
56 static ActionMap shared_actions;
59 GenericLoader(DataFile::Collection &);
62 Scene *get_scene() { Scene *s = scene; scene = 0; return s; }
64 virtual void init_actions();
66 void type(const DataFile::Symbol &);
72 typedef TypeRegistry<GenericLoader::CreateScene, GenericLoader &> SceneRegistry;
75 mutable Matrix culling_matrix;
76 mutable Vector4 frustum_edges[6];
81 Scene &operator=(const Scene &);
85 virtual void add(Renderable &) = 0;
86 virtual void remove(Renderable &) = 0;
89 bool setup_frustum(const Renderer &) const;
90 bool frustum_cull(const Renderable &) const;
94 static void register_type(const std::string &);
96 static SceneRegistry &get_scene_registry();
100 void Scene::register_type(const std::string &kw)
102 get_scene_registry().register_type<T>(kw);
106 void Scene::GenericLoader::CreateScene<T>::operator()(const std::string &, GenericLoader &ldr) const
109 throw std::logic_error("Scene type was already specified");
113 ldr.scene_loader = new typename T::Loader(*scene, ldr.coll);
114 ldr.add_auxiliary_loader(*ldr.scene_loader);