Ticket #4277: reveal-shore.patch

File reveal-shore.patch, 8.6 KB (added by Itms, 8 years ago)
  • source/simulation2/components/CCmpPathfinder.cpp

     
    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
     
    135135    }
    136136};
    137137
    138 void CCmpPathfinder::Serialize(ISerializer& serialize)
     138template<typename S>
     139void CCmpPathfinder::SerializeCommon(S& serialize)
    139140{
    140141    SerializeVector<SerializeLongRequest>()(serialize, "long requests", m_AsyncLongPathRequests);
    141142    SerializeVector<SerializeShortRequest>()(serialize, "short requests", m_AsyncShortPathRequests);
    142143    serialize.NumberU32_Unbounded("next ticket", m_NextAsyncTicket);
    143144    serialize.NumberU16_Unbounded("same turn moves count", m_SameTurnMovesCount);
     145    serialize.NumberU16_Unbounded("map size", m_MapSize);
    144146}
    145147
     148void CCmpPathfinder::Serialize(ISerializer& serialize)
     149{
     150    SerializeCommon(serialize);
     151}
     152
    146153void CCmpPathfinder::Deserialize(const CParamNode& paramNode, IDeserializer& deserialize)
    147154{
    148155    Init(paramNode);
    149156
    150     SerializeVector<SerializeLongRequest>()(deserialize, "long requests", m_AsyncLongPathRequests);
    151     SerializeVector<SerializeShortRequest>()(deserialize, "short requests", m_AsyncShortPathRequests);
    152     deserialize.NumberU32_Unbounded("next ticket", m_NextAsyncTicket);
    153     deserialize.NumberU16_Unbounded("same turn moves count", m_SameTurnMovesCount);
     157    SerializeCommon(deserialize);
    154158}
    155159
    156160void CCmpPathfinder::HandleMessage(const CMessage& msg, bool UNUSED(global))
  • source/simulation2/components/CCmpPathfinder_Common.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
     
    193193
    194194    virtual void Deinit();
    195195
     196    template<typename S>
     197    void SerializeCommon(S& serialize);
     198
    196199    virtual void Serialize(ISerializer& serialize);
    197200
    198201    virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize);
  • source/simulation2/components/CCmpRangeManager.cpp

     
    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;
     182    i8 owner;
    178183    u8 retainInFog; // boolean
    179     i8 owner;
    180184    u8 inWorld; // boolean
     185    u8 revealShore; // boolean
    181186    u8 flags; // See GetEntityFlagMask
    182187    u8 scriptedVisibility; // boolean, see ComputeLosVisibility
    183188};
     
    236241        serialize.NumberFixed_Unbounded("vision", value.visionRange);
    237242        serialize.NumberU32_Unbounded("visibilities", value.visibilities);
    238243        serialize.NumberU32_Unbounded("size", value.size);
     244        serialize.NumberI8_Unbounded("owner", value.owner);
    239245        serialize.NumberU8("retain in fog", value.retainInFog, 0, 1);
    240         serialize.NumberI8_Unbounded("owner", value.owner);
    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
     
    293299        componentManager.SubscribeGloballyToMessageType(MT_Destroy);
    294300        componentManager.SubscribeGloballyToMessageType(MT_VisionRangeChanged);
    295301
     302        componentManager.SubscribeToMessageType(MT_Deserialized);
     303
    296304        componentManager.SubscribeToMessageType(MT_Update);
    297305
    298306        componentManager.SubscribeToMessageType(MT_RenderSubmit); // for debug overlays
     
    440448        Init(paramNode);
    441449
    442450        SerializeCommon(deserialize);
    443 
    444         // Reinitialise subdivisions and LOS data
    445         m_Deserializing = true;
    446         ResetDerivedData();
    447         m_Deserializing = false;
    448451    }
    449452
    450453    virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))
     
    451454    {
    452455        switch (msg.GetType())
    453456        {
     457        case MT_Deserialized:
     458        {
     459            // Reinitialize subdivisions and LOS data after all
     460            // other components have been deserialized.
     461            m_Deserializing = true;
     462            ResetDerivedData();
     463            m_Deserializing = false;
     464            break;
     465        }
    454466        case MT_Create:
    455467        {
    456468            const CMessageCreate& msgData = static_cast<const CMessageCreate&> (msg);
     
    473485            // Store the LOS data, if any
    474486            CmpPtr<ICmpVision> cmpVision(GetSimContext(), ent);
    475487            if (cmpVision)
     488            {
    476489                entdata.visionRange = cmpVision->GetRange();
     490                entdata.revealShore = cmpVision->GetRevealShore() ? 1 : 0;
     491            }
    477492            CmpPtr<ICmpVisibility> cmpVisibility(GetSimContext(), ent);
    478493            if (cmpVisibility)
    479494                entdata.retainInFog = (cmpVisibility->GetRetainInFog() ? 1 : 0);
     
    561576                CFixedVector2D pos(it->second.x, it->second.z);
    562577                LosRemove(it->second.owner, it->second.visionRange, pos);
    563578                LosAdd(msgData.to, it->second.visionRange, pos);
     579
     580                if (it->second.revealShore)
     581                {
     582                    RevealShore(it->second.owner, false);
     583                    RevealShore(msgData.to, true);
     584                }
    564585            }
    565586
    566587            ENSURE(-128 <= msgData.to && msgData.to <= 127);
     
    751772            {
    752773                LosAdd(it->second.owner, it->second.visionRange, CFixedVector2D(it->second.x, it->second.z));
    753774                AddToTile(PosToLosTilesHelper(it->second.x, it->second.z), it->first);
     775
     776                if (it->second.revealShore)
     777                    RevealShore(it->second.owner, true);
    754778            }
    755779        }
    756780
  • source/simulation2/components/CCmpVision.cpp

     
    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()
     
    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:
     
    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
     
    2929{
    3030public:
    3131    virtual entity_pos_t GetRange() = 0;
     32    virtual bool GetRevealShore() = 0;
    3233
    3334    DECLARE_INTERFACE_TYPE(Vision)
    3435};
  • 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
     
    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
     
    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);