From 831dc77165c9e700d02c802c792f693ff3729996 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 4 Nov 2023 09:07:32 +0800 Subject: [PATCH 1/2] 1 --- server/gameserver/mapservice.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/server/gameserver/mapservice.cc b/server/gameserver/mapservice.cc index 4caf99a7..016ba776 100644 --- a/server/gameserver/mapservice.cc +++ b/server/gameserver/mapservice.cc @@ -20,10 +20,6 @@ MapService::MapService() MapService::~MapService() { - if (map_cells_) { - free(map_cells_); - map_cells_ = nullptr; - } } void MapService::Init(int width, int height, int cell_width) @@ -57,7 +53,20 @@ void MapService::Init(int width, int height, int cell_width) void MapService::UnInit() { - + for (int i = 0; i < max_grid_id_; ++i) { + list_head* head = &map_cells_[i]; + while (!list_empty(head)) { + CellNode* e = list_first_entry(head, + CellNode, + entry); + list_del_init(&e->entry); + delete e; + } + } + if (map_cells_) { + free(map_cells_); + map_cells_ = nullptr; + } } bool MapService::CanAdd(const glm::vec3& pos, int rad) From 8800fffed3b438c876b3343ac643e66c933beee8 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 4 Nov 2023 09:25:29 +0800 Subject: [PATCH 2/2] 1 --- server/gameserver/buff.cc | 11 +++++++++-- server/gameserver/room.cc | 8 +++----- server/gameserver/room.h | 4 ++-- server/gameserver/types.h | 6 ++++++ server/gameserver/virtualbullet.cc | 11 +++++++++++ server/gameserver/virtualbullet.h | 6 +++--- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/server/gameserver/buff.cc b/server/gameserver/buff.cc index e988c8b0..c268a51a 100644 --- a/server/gameserver/buff.cc +++ b/server/gameserver/buff.cc @@ -326,7 +326,7 @@ void Buff::ProcSputteringFunc(Bullet* bullet) 0, 0, nullptr); - VirtualBullet* p = new VirtualBullet(); + auto p = std::make_shared(); p->bullet_uniid = bullet_uniid; p->weapon_uniid = bullet->weapon_uniid; p->skill_meta = bullet->skill_meta; @@ -340,7 +340,14 @@ void Buff::ProcSputteringFunc(Bullet* bullet) p->born_pos = bullet_born_pos; p->born_dir = bullet_dir; p->Init(); - owner->room->AddTask(bullet_uniid, p); + owner->room->AddTask(bullet_uniid, std::make_shared + ( + [p] (const a8::Args* args) + { + if (!p->IsDone()) { + p->Update(50); + } + })); } } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 18583d7d..68c84d0e 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -230,9 +230,7 @@ void Room::Update(int delta_time) pair.second->Update(50); } for (auto& pair : task_hash_) { - if (!pair.second->IsDone()) { - pair.second->Update(50); - } + (*pair.second)(nullptr); } #ifdef DEBUG1 end_tick = a8::XGetTickCount(); @@ -3194,12 +3192,12 @@ bool Room::IsAllRealDead() return is_all_dead; } -void Room::AddTask(int task_uniid, ITask* task) +void Room::AddTask(int task_uniid, std::shared_ptr cb) { if (task_hash_.find(task_uniid) != task_hash_.end()) { abort(); } - task_hash_[task_uniid] = task; + task_hash_[task_uniid] = cb; } void Room::RemoveTask(int task_uniid) diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 50223a86..8a0a2910 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -241,7 +241,7 @@ public: bool IsInfiniteBulletMode() { return infinite_bullet_mode_; }; void AddToPostBattleAutoFreeList(a8::XTimerWp timer); bool CanAddObstacle(const glm::vec3& pos, int obstacle_id); - void AddTask(int task_uniid, ITask* task); + void AddTask(int task_uniid, std::shared_ptr cb); void RemoveTask(int task_uniid); const mt::AirLine* GetAirLine() { return airline_; } int GetPolyExtFlag(int poly_idx); @@ -401,7 +401,7 @@ private: std::map alive_player_hash_; std::map last_human_hash_; std::map> born_point_hash_; - std::map task_hash_; + std::map> task_hash_; std::map car_hash_; std::map removed_robot_hash_; diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 7a6a501e..134037dd 100644 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -103,3 +103,9 @@ typedef std::weak_ptr AttrRuduceHandle; typedef std::weak_ptr AttrAbsHandle; typedef std::weak_ptr AttrRateHandle; typedef std::weak_ptr AttrDirectHandle; + +namespace a8 +{ + class Args; + typedef std::function CommonCbProcEx; +} diff --git a/server/gameserver/virtualbullet.cc b/server/gameserver/virtualbullet.cc index 85f16f58..ad294196 100644 --- a/server/gameserver/virtualbullet.cc +++ b/server/gameserver/virtualbullet.cc @@ -124,6 +124,17 @@ void VirtualBullet::ForceRemove() { if (!later_removed_) { later_removed_ = true; + room->xtimer.SetTimeoutEx + ( + 1, + [room = room, task_uniid = bullet_uniid] (int event, const a8::Args* args) + { + if (a8::TIMER_EXEC_EVENT == event) { + room->RemoveTask(task_uniid); + } + }, + &room->xtimer_attacher_ + ); } } diff --git a/server/gameserver/virtualbullet.h b/server/gameserver/virtualbullet.h index 7660b3f5..ac765a28 100644 --- a/server/gameserver/virtualbullet.h +++ b/server/gameserver/virtualbullet.h @@ -4,7 +4,7 @@ struct GridCell; class Entity; class Room; class Obstacle; -class VirtualBullet : public IBullet, public ITask +class VirtualBullet : public IBullet { public: int bullet_uniid = 0; @@ -36,8 +36,8 @@ class VirtualBullet : public IBullet, public ITask virtual void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) override; virtual bool NoAdjustPos() override; - virtual void Update(int delta_time) override; - virtual bool IsDone() override; + virtual void Update(int delta_time); + virtual bool IsDone(); void Init(); void SetPos(Position pos) { pos_ = pos; };