Ticket #1865: 0002-Move-checking-for-reinterpolation-after-a-position-h.patch

File 0002-Move-checking-for-reinterpolation-after-a-position-h.patch, 7.7 KB (added by sbte, 11 years ago)
  • source/simulation2/components/CCmpPosition.cpp

    From c1911c9339f99f86946604dba66fdd24bf4b7859 Mon Sep 17 00:00:00 2001
    From: "Sven (Sbte)" <svenb.linux@gmail.com>
    Date: Sun, 17 Mar 2013 23:47:25 +0100
    Subject: Move checking for reinterpolation after a position has changed to
     VisualActor
    
    ---
     source/simulation2/components/CCmpPosition.cpp     | 27 ++---------------
     source/simulation2/components/CCmpVisualActor.cpp  | 34 +++++++++++++++++-----
     source/simulation2/components/ICmpPosition.cpp     |  1 -
     source/simulation2/components/ICmpPosition.h       |  2 --
     .../components/tests/test_RangeManager.h           |  1 -
     5 files changed, 28 insertions(+), 37 deletions(-)
    
    diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp
    index 3634187..57fcb1b 100644
    a b public:  
    7272    entity_pos_t m_YOffset;
    7373    bool m_RelativeToGround; // whether m_YOffset is relative to terrain/water plane, or an absolute height
    7474
    75     entity_angle_t m_RotX, m_RotY, m_LastRotY, m_PrevRotY, m_RotZ;
     75    entity_angle_t m_RotX, m_RotY, m_RotZ;
    7676    float m_InterpolatedRotY; // not serialized
    7777
    7878    static std::string GetSchema()
    public:  
    121121
    122122        m_RotYSpeed = paramNode.GetChild("TurnRate").ToFixed().ToFloat();
    123123
    124         m_RotX = m_RotY = m_RotZ = m_PrevRotY = m_LastRotY = entity_angle_t::FromInt(0);
     124        m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0);
    125125        m_InterpolatedRotY = 0;
    126 
    127         m_PositionChanged = false;
    128         m_Interpolated = false;
    129126    }
    130127
    131128    virtual void Deinit()
    public:  
    330327    virtual void SetYRotation(entity_angle_t y)
    331328    {
    332329        m_RotY = y;
    333         m_PrevRotY = y;
    334         m_LastRotY = y;
    335330        m_InterpolatedRotY = m_RotY.ToFloat();
    336331
    337332        AdvertisePositionChanges();
    public:  
    422417        {
    423418        case MT_Interpolate:
    424419        {
    425             m_Interpolated = true;
    426             if (!m_PositionChanged)
    427                 return;
    428            
    429420            const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
    430421
    431422            float rotY = m_RotY.ToFloat();
    public:  
    447438            // Store the positions from the turn before
    448439            m_PrevX = m_LastX;
    449440            m_PrevZ = m_LastZ;
    450             m_PrevRotY = m_LastRotY;
    451441
    452442            m_LastX = m_X;
    453443            m_LastZ = m_Z;
    454             m_LastRotY = m_RotY;
    455 
    456             m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ || m_RotY != m_PrevRotY || !m_Interpolated;
    457             m_Interpolated = false;
    458444
    459445            break;
    460446        }
    461447        }
    462448    }
    463449
    464     virtual bool GetReinterpolate()
    465     {
    466         return m_PositionChanged;
    467     }
    468 
    469450private:
    470451    void AdvertisePositionChanges()
    471452    {
    private:  
    479460            CMessagePositionChanged msg(GetEntityId(), false, entity_pos_t::Zero(), entity_pos_t::Zero(), entity_angle_t::Zero());
    480461            GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg);
    481462        }
    482         m_PositionChanged = true;
    483463    }
    484 
    485     bool m_PositionChanged;
    486     bool m_Interpolated;
    487464};
    488465
    489466REGISTER_COMPONENT_TYPE(Position)
  • source/simulation2/components/CCmpVisualActor.cpp

    diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp
    index fed3044..a541866 100644
    a b  
    4242#include "maths/Matrix3D.h"
    4343#include "maths/Vector3D.h"
    4444#include "ps/CLogger.h"
     45#include "ps/Game.h"
     46#include "network/NetTurnManager.h"
    4547#include "renderer/Scene.h"
    4648
    4749#include "tools/atlas/GameInterface/GameLoop.h"
    public:  
    5557        componentManager.SubscribeToMessageType(MT_Interpolate);
    5658        componentManager.SubscribeToMessageType(MT_RenderSubmit);
    5759        componentManager.SubscribeToMessageType(MT_OwnershipChanged);
     60        componentManager.SubscribeToMessageType(MT_PositionChanged);
    5861        componentManager.SubscribeGloballyToMessageType(MT_TerrainChanged);
    5962    }
    6063
    public:  
    8386    bool m_ConstructionPreview;
    8487    fixed m_ConstructionProgress;
    8588
     89    bool m_Interpolated;
     90    u32 m_PositionChangedTurn;
     91
    8692    static std::string GetSchema()
    8793    {
    8894        return
    public:  
    172178
    173179        // We need to select animation even if graphics are disabled, as this modifies serialized state
    174180        SelectAnimation("idle", false, fixed::FromInt(1), L"");
     181
     182        m_Interpolated = false;
     183        m_PositionChangedTurn = 0;
    175184    }
    176185
    177186    virtual void Deinit()
    public:  
    285294            m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1);
    286295            break;
    287296        }
     297        case MT_PositionChanged:
     298        {
     299            // The position was changed, so we need to interpolate again
     300            m_PositionChangedTurn = g_Game->GetTurnManager()->GetCurrentTurn();
     301            m_Interpolated = false;
     302            break;
     303        }
    288304        }
    289305    }
    290306
    void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)  
    726742    if (m_Unit == NULL)
    727743        return;
    728744
     745    if (m_Interpolated && m_ConstructionProgress.IsZero() && !g_AtlasGameLoop->running)
     746    {
     747        // Position hasn't changed so skip most of the work.  Special cases are when placing a building or being
     748        // in atlas (since terrain height can change in atlas)
     749        m_Unit->UpdateModel(frameTime);
     750        return;
     751    }
     752
    729753    // Disable rendering of the unit if it has no position
    730754    CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
    731755    if (!cmpPosition || !cmpPosition->IsInWorld())
    void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)  
    735759        UpdateVisibility();
    736760        m_PreviouslyRendered = true;
    737761    }
    738     else if (!cmpPosition->GetReinterpolate() && m_ConstructionProgress.IsZero() &&
    739              !g_AtlasGameLoop->running)
    740     {
    741         // Position hasn't changed so skip most of the work.  Special cases are when placing a building or being
    742         // in atlas (since terrain height can change in atlas)
    743         m_Unit->UpdateModel(frameTime);
    744         return;
    745     }
     762
     763    m_Interpolated = (g_Game->GetTurnManager()->GetCurrentTurn() > m_PositionChangedTurn);
    746764
    747765    // Even if HIDDEN due to LOS, we need to set up the transforms
    748766    // so that projectiles will be launched from the right place
  • source/simulation2/components/ICmpPosition.cpp

    diff --git a/source/simulation2/components/ICmpPosition.cpp b/source/simulation2/components/ICmpPosition.cpp
    index 4b73667..9aaeecc 100644
    a b DEFINE_INTERFACE_METHOD_1("TurnTo", void, ICmpPosition, TurnTo, entity_angle_t)  
    3838DEFINE_INTERFACE_METHOD_1("SetYRotation", void, ICmpPosition, SetYRotation, entity_angle_t)
    3939DEFINE_INTERFACE_METHOD_2("SetXZRotation", void, ICmpPosition, SetXZRotation, entity_angle_t, entity_angle_t)
    4040DEFINE_INTERFACE_METHOD_0("GetRotation", CFixedVector3D, ICmpPosition, GetRotation)
    41 DEFINE_INTERFACE_METHOD_0("GetReinterpolate", bool, ICmpPosition, GetReinterpolate)
    4241// Excluded: GetInterpolatedTransform (not safe for scripts)
    4342END_INTERFACE_WRAPPER(Position)
  • source/simulation2/components/ICmpPosition.h

    diff --git a/source/simulation2/components/ICmpPosition.h b/source/simulation2/components/ICmpPosition.h
    index 39c9a0e..3e454ce 100644
    a b public:  
    168168     */
    169169    virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0;
    170170
    171     virtual bool GetReinterpolate() = 0;
    172 
    173171    DECLARE_INTERFACE_TYPE(Position)
    174172};
    175173
  • source/simulation2/components/tests/test_RangeManager.h

    diff --git a/source/simulation2/components/tests/test_RangeManager.h b/source/simulation2/components/tests/test_RangeManager.h
    index 786b2d6..cf2ee71 100644
    a b public:  
    5959    virtual fixed GetDistanceTravelled() { return fixed::Zero(); }
    6060    virtual void GetInterpolatedPosition2D(float UNUSED(frameOffset), float& x, float& z, float& rotY) { x = z = rotY = 0; }
    6161    virtual CMatrix3D GetInterpolatedTransform(float UNUSED(frameOffset), bool UNUSED(forceFloating)) { return CMatrix3D(); }
    62     virtual bool GetReinterpolate() { return true; }
    6362};
    6463
    6564class TestCmpRangeManager : public CxxTest::TestSuite