From 613ba689ff5883f1ee7f64813c39eeb1be6f483a Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Mon, 28 Jul 2025 09:27:13 +0200 Subject: [PATCH] Work around #16221 by updating parent chains --- src/client/content_cao.cpp | 18 ++++++++++++++++++ src/client/content_cao.h | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index 81f193e9b..410059354 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "client/client.h" #include "client/renderingengine.h" #include "client/sound.h" @@ -343,6 +344,18 @@ bool GenericCAO::getSelectionBox(aabb3f *toset) const return true; } +void GenericCAO::updateParentChain() const +{ + if (!m_matrixnode) + return; + // Update the entire chain of nodes to ensure absolute position is correct + std::vector chain; + for (scene::ISceneNode *node = m_matrixnode; node; node = node->getParent()) + chain.push_back(node); + for (auto it = chain.rbegin(); it != chain.rend(); ++it) + (*it)->updateAbsolutePosition(); +} + const v3f GenericCAO::getPosition() const { if (!getParent()) @@ -350,6 +363,11 @@ const v3f GenericCAO::getPosition() const // Calculate real position in world based on MatrixNode if (m_matrixnode) { + // FIXME work around #16221 which is caused by the camera position and thus + // offset not being in sync with the player (parent) CAO position. + // A better solution might restrict this update to the local player only + // or keep player and camera position in sync. + GenericCAO::updateParentChain(); v3s16 camera_offset = m_env->getCameraOffset(); return m_matrixnode->getAbsolutePosition() + intToFloat(camera_offset, BS); diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 798b1674c..e780cf204 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -149,6 +149,7 @@ private: bool visualExpiryRequired(const ObjectProperties &newprops) const; public: + GenericCAO(Client *client, ClientEnvironment *env); ~GenericCAO(); @@ -299,4 +300,10 @@ public: } void updateMeshCulling(); + +private: + + /// Update the parent chain so getPosition() returns an up to date position. + void updateParentChain() const; + };