]> git.tdb.fi Git - libs/gl.git/blobdiff - source/materials/lighting.cpp
Make it possible to have datafiles for individual lights
[libs/gl.git] / source / materials / lighting.cpp
index bcf2bb0e2645772555b2f1bbc2eaa4b6ea3959b2..1f1c66d9b172aa41e7bf3d23674f0646962829d3 100644 (file)
@@ -111,7 +111,13 @@ void Lighting::update_shader_data(ProgramData &shdata, const Matrix &view_matrix
 DataFile::Loader::ActionMap Lighting::Loader::shared_actions;
 
 Lighting::Loader::Loader(Lighting &l):
-       DataFile::ObjectLoader<Lighting>(l)
+       CollectionObjectLoader<Lighting>(l, 0)
+{
+       set_actions(shared_actions);
+}
+
+Lighting::Loader::Loader(Lighting &l, Collection &c):
+       CollectionObjectLoader<Lighting>(l, &c)
 {
        set_actions(shared_actions);
 }
@@ -124,11 +130,12 @@ void Lighting::Loader::init_actions()
        add("fog_half_distance", &Loader::fog_half_distance);
        add("horizon_angle", &Loader::horizon_angle);
        add("light", &Loader::light);
+       add("light", &Loader::light_inline);
        add("sky_color", &Loader::sky_color);
        add("zenith_direction", &Loader::zenith_direction);
 
        // Deprecated
-       add("light", &Loader::light_index);
+       add("light", &Loader::light_inline_index);
 }
 
 void Lighting::Loader::ambient(float r, float g, float b)
@@ -156,7 +163,12 @@ void Lighting::Loader::horizon_angle(float a)
        obj.set_horizon_angle(Geometry::Angle<float>::from_degrees(a));
 }
 
-void Lighting::Loader::light()
+void Lighting::Loader::light(const string &name)
+{
+       obj.attach(get_collection().get<Light>(name));
+}
+
+void Lighting::Loader::light_inline()
 {
        RefPtr<Light> lgt = new Light;
        load_sub(*lgt);
@@ -164,7 +176,7 @@ void Lighting::Loader::light()
        obj.owned_data.push_back(lgt.release());
 }
 
-void Lighting::Loader::light_index(unsigned)
+void Lighting::Loader::light_inline_index(unsigned)
 {
        light_inline();
 }