]> git.tdb.fi Git - libs/gl.git/blob - source/render/scene.h
Use default member initializers for simple types
[libs/gl.git] / source / render / scene.h
1 #ifndef MSP_GL_SCENE_H_
2 #define MSP_GL_SCENE_H_
3
4 #include <map>
5 #include <msp/datafile/dynamicobjectloader.h>
6 #include <msp/datafile/objectloader.h>
7 #include "matrix.h"
8 #include "renderable.h"
9
10 namespace Msp {
11 namespace GL {
12
13 /**
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.
17 */
18 class Scene: public Renderable
19 {
20 protected:
21         class Loader: public DataFile::CollectionObjectLoader<Scene>
22         {
23         public:
24                 typedef std::map<std::string, Renderable *> ContentMap;
25
26         private:
27                 ContentMap *content;
28                 unsigned inst_counter;
29
30         public:
31                 Loader(Scene &s, Collection &c): Loader(s, c, 0) { }
32                 Loader(Scene &s, Collection &c, ContentMap &m) : Loader(s, c, &m) { }
33         private:
34                 Loader(Scene &, Collection &, ContentMap *);
35
36                 void object(const std::string &);
37                 void object_tagged(const std::string &, const std::string &);
38                 void scene(const std::string &);
39         };
40
41 public:
42         class GenericLoader: public DataFile::DynamicObjectLoader<Scene>
43         {
44                 friend class Scene;
45
46         public:
47                 GenericLoader(DataFile::Collection &c): DynamicObjectLoader<Scene>(&c) { }
48
49         protected:
50                 virtual const TypeRegistry &get_type_registry() const { return get_scene_registry(); }
51         };
52
53 protected:
54         mutable Matrix culling_matrix;
55         mutable Vector4 frustum_edges[6];
56
57         Scene() = default;
58 private:
59         Scene(const Scene &);
60         Scene &operator=(const Scene &);
61 public:
62         virtual ~Scene() = default;
63
64         virtual void add(Renderable &) = 0;
65         virtual void remove(Renderable &) = 0;
66
67 protected:
68         bool setup_frustum(const Renderer &) const;
69         bool frustum_cull(const Renderable &) const;
70
71 public:
72         template<typename T>
73         static void register_type(const std::string &);
74 private:
75         static GenericLoader::TypeRegistry &get_scene_registry();
76 };
77
78 template<typename T>
79 void Scene::register_type(const std::string &kw)
80 {
81         get_scene_registry().register_type<T>(kw);
82 }
83
84 } // namespace GL
85 } // namespace Msp
86
87 #endif