]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/scene.h
Use default member initializers for simple types
[libs/gl.git] / source / render / scene.h
index 639a467fa849cb526c19ac31744b957f820af7ea..8083239390fed6d765e546ae08ea2aadde14f2ce 100644 (file)
@@ -1,11 +1,11 @@
 #ifndef MSP_GL_SCENE_H_
 #define MSP_GL_SCENE_H_
 
-#include <vector>
+#include <map>
+#include <msp/datafile/dynamicobjectloader.h>
 #include <msp/datafile/objectloader.h>
 #include "matrix.h"
 #include "renderable.h"
-#include "vector.h"
 
 namespace Msp {
 namespace GL {
@@ -17,7 +17,7 @@ InstancedScene and OrderedScene.
 */
 class Scene: public Renderable
 {
-public:
+protected:
        class Loader: public DataFile::CollectionObjectLoader<Scene>
        {
        public:
@@ -25,29 +25,41 @@ public:
 
        private:
                ContentMap *content;
+               unsigned inst_counter;
 
        public:
-               Loader(Scene &, Collection &);
-               Loader(Scene &, Collection &, ContentMap &);
+               Loader(Scene &s, Collection &c): Loader(s, c, 0) { }
+               Loader(Scene &s, Collection &c, ContentMap &m) : Loader(s, c, &m) { }
        private:
-               void init();
+               Loader(Scene &, Collection &, ContentMap *);
 
                void object(const std::string &);
                void object_tagged(const std::string &, const std::string &);
+               void scene(const std::string &);
+       };
+
+public:
+       class GenericLoader: public DataFile::DynamicObjectLoader<Scene>
+       {
+               friend class Scene;
+
+       public:
+               GenericLoader(DataFile::Collection &c): DynamicObjectLoader<Scene>(&c) { }
+
+       protected:
+               virtual const TypeRegistry &get_type_registry() const { return get_scene_registry(); }
        };
 
 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;
        mutable Matrix culling_matrix;
        mutable Vector4 frustum_edges[6];
 
-       Scene() { }
+       Scene() = default;
 private:
        Scene(const Scene &);
        Scene &operator=(const Scene &);
 public:
-       virtual ~Scene();
+       virtual ~Scene() = default;
 
        virtual void add(Renderable &) = 0;
        virtual void remove(Renderable &) = 0;
@@ -55,8 +67,20 @@ public:
 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 GenericLoader::TypeRegistry &get_scene_registry();
 };
 
+template<typename T>
+void Scene::register_type(const std::string &kw)
+{
+       get_scene_registry().register_type<T>(kw);
+}
+
 } // namespace GL
 } // namespace Msp