ContentCAO: Update light of all attached entities (#9975)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Mon, 1 Jun 2020 17:01:47 +0000 (19:01 +0200)
committerGitHub <noreply@github.com>
Mon, 1 Jun 2020 17:01:47 +0000 (19:01 +0200)
src/client/clientenvironment.cpp
src/client/clientobject.h
src/client/content_cao.cpp
src/client/content_cao.h

index 6840f2db32e929441f7689b206aec6e92c762267..44ea1e4a157a53282300c203988bc1e2c9177790 100644 (file)
@@ -320,21 +320,8 @@ void ClientEnvironment::step(float dtime)
                // Step object
                cao->step(dtime, this);
 
-               if (update_lighting) {
-                       // Update lighting
-                       u8 light = 0;
-                       bool pos_ok;
-
-                       // Get node at head
-                       v3s16 p = cao->getLightPosition();
-                       MapNode n = this->m_map->getNode(p, &pos_ok);
-                       if (pos_ok)
-                               light = n.getLightBlend(day_night_ratio, m_client->ndef());
-                       else
-                               light = blend_light(day_night_ratio, LIGHT_SUN, 0);
-
-                       cao->updateLight(light);
-               }
+               if (update_lighting)
+                       cao->updateLight(day_night_ratio);
        };
 
        m_ao_manager.step(dtime, cb_state);
@@ -402,18 +389,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
        object->addToScene(m_texturesource);
 
        // Update lighting immediately
-       u8 light = 0;
-       bool pos_ok;
-
-       // Get node at head
-       v3s16 p = object->getLightPosition();
-       MapNode n = m_map->getNode(p, &pos_ok);
-       if (pos_ok)
-               light = n.getLightBlend(getDayNightRatio(), m_client->ndef());
-       else
-               light = blend_light(getDayNightRatio(), LIGHT_SUN, 0);
-
-       object->updateLight(light);
+       object->updateLight(getDayNightRatio());
        return object->getId();
 }
 
index 12e0db35b4e98e19ee73863b45bbdb07c2838c06..8e64b8406b1892e49c1f105310de7ccf933a8b5a 100644 (file)
@@ -41,10 +41,10 @@ public:
 
        virtual void addToScene(ITextureSource *tsrc) {}
        virtual void removeFromScene(bool permanent) {}
-       // 0 <= light_at_pos <= LIGHT_SUN
-       virtual void updateLight(u8 light_at_pos) {}
-       virtual void updateLightNoCheck(u8 light_at_pos) {}
+
+       virtual void updateLight(u32 day_night_ratio) {}
        virtual v3s16 getLightPosition() { return v3s16(0, 0, 0); }
+
        virtual bool getCollisionBox(aabb3f *toset) const { return false; }
        virtual bool getSelectionBox(aabb3f *toset) const { return false; }
        virtual bool collideWithObjects() const { return false; }
index dde31899b933e589d2aca80a5e0b888ee85ab81d..d0682e51eab82f9743106a01ccb41ff2061ae1b8 100644 (file)
@@ -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);
        }
 }
 
index 8e2a13ea8929d57a2235d7befd9fe2294d4a17d3..7693dd3d248305e65113be836168b47ed8f16628 100644 (file)
@@ -236,9 +236,7 @@ public:
                m_visuals_expired = true;
        }
 
-       void updateLight(u8 light_at_pos);
-
-       void updateLightNoCheck(u8 light_at_pos);
+       void updateLight(u32 day_night_ratio);
 
        void setNodeLight(u8 light);