diff --git a/server/gameserver/buff.cc b/server/gameserver/buff.cc index e58eb5c9..568e2bb4 100644 --- a/server/gameserver/buff.cc +++ b/server/gameserver/buff.cc @@ -325,7 +325,7 @@ void Buff::ProcSputteringFunc(Bullet* bullet) 0, 0, nullptr); - VirtualBullet* p = new VirtualBullet(); + std::shared_ptr p = std::make_shared(); p->bullet_uniid = bullet_uniid; p->weapon_uniid = bullet->weapon_uniid; p->skill_meta = bullet->skill_meta; @@ -339,7 +339,12 @@ 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) + { + p->Update(50); + })); } } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index fae8f1c8..af76885a 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -162,6 +162,7 @@ void Room::UnInit() delete pair.second; } discard_team_hash_.clear(); + task_hash_.clear(); A8_SAFE_DELETE(frame_event_data); PerfMonitor::Instance()->alive_count -= alive_count_; } @@ -194,9 +195,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(); @@ -3488,12 +3487,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 81d96def..16bdb391 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -223,7 +223,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); @@ -373,7 +373,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 a935d4f2..82c52a51 100644 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -37,13 +37,6 @@ struct BulletCheckResult std::set objects; }; -class ITask -{ - public: - virtual void Update(int delta_time) = 0; - virtual bool IsDone() = 0; -}; - class DelayAddBuffHandle { public: diff --git a/server/gameserver/virtualbullet.h b/server/gameserver/virtualbullet.h index 98b573b9..28815d0f 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; @@ -35,8 +35,8 @@ class VirtualBullet : public IBullet, public ITask virtual float GetHitRadius() override; virtual void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) 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; }; diff --git a/third_party/a8 b/third_party/a8 index 54fe50ed..140a61cc 160000 --- a/third_party/a8 +++ b/third_party/a8 @@ -1 +1 @@ -Subproject commit 54fe50edf11dda774dcd6fc480134c9e4ce449cd +Subproject commit 140a61cc7f6c23602d05963ab868fe9f5d36cc44