From f648fb76aef96a1da608c64346fc65d4dd44caa8 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Fri, 10 Apr 2020 19:49:20 +0200 Subject: Drop genericobject.{cpp,h} (#9629) * Drop genericobject.{cpp,h} This file is not for generic object but for ActiveObject message passing. Put ownership of the various commands to the right objects and cleanup the related code. * Protect ServerActiveObject::m_messages_out * typo fix --- src/client/clientenvironment.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/client/clientenvironment.cpp') diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 52d133781..6840f2db3 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -450,7 +450,7 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type, // Object initialized: if ((obj = getActiveObject(new_id))) { // Final step is to update all children which are already known - // Data provided by GENERIC_CMD_SPAWN_INFANT + // Data provided by AO_CMD_SPAWN_INFANT const auto &children = obj->getAttachmentChildIds(); for (auto c_id : children) { if (auto *o = getActiveObject(c_id)) -- cgit v1.2.3 From a08d18acad345363780f5286300d65b39ea9c9f9 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 1 Jun 2020 19:01:47 +0200 Subject: ContentCAO: Update light of all attached entities (#9975) --- src/client/clientenvironment.cpp | 30 +++------------------------- src/client/clientobject.h | 6 +++--- src/client/content_cao.cpp | 42 ++++++++++++++-------------------------- src/client/content_cao.h | 4 +--- 4 files changed, 22 insertions(+), 60 deletions(-) (limited to 'src/client/clientenvironment.cpp') diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 6840f2db3..44ea1e4a1 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -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(); } diff --git a/src/client/clientobject.h b/src/client/clientobject.h index 12e0db35b..8e64b8406 100644 --- a/src/client/clientobject.h +++ b/src/client/clientobject.h @@ -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; } 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); } } diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 8e2a13ea8..7693dd3d2 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -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); -- cgit v1.2.3 From ebb721a476ada0350b73fe44efa66850397b9e96 Mon Sep 17 00:00:00 2001 From: TheTermos <55103816+TheTermos@users.noreply.github.com> Date: Fri, 3 Jul 2020 17:21:42 +0200 Subject: Fix player controls only being applied for the first move --- src/client/client.cpp | 5 +---- src/client/clientenvironment.cpp | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/client/clientenvironment.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index 34f97a9de..65e5b3d8c 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -459,12 +459,9 @@ void Client::step(float dtime) /* Handle environment */ - // Control local player (0ms) LocalPlayer *player = m_env.getLocalPlayer(); - assert(player); - player->applyControl(dtime, &m_env); - // Step environment + // Step environment (also handles player controls) m_env.step(dtime); m_sound->step(dtime); diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 44ea1e4a1..895b0193c 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -216,6 +216,9 @@ void ClientEnvironment::step(float dtime) */ { + // Control local player + lplayer->applyControl(dtime_part, this); + // Apply physics if (!free_move && !is_climbing) { // Gravity -- cgit v1.2.3