X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frender%2Fscene.h;h=fcf5d33e8eb9645caccdbc9bff5f7d34a3427f27;hp=639a467fa849cb526c19ac31744b957f820af7ea;hb=3ac3a51c623271da815c8ee60c484445871753bf;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266 diff --git a/source/render/scene.h b/source/render/scene.h index 639a467f..fcf5d33e 100644 --- a/source/render/scene.h +++ b/source/render/scene.h @@ -2,6 +2,7 @@ #define MSP_GL_SCENE_H_ #include +#include #include #include "matrix.h" #include "renderable.h" @@ -17,7 +18,7 @@ InstancedScene and OrderedScene. */ class Scene: public Renderable { -public: +protected: class Loader: public DataFile::CollectionObjectLoader { public: @@ -25,6 +26,7 @@ public: private: ContentMap *content; + unsigned inst_counter; public: Loader(Scene &, Collection &); @@ -34,11 +36,42 @@ public: void object(const std::string &); void object_tagged(const std::string &, const std::string &); + void scene(const std::string &); }; +public: + class GenericLoader: public DataFile::Loader + { + private: + template + struct CreateScene + { + void operator()(const std::string &, GenericLoader &) const; + }; + + DataFile::Collection &coll; + Scene *scene; + Loader *scene_loader; + + static ActionMap shared_actions; + + public: + GenericLoader(DataFile::Collection &); + ~GenericLoader(); + + Scene *get_scene() { Scene *s = scene; scene = 0; return s; } + private: + virtual void init_actions(); + + void type(const DataFile::Symbol &); + + friend class Scene; + }; + +private: + typedef TypeRegistry SceneRegistry; + protected: - // XXX If a loaded renderable is removed from the scene it needs to be removed from here as well - std::vector owned_data; mutable Matrix culling_matrix; mutable Vector4 frustum_edges[6]; @@ -47,7 +80,7 @@ private: Scene(const Scene &); Scene &operator=(const Scene &); public: - virtual ~Scene(); + virtual ~Scene() { } virtual void add(Renderable &) = 0; virtual void remove(Renderable &) = 0; @@ -55,8 +88,32 @@ public: protected: bool setup_frustum(const Renderer &) const; bool frustum_cull(const Renderable &) const; + +public: + template + static void register_type(const std::string &); +private: + static SceneRegistry &get_scene_registry(); }; +template +void Scene::register_type(const std::string &kw) +{ + get_scene_registry().register_type(kw); +} + +template +void Scene::GenericLoader::CreateScene::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