]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/scene.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / render / scene.h
index 6fb45d6102b9fc422f71ba360da33b2e5a87c926..e6115ae56541d9e9907818da03c780f45f80660d 100644 (file)
@@ -2,7 +2,7 @@
 #define MSP_GL_SCENE_H_
 
 #include <map>
-#include <msp/core/typeregistry.h>
+#include <msp/datafile/dynamicobjectloader.h>
 #include <msp/datafile/objectloader.h>
 #include "matrix.h"
 #include "renderable.h"
@@ -11,9 +11,15 @@ namespace Msp {
 namespace GL {
 
 /**
-Scenes are containers for other Renderables.  This is a base class that can't
-be instantiated.  Examples of available Scene types are SimpleScene,
-InstancedScene and OrderedScene.
+Container for other renderables.  Subclasses provide different ways of
+rendering the contents.
+
+All types of Scenes perform frustum culling on the contents, skipping
+renderables whose bounding sphere is fully outside the view volume.  If a
+bounding sphere cannot be determined, culling is not performed on that
+renderable.
+
+SimpleScene is a good default choice if there are no specific requirements.
 */
 class Scene: public Renderable
 {
@@ -25,7 +31,8 @@ protected:
 
        private:
                ContentMap *content;
-               unsigned inst_counter;
+
+               static unsigned inline_counter;
 
        public:
                Loader(Scene &s, Collection &c): Loader(s, c, 0) { }
@@ -33,66 +40,37 @@ protected:
        private:
                Loader(Scene &, Collection &, ContentMap *);
 
+               void array(const std::string &);
                void object(const std::string &);
                void object_tagged(const std::string &, const std::string &);
                void scene(const std::string &);
+               void scene_inline();
        };
 
 public:
-       class GenericLoader: public DataFile::Loader
+       class GenericLoader: public DataFile::DynamicObjectLoader<Scene>
        {
-       private:
-               template<typename T>
-               struct CreateScene
-               {
-                       void operator()(const std::string &, GenericLoader &) const;
-               };
-
-               DataFile::Collection &coll;
-               Scene *scene;
-               Loader *scene_loader;
-
-               static ActionMap shared_actions;
+               friend class Scene;
 
        public:
-               GenericLoader(DataFile::Collection &);
-               ~GenericLoader();
-
-               Scene *get_object() { Scene *s = scene; scene = 0; return s; }
-       private:
-               virtual void init_actions();
+               GenericLoader(DataFile::Collection &c): DynamicObjectLoader<Scene>(&c) { }
 
-               void type(const DataFile::Symbol &);
-
-               friend class Scene;
+       protected:
+               virtual const TypeRegistry &get_type_registry() const { return get_scene_registry(); }
        };
 
-private:
-       typedef TypeRegistry<GenericLoader::CreateScene, GenericLoader &> SceneRegistry;
-
 protected:
-       mutable Matrix culling_matrix;
-       mutable Vector4 frustum_edges[6];
-
-       Scene() { }
-private:
-       Scene(const Scene &);
-       Scene &operator=(const Scene &);
+       Scene() = default;
 public:
-       virtual ~Scene() { }
+       virtual ~Scene() = default;
 
        virtual void add(Renderable &) = 0;
        virtual void remove(Renderable &) = 0;
 
-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 SceneRegistry &get_scene_registry();
+       static GenericLoader::TypeRegistry &get_scene_registry();
 };
 
 template<typename T>
@@ -101,18 +79,6 @@ void Scene::register_type(const std::string &kw)
        get_scene_registry().register_type<T>(kw);
 }
 
-template<typename T>
-void Scene::GenericLoader::CreateScene<T>::operator()(const std::string &, GenericLoader &ldr) const
-{
-       if(ldr.scene)
-               throw std::logic_error("Scene type was already specified");
-
-       T *scene = new T;
-       ldr.scene = scene;
-       ldr.scene_loader = new typename T::Loader(*scene, ldr.coll);
-       ldr.add_auxiliary_loader(*ldr.scene_loader);
-}
-
 } // namespace GL
 } // namespace Msp