revert part of a recent TransformManager change

setParent() is not supposed to reorder child/parents in the array
because it doesn't rely on them being orderer. This also has the
advantage of not invalidating Instances.

However, commitLocalTransformTransaction() does rely on child/parent
ordering and the previous change did fix that.
This commit is contained in:
Mathias Agopian
2020-01-13 16:55:40 -08:00
committed by Mathias Agopian
parent 59e3465b6b
commit 40c7232bb2
2 changed files with 7 additions and 15 deletions

View File

@@ -65,18 +65,10 @@ void FTransformManager::setParent(Instance i, Instance parent) noexcept {
removeNode(i);
insertNode(i, parent);
updateNodeTransform(i);
// Ensure that instances are still in order
if (!mLocalTransformTransactionOpen && i < parent) {
Instance end = manager.end();
while (i != end) {
Instance iParent = Instance(manager[i].parent);
if (UTILS_UNLIKELY(iParent > i)) {
swapNode(i, iParent);
} else {
++i;
}
}
}
// Note: setParent() doesn't reorder the child after the parent in the array,
// but that's not a problem because TransformManager doesn't rely on that.
// Also note that commitLocalTransformTransaction() does reorder all children after
// their parent, as an optimization to calculate the world transform.
}
}
}

View File

@@ -235,13 +235,13 @@ TEST(FilamentTest, TransformManager) {
tcm.create(entities[2]);
EXPECT_TRUE(tcm.hasComponent(entities[2]));
TransformManager::Instance newParent = tcm.getInstance(entities[2]);
EXPECT_TRUE(bool(newParent));
ASSERT_LT(child, newParent);
// test reparenting
tcm.setParent(child, newParent);
// make sure child/parent are out of order
ASSERT_LT(child, newParent);
// make sure child/parent are out of order (i.e.: setParent() doesn't invalidate instances)
EXPECT_LT(tcm.getInstance(entities[1]), tcm.getInstance(entities[2]));
// local transaction reorders parent/child
tcm.openLocalTransformTransaction();