ContentCAO: Update light of all attached entities (#9975)

This commit is contained in:
SmallJoker 2020-06-01 19:01:47 +02:00 committed by GitHub
parent f849917bbe
commit a08d18acad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 60 deletions

@ -320,21 +320,8 @@ void ClientEnvironment::step(float dtime)
// Step object // Step object
cao->step(dtime, this); cao->step(dtime, this);
if (update_lighting) { if (update_lighting)
// Update lighting cao->updateLight(day_night_ratio);
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);
}
}; };
m_ao_manager.step(dtime, cb_state); m_ao_manager.step(dtime, cb_state);
@ -402,18 +389,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
object->addToScene(m_texturesource); object->addToScene(m_texturesource);
// Update lighting immediately // Update lighting immediately
u8 light = 0; object->updateLight(getDayNightRatio());
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);
return object->getId(); return object->getId();
} }

@ -41,10 +41,10 @@ public:
virtual void addToScene(ITextureSource *tsrc) {} virtual void addToScene(ITextureSource *tsrc) {}
virtual void removeFromScene(bool permanent) {} virtual void removeFromScene(bool permanent) {}
// 0 <= light_at_pos <= LIGHT_SUN
virtual void updateLight(u8 light_at_pos) {} virtual void updateLight(u32 day_night_ratio) {}
virtual void updateLightNoCheck(u8 light_at_pos) {}
virtual v3s16 getLightPosition() { return v3s16(0, 0, 0); } virtual v3s16 getLightPosition() { return v3s16(0, 0, 0); }
virtual bool getCollisionBox(aabb3f *toset) const { return false; } virtual bool getCollisionBox(aabb3f *toset) const { return false; }
virtual bool getSelectionBox(aabb3f *toset) const { return false; } virtual bool getSelectionBox(aabb3f *toset) const { return false; }
virtual bool collideWithObjects() const { return false; } virtual bool collideWithObjects() const { return false; }

@ -181,7 +181,7 @@ public:
void addToScene(ITextureSource *tsrc); void addToScene(ITextureSource *tsrc);
void removeFromScene(bool permanent); void removeFromScene(bool permanent);
void updateLight(u8 light_at_pos); void updateLight(u32 day_night_ratio);
v3s16 getLightPosition(); v3s16 getLightPosition();
void updateNodePos(); void updateNodePos();
@ -254,7 +254,7 @@ void TestCAO::removeFromScene(bool permanent)
m_node = NULL; 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); 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 u8 light_at_pos = 0;
if (getParent() != NULL) { bool pos_ok;
return;
}
updateLightNoCheck(light_at_pos); 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);
// Update light of all children u8 light = decode_light(light_at_pos);
for (u16 i : m_attachment_child_ids) { if (light != m_last_light) {
ClientActiveObject *obj = m_env->getActiveObject(i); m_last_light = light;
if (obj) { setNodeLight(light);
obj->updateLightNoCheck(light_at_pos);
}
}
}
void GenericCAO::updateLightNoCheck(u8 light_at_pos)
{
if (m_glow < 0)
return;
u8 li = decode_light(light_at_pos + m_glow);
if (li != m_last_light) {
m_last_light = li;
setNodeLight(li);
} }
} }

@ -236,9 +236,7 @@ public:
m_visuals_expired = true; m_visuals_expired = true;
} }
void updateLight(u8 light_at_pos); void updateLight(u32 day_night_ratio);
void updateLightNoCheck(u8 light_at_pos);
void setNodeLight(u8 light); void setNodeLight(u8 light);