Ticket #4277: reveal-shore-notfix_v2.patch

File reveal-shore-notfix_v2.patch, 8.0 KB (added by elexis, 8 years ago)

Prior patch by Itms with his new suggestion to also serialize m_MapSize in the pathfinder. Doesn't work as there is still the OOS after deleting the lighthouse when someone rejoined after it was built.

  • source/simulation2/components/CCmpPathfinder.cpp

    void CCmpPathfinder::Serialize(ISerializ  
    139139{
    140140    SerializeVector<SerializeLongRequest>()(serialize, "long requests", m_AsyncLongPathRequests);
    141141    SerializeVector<SerializeShortRequest>()(serialize, "short requests", m_AsyncShortPathRequests);
    142142    serialize.NumberU32_Unbounded("next ticket", m_NextAsyncTicket);
    143143    serialize.NumberU16_Unbounded("same turn moves count", m_SameTurnMovesCount);
     144    serialize.NumberU16_Unbounded("map size", m_MapSize);
    144145}
    145146
    146147void CCmpPathfinder::Deserialize(const CParamNode& paramNode, IDeserializer& deserialize)
    147148{
    148149    Init(paramNode);
    149150
    150151    SerializeVector<SerializeLongRequest>()(deserialize, "long requests", m_AsyncLongPathRequests);
    151152    SerializeVector<SerializeShortRequest>()(deserialize, "short requests", m_AsyncShortPathRequests);
    152153    deserialize.NumberU32_Unbounded("next ticket", m_NextAsyncTicket);
    153154    deserialize.NumberU16_Unbounded("same turn moves count", m_SameTurnMovesCount);
     155    deserialize.NumberU16_Unbounded("map size", m_MapSize);
    154156}
    155157
    156158void CCmpPathfinder::HandleMessage(const CMessage& msg, bool UNUSED(global))
    157159{
    158160    switch (msg.GetType())
  • source/simulation2/components/CCmpRangeManager.cpp

    static std::map<entity_id_t, EntityParab  
    168168/**
    169169 * Representation of an entity, with the data needed for queries.
    170170 */
    171171struct EntityData
    172172{
    173     EntityData() : visibilities(0), size(0), retainInFog(0), owner(-1), inWorld(0), flags(1), scriptedVisibility(0) { }
     173    EntityData() :
     174        visibilities(0), size(0),
     175        owner(-1), retainInFog(0), inWorld(0), revealShore(0),
     176        flags(1), scriptedVisibility(0)
     177        { }
    174178    entity_pos_t x, z;
    175179    entity_pos_t visionRange;
    176180    u32 visibilities; // 2-bit visibility, per player
    177181    u32 size;
    178     u8 retainInFog; // boolean
    179182    i8 owner;
     183    u8 retainInFog; // boolean
    180184    u8 inWorld; // boolean
     185    u8 revealShore; // boolean
    181186    u8 flags; // See GetEntityFlagMask
    182187    u8 scriptedVisibility; // boolean, see ComputeLosVisibility
    183188};
    184189
    185190cassert(sizeof(EntityData) == 28);
    struct SerializeEntityData  
    234239        serialize.NumberFixed_Unbounded("x", value.x);
    235240        serialize.NumberFixed_Unbounded("z", value.z);
    236241        serialize.NumberFixed_Unbounded("vision", value.visionRange);
    237242        serialize.NumberU32_Unbounded("visibilities", value.visibilities);
    238243        serialize.NumberU32_Unbounded("size", value.size);
    239         serialize.NumberU8("retain in fog", value.retainInFog, 0, 1);
    240244        serialize.NumberI8_Unbounded("owner", value.owner);
     245        serialize.NumberU8("retain in fog", value.retainInFog, 0, 1);
    241246        serialize.NumberU8("in world", value.inWorld, 0, 1);
     247        serialize.NumberU8("reveal shore", value.revealShore, 0, 1);
    242248        serialize.NumberU8_Unbounded("flags", value.flags);
    243         serialize.NumberU8_Unbounded("scripted visibility", value.scriptedVisibility);
     249        serialize.NumberU8("scripted visibility", value.scriptedVisibility, 0, 1);
    244250    }
    245251};
    246252
    247253
    248254/**
    public:  
    471477            EntityData entdata;
    472478
    473479            // Store the LOS data, if any
    474480            CmpPtr<ICmpVision> cmpVision(GetSimContext(), ent);
    475481            if (cmpVision)
     482            {
    476483                entdata.visionRange = cmpVision->GetRange();
     484                entdata.revealShore = cmpVision->GetRevealShore() ? 1 : 0;
     485            }
    477486            CmpPtr<ICmpVisibility> cmpVisibility(GetSimContext(), ent);
    478487            if (cmpVisibility)
    479488                entdata.retainInFog = (cmpVisibility->GetRetainInFog() ? 1 : 0);
    480489
    481490            // Store the size
    public:  
    559568            if (it->second.inWorld)
    560569            {
    561570                CFixedVector2D pos(it->second.x, it->second.z);
    562571                LosRemove(it->second.owner, it->second.visionRange, pos);
    563572                LosAdd(msgData.to, it->second.visionRange, pos);
     573
     574                if (it->second.revealShore)
     575                {
     576                    RevealShore(it->second.owner, false);
     577                    RevealShore(msgData.to, true);
     578                }
    564579            }
    565580
    566581            ENSURE(-128 <= msgData.to && msgData.to <= 127);
    567582            it->second.owner = (i8)msgData.to;
    568583
    public:  
    749764        {
    750765            if (it->second.inWorld)
    751766            {
    752767                LosAdd(it->second.owner, it->second.visionRange, CFixedVector2D(it->second.x, it->second.z));
    753768                AddToTile(PosToLosTilesHelper(it->second.x, it->second.z), it->first);
     769
     770                if (it->second.revealShore)
     771                    RevealShore(it->second.owner, true);
    754772            }
    755773        }
    756774
    757775        m_TotalInworldVertices = 0;
    758776        for (ssize_t j = 0; j < m_TerrainVerticesPerSide; ++j)
  • source/simulation2/components/CCmpVision.cpp

    public:  
    3838    DEFAULT_COMPONENT_ALLOCATOR(Vision)
    3939
    4040    // Template state:
    4141
    4242    entity_pos_t m_Range, m_BaseRange;
     43
     44    // TODO: The reveal shore system should be replaced by a general
     45    // system of "special" vision methods that are not ranges.
    4346    bool m_RevealShore;
    4447
    4548    static std::string GetSchema()
    4649    {
    4750        return
    public:  
    8891            const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg);
    8992            if (msgData.entity != GetEntityId())
    9093                break;
    9194
    9295            ReloadRange();
    93 
    94             if (!m_RevealShore)
    95                 break;
    96             CmpPtr<ICmpRangeManager> cmpRangeManager(GetSystemEntity());
    97             cmpRangeManager->RevealShore(msgData.from, false);
    98             cmpRangeManager->RevealShore(msgData.to, true);
    9996            break;
    10097        }
    10198        case MT_ValueModification:
    10299        {
    103100            const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg);
    public:  
    135132
    136133    virtual entity_pos_t GetRange()
    137134    {
    138135        return m_Range;
    139136    }
     137
     138    virtual bool GetRevealShore()
     139    {
     140        return m_RevealShore;
     141    }
    140142};
    141143
    142144REGISTER_COMPONENT_TYPE(Vision)
  • source/simulation2/components/ICmpVision.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
     
    2727 */
    2828class ICmpVision : public IComponent
    2929{
    3030public:
    3131    virtual entity_pos_t GetRange() = 0;
     32    virtual bool GetRevealShore() = 0;
    3233
    3334    DECLARE_INTERFACE_TYPE(Vision)
    3435};
    3536
    3637#endif // INCLUDED_ICMPVISION
  • source/simulation2/components/tests/test_RangeManager.h

     
    1 /* Copyright (C) 2015 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
    class MockVision : public ICmpVision  
    2929{
    3030public:
    3131    DEFAULT_MOCK_COMPONENT()
    3232
    3333    virtual entity_pos_t GetRange() { return entity_pos_t::FromInt(66); }
    34     virtual bool GetRetainInFog() { return false; }
    35     virtual bool GetAlwaysVisible() { return false; }
     34    virtual bool GetRevealShore() { return false; }
    3635};
    3736
    3837class MockPosition : public ICmpPosition
    3938{
    4039public:
    public:  
    8382    void tearDown()
    8483    {
    8584        CXeromyces::Terminate();
    8685    }
    8786
     87    // TODO It would be nice to call Verify() with the shore revealing system
     88    // but that means testing on an actual map, with water and land.
     89
    8890    void test_basic()
    8991    {
    9092        ComponentTestHelper test(g_ScriptRuntime);
    9193
    9294        ICmpRangeManager* cmp = test.Add<ICmpRangeManager>(CID_RangeManager, "", SYSTEM_ENTITY);