Ticket #4279: update_vision_on_ownershipchange_v1.patch

File update_vision_on_ownershipchange_v1.patch, 2.3 KB (added by elexis, 8 years ago)

No clue whether that works, since I can't reproduce the error without the rejointest yet.

  • source/simulation2/components/CCmpVision.cpp

    public:  
    8383    {
    8484        switch (msg.GetType())
    8585        {
    8686        case MT_OwnershipChanged:
    8787        {
    88             if (!m_RevealShore)
    89                 break;
    90 
    9188            const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg);
    9289            if (msgData.entity != GetEntityId())
    9390                break;
    9491
     92            ReloadRange();
     93
     94            if (!m_RevealShore)
     95                break;
    9596            CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity());
    9697            cmpRangeManager->RevealShore(msgData.from, false);
    9798            cmpRangeManager->RevealShore(msgData.to, true);
    9899            break;
    99100        }
    public:  
    101102        {
    102103            const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg);
    103104            if (msgData.component != L"Vision")
    104105                break;
    105106
    106             CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
    107             if (!cmpValueModificationManager)
    108                 break;
    109 
    110             entity_pos_t newRange = cmpValueModificationManager->ApplyModifications(L"Vision/Range", m_BaseRange, GetEntityId());
    111             if (newRange == m_Range)
    112                 break;
    113 
    114             // Update our vision range and broadcast message
    115             entity_pos_t oldRange = m_Range;
    116             m_Range = newRange;
    117             CMessageVisionRangeChanged msg(GetEntityId(), oldRange, newRange);
    118             GetSimContext().GetComponentManager().BroadcastMessage(msg);
     107            ReloadRange();
    119108            break;
    120109        }
    121110        case MT_Deserialized:
    122111        {
    123112            CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
    public:  
    126115            break;
    127116        }
    128117        }
    129118    }
    130119
     120    virtual void ReloadRange()
     121    {
     122        CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
     123        if (!cmpValueModificationManager)
     124            return;
     125
     126        entity_pos_t range newRange = cmpValueModificationManager->ApplyModifications(L"Vision/Range", m_BaseRange, GetEntityId());
     127        if (newRange == m_Range)
     128            return;
     129
     130        // Update our vision range and broadcast message
     131        entity_pos_t oldRange = m_Range;
     132        m_Range = newRange;
     133        CMessageVisionRangeChanged msg(GetEntityId(), oldRange, newRange);
     134        GetSimContext().GetComponentManager().BroadcastMessage(msg);
     135    }
     136
    131137    virtual entity_pos_t GetRange()
    132138    {
    133139        return m_Range;
    134140    }
    135141};