Improve movement performance

This commit is contained in:
Yunfan Li
2024-01-10 21:46:39 +08:00
parent 8bf944c024
commit 658cc2fd6f
2 changed files with 15 additions and 16 deletions

View File

@@ -1290,50 +1290,49 @@ bool MovementAction::MoveInside(uint32 mapId, float x, float y, float z, float d
return MoveNear(mapId, x, y, z, distance); return MoveNear(mapId, x, y, z, distance);
} }
float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range, bool normal_only) float MovementAction::SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range, bool normal_only, float step)
{ {
if (!generatePath) { if (!generatePath) {
return z; return z;
} }
float min_length = MAX_PATH_LENGTH; float min_length = 100000.0f;
float current_z = INVALID_HEIGHT; float current_z = INVALID_HEIGHT;
float modified_z; float modified_z;
float delta; float delta;
for (delta = 0.0f; delta <= range / 2; delta += 2) { for (delta = 0.0f; delta <= range / 2; delta += step) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
min_length = gen.getPathLength();
current_z = modified_z;
// if (abs(current_z - z) < 0.1f) {
// return current_z;
// }
}
}
for (delta = -1.0f; delta >= -range / 2; delta -= 2) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot); PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z); gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
min_length = gen.getPathLength(); min_length = gen.getPathLength();
current_z = modified_z; current_z = modified_z;
// if (abs(current_z - z) < 0.1f) { if (abs(current_z - z) < 0.5f) {
// return current_z; return current_z;
// }
} }
} }
for (delta = range / 2 + 1.0f; delta <= range; delta += 2) { }
for (delta = -step; delta >= -range / 2; delta -= step) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta); modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot); PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z); gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) { if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
min_length = gen.getPathLength(); min_length = gen.getPathLength();
current_z = modified_z; current_z = modified_z;
// if (abs(current_z - z) < 0.1f) { if (abs(current_z - z) < 0.5f) {
// return current_z; return current_z;
// } }
}
}
for (delta = range / 2 + step; delta <= range; delta += 2) {
modified_z = bot->GetMapWaterOrGroundLevel(x, y, z + delta);
PathGenerator gen(bot);
gen.CalculatePath(x, y, modified_z);
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
min_length = gen.getPathLength();
current_z = modified_z;
if (abs(current_z - z) < 0.5f) {
return current_z;
}
} }
} }
if (current_z == INVALID_HEIGHT && normal_only) { if (current_z == INVALID_HEIGHT && normal_only) {

View File

@@ -41,7 +41,7 @@ class MovementAction : public Action
bool MoveInside(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->followDistance); bool MoveInside(uint32 mapId, float x, float y, float z, float distance = sPlayerbotAIConfig->followDistance);
void CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important = false); void CreateWp(Player* wpOwner, float x, float y, float z, float o, uint32 entry, bool important = false);
private: private:
float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 10.0f, bool normal_only = false); float SearchBestGroundZForPath(float x, float y, float z, bool generatePath, float range = 15.0f, bool normal_only = false, float step = 3.0f);
}; };
class FleeAction : public MovementAction class FleeAction : public MovementAction