Changeset 120 for trunk/src/game/ObjectAccessor.cpp
- Timestamp:
- 11/19/08 13:38:01 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/ObjectAccessor.cpp
r102 r120 506 506 507 507 void 508 ObjectAccessor::AddActiveObject( WorldObject * obj ) 509 { 510 i_activeobjects.insert(obj); 511 } 512 513 void 514 ObjectAccessor::RemoveActiveObject( WorldObject * obj ) 515 { 516 i_activeobjects.erase(obj); 517 } 518 519 void 508 520 ObjectAccessor::Update(uint32 diff) 509 521 { 510 522 { 511 typedef std::multimap<uint32, Player *> CreatureLocationHolderType; 512 CreatureLocationHolderType creature_locations; 513 //TODO: Player guard 523 // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects. 514 524 HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer(); 515 525 for(HashMapHolder<Player>::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter) … … 518 528 { 519 529 iter->second->Update(diff); 520 creature_locations.insert( CreatureLocationHolderType::value_type(iter->second->GetMapId(), iter->second) );521 530 } 531 } 532 533 // clone the active object list, because update might remove from it 534 std::set<WorldObject *> activeobjects(i_activeobjects); 535 536 std::set<WorldObject *>::const_iterator itr; 537 for(itr = activeobjects.begin(); itr != activeobjects.end(); ++itr) 538 { 539 (*itr)->GetMap()->resetMarkedCells(); 522 540 } 523 541 … … 530 548 TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer > world_object_update(updater); 531 549 532 for(CreatureLocationHolderType::iterator iter=creature_locations.begin(); iter != creature_locations.end(); ++iter) 533 { 534 MapManager::Instance().GetMap((*iter).first, (*iter).second)->resetMarkedCells(); 535 } 536 537 for(CreatureLocationHolderType::iterator iter=creature_locations.begin(); iter != creature_locations.end(); ++iter) 538 { 539 Player *player = (*iter).second; 540 map = MapManager::Instance().GetMap((*iter).first, player); 541 542 CellPair standing_cell(Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY())); 550 for(itr = activeobjects.begin(); itr != activeobjects.end(); ++itr) 551 { 552 WorldObject *obj = (*itr); 553 map = obj->GetMap(); 554 555 CellPair standing_cell(Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY())); 543 556 544 557 // Check for correctness of standing_cell, it also avoids problems with update_cell … … 577 590 578 591 bool 579 ObjectAccessor:: PlayersNearGrid(uint32 x, uint32 y, uint32 m_id, uint32 i_id) const592 ObjectAccessor::ActiveObjectsNearGrid(uint32 x, uint32 y, uint32 m_id, uint32 i_id) const 580 593 { 581 594 CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS); … … 586 599 cell_max += 2; 587 600 588 //TODO: Guard player 589 HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer(); 590 for(HashMapHolder<Player>::MapType::const_iterator iter=playerMap.begin(); iter != playerMap.end(); ++iter) 591 { 592 if( m_id != iter->second->GetMapId() || i_id != iter->second->GetInstanceId() ) 601 for(std::set<WorldObject*>::const_iterator itr = i_activeobjects.begin(); itr != i_activeobjects.end(); ++itr) 602 { 603 if( m_id != (*itr)->GetMapId() || i_id != (*itr)->GetInstanceId() ) 593 604 continue; 594 605 595 CellPair p = Trinity::ComputeCellPair( iter->second->GetPositionX(), iter->second->GetPositionY());606 CellPair p = Trinity::ComputeCellPair((*itr)->GetPositionX(), (*itr)->GetPositionY()); 596 607 if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && 597 608 (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) 598 609 return true; 610 599 611 } 600 612