Ticket #1707: range_manager_optimisation.diff
File range_manager_optimisation.diff, 4.6 KB (added by , 11 years ago) |
---|
-
source/simulation2/components/CCmpRangeManager.cpp
211 211 tag_t m_QueryNext; // next allocated id 212 212 std::map<tag_t, Query> m_Queries; 213 213 std::map<entity_id_t, EntityData> m_EntityData; 214 std::vector<EntityData> m_EntityDataArray; 214 215 SpatialSubdivision<entity_id_t> m_Subdivision; // spatial index of m_EntityData 215 216 216 217 // LOS state: … … 285 286 serialize.NumberU32_Unbounded("query next", m_QueryNext); 286 287 SerializeMap<SerializeU32_Unbounded, SerializeQuery>()(serialize, "queries", m_Queries); 287 288 SerializeMap<SerializeU32_Unbounded, SerializeEntityData>()(serialize, "entity data", m_EntityData); 289 //SerializeVector<SerializeEntityData>(serialize, "entity data array", m_EntityDataArray); 288 290 289 291 SerializeMap<SerializeI32_Unbounded, SerializeBool>()(serialize, "los reveal all", m_LosRevealAll); 290 292 serialize.Bool("los circular", m_LosCircular); … … 336 338 // (any initialisation of those values will happen later), so we can just 337 339 // use the default-constructed EntityData here 338 340 EntityData entdata; 341 339 342 340 343 // Store the LOS data, if any 341 344 CmpPtr<ICmpVision> cmpVision(GetSimContext(), ent); … … 347 350 348 351 // Remember this entity 349 352 m_EntityData.insert(std::make_pair(ent, entdata)); 353 if (ent >= m_EntityDataArray.size()) { 354 m_EntityDataArray.resize(ent+1); 355 } 356 m_EntityDataArray[ent] = entdata; 350 357 351 358 break; 352 359 } … … 358 365 std::map<entity_id_t, EntityData>::iterator it = m_EntityData.find(ent); 359 366 360 367 // Ignore if we're not already tracking this entity 361 if (it == m_EntityData.end() )368 if (it == m_EntityData.end() || ent >= m_EntityDataArray.size()) 362 369 break; 363 370 364 371 if (msgData.inWorld) … … 380 387 it->second.inWorld = 1; 381 388 it->second.x = msgData.x; 382 389 it->second.z = msgData.z; 390 391 EntityData& entData = m_EntityDataArray[ent]; 392 entData.inWorld = 1; 393 entData.x = msgData.x; 394 entData.z = msgData.z; 383 395 } 384 396 else 385 397 { … … 393 405 it->second.inWorld = 0; 394 406 it->second.x = entity_pos_t::Zero(); 395 407 it->second.z = entity_pos_t::Zero(); 408 409 EntityData& entData = m_EntityDataArray[ent]; 410 entData.inWorld = 0; 411 entData.x = entity_pos_t::Zero(); 412 entData.z = entity_pos_t::Zero(); 396 413 } 397 414 398 415 break; … … 417 434 418 435 ENSURE(-128 <= msgData.to && msgData.to <= 127); 419 436 it->second.owner = (i8)msgData.to; 437 438 m_EntityDataArray[ent].owner = (i8)msgData.to; 420 439 421 440 break; 422 441 } … … 467 486 LosRemove(it->second.owner, oldRange, pos); 468 487 469 488 it->second.visionRange = newRange; 489 m_EntityDataArray[ent].visionRange = newRange; 470 490 471 491 if (it->second.inWorld) 472 492 LosAdd(it->second.owner, newRange, pos); … … 643 663 return r; 644 664 } 645 665 666 PROFILE_START("perform"); 646 667 PerformQuery(q, r); 668 PROFILE_END("perform"); 647 669 648 670 // Return the list sorted by distance from the entity 649 671 CFixedVector2D pos = cmpSourcePosition->GetPosition2D(); … … 815 837 else 816 838 { 817 839 // Get a quick list of entities that are potentially in range 818 std::vector<entity_id_t> ents = m_Subdivision.GetNear(pos, q.maxRange); 840 std::vector<entity_id_t> ents; 841 PROFILE_START("GetNear"); 842 ents = m_Subdivision.GetNear(pos, q.maxRange); 843 PROFILE_END("GetNear"); 819 844 820 845 for (size_t i = 0; i < ents.size(); ++i) 821 846 { 822 std::map<entity_id_t, EntityData>::const_iterator it = m_EntityData.find(ents[i]); 823 ENSURE(it != m_EntityData.end()); 847 //std::map<entity_id_t, EntityData>::const_iterator it = m_EntityData.find(ents[i]); 848 //ENSURE(it != m_EntityData.end()); 849 const EntityData& entData = m_EntityDataArray[ents[i]]; 850 851 //ENSURE(entData.x == it->second.x); 852 853 //if (entData.x != it->second.x) LOGWARNING(L"hi"); 824 854 825 if (!TestEntityQuery(q, it->first, it->second))855 if (!TestEntityQuery(q, ents[i], entData)) 826 856 continue; 827 857 828 858 // Restrict based on precise distance 829 int distVsMax = (CFixedVector2D( it->second.x, it->second.z) - pos).CompareLength(q.maxRange);859 int distVsMax = (CFixedVector2D(entData.x, entData.z) - pos).CompareLength(q.maxRange); 830 860 if (distVsMax > 0) 831 861 continue; 832 862 833 863 if (!q.minRange.IsZero()) 834 864 { 835 int distVsMin = (CFixedVector2D( it->second.x, it->second.z) - pos).CompareLength(q.minRange);865 int distVsMin = (CFixedVector2D(entData.x, entData.z) - pos).CompareLength(q.minRange); 836 866 if (distVsMin < 0) 837 867 continue; 838 868 } 839 869 840 r.push_back( it->first);870 r.push_back(ents[i]); 841 871 } 842 872 } 843 873 }