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;
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 &);
41 class GenericLoader: public DataFile::Loader
47 void operator()(const std::string &, GenericLoader &) const;
50 DataFile::Collection &coll;
54 static ActionMap shared_actions;
57 GenericLoader(DataFile::Collection &);
60 Scene *get_scene() { Scene *s = scene; scene = 0; return s; }
62 virtual void init_actions();
64 void type(const DataFile::Symbol &);
70 typedef TypeRegistry<GenericLoader::CreateScene, GenericLoader &> SceneRegistry;
73 // XXX If a loaded renderable is removed from the scene it needs to be removed from here as well
74 std::vector<Renderable *> owned_data;
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);