#endif
}
-Material::MaterialRegistry &Material::get_material_registry()
+Material::GenericLoader::TypeRegistry &Material::get_material_registry()
{
- static MaterialRegistry registry;
+ static GenericLoader::TypeRegistry registry;
static bool initialized = false;
if(!initialized)
{
obj.sampler = &get_collection().get<Sampler>(name);
}
-
-DataFile::Loader::ActionMap Material::GenericLoader::shared_actions;
-
-Material::GenericLoader::GenericLoader(DataFile::Collection &c):
- coll(c),
- material(0),
- mat_loader(0)
-{
- set_actions(shared_actions);
-}
-
-Material::GenericLoader::~GenericLoader()
-{
- delete material;
- delete mat_loader;
-}
-
-void Material::GenericLoader::init_actions()
-{
- add("type", &GenericLoader::type);
-}
-
-void Material::GenericLoader::type(const DataFile::Symbol &sym)
-{
- get_material_registry().invoke(sym.name, *this);
-}
-
} // namespace GL
} // namespace Msp
#ifndef MSP_GL_MATERIAL_H_
#define MSP_GL_MATERIAL_H_
-#include <msp/core/typeregistry.h>
#include <msp/datafile/collection.h>
+#include <msp/datafile/dynamicobjectloader.h>
#include <msp/datafile/objectloader.h>
#include "color.h"
#include "programdata.h"
};
public:
- class GenericLoader: public DataFile::Loader
+ class GenericLoader: public DataFile::DynamicObjectLoader<Material>
{
- private:
- template<typename T>
- struct CreateMaterial
- {
- void operator()(const std::string &, GenericLoader &) const;
- };
-
- DataFile::Collection &coll;
- Material *material;
- Loader *mat_loader;
-
- static ActionMap shared_actions;
+ friend class Material;
public:
- GenericLoader(DataFile::Collection &);
- ~GenericLoader();
+ GenericLoader(Collection &c): DynamicObjectLoader<Material>(&c) { }
- Material *get_object() { Material *m = material; material = 0; return m; }
- private:
- virtual void init_actions();
-
- void type(const DataFile::Symbol &);
-
- friend class Material;
+ protected:
+ virtual const TypeRegistry &get_type_registry() const { return get_material_registry(); }
};
-private:
- typedef TypeRegistry<GenericLoader::CreateMaterial, GenericLoader &> MaterialRegistry;
-
protected:
const Sampler *sampler;
ProgramData shdata;
template<typename T>
static void register_type(const std::string &);
private:
- static MaterialRegistry &get_material_registry();
+ static GenericLoader::TypeRegistry &get_material_registry();
};
template<typename T>
(static_cast<C &>(obj).*set_texture)(&static_cast<Collection &>(get_collection()).get<Texture>(name));
}
-
-template<typename T>
-void Material::GenericLoader::CreateMaterial<T>::operator()(const std::string &, GenericLoader &ldr) const
-{
- if(ldr.material)
- throw std::logic_error("Material type was already specified");
-
- T *mat = new T;
- ldr.material = mat;
- ldr.mat_loader = new typename T::Loader(*mat, ldr.coll);
- ldr.add_auxiliary_loader(*ldr.mat_loader);
-}
-
} // namespace GL
} // namespace Msp
return false;
}
-Scene::SceneRegistry &Scene::get_scene_registry()
+Scene::GenericLoader::TypeRegistry &Scene::get_scene_registry()
{
- static SceneRegistry registry;
+ static Scene::GenericLoader::TypeRegistry registry;
static bool initialized = false;
if(!initialized)
{
obj.add(get_collection().get<Scene>(n));
}
-
-DataFile::Loader::ActionMap Scene::GenericLoader::shared_actions;
-
-Scene::GenericLoader::GenericLoader(DataFile::Collection &c):
- coll(c),
- scene(0),
- scene_loader(0)
-{
- set_actions(shared_actions);
-}
-
-Scene::GenericLoader::~GenericLoader()
-{
- delete scene;
- delete scene_loader;
-}
-
-void Scene::GenericLoader::init_actions()
-{
- add("type", &GenericLoader::type);
-}
-
-void Scene::GenericLoader::type(const DataFile::Symbol &sym)
-{
- get_scene_registry().invoke(sym.name, *this);
-}
-
} // namespace GL
} // namespace Msp
#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"
};
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();
+ GenericLoader(DataFile::Collection &c): DynamicObjectLoader<Scene>(&c) { }
- Scene *get_object() { Scene *s = scene; scene = 0; return s; }
- private:
- virtual void init_actions();
-
- 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];
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>
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