Changeset 120
- Timestamp:
- 11/19/08 13:38:01 (17 years ago)
- Location:
- trunk/src/game
- Files:
-
- 13 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/game/DynamicObject.cpp
r102 r120 48 48 ///- Register the dynamicObject for guid lookup 49 49 if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); 50 Object::AddToWorld();50 WorldObject::AddToWorld(); 51 51 } 52 52 … … 55 55 ///- Remove the dynamicObject from the accessor 56 56 if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); 57 Object::RemoveFromWorld();57 WorldObject::RemoveFromWorld(); 58 58 } 59 59 -
trunk/src/game/GameObject.cpp
r102 r120 83 83 ///- Register the gameobject for guid lookup 84 84 if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); 85 Object::AddToWorld();85 WorldObject::AddToWorld(); 86 86 } 87 87 … … 90 90 ///- Remove the gameobject from the accessor 91 91 if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); 92 Object::RemoveFromWorld();92 WorldObject::RemoveFromWorld(); 93 93 } 94 94 -
trunk/src/game/GridStates.cpp
r102 r120 37 37 if( info.getTimeTracker().Passed() ) 38 38 { 39 if( grid.ActiveObjectsInGrid() == 0 && !ObjectAccessor::Instance(). PlayersNearGrid(x, y, m.GetId(), m.GetInstanceId()) )39 if( grid.ActiveObjectsInGrid() == 0 && !ObjectAccessor::Instance().ActiveObjectsNearGrid(x, y, m.GetId(), m.GetInstanceId()) ) 40 40 { 41 41 ObjectGridStoper stoper(grid); -
trunk/src/game/Map.cpp
r118 r120 879 879 880 880 { 881 if(!pForce && ObjectAccessor::Instance(). PlayersNearGrid(x, y, i_id, i_InstanceId) )881 if(!pForce && ObjectAccessor::Instance().ActiveObjectsNearGrid(x, y, i_id, i_InstanceId) ) 882 882 return false; 883 883 -
trunk/src/game/Object.cpp
r119 r120 975 975 976 976 mSemaphoreTeleport = false; 977 978 m_isActive = false; 979 } 980 981 WorldObject::~WorldObject() 982 { 983 if(m_isActive && IsInWorld()) 984 ObjectAccessor::Instance().RemoveActiveObject(this); 985 } 986 987 void WorldObject::setActive(bool isActive) 988 { 989 // if already in the same activity state as we try to set, do nothing 990 if(isActive == m_isActive) 991 return; 992 m_isActive = isActive; 993 if(IsInWorld()) 994 { 995 if(isActive) 996 ObjectAccessor::Instance().AddActiveObject(this); 997 else 998 ObjectAccessor::Instance().RemoveActiveObject(this); 999 } 1000 } 1001 1002 void WorldObject::AddToWorld() 1003 { 1004 Object::AddToWorld(); 1005 if(m_isActive) 1006 ObjectAccessor::Instance().AddActiveObject(this); 1007 } 1008 1009 void WorldObject::RemoveFromWorld() 1010 { 1011 if(m_isActive) 1012 ObjectAccessor::Instance().RemoveActiveObject(this); 1013 Object::RemoveFromWorld(); 977 1014 } 978 1015 -
trunk/src/game/Object.h
r119 r120 28 28 #include "GameSystem/GridReference.h" 29 29 #include "ObjectDefines.h" 30 #include "GridDefines.h" 30 31 31 32 #include <set> … … 324 325 { 325 326 public: 326 virtual ~WorldObject ( ) {} 327 virtual ~WorldObject ( ); 328 329 virtual void AddToWorld(); 330 331 virtual void RemoveFromWorld(); 327 332 328 333 virtual void Update ( uint32 /*time_diff*/ ) { } … … 449 454 Creature* SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime); 450 455 GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime); 456 bool isActive() const { return m_isActive; } 457 virtual void setActive(bool isActive); 451 458 protected: 452 459 explicit WorldObject(); 453 460 std::string m_name; 461 bool m_isActive; 454 462 455 463 private: -
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 -
trunk/src/game/ObjectAccessor.h
r102 r120 194 194 Corpse* ConvertCorpseForPlayer(uint64 player_guid); 195 195 196 bool PlayersNearGrid(uint32 x,uint32 y,uint32 m_id,uint32 i_id) const;196 bool ActiveObjectsNearGrid(uint32 x,uint32 y,uint32 m_id,uint32 i_id) const; 197 197 198 198 static void UpdateObject(Object* obj, Player* exceptPlayer); … … 201 201 static void UpdateObjectVisibility(WorldObject* obj); 202 202 static void UpdateVisibilityForPlayer(Player* player); 203 204 void AddActiveObject(WorldObject*); 205 void RemoveActiveObject(WorldObject*); 203 206 private: 204 207 struct WorldObjectChangeAccumulator … … 221 224 void _update(void); 222 225 std::set<Object *> i_objects; 226 std::set<WorldObject *> i_activeobjects; 223 227 LockType i_playerGuard; 224 228 LockType i_updateGuard; -
trunk/src/game/Pet.cpp
r102 r120 97 97 m_autospells.clear(); 98 98 m_declinedname = NULL; 99 m_isActive = true; 99 100 } 100 101 -
trunk/src/game/Pet.h
r102 r120 123 123 void AddToWorld(); 124 124 void RemoveFromWorld(); 125 // always active 126 void setActive() {} 125 127 126 128 PetType getPetType() const { return m_petType; } -
trunk/src/game/Player.cpp
r111 r120 426 426 427 427 m_declinedname = NULL; 428 429 m_isActive = true; 428 430 } 429 431 -
trunk/src/game/Player.h
r102 r120 903 903 void AddToWorld(); 904 904 void RemoveFromWorld(); 905 // always active 906 void setActive() {} 905 907 906 908 bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options = 0); -
trunk/src/game/Unit.cpp
r111 r120 9827 9827 void Unit::AddToWorld() 9828 9828 { 9829 Object::AddToWorld();9829 WorldObject::AddToWorld(); 9830 9830 } 9831 9831 … … 9838 9838 } 9839 9839 9840 Object::RemoveFromWorld();9840 WorldObject::RemoveFromWorld(); 9841 9841 } 9842 9842