X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Flighting.cpp;h=1f1c66d9b172aa41e7bf3d23674f0646962829d3;hb=bb386d895f5fce2f0099886fdf7e7073b18246e8;hp=fa0c26b41bfa815abe6902394e505cf474c3276c;hpb=aeef1c75d50f39bf57c3e608bbe41005479c44da;p=libs%2Fgl.git diff --git a/source/materials/lighting.cpp b/source/materials/lighting.cpp index fa0c26b4..1f1c66d9 100644 --- a/source/materials/lighting.cpp +++ b/source/materials/lighting.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "error.h" #include "light.h" #include "lighting.h" @@ -63,12 +64,17 @@ void Lighting::set_fog_half_distance(float d) set_fog_density(-log(pow(0.5, 1.0/d))); } -void Lighting::attach(unsigned i, const Light &l) +void Lighting::attach(const Light &l) { - if(i>=lights.size()) - lights.resize(i+1); + if(find(lights, &l)==lights.end()) + lights.push_back(&l); +} - lights[i] = &l; +void Lighting::detach(const Light &l) +{ + vector::iterator i = find(lights, &l); + if(i!=lights.end()) + lights.erase(i); } void Lighting::detach(unsigned i) @@ -76,7 +82,7 @@ void Lighting::detach(unsigned i) if(i>=lights.size()) return; - lights[i] = 0; + detach(*lights[i]); } const Light *Lighting::get_attached_light(unsigned i) const @@ -105,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(l) + CollectionObjectLoader(l, 0) +{ + set_actions(shared_actions); +} + +Lighting::Loader::Loader(Lighting &l, Collection &c): + CollectionObjectLoader(l, &c) { set_actions(shared_actions); } @@ -118,8 +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_inline_index); } void Lighting::Loader::ambient(float r, float g, float b) @@ -147,14 +163,24 @@ void Lighting::Loader::horizon_angle(float a) obj.set_horizon_angle(Geometry::Angle::from_degrees(a)); } -void Lighting::Loader::light(unsigned i) +void Lighting::Loader::light(const string &name) +{ + obj.attach(get_collection().get(name)); +} + +void Lighting::Loader::light_inline() { RefPtr lgt = new Light; load_sub(*lgt); - obj.attach(i, *lgt); + obj.attach(*lgt); obj.owned_data.push_back(lgt.release()); } +void Lighting::Loader::light_inline_index(unsigned) +{ + light_inline(); +} + void Lighting::Loader::sky_color(float r, float g, float b) { obj.set_sky_color(Color(r, g, b));