aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2020-08-06 12:58:39 +0000
committerShauren <shauren.trinity@gmail.com>2022-01-26 16:22:00 +0100
commitffd85f9139119ec56a8a6f3add4ef4c0f047b838 (patch)
tree45e24332c9c209723f4d812561eefbc3763cef91 /src
parent7603dacc6431598ce5e770907bf9f53c51a29014 (diff)
Scripts/Comamnds: Improve ".debug objectcount" command (#25208)
* Scripts/Comamnds: Improve ".debug objectcount" command Include the top 5 most common creatures in the map * Use C++ features to copy data * Fix build warnings * Update src/server/scripts/Commands/cs_debug.cpp Co-authored-by: Shauren <shauren.trinity@gmail.com> * Update src/server/scripts/Commands/cs_debug.cpp Co-authored-by: Shauren <shauren.trinity@gmail.com> * Update src/server/scripts/Commands/cs_debug.cpp Co-authored-by: Shauren <shauren.trinity@gmail.com> * Move CreatureCountWorker out of function and use template for unhandled cases * Code cleanup Co-authored-by: Shauren <shauren.trinity@gmail.com> (cherry picked from commit bd5e832a648aadf1d1be94f913ea00b67398f249)
Diffstat (limited to 'src')
-rw-r--r--src/server/scripts/Commands/cs_debug.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp
index 86400739bc7..7f1dc590e4c 100644
--- a/src/server/scripts/Commands/cs_debug.cpp
+++ b/src/server/scripts/Commands/cs_debug.cpp
@@ -1867,12 +1867,57 @@ public:
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: " UI64FMTD " GameObjects: " UI64FMTD,
map->GetId(), map->GetMapName(), map->GetInstanceId(),
uint64(map->GetObjectsStore().Size<Creature>()),
uint64(map->GetObjectsStore().Size<GameObject>()));
+
+ 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, CommandArgs* /*args*/)