Ticket #4277: reveal-shore-notfix_v2.patch
File reveal-shore-notfix_v2.patch, 8.0 KB (added by , 8 years ago) |
---|
-
source/simulation2/components/CCmpPathfinder.cpp
void CCmpPathfinder::Serialize(ISerializ 139 139 { 140 140 SerializeVector<SerializeLongRequest>()(serialize, "long requests", m_AsyncLongPathRequests); 141 141 SerializeVector<SerializeShortRequest>()(serialize, "short requests", m_AsyncShortPathRequests); 142 142 serialize.NumberU32_Unbounded("next ticket", m_NextAsyncTicket); 143 143 serialize.NumberU16_Unbounded("same turn moves count", m_SameTurnMovesCount); 144 serialize.NumberU16_Unbounded("map size", m_MapSize); 144 145 } 145 146 146 147 void CCmpPathfinder::Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) 147 148 { 148 149 Init(paramNode); 149 150 150 151 SerializeVector<SerializeLongRequest>()(deserialize, "long requests", m_AsyncLongPathRequests); 151 152 SerializeVector<SerializeShortRequest>()(deserialize, "short requests", m_AsyncShortPathRequests); 152 153 deserialize.NumberU32_Unbounded("next ticket", m_NextAsyncTicket); 153 154 deserialize.NumberU16_Unbounded("same turn moves count", m_SameTurnMovesCount); 155 deserialize.NumberU16_Unbounded("map size", m_MapSize); 154 156 } 155 157 156 158 void CCmpPathfinder::HandleMessage(const CMessage& msg, bool UNUSED(global)) 157 159 { 158 160 switch (msg.GetType()) -
source/simulation2/components/CCmpRangeManager.cpp
static std::map<entity_id_t, EntityParab 168 168 /** 169 169 * Representation of an entity, with the data needed for queries. 170 170 */ 171 171 struct EntityData 172 172 { 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 { } 174 178 entity_pos_t x, z; 175 179 entity_pos_t visionRange; 176 180 u32 visibilities; // 2-bit visibility, per player 177 181 u32 size; 178 u8 retainInFog; // boolean179 182 i8 owner; 183 u8 retainInFog; // boolean 180 184 u8 inWorld; // boolean 185 u8 revealShore; // boolean 181 186 u8 flags; // See GetEntityFlagMask 182 187 u8 scriptedVisibility; // boolean, see ComputeLosVisibility 183 188 }; 184 189 185 190 cassert(sizeof(EntityData) == 28); … … struct SerializeEntityData 234 239 serialize.NumberFixed_Unbounded("x", value.x); 235 240 serialize.NumberFixed_Unbounded("z", value.z); 236 241 serialize.NumberFixed_Unbounded("vision", value.visionRange); 237 242 serialize.NumberU32_Unbounded("visibilities", value.visibilities); 238 243 serialize.NumberU32_Unbounded("size", value.size); 239 serialize.NumberU8("retain in fog", value.retainInFog, 0, 1);240 244 serialize.NumberI8_Unbounded("owner", value.owner); 245 serialize.NumberU8("retain in fog", value.retainInFog, 0, 1); 241 246 serialize.NumberU8("in world", value.inWorld, 0, 1); 247 serialize.NumberU8("reveal shore", value.revealShore, 0, 1); 242 248 serialize.NumberU8_Unbounded("flags", value.flags); 243 serialize.NumberU8 _Unbounded("scripted visibility", value.scriptedVisibility);249 serialize.NumberU8("scripted visibility", value.scriptedVisibility, 0, 1); 244 250 } 245 251 }; 246 252 247 253 248 254 /** … … public: 471 477 EntityData entdata; 472 478 473 479 // Store the LOS data, if any 474 480 CmpPtr<ICmpVision> cmpVision(GetSimContext(), ent); 475 481 if (cmpVision) 482 { 476 483 entdata.visionRange = cmpVision->GetRange(); 484 entdata.revealShore = cmpVision->GetRevealShore() ? 1 : 0; 485 } 477 486 CmpPtr<ICmpVisibility> cmpVisibility(GetSimContext(), ent); 478 487 if (cmpVisibility) 479 488 entdata.retainInFog = (cmpVisibility->GetRetainInFog() ? 1 : 0); 480 489 481 490 // Store the size … … public: 559 568 if (it->second.inWorld) 560 569 { 561 570 CFixedVector2D pos(it->second.x, it->second.z); 562 571 LosRemove(it->second.owner, it->second.visionRange, pos); 563 572 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 } 564 579 } 565 580 566 581 ENSURE(-128 <= msgData.to && msgData.to <= 127); 567 582 it->second.owner = (i8)msgData.to; 568 583 … … public: 749 764 { 750 765 if (it->second.inWorld) 751 766 { 752 767 LosAdd(it->second.owner, it->second.visionRange, CFixedVector2D(it->second.x, it->second.z)); 753 768 AddToTile(PosToLosTilesHelper(it->second.x, it->second.z), it->first); 769 770 if (it->second.revealShore) 771 RevealShore(it->second.owner, true); 754 772 } 755 773 } 756 774 757 775 m_TotalInworldVertices = 0; 758 776 for (ssize_t j = 0; j < m_TerrainVerticesPerSide; ++j) -
source/simulation2/components/CCmpVision.cpp
public: 38 38 DEFAULT_COMPONENT_ALLOCATOR(Vision) 39 39 40 40 // Template state: 41 41 42 42 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. 43 46 bool m_RevealShore; 44 47 45 48 static std::string GetSchema() 46 49 { 47 50 return … … public: 88 91 const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg); 89 92 if (msgData.entity != GetEntityId()) 90 93 break; 91 94 92 95 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);99 96 break; 100 97 } 101 98 case MT_ValueModification: 102 99 { 103 100 const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg); … … public: 135 132 136 133 virtual entity_pos_t GetRange() 137 134 { 138 135 return m_Range; 139 136 } 137 138 virtual bool GetRevealShore() 139 { 140 return m_RevealShore; 141 } 140 142 }; 141 143 142 144 REGISTER_COMPONENT_TYPE(Vision) -
source/simulation2/components/ICmpVision.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … 27 27 */ 28 28 class ICmpVision : public IComponent 29 29 { 30 30 public: 31 31 virtual entity_pos_t GetRange() = 0; 32 virtual bool GetRevealShore() = 0; 32 33 33 34 DECLARE_INTERFACE_TYPE(Vision) 34 35 }; 35 36 36 37 #endif // INCLUDED_ICMPVISION -
source/simulation2/components/tests/test_RangeManager.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … class MockVision : public ICmpVision 29 29 { 30 30 public: 31 31 DEFAULT_MOCK_COMPONENT() 32 32 33 33 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; } 36 35 }; 37 36 38 37 class MockPosition : public ICmpPosition 39 38 { 40 39 public: … … public: 83 82 void tearDown() 84 83 { 85 84 CXeromyces::Terminate(); 86 85 } 87 86 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 88 90 void test_basic() 89 91 { 90 92 ComponentTestHelper test(g_ScriptRuntime); 91 93 92 94 ICmpRangeManager* cmp = test.Add<ICmpRangeManager>(CID_RangeManager, "", SYSTEM_ENTITY);