Ticket #3271: visibility_serialization.patch
File visibility_serialization.patch, 5.4 KB (added by , 8 years ago) |
---|
-
source/simulation2/components/CCmpRangeManager.cpp
303 303 bool m_DebugOverlayDirty; 304 304 std::vector<SOverlayLine> m_DebugOverlayLines; 305 305 306 // Deserialization flag. A lot of different functions are called by Deserialize() 307 // and we don't want to pass isDeserializing bool arguments to all of them... 308 bool m_Deserializing; 309 306 310 // World bounds (entities are expected to be within this range) 307 311 entity_pos_t m_WorldX0; 308 312 entity_pos_t m_WorldZ0; … … 323 327 bool m_LosCircular; 324 328 i32 m_TerrainVerticesPerSide; 325 329 326 // Cache for visibility tracking (not serialized)330 // Cache for visibility tracking 327 331 i32 m_LosTilesPerSide; 328 332 bool m_GlobalVisibilityUpdate; 329 333 std::vector<u8> m_GlobalPlayerVisibilityUpdate; … … 367 371 m_DebugOverlayEnabled = false; 368 372 m_DebugOverlayDirty = true; 369 373 374 m_Deserializing = false; 370 375 m_WorldX0 = m_WorldZ0 = m_WorldX1 = m_WorldZ1 = entity_pos_t::Zero(); 371 376 372 377 // Initialise with bogus values (these will get replaced when … … 380 385 m_SharedLosMasks.resize(MAX_LOS_PLAYER_ID+2,0); 381 386 m_SharedDirtyVisibilityMasks.resize(MAX_LOS_PLAYER_ID + 2, 0); 382 387 388 m_GlobalVisibilityUpdate = true; 389 m_GlobalPlayerVisibilityUpdate.resize(MAX_LOS_PLAYER_ID); 390 383 391 m_LosCircular = false; 384 392 m_TerrainVerticesPerSide = 0; 385 393 } … … 404 412 serialize.Bool("los circular", m_LosCircular); 405 413 serialize.NumberI32_Unbounded("terrain verts per side", m_TerrainVerticesPerSide); 406 414 415 serialize.Bool("global visibility update", m_GlobalVisibilityUpdate); 416 SerializeVector<SerializeU8_Unbounded>()(serialize, "global player visibility update", m_GlobalPlayerVisibilityUpdate); 417 SerializeVector<SerializeU16_Unbounded>()(serialize, "dirty visibility", m_DirtyVisibility); 407 418 SerializeVector<SerializeU32_Unbounded>()(serialize, "modified entities", m_ModifiedEntities); 408 419 409 420 // We don't serialize m_Subdivision, m_LosPlayerCounts or m_LosTiles … … 427 438 SerializeCommon(deserialize); 428 439 429 440 // Reinitialise subdivisions and LOS data 430 ResetDerivedData(true); 441 m_Deserializing = true; 442 ResetDerivedData(); 443 m_Deserializing = false; 431 444 } 432 445 433 446 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) … … 631 644 m_WorldZ1 = z1; 632 645 m_TerrainVerticesPerSide = (i32)vertices; 633 646 634 ResetDerivedData( false);647 ResetDerivedData(); 635 648 } 636 649 637 650 virtual void Verify() … … 648 661 FastSpatialSubdivision oldSubdivision = m_Subdivision; 649 662 std::vector<std::set<entity_id_t> > oldLosTiles = m_LosTiles; 650 663 651 ResetDerivedData(true); 664 m_Deserializing = true; 665 ResetDerivedData(); 666 m_Deserializing = false; 652 667 653 668 if (oldPlayerCounts != m_LosPlayerCounts) 654 669 { … … 682 697 } 683 698 684 699 // Reinitialise subdivisions and LOS data, based on entity data 685 void ResetDerivedData( bool skipLosState)700 void ResetDerivedData() 686 701 { 687 702 ENSURE(m_WorldX0.IsZero() && m_WorldZ0.IsZero()); // don't bother implementing non-zero offsets yet 688 703 ResetSubdivisions(m_WorldX1, m_WorldZ1); … … 693 708 m_LosPlayerCounts.resize(MAX_LOS_PLAYER_ID+1); 694 709 m_ExploredVertices.clear(); 695 710 m_ExploredVertices.resize(MAX_LOS_PLAYER_ID+1, 0); 696 if ( skipLosState)711 if (m_Deserializing) 697 712 { 698 713 // recalc current exploration stats. 699 714 for (i32 j = 0; j < m_TerrainVerticesPerSide; j++) … … 715 730 } 716 731 m_LosStateRevealed.clear(); 717 732 m_LosStateRevealed.resize(m_TerrainVerticesPerSide*m_TerrainVerticesPerSide); 718 719 m_DirtyVisibility.clear(); 720 m_DirtyVisibility.resize(m_LosTilesPerSide*m_LosTilesPerSide); 733 734 if (!m_Deserializing) 735 { 736 m_DirtyVisibility.clear(); 737 m_DirtyVisibility.resize(m_LosTilesPerSide*m_LosTilesPerSide); 738 } 739 ENSURE(m_DirtyVisibility.size() == m_LosTilesPerSide*m_LosTilesPerSide); 740 721 741 m_LosTiles.clear(); 722 742 m_LosTiles.resize(m_LosTilesPerSide*m_LosTilesPerSide); 723 m_GlobalVisibilityUpdate = true;724 m_GlobalPlayerVisibilityUpdate.clear();725 m_GlobalPlayerVisibilityUpdate.resize(MAX_LOS_PLAYER_ID);726 743 727 744 for (EntityMap<EntityData>::const_iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it) 728 745 { … … 1711 1728 { 1712 1729 m_LosCircular = enabled; 1713 1730 1714 ResetDerivedData( false);1731 ResetDerivedData(); 1715 1732 } 1716 1733 1717 1734 virtual bool GetLosCircular() … … 1971 1988 1972 1989 inline void MarkVisibilityDirtyAroundTile(u8 owner, i32 i, i32 j) 1973 1990 { 1991 // If we're still in the deserializing process, we must not modify m_DirtyVisibility 1992 if (m_Deserializing) 1993 return; 1994 1974 1995 // Mark the LoS tiles around the updated vertex 1975 1996 // 1: left-up, 2: right-up, 3: left-down, 4: right-down 1976 1997 int n1 = ((j-1)/LOS_TILES_RATIO)*m_LosTilesPerSide + (i-1)/LOS_TILES_RATIO; -
source/simulation2/serialization/SerializeTemplates.h
151 151 } 152 152 }; 153 153 154 struct SerializeU8_Unbounded 155 { 156 void operator()(ISerializer& serialize, const char* name, u8 value) 157 { 158 serialize.NumberU8_Unbounded(name, value); 159 } 160 161 void operator()(IDeserializer& deserialize, const char* name, u8& value) 162 { 163 deserialize.NumberU8_Unbounded(name, value); 164 } 165 }; 166 154 167 struct SerializeU16_Unbounded 155 168 { 156 169 void operator()(ISerializer& serialize, const char* name, u16 value)