Changeset 268 for trunk

Show
Ignore:
Timestamp:
11/21/08 21:45:30 (17 years ago)
Author:
yumileroy
Message:

*Move object update from objectaccessor to map
*Move activeobject list from objectaccessor to map
*Open grid for all active creatures (previously only for possessed ones)

Original author: megamage
Date: 2008-11-21 15:41:18-06:00

Location:
trunk/src/game
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/GridStates.cpp

    r120 r268  
    1111 * This program is distributed in the hope that it will be useful, 
    1212 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414 * GNU General Public License for more details. 
    1515 * 
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
    1919 */ 
    2020 
     
    3737    if( info.getTimeTracker().Passed() ) 
    3838    { 
    39         if( grid.ActiveObjectsInGrid() == 0 && !ObjectAccessor::Instance().ActiveObjectsNearGrid(x, y, m.GetId(), m.GetInstanceId()) ) 
     39        if( grid.ActiveObjectsInGrid() == 0 && !m.ActiveObjectsNearGrid(x, y) ) 
    4040        { 
    4141            ObjectGridStoper stoper(grid); 
     
    5151 
    5252void 
    53 IdleState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 &x, const uint32 &y, const uint32 &) const 
     53IdleState::Update(Map &m, NGridType &grid, GridInfo &, const uint32 &x, const uint32 &y, const uint32 &) const 
    5454{ 
    5555    m.ResetGridExpiry(grid); 
  • trunk/src/game/Map.cpp

    r266 r268  
    595595} 
    596596 
    597 void Map::Update(const uint32 &t_diff) 
    598 { 
    599     // TODO: need have an active object list for every map 
    600  
    601     /*resetMarkedCells(); 
    602  
     597void Map::UpdateActiveCells(const float &x, const float &y, const uint32 &t_diff) 
     598{ 
     599    CellPair standing_cell(Trinity::ComputeCellPair(x, y)); 
     600 
     601    // Check for correctness of standing_cell, it also avoids problems with update_cell 
     602    if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) 
     603        return; 
     604 
     605    // will this reduce the speed? 
    603606    Trinity::ObjectUpdater updater(t_diff); 
    604607    // for creature 
     
    607610    TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer > world_object_update(updater); 
    608611 
     612    // the overloaded operators handle range checking 
     613    // so ther's no need for range checking inside the loop 
     614    CellPair begin_cell(standing_cell), end_cell(standing_cell); 
     615    begin_cell << 1; begin_cell -= 1;               // upper left 
     616    end_cell >> 1; end_cell += 1;                   // lower right 
     617 
     618    for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) 
     619    { 
     620        for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) 
     621        { 
     622            // marked cells are those that have been visited 
     623            // don't visit the same cell twice 
     624            uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x; 
     625            if(!isCellMarked(cell_id)) 
     626            { 
     627                markCell(cell_id); 
     628                CellPair pair(x,y); 
     629                Cell cell(pair); 
     630                cell.data.Part.reserved = CENTER_DISTRICT; 
     631                cell.SetNoCreate(); 
     632                CellLock<NullGuard> cell_lock(cell, pair); 
     633                cell_lock->Visit(cell_lock, grid_object_update,  *this); 
     634                cell_lock->Visit(cell_lock, world_object_update, *this); 
     635            } 
     636        } 
     637    } 
     638} 
     639 
     640void Map::Update(const uint32 &t_diff) 
     641{ 
     642    resetMarkedCells(); 
     643 
     644    // update cells around players 
    609645    for(MapRefManager::iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) 
    610646    { 
    611647        Player* plr = iter->getSource(); 
    612         if(!plr->IsInWorld()) 
    613             continue; 
    614  
    615         CellPair standing_cell(Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY())); 
    616  
    617         // Check for correctness of standing_cell, it also avoids problems with update_cell 
    618         if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) 
    619             continue; 
    620  
    621         // the overloaded operators handle range checking 
    622         // so ther's no need for range checking inside the loop 
    623         CellPair begin_cell(standing_cell), end_cell(standing_cell); 
    624         begin_cell << 1; begin_cell -= 1;               // upper left 
    625         end_cell >> 1; end_cell += 1;                   // lower right 
    626  
    627         for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) 
    628         { 
    629             for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) 
    630             { 
    631                 // marked cells are those that have been visited 
    632                 // don't visit the same cell twice 
    633                 uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x; 
    634                 if(!isCellMarked(cell_id)) 
    635                 { 
    636                     markCell(cell_id); 
    637                     CellPair pair(x,y); 
    638                     Cell cell(pair); 
    639                     cell.data.Part.reserved = CENTER_DISTRICT; 
    640                     cell.SetNoCreate(); 
    641                     CellLock<NullGuard> cell_lock(cell, pair); 
    642                     cell_lock->Visit(cell_lock, grid_object_update,  *this); 
    643                     cell_lock->Visit(cell_lock, world_object_update, *this); 
    644                 } 
    645             } 
    646         } 
    647     }*/ 
     648        if(plr->IsInWorld()) 
     649            UpdateActiveCells(plr->GetPositionX(), plr->GetPositionY(), t_diff); 
     650    } 
     651 
     652    // update cells around active objects 
     653    // clone the active object list, because update might remove from it 
     654    std::set<WorldObject *> activeObjects(i_activeObjects); 
     655    for(std::set<WorldObject *>::iterator iter = activeObjects.begin(); iter != activeObjects.end(); ++iter) 
     656    { 
     657        if((*iter)->IsInWorld()) 
     658            UpdateActiveCells((*iter)->GetPositionX(), (*iter)->GetPositionY(), t_diff); 
     659    } 
    648660 
    649661    // Don't unload grids if it's battleground, since we may have manually added GOs,creatures, those doesn't load from DB at grid re-load ! 
     
    814826        AddCreatureToMoveList(creature,x,y,z,ang); 
    815827        // in diffcell/diffgrid case notifiers called at finishing move creature in Map::MoveAllCreaturesInMoveList 
    816         if(creature->isPossessedByPlayer()) 
    817             EnsureGridLoadedForPlayer(new_cell, (Player*)creature->GetCharmer(), false); 
     828        if(creature->isActive()) 
     829        { 
     830            if(creature->isPossessedByPlayer()) 
     831                EnsureGridLoadedForPlayer(new_cell, (Player*)creature->GetCharmer(), false); 
     832            else 
     833                EnsureGridLoadedForPlayer(new_cell, NULL, false); 
     834        } 
    818835    } 
    819836    else 
     
    15021519 
    15031520        CellPair p = Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY()); 
     1521        if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && 
     1522            (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) 
     1523            return true; 
     1524    } 
     1525 
     1526    return false; 
     1527} 
     1528 
     1529bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const 
     1530{ 
     1531    CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS); 
     1532    CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); 
     1533    cell_min << 2; 
     1534    cell_min -= 2; 
     1535    cell_max >> 2; 
     1536    cell_max += 2; 
     1537 
     1538    for(MapRefManager::const_iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) 
     1539    { 
     1540        Player* plr = iter->getSource(); 
     1541 
     1542        CellPair p = Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY()); 
     1543        if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && 
     1544            (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) 
     1545            return true; 
     1546    } 
     1547 
     1548    for(std::set<WorldObject*>::const_iterator itr = i_activeObjects.begin(); itr != i_activeObjects.end(); ++itr) 
     1549    { 
     1550        CellPair p = Trinity::ComputeCellPair((*itr)->GetPositionX(), (*itr)->GetPositionY()); 
    15041551        if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && 
    15051552            (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) 
  • trunk/src/game/Map.h

    r260 r268  
    243243        uint32 GetPlayersCountExceptGMs() const; 
    244244        bool PlayersNearGrid(uint32 x,uint32 y) const; 
     245        bool ActiveObjectsNearGrid(uint32 x, uint32 y) const; 
     246 
     247        void AddActiveObject(WorldObject* obj) { i_activeObjects.insert(obj); } 
     248        void RemoveActiveObject(WorldObject* obj) { i_activeObjects.erase(obj); } 
    245249 
    246250        void SendToPlayers(WorldPacket const* data) const; 
     
    288292        inline void setNGrid(NGridType* grid, uint32 x, uint32 y); 
    289293 
     294        void UpdateActiveCells(const float &x, const float &y, const uint32 &t_diff); 
    290295    protected: 
    291296        typedef Trinity::ObjectLevelLockable<Map, ZThread::Mutex>::Lock Guard; 
     
    308313        time_t i_gridExpiry; 
    309314 
     315        std::set<WorldObject *> i_activeObjects; 
    310316        std::set<WorldObject *> i_objectsToRemove; 
    311317 
  • trunk/src/game/Object.cpp

    r230 r268  
    991991WorldObject::~WorldObject() 
    992992{ 
    993     if(m_isActive && IsInWorld()) 
    994         ObjectAccessor::Instance().RemoveActiveObject(this); 
     993    if(m_isActive && !isType(TYPEMASK_PLAYER) && IsInWorld()) 
     994        GetMap()->RemoveActiveObject(this); 
    995995} 
    996996 
     
    998998{ 
    999999    // if already in the same activity state as we try to set, do nothing 
    1000     if(isActive == m_isActive) 
     1000    if(isActive == m_isActive || isType(TYPEMASK_PLAYER)) 
    10011001        return; 
     1002 
    10021003    m_isActive = isActive; 
    10031004    if(IsInWorld()) 
    10041005    { 
    10051006        if(isActive) 
    1006             ObjectAccessor::Instance().AddActiveObject(this); 
     1007            GetMap()->AddActiveObject(this); 
    10071008        else 
    1008             ObjectAccessor::Instance().RemoveActiveObject(this); 
     1009            GetMap()->RemoveActiveObject(this); 
    10091010    } 
    10101011} 
     
    10131014{ 
    10141015    Object::AddToWorld(); 
    1015     if(m_isActive) 
    1016         ObjectAccessor::Instance().AddActiveObject(this); 
     1016    if(m_isActive && !isType(TYPEMASK_PLAYER)) 
     1017        GetMap()->AddActiveObject(this); 
    10171018} 
    10181019 
    10191020void WorldObject::RemoveFromWorld() 
    10201021{ 
    1021     if(m_isActive) 
    1022         ObjectAccessor::Instance().RemoveActiveObject(this); 
     1022    if(m_isActive && !isType(TYPEMASK_PLAYER)) 
     1023        GetMap()->RemoveActiveObject(this); 
    10231024    Object::RemoveFromWorld(); 
    10241025} 
  • trunk/src/game/Object.h

    r230 r268  
    456456        GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime); 
    457457        bool isActive() const { return m_isActive; } 
    458         virtual void setActive(bool isActive); 
     458        void setActive(bool isActive); 
    459459    protected: 
    460460        explicit WorldObject(); 
  • trunk/src/game/ObjectAccessor.cpp

    r266 r268  
    488488 
    489489void 
    490 ObjectAccessor::AddActiveObject( WorldObject * obj ) 
    491 { 
    492     i_activeobjects.insert(obj); 
    493 } 
    494  
    495 void 
    496 ObjectAccessor::RemoveActiveObject( WorldObject * obj ) 
    497 { 
    498     i_activeobjects.erase(obj); 
    499 } 
    500  
    501 void 
    502490ObjectAccessor::Update(uint32 diff) 
    503491{ 
    504  
    505     { 
     492/*    { 
    506493        //Player update now in MapManager -> UpdatePlayers 
    507         /* 
    508494        // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects. 
    509495        HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer(); 
     
    514500                iter->second->Update(diff); 
    515501            } 
    516         }*/ 
     502        } 
    517503 
    518504        // TODO: move this to Map::Update 
     
    575561            } 
    576562        } 
    577     } 
     563    }*/ 
    578564 
    579565    UpdateDataMapType update_players; 
     
    609595} 
    610596 
    611 bool 
    612 ObjectAccessor::ActiveObjectsNearGrid(uint32 x, uint32 y, uint32 m_id, uint32 i_id) const 
    613 { 
    614     CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS); 
    615     CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); 
    616     cell_min << 2; 
    617     cell_min -= 2; 
    618     cell_max >> 2; 
    619     cell_max += 2; 
    620  
    621     for(std::set<WorldObject*>::const_iterator itr = i_activeobjects.begin(); itr != i_activeobjects.end(); ++itr) 
    622     { 
    623         if( m_id != (*itr)->GetMapId() || i_id != (*itr)->GetInstanceId() ) 
    624             continue; 
    625  
    626         CellPair p = Trinity::ComputeCellPair((*itr)->GetPositionX(), (*itr)->GetPositionY()); 
    627         if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && 
    628             (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) 
    629             return true; 
    630     } 
    631  
    632     return false; 
    633 } 
    634  
    635597void 
    636598ObjectAccessor::WorldObjectChangeAccumulator::Visit(PlayerMapType &m) 
  • trunk/src/game/ObjectAccessor.h

    r257 r268  
    195195        Corpse* ConvertCorpseForPlayer(uint64 player_guid); 
    196196 
    197         bool ActiveObjectsNearGrid(uint32 x,uint32 y,uint32 m_id,uint32 i_id) const; 
    198  
    199197        static void UpdateObject(Object* obj, Player* exceptPlayer); 
    200198        static void _buildUpdateObject(Object* obj, UpdateDataMapType &); 
     
    202200        static void UpdateObjectVisibility(WorldObject* obj); 
    203201        static void UpdateVisibilityForPlayer(Player* player); 
    204  
    205         void AddActiveObject(WorldObject*); 
    206         void RemoveActiveObject(WorldObject*); 
    207202    private: 
    208203        struct WorldObjectChangeAccumulator 
     
    229224        void _update(void); 
    230225        std::set<Object *> i_objects; 
    231         std::set<WorldObject *> i_activeobjects; 
    232226        LockType i_playerGuard; 
    233227        LockType i_updateGuard; 
  • trunk/src/game/Player.h

    r257 r268  
    898898        void AddToWorld(); 
    899899        void RemoveFromWorld(); 
    900         // always active 
    901         void setActive(bool) {} 
    902900 
    903901        void SetViewport(uint64 guid, bool movable);