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

File 0003-Move-checking-for-reinterpolation-after-a-position-h.2.patch, 7.2 KB (added by historic_bruno, 11 years ago)

Removed checks for special cases, update them appropriately

  • source/simulation2/components/CCmpPosition.cpp

     
    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()
     
    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()
     
    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();
     
    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();
     
    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;
    455444
    456             m_PositionChanged = m_X != m_PrevX || m_Z != m_PrevZ || m_RotY != m_PrevRotY || !m_Interpolated;
    457             m_Interpolated = false;
    458 
    459445            break;
    460446        }
    461447        }
    462448    }
    463449
    464     virtual bool GetReinterpolate()
    465     {
    466         return m_PositionChanged;
    467     }
    468 
    469450private:
    470451    void AdvertisePositionChanges()
    471452    {
     
    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

     
    5555        componentManager.SubscribeToMessageType(MT_Interpolate);
    5656        componentManager.SubscribeToMessageType(MT_RenderSubmit);
    5757        componentManager.SubscribeToMessageType(MT_OwnershipChanged);
     58        componentManager.SubscribeToMessageType(MT_PositionChanged);
     59        componentManager.SubscribeToMessageType(MT_TurnStart);
    5860        componentManager.SubscribeGloballyToMessageType(MT_TerrainChanged);
    5961    }
    6062
     
    8385    bool m_ConstructionPreview;
    8486    fixed m_ConstructionProgress;
    8587
     88    bool m_NeedsInterpolation;
     89    bool m_PositionChanged;
     90
    8691    static std::string GetSchema()
    8792    {
    8893        return
     
    172177
    173178        // We need to select animation even if graphics are disabled, as this modifies serialized state
    174179        SelectAnimation("idle", false, fixed::FromInt(1), L"");
     180
     181        m_NeedsInterpolation = true;
     182        m_PositionChanged = true;
    175183    }
    176184
    177185    virtual void Deinit()
     
    283291        {
    284292            const CMessageTerrainChanged& msgData = static_cast<const CMessageTerrainChanged&> (msg);
    285293            m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1);
     294            // Terrain has changed, so we need to interpolate again
     295            m_NeedsInterpolation = true;
    286296            break;
    287297        }
     298        case MT_PositionChanged:
     299        {
     300            // The position was changed, so we need to interpolate again
     301            m_PositionChanged = true;
     302            m_NeedsInterpolation = true;
     303            break;
    288304        }
     305        case MT_TurnStart:
     306        {
     307            // Check whether we need to reinterpolate during this turn
     308            m_NeedsInterpolation = m_PositionChanged || m_NeedsInterpolation;
     309            m_PositionChanged = false;
     310            break;
     311        }
     312        }
    289313    }
    290314
    291315    virtual CBoundingBoxAligned GetBounds()
     
    453477
    454478    virtual void SetConstructionProgress(fixed progress)
    455479    {
    456         m_ConstructionProgress = progress;
     480        if (progress != m_ConstructionProgress)
     481        {
     482            m_ConstructionProgress = progress;
     483            // Visual height changed, so we need to interpolate again
     484            m_NeedsInterpolation = true;
     485        }
    457486    }
    458487
    459488    virtual void Hotload(const VfsPath& name)
     
    726755    if (m_Unit == NULL)
    727756        return;
    728757
     758    if (!m_NeedsInterpolation)
     759    {
     760        // Position hasn't changed so skip most of the work
     761        m_Unit->UpdateModel(frameTime);
     762        return;
     763    }
     764
    729765    // Disable rendering of the unit if it has no position
    730766    CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
    731767    if (!cmpPosition || !cmpPosition->IsInWorld())
     
    735771        UpdateVisibility();
    736772        m_PreviouslyRendered = true;
    737773    }
    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     }
    746774
     775    m_NeedsInterpolation = m_PositionChanged;
     776
    747777    // Even if HIDDEN due to LOS, we need to set up the transforms
    748778    // so that projectiles will be launched from the right place
    749779
  • source/simulation2/components/ICmpPosition.cpp

     
    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

     
    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

     
    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