Skip to content

Commit

Permalink
Travel: Increased range and improved performance of travel destinatio…
Browse files Browse the repository at this point in the history
…n fetching
  • Loading branch information
mostlikely4r committed Jan 27, 2025
1 parent 29580ea commit d495808
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
50 changes: 20 additions & 30 deletions playerbot/TravelMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,44 +2056,36 @@ DestinationList TravelMgr::GetDestinations(const PlayerTravelInfo& info, uint32
WorldPosition center = info.GetPosition();
DestinationList retDests;

//std::mutex resultMutex;

for (auto& [purpose, entryDests] : destinationMap)
{

if (purposeFlag != (uint32)TravelDestinationPurpose::None && !((uint32)purpose & (uint32)purposeFlag))
continue;

std::for_each(
std::execution::seq,
entryDests.begin(),
entryDests.end(),
[&](auto& entryDests) {
if (entry && entryDests.first != entry)
return;

DestinationList dests = entryDests.second;

for (auto& dest : dests)
{
if (onlyPossible && !dest->IsPossible(info))
return;
for (auto& [destEntry, dests] : entryDests)
{
if (entry && destEntry != entry)
continue;

if (maxDistance > 0 && dest->DistanceTo(center) > maxDistance)
return;
for (auto& dest : dests)
{
if (onlyPossible && !dest->IsPossible(info))
continue;

//std::lock_guard<std::mutex> guard(resultMutex);
retDests.push_back(dest);
}
});
if (maxDistance > 0 && dest->DistanceTo(center) > maxDistance)
continue;

retDests.push_back(dest);
}
}
}

return retDests;
}

PartitionedTravelList TravelMgr::GetPartitions(const WorldPosition& center, const std::vector<uint32>& distancePartitions, const PlayerTravelInfo& info, uint32 purposeFlag, const int32 entry, bool onlyPossible, float maxDistance) const
{
std::unordered_map<uint32, std::vector<TravelPoint>> pointMap;
PartitionedTravelList pointMap;
DestinationList destinations = GetDestinations(info, purposeFlag, entry, onlyPossible, maxDistance);

bool canFightElite = info.GetBoolValue("can fight elite");
Expand Down Expand Up @@ -2137,21 +2129,18 @@ PartitionedTravelList TravelMgr::GetPartitions(const WorldPosition& center, cons
}
}

PartitionedTravelList retList;

for (auto& [partition, points] : pointMap)
{
ShuffleTravelPoints(points);

for (auto& point : points)
retList[partition].push_back(point);
}

return retList;
return pointMap;
}

void TravelMgr::ShuffleTravelPoints(std::vector<TravelPoint>&points)
{
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::shuffle(points.begin(), points.end(), std::default_random_engine(seed));
/*
std::vector<uint32> weights;
std::transform(points.begin(), points.end(), std::back_inserter(weights), [](TravelPoint point) { return 200000 / (1 + std::get<2>(point)); });
Expand All @@ -2168,6 +2157,7 @@ void TravelMgr::ShuffleTravelPoints(std::vector<TravelPoint>&points)
std::mt19937 gen(time(0));
WeightedShuffle(points.begin(), points.end(), weights.begin(), weights.end(), gen);
*/
}

void TravelMgr::SetNullTravelTarget(TravelTarget* target) const
Expand Down
4 changes: 2 additions & 2 deletions playerbot/TravelMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ namespace ai
EntryDestinationMap GetExploreLocs() const { return destinationMap.at(TravelDestinationPurpose::Explore); };
void SetMobAvoidArea();

DestinationList GetDestinations(const PlayerTravelInfo& info, uint32 purposeFlag = (uint32)TravelDestinationPurpose::None, const int32 entry = 0, bool onlyPossible = true, float maxDistance = 5000) const;
PartitionedTravelList GetPartitions(const WorldPosition& center, const std::vector<uint32>& distancePartitions, const PlayerTravelInfo& info, uint32 purposeFlag = (uint32)TravelDestinationPurpose::None, const int32 entry = 0, bool onlyPossible = true, float maxDistance = 5000) const;
DestinationList GetDestinations(const PlayerTravelInfo& info, uint32 purposeFlag = (uint32)TravelDestinationPurpose::None, const int32 entry = 0, bool onlyPossible = true, float maxDistance = 10000.0f) const;
PartitionedTravelList GetPartitions(const WorldPosition& center, const std::vector<uint32>& distancePartitions, const PlayerTravelInfo& info, uint32 purposeFlag = (uint32)TravelDestinationPurpose::None, const int32 entry = 0, bool onlyPossible = true, float maxDistance = 10000.0f) const;
static void ShuffleTravelPoints(std::vector<TravelPoint>& points);

void SetNullTravelTarget(TravelTarget* target) const;
Expand Down

0 comments on commit d495808

Please sign in to comment.