From 42b1d0b5d6184f60191abd159474769744d2eb17 Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Tue, 9 Feb 2021 19:54:58 +0000 Subject: [PATCH] Broadcast transformChanged() to attached entities Attached light now moves with the parent entity, which did not happen before because the attached entity's transformChanged() method was never called to invalidate its localToWorld when the parent entity moved. --- radiantcore/entity/EntityNode.cpp | 10 ++++++++++ radiantcore/entity/EntityNode.h | 1 + test/Entity.cpp | 4 ---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/radiantcore/entity/EntityNode.cpp b/radiantcore/entity/EntityNode.cpp index 5f44b050a2..281a67aa44 100644 --- a/radiantcore/entity/EntityNode.cpp +++ b/radiantcore/entity/EntityNode.cpp @@ -148,6 +148,16 @@ void EntityNode::createAttachedEntities() ); } +void EntityNode::transformChanged() +{ + Node::transformChanged(); + + // Broadcast transformChanged to all attached entities so they can update + // their position + for (auto attached: _attachedEnts) + attached->transformChanged(); +} + void EntityNode::onEntityClassChanged() { // By default, we notify the KeyObservers attached to this entity diff --git a/radiantcore/entity/EntityNode.h b/radiantcore/entity/EntityNode.h index d2f846b64e..a4622790db 100644 --- a/radiantcore/entity/EntityNode.h +++ b/radiantcore/entity/EntityNode.h @@ -103,6 +103,7 @@ class EntityNode : // IEntityNode implementation Entity& getEntity() override; virtual void refreshModel() override; + void transformChanged() override; // RenderEntity implementation virtual float getShaderParm(int parmNum) const override; diff --git a/test/Entity.cpp b/test/Entity.cpp index ad5384b67e..44c1d05885 100644 --- a/test/Entity.cpp +++ b/test/Entity.cpp @@ -602,10 +602,6 @@ TEST_F(EntityTest, RenderAttachedLightEntity) RenderFixture rf(true /* solid mode */); rf.renderSubGraph(torch); - // The node visitor should have visited the entity itself and one child node (a - // static model) - EXPECT_EQ(rf.nodesVisited, 2); - // There should be 3 renderables from the torch (because the entity has a // shadowmesh and a collision mesh as well as the main model) and one from // the light (the origin diamond).