From 6b73ba029625d2fa2477a160e530397dfe8be4c9 Mon Sep 17 00:00:00 2001 From: Matei Date: Sat, 16 Sep 2006 21:30:23 +0000 Subject: [PATCH] - Terrain conformance should now work in Atlas as well. - Renamed Passive stance to Hold (which is what it's called in the design doc and GUI). This was SVN commit r4345. --- source/simulation/Entity.cpp | 22 +++++++++++++++++---- source/simulation/Entity.h | 1 + source/simulation/EntityManager.cpp | 15 ++------------ source/simulation/EntityStateProcessing.cpp | 15 +------------- source/simulation/Stance.h | 8 ++++---- 5 files changed, 26 insertions(+), 35 deletions(-) diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 9e912bcdee..c0aa94e2b9 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -51,7 +51,7 @@ CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, m_player = NULL; m_productionQueue = new CProductionQueue( this ); - m_stance = new CPassiveStance( this ); + m_stance = new CHoldStance( this ); for( int t = 0; t < EVENT_LAST; t++ ) { @@ -109,7 +109,7 @@ CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, m_visible = true; m_associatedTerritory = 0; - + m_player = g_Game->GetPlayer( 0 ); } @@ -287,6 +287,18 @@ void CEntity::snapToGround() m_graphics_position.Y = getAnchorLevel( m_graphics_position.X, m_graphics_position.Z ); } +void CEntity::updateXZOrientation() +{ + // Make sure m_ahead is correct + m_ahead.x = sin( m_orientation.Y ); + m_ahead.y = cos( m_orientation.Y ); + + CVector2D targetXZ = g_Game->GetWorld()->GetTerrain()->getSlopeAngleFace(this); + m_orientation.X = clamp( targetXZ.x, -m_base->m_anchorConformX, m_base->m_anchorConformX ); + m_orientation.Z = clamp( targetXZ.y, -m_base->m_anchorConformZ, m_base->m_anchorConformZ ); + m_orientation_unclamped.x = targetXZ.x; + m_orientation_unclamped.y = targetXZ.y; +} jsval CEntity::getClassSet() { @@ -816,9 +828,9 @@ void CEntity::stanceChanged() { m_stance = new CStandStance( this ); } - else + else // m_stanceName == "hold" or undefined stance { - m_stance = new CPassiveStance( this ); + m_stance = new CHoldStance( this ); } } @@ -871,6 +883,8 @@ void CEntity::interpolate( float relativeoffset ) while( m_orientation.Z > m_orientation_previous.Z + PI ) m_orientation_previous.Z += 2 * PI; + updateXZOrientation(); + m_graphics_orientation = Interpolate( m_orientation_previous, m_orientation, relativeoffset ); // Mark the actor transform data as invalid if the entity has moved since diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index fe4b01e76c..59026c9d00 100644 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -312,6 +312,7 @@ public: void snapToGround(); void updateActorTransforms(); + void updateXZOrientation(); // Getter and setter for the class sets jsval getClassSet(); diff --git a/source/simulation/EntityManager.cpp b/source/simulation/EntityManager.cpp index 903bdf1d8c..ac0d76c983 100644 --- a/source/simulation/EntityManager.cpp +++ b/source/simulation/EntityManager.cpp @@ -295,19 +295,8 @@ void CEntityManager::conformAll() { if( isEntityRefd(i) ) { - CEntity* entity = m_entities[i].m_entity; - CVector2D targetXZ = g_Game->GetWorld()->GetTerrain()->getSlopeAngleFace(entity ); - - while( targetXZ.x > PI ) targetXZ.x -= 2 * PI; - while( targetXZ.x < -PI ) targetXZ.x += 2 * PI; - while( targetXZ.y > PI ) targetXZ.y -= 2 * PI; - while( targetXZ.y < -PI ) targetXZ.y += 2 * PI; - - entity->m_orientation.X = clamp( targetXZ.x, -entity->m_base->m_anchorConformX, entity->m_base->m_anchorConformX ); - entity->m_orientation.Z = clamp( targetXZ.y, -entity->m_base->m_anchorConformZ, entity->m_base->m_anchorConformZ ); - entity->m_orientation_unclamped.x = targetXZ.x; - entity->m_orientation_unclamped.y = targetXZ.y; - entity->updateActorTransforms(); + m_entities[i].m_entity->updateXZOrientation(); + m_entities[i].m_entity->updateActorTransforms(); } } PROFILE_END("conform all"); diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 7afba1d7fb..cc524949c3 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -152,21 +152,8 @@ uint CEntity::processGotoHelper( CEntityOrder* current, size_t timestep_millis, m_ahead = delta / len; m_orientation.Y = m_targetorientation; } - CVector2D targetXZ = g_Game->GetWorld()->GetTerrain()->getSlopeAngleFace(this); - while( targetXZ.x > PI ) targetXZ.x -= 2 * PI; - while( targetXZ.x < -PI ) targetXZ.x += 2 * PI; - while( targetXZ.y > PI ) targetXZ.y -= 2 * PI; - while( targetXZ.y < -PI ) targetXZ.y += 2 * PI; - - float cX = m_base->m_anchorConformX, cZ = m_base->m_anchorConformZ; - m_orientation.X = clamp( targetXZ.x, -cX, cX ); - m_orientation.Z = clamp( targetXZ.y, -cZ, cZ ); - m_orientation_unclamped.x = targetXZ.x; - m_orientation_unclamped.y = targetXZ.y; - - //CMovementEvent evt( m_orientation_unclamped.x ); - //DispatchEvent(&evt); + updateXZOrientation(); if( m_bounds && m_bounds->m_type == CBoundingObject::BOUND_OABB ) ((CBoundingBox*)m_bounds)->setOrientation( m_ahead ); diff --git a/source/simulation/Stance.h b/source/simulation/Stance.h index e483ffebb7..2ac79b640b 100644 --- a/source/simulation/Stance.h +++ b/source/simulation/Stance.h @@ -36,13 +36,13 @@ public: }; /** - * Passive stance: Unit never attacks, not even to fight back. + * Hold Fire stance: Unit never attacks, not even to fight back. **/ -class CPassiveStance : public CStance +class CHoldStance : public CStance { public: - CPassiveStance(CEntity* ent): CStance(ent) {}; - virtual ~CPassiveStance() {}; + CHoldStance(CEntity* ent): CStance(ent) {}; + virtual ~CHoldStance() {}; virtual void onIdle() {}; virtual void onDamaged(CEntity* UNUSED(source)) {}; virtual bool allowsMovement() { return false; };