aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2009-03-31 14:40:54 -0600
committermegamage <none@none>2009-03-31 14:40:54 -0600
commitb91529fd8e97232d272cd609bc7d07730d24b2d1 (patch)
treeb6ef724894fa1c141e0b537db71a409dd3c1e7d1 /src
parentf2df7bbdcc7ba952083d3eb96230ee2eea391fd8 (diff)
*Backport some code from TC2.
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/GridStates.cpp5
-rw-r--r--src/game/Map.cpp34
-rw-r--r--src/game/Map.h14
-rw-r--r--src/game/ObjectGridLoader.cpp87
-rw-r--r--src/game/ObjectGridLoader.h29
5 files changed, 114 insertions, 55 deletions
diff --git a/src/game/GridStates.cpp b/src/game/GridStates.cpp
index bb47428553c..fa1c0a2b534 100644
--- a/src/game/GridStates.cpp
+++ b/src/game/GridStates.cpp
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
- * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
+ * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,7 +20,6 @@
#include "GridStates.h"
#include "GridNotifiers.h"
-#include "ObjectAccessor.h"
#include "GameSystem/Grid.h"
#include "Log.h"
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index fb7664616dc..4c7e1471d4a 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2005-2008 Trinity <http://www.mangosproject.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
- * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
+ * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -81,7 +81,6 @@ bool Map::ExistMap(uint32 mapid,int x,int y)
delete [] tmp;
fclose(pf);
-
return true;
}
@@ -508,7 +507,8 @@ Map::Add(T *obj)
DEBUG_LOG("Object %u enters grid[%u,%u]", GUID_LOPART(obj->GetGUID()), cell.GridX(), cell.GridY());
- UpdateObjectVisibility(obj,cell,p);
+ if(obj->GetTypeId() != TYPEID_UNIT)
+ UpdateObjectVisibility(obj,cell,p);
AddNotifier(obj);
}
@@ -1113,27 +1113,31 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool unloadAll)
return false;
DEBUG_LOG("Unloading grid[%u,%u] for map %u", x,y, i_id);
+
ObjectGridUnloader unloader(*grid);
if(!unloadAll)
{
// Finish creature moves, remove and delete all creatures with delayed remove before moving to respawn grids
// Must know real mob position before move
- DoDelayedMovesAndRemoves();
+ MoveAllCreaturesInMoveList();
// move creatures to respawn grids if this is diff.grid or to remove list
unloader.MoveToRespawnN();
// Finish creature moves, remove and delete all creatures with delayed remove before unload
- DoDelayedMovesAndRemoves();
+ MoveAllCreaturesInMoveList();
}
- else
- RemoveAllObjectsInRemoveList();
- //assert(grid.NoWorldObjectInGrid());
+ ObjectGridCleaner cleaner(*grid);
+ cleaner.CleanN();
+
+ RemoveAllObjectsInRemoveList();
+
unloader.UnloadN();
- //assert(grid.NoWorldObjectInGrid());
- //assert(grid.NoGridObjectInGrid());
+
+ assert(i_objectsToRemove.empty());
+
delete grid;
setNGrid(NULL, x, y);
}
@@ -1633,8 +1637,8 @@ void Map::RemoveAllObjectsInRemoveList()
//sLog.outDebug("Object remover 1 check.");
while(!i_objectsToRemove.empty())
{
- WorldObject* obj = *i_objectsToRemove.begin();
- i_objectsToRemove.erase(i_objectsToRemove.begin());
+ std::set<WorldObject*>::iterator itr = i_objectsToRemove.begin();
+ WorldObject* obj = *itr;
switch(obj->GetTypeId())
{
@@ -1642,7 +1646,7 @@ void Map::RemoveAllObjectsInRemoveList()
{
Corpse* corpse = ObjectAccessor::Instance().GetCorpse(*obj, obj->GetGUID());
if (!corpse)
- sLog.outError("ERROR: Try delete corpse/bones %u that not in map", obj->GetGUIDLow());
+ sLog.outError("Try delete corpse/bones %u that not in map", obj->GetGUIDLow());
else
Remove(corpse,true);
break;
@@ -1663,6 +1667,8 @@ void Map::RemoveAllObjectsInRemoveList()
sLog.outError("Non-grid object (TypeId: %u) in grid object removing list, ignored.",obj->GetTypeId());
break;
}
+
+ i_objectsToRemove.erase(itr);
}
//sLog.outDebug("Object remover 2 check.");
}
diff --git a/src/game/Map.h b/src/game/Map.h
index 23ae08d1167..c5acedab174 100644
--- a/src/game/Map.h
+++ b/src/game/Map.h
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
- * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
+ * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -136,10 +136,8 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
// currently unused for normal maps
bool CanUnload(uint32 diff)
{
- if(!m_unloadTimer)
- return false;
- if(m_unloadTimer <= diff)
- return true;
+ if(!m_unloadTimer) return false;
+ if(m_unloadTimer <= diff) return true;
m_unloadTimer -= diff;
return false;
}
@@ -161,7 +159,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
template<class LOCK_TYPE, class T, class CONTAINER> void Visit(const CellLock<LOCK_TYPE> &cell, TypeContainerVisitor<T, CONTAINER> &visitor);
- inline bool IsRemovalGrid(float x, float y) const
+ bool IsRemovalGrid(float x, float y) const
{
GridPair p = Trinity::ComputeGridPair(x, y);
return( !getNGrid(p.x_coord, p.y_coord) || getNGrid(p.x_coord, p.y_coord)->GetGridState() == GRID_STATE_REMOVAL );
@@ -310,7 +308,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
bool isGridObjectDataLoaded(uint32 x, uint32 y) const { return getNGrid(x,y)->isGridObjectDataLoaded(); }
void setGridObjectDataLoaded(bool pLoaded, uint32 x, uint32 y) { getNGrid(x,y)->setGridObjectDataLoaded(pLoaded); }
- inline void setNGrid(NGridType* grid, uint32 x, uint32 y);
+ void setNGrid(NGridType* grid, uint32 x, uint32 y);
void UpdateActiveCells(const float &x, const float &y, const uint32 &t_diff);
protected:
diff --git a/src/game/ObjectGridLoader.cpp b/src/game/ObjectGridLoader.cpp
index 0c1de5859e9..9c36aa80f1a 100644
--- a/src/game/ObjectGridLoader.cpp
+++ b/src/game/ObjectGridLoader.cpp
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
- * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
+ * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,7 +21,6 @@
#include "ObjectGridLoader.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
-#include "MapManager.h"
#include "Creature.h"
#include "GameObject.h"
#include "DynamicObject.h"
@@ -70,7 +69,7 @@ ObjectGridRespawnMover::Visit(CreatureMapType &m)
if(cur_cell.DiffGrid(resp_cell))
{
- MapManager::Instance().GetMap(c->GetMapId(), c)->CreatureRespawnRelocation(c);
+ c->GetMap()->CreatureRespawnRelocation(c);
// false result ignored: will be unload with other creatures at grid
}
}
@@ -135,6 +134,36 @@ void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> &
}
}
+void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, CreatureMapType &m, uint32 &count, Map* map)
+{
+ for(CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid)
+ {
+ Creature* obj = new Creature;
+ uint32 guid = *i_guid;
+ //sLog.outString("DEBUG: LoadHelper from table: %s for (guid: %u) Loading",table,guid);
+ if(!obj->LoadFromDB(guid, map))
+ {
+ delete obj;
+ obj = new Vehicle;
+ if(!((Vehicle*)obj)->LoadFromDB(guid, map))
+ {
+ delete (Vehicle*)obj;
+ continue;
+ }
+ }
+
+ obj->GetGridRef().link(&m, obj);
+
+ addUnitState(obj,cell);
+ obj->AddToWorld();
+ if(obj->isActiveObject())
+ map->AddToActive(obj);
+
+ ++count;
+
+ }
+}
+
void LoadHelper(CellCorpseSet const& cell_corpses, CellPair &cell, CorpseMapType &m, uint32 &count, Map* map)
{
if(cell_corpses.empty())
@@ -263,29 +292,7 @@ ObjectGridUnloader::Visit(GridRefManager<T> &m)
// if option set then object already saved at this moment
if(!sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY))
obj->SaveRespawnTime();
- ///- object must be out of world before delete
- obj->RemoveFromWorld();
- ///- object will get delinked from the manager when deleted
- delete obj;
- }
-}
-
-template<>
-void
-ObjectGridUnloader::Visit(CreatureMapType &m)
-{
- // remove all cross-reference before deleting
- for(CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
- iter->getSource()->CleanupsBeforeDelete();
-
- while(!m.isEmpty())
- {
- Creature *obj = m.getFirst()->getSource();
- // if option set then object already saved at this moment
- if(!sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY))
- obj->SaveRespawnTime();
///- object will get delinked from the manager when deleted
- obj->CleanupsBeforeDelete();
delete obj;
}
}
@@ -309,6 +316,32 @@ ObjectGridStoper::Visit(CreatureMapType &m)
}
}
+void
+ObjectGridCleaner::Stop(GridType &grid)
+{
+ TypeContainerVisitor<ObjectGridCleaner, GridTypeMapContainer > stoper(*this);
+ grid.Visit(stoper);
+}
+
+void
+ObjectGridCleaner::Visit(CreatureMapType &m)
+{
+ for(CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
+ iter->getSource()->CleanupsBeforeDelete();
+}
+
+template<class T>
+void
+ObjectGridCleaner::Visit(GridRefManager<T> &m)
+{
+ for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
+ iter->getSource()->RemoveFromWorld();
+}
+
+template void ObjectGridUnloader::Visit(CreatureMapType &);
template void ObjectGridUnloader::Visit(GameObjectMapType &);
template void ObjectGridUnloader::Visit(DynamicObjectMapType &);
-
+template void ObjectGridUnloader::Visit(CorpseMapType &);
+template void ObjectGridCleaner::Visit<GameObject>(GameObjectMapType &);
+template void ObjectGridCleaner::Visit<DynamicObject>(DynamicObjectMapType &);
+template void ObjectGridCleaner::Visit<Corpse>(CorpseMapType &);
diff --git a/src/game/ObjectGridLoader.h b/src/game/ObjectGridLoader.h
index d076d0ba29b..768f1f994db 100644
--- a/src/game/ObjectGridLoader.h
+++ b/src/game/ObjectGridLoader.h
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
- * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
+ * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -85,7 +85,6 @@ class TRINITY_DLL_DECL ObjectGridStoper
public:
ObjectGridStoper(NGridType &grid) : i_grid(grid) {}
- void MoveToRespawnN();
void StopN()
{
for(unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x)
@@ -106,6 +105,30 @@ class TRINITY_DLL_DECL ObjectGridStoper
NGridType &i_grid;
};
+class TRINITY_DLL_DECL ObjectGridCleaner
+{
+ public:
+ ObjectGridCleaner(NGridType &grid) : i_grid(grid) {}
+
+ void CleanN()
+ {
+ for(unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x)
+ {
+ for(unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y)
+ {
+ GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader;
+ loader.Stop(i_grid(x, y), *this);
+ }
+ }
+ }
+
+ void Stop(GridType &grid);
+ void Visit(CreatureMapType &m);
+ template<class T> void Visit(GridRefManager<T> &);
+ private:
+ NGridType &i_grid;
+};
+
typedef GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> GridLoaderType;
#endif