- Timestamp:
- 08/01/11 23:25:12 (13 years ago)
- Location:
- ps/trunk/source/simulation2
- Files:
-
- 3 edited
-
MessageTypes.h (modified) (1 diff)
-
components/CCmpRangeManager.cpp (modified) (11 diffs)
-
components/CCmpTerritoryManager.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/simulation2/MessageTypes.h
r9019 r9951 279 279 DEFAULT_MESSAGE_IMPL(TerrainChanged) 280 280 281 CMessageTerrainChanged( ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) :281 CMessageTerrainChanged(int32_t i0, int32_t j0, int32_t i1, int32_t j1) : 282 282 i0(i0), j0(j0), i1(i1), j1(j1) 283 283 { 284 284 } 285 285 286 ssize_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles286 int32_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles 287 287 }; 288 288 -
ps/trunk/source/simulation2/components/CCmpRangeManager.cpp
r9720 r9951 21 21 #include "ICmpRangeManager.h" 22 22 23 #include "ICmpPosition.h"24 #include "ICmpVision.h"25 23 #include "simulation2/MessageTypes.h" 24 #include "simulation2/components/ICmpPosition.h" 25 #include "simulation2/components/ICmpTerritoryManager.h" 26 #include "simulation2/components/ICmpVision.h" 26 27 #include "simulation2/helpers/Render.h" 27 28 #include "simulation2/helpers/Spatial.h" … … 189 190 bool m_LosCircular; 190 191 i32 m_TerrainVerticesPerSide; 192 size_t m_TerritoriesDirtyID; 191 193 192 194 // Counts of units seeing vertex, per vertex, per player (starting with player 0). … … 229 231 m_LosCircular = false; 230 232 m_TerrainVerticesPerSide = 0; 233 234 m_TerritoriesDirtyID = 0; 231 235 } 232 236 … … 251 255 serialize.NumberI32_Unbounded("terrain verts per side", m_TerrainVerticesPerSide); 252 256 253 // We don't serialize m_Subdivision, m_LosPlayerCounts, m_LosState 254 // since they can be recomputed from the entity data when deserializing 257 // We don't serialize m_Subdivision or m_LosPlayerCounts 258 // since they can be recomputed from the entity data when deserializing; 259 // m_LosState must be serialized since it depends on the history of exploration 260 261 SerializeVector<SerializeU32_Unbounded>()(serialize, "los state", m_LosState); 255 262 } 256 263 … … 267 274 268 275 // Reinitialise subdivisions and LOS data 269 ResetDerivedData( );276 ResetDerivedData(true); 270 277 } 271 278 … … 396 403 { 397 404 m_DebugOverlayDirty = true; 405 UpdateTerritoriesLos(); 398 406 ExecuteActiveQueries(); 399 407 break; … … 416 424 m_TerrainVerticesPerSide = vertices; 417 425 418 ResetDerivedData( );426 ResetDerivedData(false); 419 427 } 420 428 421 429 // Reinitialise subdivisions and LOS data, based on entity data 422 void ResetDerivedData( )430 void ResetDerivedData(bool skipLosState) 423 431 { 424 432 ENSURE(m_WorldX0.IsZero() && m_WorldZ0.IsZero()); // don't bother implementing non-zero offsets yet … … 427 435 m_LosPlayerCounts.clear(); 428 436 m_LosPlayerCounts.resize(MAX_LOS_PLAYER_ID+1); 429 m_LosState.clear(); 430 m_LosState.resize(m_TerrainVerticesPerSide*m_TerrainVerticesPerSide); 437 if (!skipLosState) 438 { 439 m_LosState.clear(); 440 m_LosState.resize(m_TerrainVerticesPerSide*m_TerrainVerticesPerSide); 441 } 431 442 m_LosStateRevealed.clear(); 432 443 m_LosStateRevealed.resize(m_TerrainVerticesPerSide*m_TerrainVerticesPerSide); … … 801 812 } 802 813 814 // **************************************************************** 803 815 804 816 // LOS implementation: … … 880 892 m_LosCircular = enabled; 881 893 882 ResetDerivedData( );894 ResetDerivedData(false); 883 895 } 884 896 … … 886 898 { 887 899 return m_LosCircular; 900 } 901 902 void UpdateTerritoriesLos() 903 { 904 CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSimContext(), SYSTEM_ENTITY); 905 if (cmpTerritoryManager.null() || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID)) 906 return; 907 908 const Grid<u8>& grid = cmpTerritoryManager->GetTerritoryGrid(); 909 ENSURE(grid.m_W == m_TerrainVerticesPerSide-1 && grid.m_H == m_TerrainVerticesPerSide-1); 910 911 // For each tile, if it is owned by a valid player then update the LOS 912 // for every vertex around that tile, to mark them as explored 913 914 for (size_t j = 0; j < grid.m_H; ++j) 915 { 916 for (size_t i = 0; i < grid.m_W; ++i) 917 { 918 u8 p = grid.get(i, j); 919 if (p > 0 && p <= MAX_LOS_PLAYER_ID) 920 { 921 m_LosState[i + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 922 m_LosState[i+1 + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 923 m_LosState[i + (j+1)*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 924 m_LosState[i+1 + (j+1)*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 925 } 926 } 927 } 888 928 } 889 929 -
ps/trunk/source/simulation2/components/CCmpTerritoryManager.cpp
r9929 r9951 183 183 virtual bool NeedUpdate(size_t* dirtyID) 184 184 { 185 ENSURE(*dirtyID <= m_DirtyID); 186 if (*dirtyID < m_DirtyID) 185 if (*dirtyID != m_DirtyID) 187 186 { 188 187 *dirtyID = m_DirtyID;
Note:
See TracChangeset
for help on using the changeset viewer.
