Ticket #1846: 0001-Don-t-reinterpolate-if-the-position-of-a-component-d.2.patch

File 0001-Don-t-reinterpolate-if-the-position-of-a-component-d.2.patch, 4.2 KB (added by sbte, 11 years ago)

Sim interpolation speedup patch v2

  • source/simulation2/components/CCmpPosition.cpp

    From c4125767c6040789a90c7549a93e4fe5c3436326 Mon Sep 17 00:00:00 2001
    From: "Sven (Sbte)" <svenb.linux@gmail.com>
    Date: Sun, 24 Feb 2013 15:59:54 +0100
    Subject: Don't reinterpolate if the position of a component does not change
    
    ---
     source/simulation2/components/CCmpPosition.cpp          | 12 ++++++++++++
     source/simulation2/components/CCmpVisualActor.cpp       |  5 +++++
     source/simulation2/components/ICmpPosition.cpp          |  1 +
     source/simulation2/components/ICmpPosition.h            |  2 ++
     source/simulation2/components/tests/test_RangeManager.h |  1 +
     5 files changed, 21 insertions(+)
    
    diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp
    index 80c72d9..97110dc 100644
    a b public:  
    123123
    124124        m_RotX = m_RotY = m_RotZ = entity_angle_t::FromInt(0);
    125125        m_InterpolatedRotY = 0;
     126
     127        m_PositionChanged = false;
    126128    }
    127129
    128130    virtual void Deinit()
    public:  
    454456            m_LastX = m_X;
    455457            m_LastZ = m_Z;
    456458
     459            m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ;
     460
    457461            break;
    458462        }
    459463        }
    460464    }
    461465
     466    virtual bool GetReinterpolate()
     467    {
     468        return m_PositionChanged;
     469    }
     470
    462471private:
    463472    void AdvertisePositionChanges()
    464473    {
    private:  
    472481            CMessagePositionChanged msg(GetEntityId(), false, entity_pos_t::Zero(), entity_pos_t::Zero(), entity_angle_t::Zero());
    473482            GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg);
    474483        }
     484        m_PositionChanged = true;
    475485    }
     486
     487    bool m_PositionChanged;
    476488};
    477489
    478490REGISTER_COMPONENT_TYPE(Position)
  • source/simulation2/components/CCmpVisualActor.cpp

    diff --git a/source/simulation2/components/CCmpVisualActor.cpp b/source/simulation2/components/CCmpVisualActor.cpp
    index 376ddbb..04fb44e 100644
    a b void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)  
    733733        UpdateVisibility();
    734734        m_PreviouslyRendered = true;
    735735    }
     736    else if (!cmpPosition->GetReinterpolate() && m_ConstructionProgress.IsZero())
     737    {
     738        m_Unit->UpdateModel(frameTime);
     739        return;
     740    }
    736741
    737742    // Even if HIDDEN due to LOS, we need to set up the transforms
    738743    // 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 9aaeecc..4b73667 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)
     41DEFINE_INTERFACE_METHOD_0("GetReinterpolate", bool, ICmpPosition, GetReinterpolate)
    4142// Excluded: GetInterpolatedTransform (not safe for scripts)
    4243END_INTERFACE_WRAPPER(Position)
  • source/simulation2/components/ICmpPosition.h

    diff --git a/source/simulation2/components/ICmpPosition.h b/source/simulation2/components/ICmpPosition.h
    index 3e454ce..39c9a0e 100644
    a b public:  
    168168     */
    169169    virtual CMatrix3D GetInterpolatedTransform(float frameOffset, bool forceFloating) = 0;
    170170
     171    virtual bool GetReinterpolate() = 0;
     172
    171173    DECLARE_INTERFACE_TYPE(Position)
    172174};
    173175
  • 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 cf2ee71..f8328dc 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; }
    6263};
    6364
    6465class TestCmpRangeManager : public CxxTest::TestSuite