More scanning work to unify data structures

This commit is contained in:
Akkadius 2019-12-29 02:01:48 -06:00
parent 9481e9eb2d
commit 6b465c576d
11 changed files with 57 additions and 35 deletions

View File

@ -111,6 +111,7 @@ namespace Logs {
AIYellForHelp, AIYellForHelp,
AICastBeneficialClose, AICastBeneficialClose,
AoeCast, AoeCast,
EntityManagement,
MaxCategoryID /* Don't Remove this */ MaxCategoryID /* Don't Remove this */
}; };
@ -181,6 +182,7 @@ namespace Logs {
"AI Yell For Help", "AI Yell For Help",
"AI Cast Beneficial Close", "AI Cast Beneficial Close",
"AOE Cast", "AOE Cast",
"Entity Management",
}; };
} }

View File

@ -531,6 +531,16 @@
OutF(LogSys, Logs::Detail, Logs::AoeCast, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\ OutF(LogSys, Logs::Detail, Logs::AoeCast, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0) } while (0)
#define LogEntityManagement(message, ...) do {\
if (LogSys.log_settings[Logs::EntityManagement].is_category_enabled == 1)\
OutF(LogSys, Logs::General, Logs::EntityManagement, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogEntityManagementDetail(message, ...) do {\
if (LogSys.log_settings[Logs::EntityManagement].is_category_enabled == 1)\
OutF(LogSys, Logs::Detail, Logs::EntityManagement, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\ #define Log(debug_level, log_category, message, ...) do {\
if (LogSys.log_settings[log_category].is_category_enabled == 1)\ if (LogSys.log_settings[log_category].is_category_enabled == 1)\
LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\ LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\

View File

@ -268,10 +268,10 @@ bool Client::Process() {
if (mob->IsNPC()) { if (mob->IsNPC()) {
if (distance <= scan_range) { if (distance <= scan_range) {
close_mobs.insert(std::pair<Mob *, float>(mob, distance)); close_mobs.insert(std::pair<uint16, Mob *>(mob->GetID(), mob));
} }
else if ((mob->GetAggroRange() * mob->GetAggroRange()) > scan_range) { else if ((mob->GetAggroRange() * mob->GetAggroRange()) > scan_range) {
close_mobs.insert(std::pair<Mob *, float>(mob, distance)); close_mobs.insert(std::pair<uint16, Mob *>(mob->GetID(), mob));
} }
} }
} }
@ -597,7 +597,7 @@ bool Client::Process() {
if (zone->CanDoCombat() && ret && !GetFeigned() && client_scan_npc_aggro_timer.Check()) { if (zone->CanDoCombat() && ret && !GetFeigned() && client_scan_npc_aggro_timer.Check()) {
int npc_scan_count = 0; int npc_scan_count = 0;
for (auto & close_mob : close_mobs) { for (auto & close_mob : close_mobs) {
Mob *mob = close_mob.first; Mob *mob = close_mob.second;
if (!mob) if (!mob)
continue; continue;

View File

@ -761,7 +761,7 @@ void EntityList::AESpell(
LogAoeCast("Using close scan mob list"); LogAoeCast("Using close scan mob list");
for (auto &it : caster_mob->close_mobs) { for (auto &it : caster_mob->close_mobs) {
current_mob = it.first; current_mob = it.second;
if (!current_mob) { if (!current_mob) {
continue; continue;

View File

@ -63,6 +63,7 @@ extern char errorname[32];
Entity::Entity() Entity::Entity()
{ {
id = 0; id = 0;
initial_id = 0;
spawn_timestamp = time(nullptr); spawn_timestamp = time(nullptr);
} }
@ -2566,11 +2567,22 @@ bool EntityList::RemoveNPC(uint16 delete_id)
*/ */
bool EntityList::RemoveMobFromCloseLists(Mob *mob) bool EntityList::RemoveMobFromCloseLists(Mob *mob)
{ {
LogDebug("Removing mob [{}] from close lists", mob->GetCleanName()); LogEntityManagement(
"Attempting to remove mob [{}] from close lists entity_id ({})",
mob->GetCleanName(),
mob->GetInitialId()
);
auto it = mob_list.begin(); auto it = mob_list.begin();
while (it != mob_list.end()) { while (it != mob_list.end()) {
it->second->close_mobs.erase(mob); LogEntityManagement(
"Removing mob [{}] from [{}] close list entity_id ({})",
mob->GetCleanName(),
it->second->GetCleanName(),
mob->GetInitialId()
);
it->second->close_mobs.erase(mob->GetInitialId());
++it; ++it;
} }
@ -2581,7 +2593,7 @@ bool EntityList::RemoveMobFromCloseLists(Mob *mob)
* @param close_mobs * @param close_mobs
* @param scanning_mob * @param scanning_mob
*/ */
void EntityList::ScanCloseMobs(std::unordered_map<Mob *, float> &close_mobs, Mob *scanning_mob) void EntityList::ScanCloseMobs(std::unordered_map<uint16, Mob *> &close_mobs, Mob *scanning_mob)
{ {
float scan_range = RuleI(Range, MobCloseScanDistance) * RuleI(Range, MobCloseScanDistance); float scan_range = RuleI(Range, MobCloseScanDistance) * RuleI(Range, MobCloseScanDistance);
int list_count = 0; int list_count = 0;
@ -2590,13 +2602,15 @@ void EntityList::ScanCloseMobs(std::unordered_map<Mob *, float> &close_mobs, Mob
auto it = mob_list.begin(); auto it = mob_list.begin();
while (it != mob_list.end()) { while (it != mob_list.end()) {
Mob *mob = it->second;
float distance = DistanceSquared(scanning_mob->GetPosition(), it->second->GetPosition()); float distance = DistanceSquared(scanning_mob->GetPosition(), it->second->GetPosition());
if (distance <= scan_range) { if (distance <= scan_range) {
close_mobs.insert(std::pair<Mob *, float>(it->second, distance)); close_mobs.insert(std::pair<uint16, Mob *>(mob->GetID(), mob));
list_count++; list_count++;
} }
else if (it->second->GetAggroRange() >= scan_range) { else if (it->second->GetAggroRange() >= scan_range) {
close_mobs.insert(std::pair<Mob *, float>(it->second, distance)); close_mobs.insert(std::pair<uint16, Mob *>(mob->GetID(), mob));
list_count++; list_count++;
} }
++it; ++it;

View File

@ -109,6 +109,7 @@ public:
const Beacon *CastToBeacon() const; const Beacon *CastToBeacon() const;
const Encounter *CastToEncounter() const; const Encounter *CastToEncounter() const;
inline const uint16& GetInitialId() const { return initial_id; }
inline const uint16& GetID() const { return id; } inline const uint16& GetID() const { return id; }
inline const time_t& GetSpawnTimeStamp() const { return spawn_timestamp; } inline const time_t& GetSpawnTimeStamp() const { return spawn_timestamp; }
@ -122,10 +123,17 @@ public:
protected: protected:
friend class EntityList; friend class EntityList;
inline virtual void SetID(uint16 set_id) { id = set_id; } inline virtual void SetID(uint16 set_id) {
id = set_id;
if (initial_id == 0 && set_id > 0) {
initial_id = set_id;
}
}
uint32 pDBAsyncWorkID; uint32 pDBAsyncWorkID;
private: private:
uint16 id; uint16 id;
uint16 initial_id;
time_t spawn_timestamp; time_t spawn_timestamp;
}; };
@ -523,7 +531,7 @@ public:
void RefreshAutoXTargets(Client *c); void RefreshAutoXTargets(Client *c);
void RefreshClientXTargets(Client *c); void RefreshClientXTargets(Client *c);
void SendAlternateAdvancementStats(); void SendAlternateAdvancementStats();
void ScanCloseMobs(std::unordered_map<Mob *, float> &close_mobs, Mob *scanning_mob); void ScanCloseMobs(std::unordered_map<uint16, Mob *> &close_mobs, Mob *scanning_mob);
void GetTrapInfo(Client* client); void GetTrapInfo(Client* client);
bool IsTrapGroupSpawned(uint32 trap_id, uint8 group); bool IsTrapGroupSpawned(uint32 trap_id, uint8 group);

View File

@ -500,6 +500,7 @@ Mob::~Mob()
UninitializeBuffSlots(); UninitializeBuffSlots();
entity_list.RemoveMobFromCloseLists(this); entity_list.RemoveMobFromCloseLists(this);
close_mobs.clear();
#ifdef BOTS #ifdef BOTS
LeaveHealRotationTargetPool(); LeaveHealRotationTargetPool();
@ -531,16 +532,6 @@ uint32 Mob::GetAppearanceValue(EmuAppearance iAppearance) {
return(ANIM_STAND); return(ANIM_STAND);
} }
void Mob::GetCloseMobList(std::list<std::pair<Mob *, float>> &m_list)
{
m_list.clear();
auto it = close_mobs.begin();
while (it != close_mobs.end()) {
m_list.push_back(std::make_pair(it->first, it->second));
++it;
}
}
void Mob::SetInvisible(uint8 state) void Mob::SetInvisible(uint8 state)
{ {
invisible = state; invisible = state;

View File

@ -170,12 +170,10 @@ public:
void DisplayInfo(Mob *mob); void DisplayInfo(Mob *mob);
std::unordered_map<Mob *, float> close_mobs; std::unordered_map<uint16, Mob *> close_mobs;
Timer mob_scan_close; Timer mob_scan_close;
Timer mob_check_moving_timer; Timer mob_check_moving_timer;
void GetCloseMobList(std::list<std::pair<Mob *, float>> &m_list);
//Somewhat sorted: needs documenting! //Somewhat sorted: needs documenting!
//Attack //Attack

View File

@ -1366,8 +1366,7 @@ void Mob::AI_Process() {
* NPC to NPC aggro (npc_aggro flag set) * NPC to NPC aggro (npc_aggro flag set)
*/ */
for (auto &close_mob : close_mobs) { for (auto &close_mob : close_mobs) {
Mob *mob = close_mob.first; Mob *mob = close_mob.second;
float distance = close_mob.second;
if (mob->IsClient()) { if (mob->IsClient()) {
continue; continue;

View File

@ -3070,21 +3070,22 @@ bool NPC::AICheckCloseBeneficialSpells(
* Check through close range mobs * Check through close range mobs
*/ */
for (auto & close_mob : close_mobs) { for (auto & close_mob : close_mobs) {
Mob *mob = close_mob.first; Mob *mob = close_mob.second;
float cached_close_mob_distance = close_mob.second;
if (mob->IsClient()) { if (mob->IsClient()) {
continue; continue;
} }
if (cached_close_mob_distance > in_cast_range) { float distance = DistanceSquared(mob->GetPosition(), GetPosition());
if (distance > in_cast_range) {
continue; continue;
} }
LogAICastBeneficialClose( LogAICastBeneficialClose(
"NPC [{}] Distance [{}] Cast Range [{}] Caster [{}]", "NPC [{}] Distance [{}] Cast Range [{}] Caster [{}]",
mob->GetCleanName(), mob->GetCleanName(),
cached_close_mob_distance, distance,
in_cast_range, in_cast_range,
caster->GetCleanName() caster->GetCleanName()
); );
@ -3133,9 +3134,8 @@ void NPC::AIYellForHelp(Mob *sender, Mob *attacker)
GetID() GetID()
); );
for (auto & close_mob : close_mobs) { for (auto &close_mob : close_mobs) {
Mob *mob = close_mob.first; Mob *mob = close_mob.second;
float distance = DistanceSquared(m_Position, mob->GetPosition()); float distance = DistanceSquared(m_Position, mob->GetPosition());
if (mob->IsClient()) { if (mob->IsClient()) {