mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 07:48:02 +00:00
feat(Scripts/Commands): debug objectcount
This commit is contained in:
committed by
GitHub
parent
cc5f26db7f
commit
6e2e73d6ae
@@ -0,0 +1,5 @@
|
|||||||
|
INSERT INTO `version_db_world` (`sql_rev`) VALUES ('1646287552186744609');
|
||||||
|
|
||||||
|
DELETE FROM `command` WHERE `name`='debug objectcount';
|
||||||
|
INSERT INTO `command` (`name`,`security`,`help`) VALUES
|
||||||
|
('debug objectcount',3,'Syntax: .debug objectcount <optional map id> Shows the number of Creatures and GameObjects for the specified map id or for all maps if none is specified');
|
||||||
@@ -635,6 +635,11 @@ public:
|
|||||||
_updateObjects.erase(obj);
|
_updateObjects.erase(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t GetActiveNonPlayersCount() const
|
||||||
|
{
|
||||||
|
return m_activeNonPlayers.size();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadMapAndVMap(int gx, int gy);
|
void LoadMapAndVMap(int gx, int gy);
|
||||||
void LoadVMap(int gx, int gy);
|
void LoadVMap(int gx, int gy);
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ public:
|
|||||||
{ "los", HandleDebugLoSCommand, SEC_ADMINISTRATOR, Console::No },
|
{ "los", HandleDebugLoSCommand, SEC_ADMINISTRATOR, Console::No },
|
||||||
{ "moveflags", HandleDebugMoveflagsCommand, SEC_ADMINISTRATOR, Console::No },
|
{ "moveflags", HandleDebugMoveflagsCommand, SEC_ADMINISTRATOR, Console::No },
|
||||||
{ "unitstate", HandleDebugUnitStateCommand, SEC_ADMINISTRATOR, Console::No },
|
{ "unitstate", HandleDebugUnitStateCommand, SEC_ADMINISTRATOR, Console::No },
|
||||||
|
{ "objectcount", HandleDebugObjectCountCommand, SEC_ADMINISTRATOR, Console::Yes},
|
||||||
{ "dummy", HandleDebugDummyCommand, SEC_ADMINISTRATOR, Console::No }
|
{ "dummy", HandleDebugDummyCommand, SEC_ADMINISTRATOR, Console::No }
|
||||||
};
|
};
|
||||||
static ChatCommandTable commandTable =
|
static ChatCommandTable commandTable =
|
||||||
@@ -1244,6 +1245,84 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool HandleDebugObjectCountCommand(ChatHandler* handler, Optional<uint32> mapId)
|
||||||
|
{
|
||||||
|
if (mapId)
|
||||||
|
{
|
||||||
|
sMapMgr->DoForAllMapsWithMapId(mapId.value(),
|
||||||
|
[handler](Map* map) -> void
|
||||||
|
{
|
||||||
|
HandleDebugObjectCountMap(handler, map);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sMapMgr->DoForAllMaps(
|
||||||
|
[handler](Map* map) -> void
|
||||||
|
{
|
||||||
|
HandleDebugObjectCountMap(handler, map);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CreatureCountWorker
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CreatureCountWorker() { }
|
||||||
|
|
||||||
|
void Visit(std::unordered_map<ObjectGuid, Creature*>& creatureMap)
|
||||||
|
{
|
||||||
|
for (auto const& p : creatureMap)
|
||||||
|
{
|
||||||
|
uint32& count = creatureIds[p.second->GetEntry()];
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void Visit(std::unordered_map<ObjectGuid, T*>&) { }
|
||||||
|
|
||||||
|
std::vector<std::pair<uint32, uint32>> GetTopCreatureCount(uint32 count)
|
||||||
|
{
|
||||||
|
auto comp = [](std::pair<uint32, uint32> const& a, std::pair<uint32, uint32> const& b)
|
||||||
|
{
|
||||||
|
return a.second > b.second;
|
||||||
|
};
|
||||||
|
std::set<std::pair<uint32, uint32>, decltype(comp)> set(creatureIds.begin(), creatureIds.end(), comp);
|
||||||
|
|
||||||
|
count = std::min(count, uint32(set.size()));
|
||||||
|
std::vector<std::pair<uint32, uint32>> result(count);
|
||||||
|
std::copy_n(set.begin(), count, result.begin());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<uint32, uint32> creatureIds;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void HandleDebugObjectCountMap(ChatHandler* handler, Map* map)
|
||||||
|
{
|
||||||
|
handler->PSendSysMessage("Map Id: %u Name: '%s' Instance Id: %u Creatures: %u GameObjects: %u SetActive Objects: %u",
|
||||||
|
map->GetId(), map->GetMapName(), map->GetInstanceId(),
|
||||||
|
uint64(map->GetObjectsStore().Size<Creature>()),
|
||||||
|
uint64(map->GetObjectsStore().Size<GameObject>()),
|
||||||
|
uint64(map->GetActiveNonPlayersCount()));
|
||||||
|
|
||||||
|
CreatureCountWorker worker;
|
||||||
|
TypeContainerVisitor<CreatureCountWorker, MapStoredObjectTypesContainer> visitor(worker);
|
||||||
|
visitor.Visit(map->GetObjectsStore());
|
||||||
|
|
||||||
|
handler->PSendSysMessage("Top Creatures count:");
|
||||||
|
|
||||||
|
for (auto&& p : worker.GetTopCreatureCount(5))
|
||||||
|
handler->PSendSysMessage("Entry: %u Count: %u", p.first, p.second);
|
||||||
|
}
|
||||||
|
|
||||||
static bool HandleDebugDummyCommand(ChatHandler* handler)
|
static bool HandleDebugDummyCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
handler->SendSysMessage("This command does nothing right now. Edit your local core (cs_debug.cpp) to make it do whatever you need for testing.");
|
handler->SendSysMessage("This command does nothing right now. Edit your local core (cs_debug.cpp) to make it do whatever you need for testing.");
|
||||||
|
|||||||
Reference in New Issue
Block a user