]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resources/resources.cpp
Add keywords for light and material to Resources::Loader
[libs/gl.git] / source / resources / resources.cpp
index 32f59d93d6e5a85f0bea998fd6bc446deb3fe88f..12448a901fc436ce1059b7a92bc834b57f0d6166 100644 (file)
@@ -4,10 +4,10 @@
 #include "armature.h"
 #include "basicmaterial.h"
 #include "camera.h"
+#include "directionallight.h"
 #include "error.h"
 #include "font.h"
 #include "keyframe.h"
-#include "light.h"
 #include "lighting.h"
 #include "mesh.h"
 #include "module.h"
@@ -16,6 +16,7 @@
 #include "orderedscene.h"
 #include "pbrmaterial.h"
 #include "sequencetemplate.h"
+#include "pointlight.h"
 #include "pose.h"
 #include "program.h"
 #include "resourcemanager.h"
@@ -52,9 +53,10 @@ Resources::Resources(bool set_as_global):
                .notify(&set_debug_name<Material>);
        add_type<Camera>().keyword("camera")
                .notify(&set_debug_name<Camera>);
+       add_type<DirectionalLight>().base<Light>().suffix(".light")
+               .creator([this](const string &n) -> DirectionalLight * { create_generic<Light>(n); return 0; });
        add_type<Font>().keyword("font");
        add_type<KeyFrame>().suffix(".kframe").keyword("keyframe");
-       add_type<Light>().keyword("light");
        add_type<Lighting>().suffix(".lightn").keyword("lighting")
                .notify(&set_debug_name<Lighting>);
        add_type<Mesh>().keyword("mesh")
@@ -70,6 +72,8 @@ Resources::Resources(bool set_as_global):
        add_type<PbrMaterial>().base<Material>().suffix(".mat")
                .creator([this](const string &n) -> PbrMaterial * { create_generic<Material>(n); return 0; })
                .notify(&set_debug_name<Material>);
+       add_type<PointLight>().base<Light>().suffix(".light")
+               .creator([this](const string &n) -> PointLight * { create_generic<Light>(n); return 0; });
        add_type<SequenceTemplate>().suffix(".seq").keyword("sequence");
        add_type<Pose>().keyword("pose");
        add_type<Program>().keyword("shader")
@@ -163,7 +167,8 @@ Mesh *Resources::create_mesh(const string &name)
 
        if(RefPtr<IO::Seekable> io = open_raw(name))
        {
-               RefPtr<Mesh> mesh = new Mesh(resource_manager);
+               RefPtr<Mesh> mesh = new Mesh;
+               mesh->set_manager(resource_manager);
                resource_manager->set_resource_location(*mesh, *this, name);
                return mesh.release();
        }
@@ -183,7 +188,8 @@ Texture2D *Resources::create_texture2d(const string &name)
 
                if(ext==".tex2d")
                {
-                       tex = new Texture2D(resource_manager);
+                       tex = new Texture2D;
+                       tex->set_manager(resource_manager);
                        DataFile::Parser parser(*io, name);
                        Texture2D::Loader ldr(*tex, *this);
                        ldr.load(parser);
@@ -271,14 +277,17 @@ void Resources::set_debug_name(const string &name, T &item)
 Resources::Loader::Loader(Resources &r):
        DerivedObjectLoader<Resources, Collection::Loader>(r)
 {
-       add("scene", &Loader::scene);
+       add("light", &Loader::generic<Light>);
+       add("material", &Loader::generic<Material>);
+       add("scene", &Loader::generic<Scene>);
 }
 
-void Resources::Loader::scene(const string &name)
+template<typename T>
+void Resources::Loader::generic(const string &name)
 {
-       Scene::GenericLoader ldr(obj);
+       typename T::GenericLoader ldr(obj);
        load_sub_with(ldr);
-       obj.add(name, ldr.get_object());
+       ldr.store_object(obj, name);
 }
 
 } // namespace GL