mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +00:00
Bulk load grids at repop and zone init instead of 2 costly individual selects per NPC, create repositories to decouple database logic from business logic
This commit is contained in:
+32
-39
@@ -561,62 +561,54 @@ void Mob::StopNavigation() {
|
||||
mMovementManager->StopNavigation(this);
|
||||
}
|
||||
|
||||
void NPC::AssignWaypoints(int32 grid, int start_wp)
|
||||
void NPC::AssignWaypoints(int32 grid_id, int start_wp)
|
||||
{
|
||||
if (grid == 0)
|
||||
if (grid_id == 0)
|
||||
return; // grid ID 0 not supported
|
||||
|
||||
if (grid < 0) {
|
||||
if (grid_id < 0) {
|
||||
// Allow setting negative grid values for pausing pathing
|
||||
this->CastToNPC()->SetGrid(grid);
|
||||
this->CastToNPC()->SetGrid(grid_id);
|
||||
return;
|
||||
}
|
||||
|
||||
Waypoints.clear();
|
||||
roamer = false;
|
||||
|
||||
// Retrieve the wander and pause types for this grid
|
||||
std::string query = StringFormat("SELECT `type`, `type2` FROM `grid` WHERE `id` = %i AND `zoneid` = %i", grid,
|
||||
zone->GetZoneID());
|
||||
auto results = content_db.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
auto grid_entry = GridRepository::GetGrid(zone->grids, grid_id);
|
||||
if (grid_entry.id == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (results.RowCount() == 0)
|
||||
return;
|
||||
wandertype = grid_entry.type;
|
||||
pausetype = grid_entry.type2;
|
||||
|
||||
auto row = results.begin();
|
||||
|
||||
wandertype = atoi(row[0]);
|
||||
pausetype = atoi(row[1]);
|
||||
|
||||
SetGrid(grid); // Assign grid number
|
||||
|
||||
// Retrieve all waypoints for this grid
|
||||
query = StringFormat("SELECT `x`,`y`,`z`,`pause`,`heading`, `centerpoint` "
|
||||
"FROM grid_entries WHERE `gridid` = %i AND `zoneid` = %i "
|
||||
"ORDER BY `number`", grid, zone->GetZoneID());
|
||||
results = content_db.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return;
|
||||
}
|
||||
SetGrid(grid_id); // Assign grid number
|
||||
|
||||
roamer = true;
|
||||
max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row, ++max_wp)
|
||||
{
|
||||
wplist newwp;
|
||||
newwp.index = max_wp;
|
||||
newwp.x = atof(row[0]);
|
||||
newwp.y = atof(row[1]);
|
||||
newwp.z = atof(row[2]);
|
||||
for (auto &entry : zone->grid_entries) {
|
||||
if (entry.gridid == grid_id) {
|
||||
wplist new_waypoint{};
|
||||
new_waypoint.index = max_wp;
|
||||
new_waypoint.x = entry.x;
|
||||
new_waypoint.y = entry.y;
|
||||
new_waypoint.z = entry.z;
|
||||
new_waypoint.pause = entry.pause;
|
||||
new_waypoint.heading = entry.heading;
|
||||
new_waypoint.centerpoint = entry.centerpoint;
|
||||
|
||||
newwp.pause = atoi(row[3]);
|
||||
newwp.heading = atof(row[4]);
|
||||
newwp.centerpoint = atobool(row[5]);
|
||||
Waypoints.push_back(newwp);
|
||||
LogPathing(
|
||||
"Loading Grid [{}] number [{}] name [{}]",
|
||||
grid_id,
|
||||
entry.number,
|
||||
GetCleanName()
|
||||
);
|
||||
|
||||
Waypoints.push_back(new_waypoint);
|
||||
max_wp++;
|
||||
}
|
||||
}
|
||||
|
||||
cur_wp = start_wp;
|
||||
@@ -628,8 +620,9 @@ void NPC::AssignWaypoints(int32 grid, int start_wp)
|
||||
patrol = cur_wp;
|
||||
}
|
||||
|
||||
if (wandertype == GridRandom10 || wandertype == GridRandom || wandertype == GridRand5LoS)
|
||||
if (wandertype == GridRandom10 || wandertype == GridRandom || wandertype == GridRand5LoS) {
|
||||
CalculateNewWaypoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -737,7 +730,7 @@ void Mob::FixZ(int32 z_find_offset /*= 5*/, bool fix_client_z /*= false*/) {
|
||||
if (IsClient() && !fix_client_z) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (flymode == GravityBehavior::Flying) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user