diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2020-08-06 12:58:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-06 14:58:39 +0200 |
commit | bd5e832a648aadf1d1be94f913ea00b67398f249 (patch) | |
tree | d9e2eff56220d1c16a5a4a5c76dc90061a6c1150 | |
parent | 44a3aad0af4bdd132b8761761dc83df2d7d6c601 (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>
-rw-r--r-- | src/server/scripts/Commands/cs_debug.cpp | 45 |
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 022520c6de7..5a9c94b384f 100644 --- a/src/server/scripts/Commands/cs_debug.cpp +++ b/src/server/scripts/Commands/cs_debug.cpp @@ -1970,12 +1970,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*/) |