From: Mikko Rasa Date: Sat, 17 Apr 2021 19:01:19 +0000 (+0300) Subject: Make it possible to have datafiles for individual lights X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3b0cb993f410b05fc6309d41aa292f4e57c35519;p=libs%2Fgl.git Make it possible to have datafiles for individual lights --- diff --git a/source/materials/lighting.cpp b/source/materials/lighting.cpp index bcf2bb0e..1f1c66d9 100644 --- a/source/materials/lighting.cpp +++ b/source/materials/lighting.cpp @@ -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(l) + CollectionObjectLoader(l, 0) +{ + set_actions(shared_actions); +} + +Lighting::Loader::Loader(Lighting &l, Collection &c): + CollectionObjectLoader(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::from_degrees(a)); } -void Lighting::Loader::light() +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); @@ -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(); } diff --git a/source/materials/lighting.h b/source/materials/lighting.h index 226dee1c..2a8756c3 100644 --- a/source/materials/lighting.h +++ b/source/materials/lighting.h @@ -19,13 +19,14 @@ sources. class Lighting { public: - class Loader: public DataFile::ObjectLoader + class Loader: public DataFile::CollectionObjectLoader { private: static ActionMap shared_actions; public: Loader(Lighting &); + Loader(Lighting &, Collection &); private: virtual void init_actions(); @@ -35,8 +36,9 @@ public: void fog_density(float); void fog_half_distance(float); void horizon_angle(float); - void light(); - void light_index(unsigned); + void light(const std::string &); + void light_inline(); + void light_inline_index(unsigned); void sky_color(float, float, float); void zenith_direction(float, float, float); }; diff --git a/source/resources/resources.cpp b/source/resources/resources.cpp index b5093932..c9db211b 100644 --- a/source/resources/resources.cpp +++ b/source/resources/resources.cpp @@ -5,6 +5,7 @@ #include "camera.h" #include "font.h" #include "keyframe.h" +#include "light.h" #include "lighting.h" #include "material.h" #include "mesh.h" @@ -43,6 +44,7 @@ Resources::Resources(): add_type().keyword("camera"); add_type().keyword("font"); add_type().suffix(".kframe").keyword("keyframe"); + add_type().keyword("light"); add_type().suffix(".lightn").keyword("lighting"); add_type().suffix(".mat").creator(&Resources::create_material); add_type().keyword("mesh").creator(&Resources::create_mesh);