mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-03 02:43:49 +00:00
Improper singletons migration to clean Meyer's singletons (cherry-pick) (#2082)
# Pull Request
- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )
Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---
## Complexity & Impact
- Does this change add new decision branches?
- [x] No
- [ ] Yes (**explain below**)
- Does this change increase per-bot or per-tick processing?
- [x] No
- [ ] Yes (**describe and justify impact**)
- Could this logic scale poorly under load?
- [x] No
- [ ] Yes (**explain why**)
---
## Defaults & Configuration
- Does this change modify default bot behavior?
- [x] No
- [ ] Yes (**explain why**)
---
## AI Assistance
- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
- [x] No
- [ ] Yes (**explain below**)
---
## Final Checklist
- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed
---
## Notes for Reviewers
Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.
---------
Co-authored-by: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
This commit is contained in:
@@ -19,7 +19,7 @@ bool DebugAction::Execute(Event event)
|
||||
|
||||
if (text == "scan")
|
||||
{
|
||||
sPlayerbotAIConfig->openLog("scan.csv", "w");
|
||||
sPlayerbotAIConfig.openLog("scan.csv", "w");
|
||||
|
||||
uint32 i = 0;
|
||||
for (auto p : WorldPosition().getCreaturesNear())
|
||||
@@ -36,15 +36,15 @@ bool DebugAction::Execute(Event event)
|
||||
|
||||
pos.printWKT(out);
|
||||
|
||||
sPlayerbotAIConfig->log("scan.csv", out.str().c_str());
|
||||
sPlayerbotAIConfig.log("scan.csv", out.str().c_str());
|
||||
|
||||
if (zoneId == 0 && areaId == 0)
|
||||
{
|
||||
sPlayerbotAIConfig->log("x", out.str().c_str());
|
||||
sPlayerbotAIConfig.log("x", out.str().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
sPlayerbotAIConfig->log("y", out.str().c_str());
|
||||
sPlayerbotAIConfig.log("y", out.str().c_str());
|
||||
}
|
||||
|
||||
i = zoneId;
|
||||
@@ -53,8 +53,8 @@ bool DebugAction::Execute(Event event)
|
||||
}
|
||||
else if (text.find("printmap") != std::string::npos)
|
||||
{
|
||||
sTravelNodeMap->printMap();
|
||||
sTravelNodeMap->printNodeStore();
|
||||
TravelNodeMap::instance().printMap();
|
||||
TravelNodeMap::instance().printNodeStore();
|
||||
return true;
|
||||
}
|
||||
else if (text.find("travel ") != std::string::npos)
|
||||
@@ -72,7 +72,7 @@ bool DebugAction::Execute(Event event)
|
||||
return false;
|
||||
|
||||
std::vector<WorldPosition> beginPath, endPath;
|
||||
TravelNodeRoute route = sTravelNodeMap->getRoute(botPos, *points.front(), beginPath, bot);
|
||||
TravelNodeRoute route = TravelNodeMap::instance().getRoute(botPos, *points.front(), beginPath, bot);
|
||||
|
||||
std::ostringstream out;
|
||||
out << "Traveling to " << dest->getTitle() << ": ";
|
||||
@@ -108,7 +108,7 @@ bool DebugAction::Execute(Event event)
|
||||
|
||||
out << quest->GetTitle() << ": ";
|
||||
|
||||
QuestContainer* cont = sTravelMgr->quests[questId];
|
||||
QuestContainer* cont = TravelMgr::instance().quests[questId];
|
||||
|
||||
for (auto g : cont->questGivers)
|
||||
{
|
||||
@@ -135,11 +135,11 @@ bool DebugAction::Execute(Event event)
|
||||
else if (text.find("quest") != std::string::npos)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << sTravelMgr->quests.size() << " quests ";
|
||||
out << TravelMgr::instance().quests.size() << " quests ";
|
||||
|
||||
uint32 noT = 0, noG = 0, noO = 0;
|
||||
|
||||
for (auto q : sTravelMgr->quests)
|
||||
for (auto q : TravelMgr::instance().quests)
|
||||
{
|
||||
if (q.second->questGivers.empty())
|
||||
noG++;
|
||||
@@ -164,7 +164,7 @@ bool DebugAction::Execute(Event event)
|
||||
|
||||
// uint32 noT = 0, noG = 0, noO = 0; //not used, line marked for removal.
|
||||
|
||||
for (auto q : sTravelMgr->quests)
|
||||
for (auto q : TravelMgr::instance().quests)
|
||||
{
|
||||
Quest const* quest = sObjectMgr->GetQuestTemplate(q.first);
|
||||
|
||||
@@ -194,16 +194,16 @@ bool DebugAction::Execute(Event event)
|
||||
|
||||
std::string const name = "USER:" + text.substr(9);
|
||||
|
||||
/* TravelNode* startNode = */ sTravelNodeMap->addNode(pos, name, false, false); // startNode not used, but addNode as side effect, fragment marked for removal.
|
||||
/* TravelNode* startNode = */ TravelNodeMap::instance().addNode(pos, name, false, false); // startNode not used, but addNode as side effect, fragment marked for removal.
|
||||
|
||||
for (auto& endNode : sTravelNodeMap->getNodes(pos, 2000))
|
||||
for (auto& endNode : TravelNodeMap::instance().getNodes(pos, 2000))
|
||||
{
|
||||
endNode->setLinked(false);
|
||||
}
|
||||
|
||||
botAI->TellMasterNoFacing("Node " + name + " created.");
|
||||
|
||||
sTravelNodeMap->setHasToGen();
|
||||
TravelNodeMap::instance().setHasToGen();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -211,7 +211,7 @@ bool DebugAction::Execute(Event event)
|
||||
{
|
||||
WorldPosition pos(bot);
|
||||
|
||||
TravelNode* startNode = sTravelNodeMap->getNode(pos, nullptr, 50);
|
||||
TravelNode* startNode = TravelNodeMap::instance().getNode(pos, nullptr, 50);
|
||||
|
||||
if (!startNode)
|
||||
return false;
|
||||
@@ -221,24 +221,24 @@ bool DebugAction::Execute(Event event)
|
||||
botAI->TellMasterNoFacing("Node can not be removed.");
|
||||
}
|
||||
|
||||
sTravelNodeMap->m_nMapMtx.lock();
|
||||
sTravelNodeMap->removeNode(startNode);
|
||||
TravelNodeMap::instance().m_nMapMtx.lock();
|
||||
TravelNodeMap::instance().removeNode(startNode);
|
||||
botAI->TellMasterNoFacing("Node removed.");
|
||||
sTravelNodeMap->m_nMapMtx.unlock();
|
||||
TravelNodeMap::instance().m_nMapMtx.unlock();
|
||||
|
||||
sTravelNodeMap->setHasToGen();
|
||||
TravelNodeMap::instance().setHasToGen();
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (text.find("reset node") != std::string::npos)
|
||||
{
|
||||
for (auto& node : sTravelNodeMap->getNodes())
|
||||
for (auto& node : TravelNodeMap::instance().getNodes())
|
||||
node->setLinked(false);
|
||||
return true;
|
||||
}
|
||||
else if (text.find("reset path") != std::string::npos)
|
||||
{
|
||||
for (auto& node : sTravelNodeMap->getNodes())
|
||||
for (auto& node : TravelNodeMap::instance().getNodes())
|
||||
for (auto& path : *node->getLinks())
|
||||
node->removeLinkTo(path.first, true);
|
||||
return true;
|
||||
@@ -246,23 +246,23 @@ bool DebugAction::Execute(Event event)
|
||||
else if (text.find("gen node") != std::string::npos)
|
||||
{
|
||||
// Pathfinder
|
||||
sTravelNodeMap->generateNodes();
|
||||
TravelNodeMap::instance().generateNodes();
|
||||
return true;
|
||||
}
|
||||
else if (text.find("gen path") != std::string::npos)
|
||||
{
|
||||
sTravelNodeMap->generatePaths();
|
||||
TravelNodeMap::instance().generatePaths();
|
||||
return true;
|
||||
}
|
||||
else if (text.find("crop path") != std::string::npos)
|
||||
{
|
||||
sTravelNodeMap->removeUselessPaths();
|
||||
TravelNodeMap::instance().removeUselessPaths();
|
||||
return true;
|
||||
}
|
||||
else if (text.find("save node") != std::string::npos)
|
||||
{
|
||||
sTravelNodeMap->printNodeStore();
|
||||
sTravelNodeMap->saveNodeStore();
|
||||
TravelNodeMap::instance().printNodeStore();
|
||||
TravelNodeMap::instance().saveNodeStore();
|
||||
return true;
|
||||
}
|
||||
else if (text.find("load node") != std::string::npos)
|
||||
@@ -270,8 +270,8 @@ bool DebugAction::Execute(Event event)
|
||||
std::thread t(
|
||||
[]
|
||||
{
|
||||
sTravelNodeMap->removeNodes();
|
||||
sTravelNodeMap->loadNodeStore();
|
||||
TravelNodeMap::instance().removeNodes();
|
||||
TravelNodeMap::instance().loadNodeStore();
|
||||
});
|
||||
|
||||
t.detach();
|
||||
@@ -282,7 +282,7 @@ bool DebugAction::Execute(Event event)
|
||||
{
|
||||
WorldPosition pos(bot);
|
||||
|
||||
std::vector<TravelNode*> nodes = sTravelNodeMap->getNodes(pos, 500);
|
||||
std::vector<TravelNode*> nodes = TravelNodeMap::instance().getNodes(pos, 500);
|
||||
|
||||
for (auto& node : nodes)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user