1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Work around #16221 by updating parent chains

This commit is contained in:
Lars Mueller 2025-07-28 09:27:13 +02:00 committed by SmallJoker
parent 26aab6ecf2
commit 613ba689ff
2 changed files with 25 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include <ICameraSceneNode.h>
#include <IMeshManipulator.h>
#include <IAnimatedMeshSceneNode.h>
#include <ISceneNode.h>
#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<scene::ISceneNode *> 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);

View file

@ -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;
};