Ticket #1858: 0002-Improve-detection-of-whether-we-have-to-interpolate.patch

File 0002-Improve-detection-of-whether-we-have-to-interpolate.patch, 2.8 KB (added by sbte, 11 years ago)
  • source/simulation2/components/CCmpPosition.cpp

    From e81e91cc392914369f71430d1fcf94e8a9c6acdc Mon Sep 17 00:00:00 2001
    From: "Sven (Sbte)" <svenb.linux@gmail.com>
    Date: Sun, 10 Mar 2013 11:59:49 +0100
    Subject: Improve detection of whether we have to interpolate
    
    Fixes angle interpolation in a nicer way and also fixed case where a turn
    started before anything was rendered
    ---
     source/simulation2/components/CCmpPosition.cpp | 23 +++++++++++++++--------
     1 file changed, 15 insertions(+), 8 deletions(-)
    
    diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp
    index c24ec8f..7306a00 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_RotZ;
     75    entity_angle_t m_RotX, m_RotY, m_LastRotY, m_PrevRotY, 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 = entity_angle_t::FromInt(0);
     124        m_RotX = m_RotY = m_RotZ = m_PrevRotY = m_LastRotY = entity_angle_t::FromInt(0);
    125125        m_InterpolatedRotY = 0;
    126126
    127127        m_PositionChanged = false;
     128        m_Interpolated = false;
    128129    }
    129130
    130131    virtual void Deinit()
    public:  
    329330    virtual void SetYRotation(entity_angle_t y)
    330331    {
    331332        m_RotY = y;
     333        m_PrevRotY = y;
     334        m_LastRotY = y;
    332335        m_InterpolatedRotY = m_RotY.ToFloat();
    333336
    334337        AdvertisePositionChanges();
    public:  
    420423        {
    421424        case MT_Interpolate:
    422425        {
     426            m_Interpolated = true;
     427            if (!m_PositionChanged)
     428                return;
     429
    423430            const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
    424431
    425432            float rotY = m_RotY.ToFloat();
    public:  
    433440            // Calculate new orientation, in a peculiar way in order to make sure the
    434441            // result gets close to m_orientation (rather than being n*2*M_PI out)
    435442            m_InterpolatedRotY = rotY + deltaClamped - delta;
    436            
    437             // Anything smaller than this will not be visible
    438             if (abs(delta) > 0.0001)
    439                 m_PositionChanged = true;
    440443
    441444            break;
    442445        }
    public:  
    445448            // Store the positions from the turn before
    446449            m_PrevX = m_LastX;
    447450            m_PrevZ = m_LastZ;
    448            
     451            m_PrevRotY = m_LastRotY;
     452
    449453            m_LastX = m_X;
    450454            m_LastZ = m_Z;
     455            m_LastRotY = m_RotY;
    451456
    452             m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ;
     457            m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ || m_RotY != m_PrevRotY || !m_Interpolated;
     458            m_Interpolated = false;
    453459
    454460            break;
    455461        }
    private:  
    478484    }
    479485
    480486    bool m_PositionChanged;
     487    bool m_Interpolated;
    481488};
    482489
    483490REGISTER_COMPONENT_TYPE(Position)