From 8529426fa8074c094cce0e47d62e2d2c5a9d833c Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Fri, 7 Oct 2005 02:44:54 +0000 Subject: [PATCH] Optimisation: Don't recalculate actor transform data for entities that haven't moved This was SVN commit r2862. --- source/simulation/Entity.cpp | 24 ++++++++++++++++++++++-- source/simulation/Entity.h | 4 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index ae67f3783d..52bb237e96 100755 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -87,6 +87,7 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation ) m_graphics_position = m_position; m_graphics_orientation = m_orientation; + m_actor_transform_valid = false; m_destroyed = false; @@ -573,6 +574,9 @@ void CEntity::checkGroup() void CEntity::interpolate( float relativeoffset ) { + CVector3D old_graphics_position = m_graphics_position; + float old_graphics_orientation = m_graphics_orientation; + m_graphics_position = Interpolate( m_position_previous, m_position, relativeoffset ); // Avoid wraparound glitches for interpolating angles. @@ -582,8 +586,24 @@ void CEntity::interpolate( float relativeoffset ) m_orientation_previous += 2 * PI; m_graphics_orientation = Interpolate( m_orientation_previous, m_orientation, relativeoffset ); - snapToGround(); - updateActorTransforms(); + + // Mark the actor transform data as invalid if the entity has moved since + // the last call to 'interpolate'. + // position.Y is ignored because we can't determine the new value without + // calling snapToGround, which is slow. TODO: This may need to be adjusted to + // handle flying units or moving terrain. + if( m_graphics_orientation != old_graphics_orientation || + m_graphics_position.X != old_graphics_position.X || + m_graphics_position.Z != old_graphics_position.Z ) + m_actor_transform_valid = false; + + // Update the actor transform data when necessary. + if( !m_actor_transform_valid ) + { + snapToGround(); + updateActorTransforms(); + m_actor_transform_valid = true; + } } void CEntity::render() diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index d300eedb66..1911594649 100755 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -106,6 +106,10 @@ public: float m_orientation_previous; float m_graphics_orientation; + // If the actor's current transform data is valid (i.e. the entity hasn't + // moved since it was last calculated). + bool m_actor_transform_valid; + //-- Scripts // Get script execution contexts - always run in the context of the entity that fired it.