Ticket #2012: percent-explored.patch
File percent-explored.patch, 7.3 KB (added by , 11 years ago) |
---|
-
source/simulation2/components/CCmpRangeManager.cpp
238 238 // Shared LOS masks, one per player. 239 239 std::map<player_id_t, u32> m_SharedLosMasks; 240 240 241 u32 m_OverallVisibleVertices; 242 // Number of explored vertices per player. 243 std::vector<u32> m_ExploredVertices; 244 241 245 static std::string GetSchema() 242 246 { 243 247 return "<a:component type='system'/><empty/>"; … … 514 518 SpatialSubdivision<entity_id_t> oldSubdivision = m_Subdivision; 515 519 516 520 ResetDerivedData(true); 517 521 518 522 if (oldPlayerCounts != m_LosPlayerCounts) 519 523 { 520 524 for (size_t i = 0; i < oldPlayerCounts.size(); ++i) … … 547 551 548 552 m_LosPlayerCounts.clear(); 549 553 m_LosPlayerCounts.resize(MAX_LOS_PLAYER_ID+1); 550 if (!skipLosState) 554 m_ExploredVertices.clear(); 555 m_ExploredVertices.resize(MAX_LOS_PLAYER_ID+1, 0); 556 if (skipLosState) { 557 // recalc current exploration stats. 558 for (i32 j = 0; j < m_TerrainVerticesPerSide; j++) 559 { 560 for (i32 i = 0; i < m_TerrainVerticesPerSide; i++) 561 { 562 if (!LosIsOffWorld(i, j)) 563 { 564 for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k) { 565 m_ExploredVertices.at(k) += ((m_LosState[j*m_TerrainVerticesPerSide + i] & (LOS_EXPLORED << (2*(k-1)))) > 0); 566 } 567 } 568 } 569 } 570 } 571 else 551 572 { 552 573 m_LosState.clear(); 553 574 m_LosState.resize(m_TerrainVerticesPerSide*m_TerrainVerticesPerSide); … … 561 582 LosAdd(it->second.owner, it->second.visionRange, CFixedVector2D(it->second.x, it->second.z)); 562 583 } 563 584 585 m_OverallVisibleVertices = 0; 564 586 for (ssize_t j = 0; j < m_TerrainVerticesPerSide; ++j) 565 587 for (ssize_t i = 0; i < m_TerrainVerticesPerSide; ++i) 566 m_LosStateRevealed[i + j*m_TerrainVerticesPerSide] = LosIsOffWorld(i, j) ? 0 : 0xFFFFFFFFu; 588 { 589 if (LosIsOffWorld(i,j)) 590 { 591 m_LosStateRevealed[i + j*m_TerrainVerticesPerSide] = 0; 592 } 593 else 594 { 595 m_LosStateRevealed[i + j*m_TerrainVerticesPerSide] = 0xFFFFFFFFu; 596 m_OverallVisibleVertices++; 597 } 598 } 567 599 } 568 600 569 601 void ResetSubdivisions(entity_pos_t x1, entity_pos_t z1) … … 931 963 for (size_t i = 0; i < m_DebugOverlayLines.size(); ++i) 932 964 collector.Submit(&m_DebugOverlayLines[i]); 933 965 } 934 966 935 967 virtual u8 GetEntityFlagMask(std::string identifier) 936 968 { 937 969 if (identifier == "normal") … … 942 974 LOGWARNING(L"CCmpRangeManager: Invalid flag identifier %hs", identifier.c_str()); 943 975 return 0; 944 976 } 945 977 946 978 virtual void SetEntityFlag(entity_id_t ent, std::string identifier, bool value) 947 979 { 948 980 std::map<entity_id_t, EntityData>::iterator it = m_EntityData.find(ent); … … 1085 1117 u8 p = grid.get(i, j) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK; 1086 1118 if (p > 0 && p <= MAX_LOS_PLAYER_ID) 1087 1119 { 1120 u32 &explored = m_ExploredVertices.at(p); 1121 explored += !(m_LosState[i + j*m_TerrainVerticesPerSide] & (LOS_EXPLORED << (2*(p-1)))); 1088 1122 m_LosState[i + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 1123 explored += !(m_LosState[i+1 + j*m_TerrainVerticesPerSide] & (LOS_EXPLORED << (2*(p-1)))); 1089 1124 m_LosState[i+1 + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 1125 explored += !(m_LosState[i + (j+1)*m_TerrainVerticesPerSide] & (LOS_EXPLORED << (2*(p-1)))); 1090 1126 m_LosState[i + (j+1)*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 1127 explored += !(m_LosState[i+1 + (j+1)*m_TerrainVerticesPerSide] & (LOS_EXPLORED << (2*(p-1)))); 1091 1128 m_LosState[i+1 + (j+1)*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1))); 1092 1129 } 1093 1130 } … … 1135 1172 1136 1173 i32 idx0 = j*m_TerrainVerticesPerSide + i0; 1137 1174 i32 idx1 = j*m_TerrainVerticesPerSide + i1; 1138 1175 u32 &explored = m_ExploredVertices.at(owner); 1139 1176 for (i32 idx = idx0; idx <= idx1; ++idx) 1140 1177 { 1141 1178 // Increasing from zero to non-zero - move from unexplored/explored to visible+explored 1142 1179 if (counts[idx] == 0) 1143 1180 { 1144 1181 i32 i = i0 + idx - idx0; 1145 if (!LosIsOffWorld(i, j)) 1182 if (!LosIsOffWorld(i, j)) { 1183 explored += !(m_LosState[idx] & (LOS_EXPLORED << (2*(owner-1)))); 1146 1184 m_LosState[idx] |= ((LOS_VISIBLE | LOS_EXPLORED) << (2*(owner-1))); 1185 } 1147 1186 } 1148 1187 1149 1188 ASSERT(counts[idx] < 65535); … … 1161 1200 1162 1201 i32 idx0 = j*m_TerrainVerticesPerSide + i0; 1163 1202 i32 idx1 = j*m_TerrainVerticesPerSide + i1; 1164 1165 1203 for (i32 idx = idx0; idx <= idx1; ++idx) 1166 1204 { 1167 1205 ASSERT(counts[idx] > 0); … … 1432 1470 } 1433 1471 } 1434 1472 1435 virtual i32GetPercentMapExplored(player_id_t player)1473 virtual u8 GetPercentMapExplored(player_id_t player) 1436 1474 { 1437 i32 exploredVertices = 0; 1438 i32 overallVisibleVertices = 0; 1439 CLosQuerier los(CalcPlayerLosMask(player), m_LosState, m_TerrainVerticesPerSide); 1440 1441 for (i32 j = 0; j < m_TerrainVerticesPerSide; j++) 1442 { 1443 for (i32 i = 0; i < m_TerrainVerticesPerSide; i++) 1444 { 1445 if (!LosIsOffWorld(i, j)) 1446 { 1447 overallVisibleVertices++; 1448 exploredVertices += (i32)los.IsExplored_UncheckedRange(i, j); 1449 } 1450 } 1451 } 1452 1453 if (overallVisibleVertices == 0) // avoid divide-by-zero 1454 return 0; 1455 1456 return exploredVertices * 100 / overallVisibleVertices; 1475 return m_ExploredVertices.at((u8)player) * 100 / m_OverallVisibleVertices; 1457 1476 } 1458 1477 }; 1459 1478 -
source/simulation2/components/ICmpRangeManager.cpp
49 49 DEFINE_INTERFACE_METHOD_1("SetLosCircular", void, ICmpRangeManager, SetLosCircular, bool) 50 50 DEFINE_INTERFACE_METHOD_0("GetLosCircular", bool, ICmpRangeManager, GetLosCircular) 51 51 DEFINE_INTERFACE_METHOD_2("SetSharedLos", void, ICmpRangeManager, SetSharedLos, player_id_t, std::vector<player_id_t>) 52 DEFINE_INTERFACE_METHOD_1("GetPercentMapExplored", i32, ICmpRangeManager, GetPercentMapExplored, player_id_t)52 DEFINE_INTERFACE_METHOD_1("GetPercentMapExplored", u8, ICmpRangeManager, GetPercentMapExplored, player_id_t) 53 53 END_INTERFACE_WRAPPER(RangeManager) -
source/simulation2/components/ICmpRangeManager.h
317 317 /** 318 318 * Get percent map explored statistics for specified player. 319 319 */ 320 virtual i32GetPercentMapExplored(player_id_t player) = 0;320 virtual u8 GetPercentMapExplored(player_id_t player) = 0; 321 321 322 322 323 323 /** -
binaries/data/mods/public/simulation/components/StatisticsTracker.js
225 225 { 226 226 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 227 227 var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); 228 return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID()); 228 if (cmpPlayer.GetPlayerID() == 0) return 0; 229 return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID()); 229 230 }; 230 231 231 232 Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker);