Skip to content

Commit

Permalink
[12783] Create function to load active entities.
Browse files Browse the repository at this point in the history
Note this function is considered WIP, and will require further work pending more features

Ideas and loop to load all grids on a map by Neo2003.
  • Loading branch information
Schmoozerd committed Nov 13, 2014
1 parent e5182a3 commit aaf514c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/game/Creature.cpp
Expand Up @@ -174,6 +174,11 @@ void Creature::AddToWorld()
GetMap()->GetObjectsStore().insert<Creature>(GetObjectGuid(), (Creature*)this);

Unit::AddToWorld();

// Make active if required
std::set<uint32> const* mapList = sWorld.getConfigForceLoadMapIds();
if ((mapList && mapList->find(GetMapId()) != mapList->end()) /*|| FlagsExtra & ACTIVE*/)
SetActiveObjectState(true);
}

void Creature::RemoveFromWorld()
Expand Down
2 changes: 1 addition & 1 deletion src/game/Map.h
Expand Up @@ -188,14 +188,14 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>
MapDifficultyEntry const* GetMapDifficulty() const; // dependent from map difficulty

bool Instanceable() const { return i_mapEntry && i_mapEntry->Instanceable(); }
// NOTE: this duplicate of Instanceable(), but Instanceable() can be changed when BG also will be instanceable
bool IsDungeon() const { return i_mapEntry && i_mapEntry->IsDungeon(); }
bool IsRaid() const { return i_mapEntry && i_mapEntry->IsRaid(); }
bool IsNonRaidDungeon() const { return i_mapEntry && i_mapEntry->IsNonRaidDungeon(); }
bool IsRaidOrHeroicDungeon() const { return IsRaid() || GetDifficulty() > DUNGEON_DIFFICULTY_NORMAL; }
bool IsBattleGround() const { return i_mapEntry && i_mapEntry->IsBattleGround(); }
bool IsBattleArena() const { return i_mapEntry && i_mapEntry->IsBattleArena(); }
bool IsBattleGroundOrArena() const { return i_mapEntry && i_mapEntry->IsBattleGroundOrArena(); }
bool IsContinent() const { return i_mapEntry && i_mapEntry->IsContinent(); }

// can't be NULL for loaded map
MapPersistentState* GetPersistentState() const { return m_persistentState; }
Expand Down
2 changes: 2 additions & 0 deletions src/game/MapManager.cpp
Expand Up @@ -102,6 +102,8 @@ Map* MapManager::CreateMap(uint32 id, const WorldObject* obj)
MANGOS_ASSERT(obj && obj->GetTypeId() == TYPEID_PLAYER);
// create DungeonMap object
m = CreateInstance(id, (Player*)obj);
// Load active objects for this map
sObjectMgr.LoadActiveEntities(m);
}
else
{
Expand Down
43 changes: 43 additions & 0 deletions src/game/ObjectMgr.cpp
Expand Up @@ -9076,6 +9076,49 @@ void ObjectMgr::LoadVendorTemplates()
sLog.outErrorDb("Table `npc_vendor_template` has vendor template %u not used by any vendors ", *vItr);
}

/* This function is supposed to take care of three things:
* 1) Load Transports on Map or on Continents
* 2) Load Active Npcs on Map or Continents
* 3) Load Everything dependend on config setting LoadAllGridsOnMaps
*
* This function is currently WIP, hence many things are only existing as draft.
*/
void ObjectMgr::LoadActiveEntities(Map* _map)
{
// Special case on startup - load continents
if (!_map)
{
uint32 continents[] = {0, 1, 530, 571};
for (int i = 0; i < countof(continents); ++i)
{
_map = sMapMgr.FindMap(continents[i]);
if (!_map)
_map = sMapMgr.CreateMap(continents[i], NULL);

if (_map)
LoadActiveEntities(_map);
else
sLog.outError("ObjectMgr::LoadActiveEntities - Unable to create Map %u", continents[i]);
}

return;
}

// Load active objects for _map
std::set<uint32> const* mapList = sWorld.getConfigForceLoadMapIds();
if (mapList && mapList->find(_map->GetId()) != mapList->end())
{
for (CreatureDataMap::const_iterator itr = mCreatureDataMap.begin(); itr != mCreatureDataMap.end(); ++itr)
{
if (itr->second.mapid == _map->GetId())
_map->ForceLoadGrid(itr->second.posX, itr->second.posY);
}
}
//else // Normal case - Load all npcs that are active

// Load Transports on Map _map
}

void ObjectMgr::LoadNpcGossips()
{
m_mCacheNpcTextIdMap.clear();
Expand Down
5 changes: 4 additions & 1 deletion src/game/ObjectMgr.h
Expand Up @@ -137,7 +137,7 @@ struct MangosStringLocale
uint32 Emote;
};

typedef UNORDERED_MAP<uint32, CreatureData> CreatureDataMap;
typedef UNORDERED_MAP<uint32 /*guid*/, CreatureData> CreatureDataMap;
typedef CreatureDataMap::value_type CreatureDataPair;

class FindCreatureData
Expand Down Expand Up @@ -757,6 +757,9 @@ class ObjectMgr
void LoadTrainerTemplates();
void LoadTrainers() { LoadTrainers("npc_trainer", false); }

/// @param _map Map* of the map for which to load active entities. If NULL active entities on continents are loaded
void LoadActiveEntities(Map* _map);

void LoadVehicleAccessory();

std::string GeneratePetName(uint32 entry);
Expand Down
4 changes: 4 additions & 0 deletions src/game/World.cpp
Expand Up @@ -1455,6 +1455,10 @@ void World::SetInitialWorldSettings()
m_timers[WUPDATE_EVENTS].SetInterval(nextGameEvent); // depend on next event
sLog.outString();

sLog.outString("Loading grids for active creatures or transports...");
sObjectMgr.LoadActiveEntities(NULL);
sLog.outString();

// Delete all characters which have been deleted X days before
Player::DeleteOldCharacters();

Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12782"
#define REVISION_NR "12783"
#endif // __REVISION_NR_H__

4 comments on commit aaf514c

@Schmoozerd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually poke @Ambal about this:
Now you can do real badass performance tests :)

On my system loading maps 0 and 1 costs full cpu and 2.5gig of ram (i think without vmaps/mmaps)

@xfurry
Copy link
Member

@xfurry xfurry commented on aaf514c Nov 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should try with LoadAllGridsOnMaps = "0, 1, 530, 571, 609"
Also, I don't think that loading grids on instanced maps make sense.

@Schmoozerd
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

609 == ebon-hold?
Is this map considered to be a continent? If so i should add it in one of the next commits trying to make things easier between different client-versions

But i think it is also possible that in some cases we might want to test such activity in instance-maps.

@xfurry
Copy link
Member

@xfurry xfurry commented on aaf514c Nov 14, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

609 == ebon-hold?

Yes, this is ebon hold, and it's considered a world map.
Actually these kind of small world maps are pretty common starting from 4.x.

Please sign in to comment.