summaryrefslogtreecommitdiff
path: root/src/client/content_cao.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2020-06-01 19:01:47 +0200
committerGitHub <noreply@github.com>2020-06-01 19:01:47 +0200
commita08d18acad345363780f5286300d65b39ea9c9f9 (patch)
tree0929b7f73ea7c781a8c46aeafdd445634b55a443 /src/client/content_cao.cpp
parentf849917bbe9c5eff51bee0a3125eabed16efb172 (diff)
downloadminetest-a08d18acad345363780f5286300d65b39ea9c9f9.tar.gz
minetest-a08d18acad345363780f5286300d65b39ea9c9f9.tar.bz2
minetest-a08d18acad345363780f5286300d65b39ea9c9f9.zip
ContentCAO: Update light of all attached entities (#9975)
Diffstat (limited to 'src/client/content_cao.cpp')
-rw-r--r--src/client/content_cao.cpp42
1 files changed, 15 insertions, 27 deletions
diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp
index dde31899b..d0682e51e 100644
--- a/src/client/content_cao.cpp
+++ b/src/client/content_cao.cpp
@@ -181,7 +181,7 @@ public:
void addToScene(ITextureSource *tsrc);
void removeFromScene(bool permanent);
- void updateLight(u8 light_at_pos);
+ void updateLight(u32 day_night_ratio);
v3s16 getLightPosition();
void updateNodePos();
@@ -254,7 +254,7 @@ void TestCAO::removeFromScene(bool permanent)
m_node = NULL;
}
-void TestCAO::updateLight(u8 light_at_pos)
+void TestCAO::updateLight(u32 day_night_ratio)
{
}
@@ -784,34 +784,22 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
setNodeLight(m_last_light);
}
-void GenericCAO::updateLight(u8 light_at_pos)
+void GenericCAO::updateLight(u32 day_night_ratio)
{
- // Don't update light of attached one
- if (getParent() != NULL) {
- return;
- }
-
- updateLightNoCheck(light_at_pos);
-
- // Update light of all children
- for (u16 i : m_attachment_child_ids) {
- ClientActiveObject *obj = m_env->getActiveObject(i);
- if (obj) {
- obj->updateLightNoCheck(light_at_pos);
- }
- }
-}
-
-void GenericCAO::updateLightNoCheck(u8 light_at_pos)
-{
- if (m_glow < 0)
- return;
+ u8 light_at_pos = 0;
+ bool pos_ok;
- u8 li = decode_light(light_at_pos + m_glow);
+ v3s16 p = getLightPosition();
+ MapNode n = m_env->getMap().getNode(p, &pos_ok);
+ if (pos_ok)
+ light_at_pos = n.getLightBlend(day_night_ratio, m_client->ndef());
+ else
+ light_at_pos = blend_light(day_night_ratio, LIGHT_SUN, 0);
- if (li != m_last_light) {
- m_last_light = li;
- setNodeLight(li);
+ u8 light = decode_light(light_at_pos);
+ if (light != m_last_light) {
+ m_last_light = light;
+ setNodeLight(light);
}
}