From 7e6e22b6b65b3bc4ce51ce09a6db4c5fe3c423c7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 25 May 2021 17:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D7.=E5=B1=8F=E5=B9=95=E5=A4=96?= =?UTF-8?q?=EF=BC=8C=E9=98=9F=E5=8F=8B=E4=B9=98=E5=9D=90=E6=9C=BA=E7=94=B2?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E5=B1=8F=E5=90=8E=E5=AF=B9=E6=96=B9=E6=9C=AA?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=9C=BA=E7=94=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/creature.h | 9 +++++++++ server/gameserver/human.cc | 32 ++++++++++++++++---------------- server/gameserver/human.h | 18 +++++++++--------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index ed2d3db..0fc09f7 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -61,6 +61,15 @@ class Creature : public MoveableEntity virtual ~Creature() override; virtual void Initialize() override; virtual void SetMoveDir(const a8::Vec2& move_dir) override; + virtual void AddToNewObjects(Entity* entity) {}; + virtual void AddToPartObjects(Entity* entity) {}; + virtual void RemovePartObjects(Entity* entity) {}; + virtual bool InNewObjects(Entity* target) { return false; }; + virtual bool InPartObjects(Entity* target) { return false; }; + virtual int GetPartObjectsCount() { return 0; }; + virtual void RemoveObjects(Entity* entity) {}; + virtual void AddOutObjects(Entity* entity) {}; + virtual void RemoveOutObjects(Entity* entity) {}; bool HasBuffEffect(int buff_effect_id); Buff* GetBuffByEffectId(int effect_id); Buff* GetBuffById(int buff_id); diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 73857e4..a3b6fd3 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -2900,19 +2900,19 @@ void Human::ProcIncGridList(std::set& old_grids, std::set& inc_grids, std::set& dec_grids) { - room->grid_service->TraverseAllLayerHumanList + room->grid_service->TraverseCreatures ( room->GetRoomIdx(), inc_grids, - [this, &old_grids] (Human* hum, bool& stop) + [this, &old_grids] (Creature* c, bool& stop) { - if (!room->grid_service->CreatureInGridList(hum, old_grids)) { - hum->AddToNewObjects(this); - hum->AddToPartObjects(this); - hum->RemoveOutObjects(this); - AddToNewObjects(hum); - AddToPartObjects(hum); - RemoveOutObjects(hum); + if (!room->grid_service->CreatureInGridList(c, old_grids)) { + c->AddToNewObjects(this); + c->AddToPartObjects(this); + c->RemoveOutObjects(this); + AddToNewObjects(c); + AddToPartObjects(c); + RemoveOutObjects(c); } }); room->grid_service->TraverseAllLayerEntityList @@ -2942,21 +2942,21 @@ void Human::ProcDecGridList(std::set& old_grids, std::set& inc_grids, std::set& dec_grids) { - room->grid_service->TraverseAllLayerHumanList + room->grid_service->TraverseCreatures ( room->GetRoomIdx(), dec_grids, - [this] (Human* hum, bool& stop) + [this] (Creature* c, bool& stop) { - if (!room->grid_service->CreatureInGridList(hum, GetGridList())) { - AddOutObjects(hum); - hum->AddOutObjects(this); + if (!room->grid_service->CreatureInGridList(c, GetGridList())) { + AddOutObjects(c); + c->AddOutObjects(this); #ifdef DEBUG #if 0 a8::UdpLog::Instance()->Debug("addoutobjects %d %d", { - (long long)hum, - hum->GetEntityUniId() + (long long)c, + c->GetEntityUniId() }); #endif #endif diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 2b74be2..9a97d37 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -169,15 +169,15 @@ class Human : public Creature void FindPathInMapService(); void BeKill(int killer_id, const std::string& killer_name, int weapon_id); virtual void DecHP(float dec_hp, int killer_id, const std::string& killer_name, int weapon_id) override; - void AddToNewObjects(Entity* entity); - void AddToPartObjects(Entity* entity); - void RemovePartObjects(Entity* entity); - bool InNewObjects(Entity* target); - bool InPartObjects(Entity* target); - int GetPartObjectsCount(); - void RemoveObjects(Entity* entity); - void AddOutObjects(Entity* entity); - void RemoveOutObjects(Entity* entity); + virtual void AddToNewObjects(Entity* entity) override; + virtual void AddToPartObjects(Entity* entity) override; + virtual void RemovePartObjects(Entity* entity) override; + virtual bool InNewObjects(Entity* target) override; + virtual bool InPartObjects(Entity* target) override; + virtual int GetPartObjectsCount() override; + virtual void RemoveObjects(Entity* entity) override; + virtual void AddOutObjects(Entity* entity) override; + virtual void RemoveOutObjects(Entity* entity) override; bool HasLiveTeammate(); bool HasNoDownedTeammate(); int GetNearbyTeammateNum(float range);