This commit is contained in:
aozhiwei 2023-11-04 09:25:29 +08:00
parent 831dc77165
commit 8800fffed3
6 changed files with 34 additions and 12 deletions

View File

@ -326,7 +326,7 @@ void Buff::ProcSputteringFunc(Bullet* bullet)
0, 0,
0, 0,
nullptr); nullptr);
VirtualBullet* p = new VirtualBullet(); auto p = std::make_shared<VirtualBullet>();
p->bullet_uniid = bullet_uniid; p->bullet_uniid = bullet_uniid;
p->weapon_uniid = bullet->weapon_uniid; p->weapon_uniid = bullet->weapon_uniid;
p->skill_meta = bullet->skill_meta; p->skill_meta = bullet->skill_meta;
@ -340,7 +340,14 @@ void Buff::ProcSputteringFunc(Bullet* bullet)
p->born_pos = bullet_born_pos; p->born_pos = bullet_born_pos;
p->born_dir = bullet_dir; p->born_dir = bullet_dir;
p->Init(); p->Init();
owner->room->AddTask(bullet_uniid, p); owner->room->AddTask(bullet_uniid, std::make_shared<a8::CommonCbProcEx>
(
[p] (const a8::Args* args)
{
if (!p->IsDone()) {
p->Update(50);
}
}));
} }
} }

View File

@ -230,9 +230,7 @@ void Room::Update(int delta_time)
pair.second->Update(50); pair.second->Update(50);
} }
for (auto& pair : task_hash_) { for (auto& pair : task_hash_) {
if (!pair.second->IsDone()) { (*pair.second)(nullptr);
pair.second->Update(50);
}
} }
#ifdef DEBUG1 #ifdef DEBUG1
end_tick = a8::XGetTickCount(); end_tick = a8::XGetTickCount();
@ -3194,12 +3192,12 @@ bool Room::IsAllRealDead()
return is_all_dead; return is_all_dead;
} }
void Room::AddTask(int task_uniid, ITask* task) void Room::AddTask(int task_uniid, std::shared_ptr<a8::CommonCbProcEx> cb)
{ {
if (task_hash_.find(task_uniid) != task_hash_.end()) { if (task_hash_.find(task_uniid) != task_hash_.end()) {
abort(); abort();
} }
task_hash_[task_uniid] = task; task_hash_[task_uniid] = cb;
} }
void Room::RemoveTask(int task_uniid) void Room::RemoveTask(int task_uniid)

View File

@ -241,7 +241,7 @@ public:
bool IsInfiniteBulletMode() { return infinite_bullet_mode_; }; bool IsInfiniteBulletMode() { return infinite_bullet_mode_; };
void AddToPostBattleAutoFreeList(a8::XTimerWp timer); void AddToPostBattleAutoFreeList(a8::XTimerWp timer);
bool CanAddObstacle(const glm::vec3& pos, int obstacle_id); bool CanAddObstacle(const glm::vec3& pos, int obstacle_id);
void AddTask(int task_uniid, ITask* task); void AddTask(int task_uniid, std::shared_ptr<a8::CommonCbProcEx> cb);
void RemoveTask(int task_uniid); void RemoveTask(int task_uniid);
const mt::AirLine* GetAirLine() { return airline_; } const mt::AirLine* GetAirLine() { return airline_; }
int GetPolyExtFlag(int poly_idx); int GetPolyExtFlag(int poly_idx);
@ -401,7 +401,7 @@ private:
std::map<int, Human*> alive_player_hash_; std::map<int, Human*> alive_player_hash_;
std::map<int, Human*> last_human_hash_; std::map<int, Human*> last_human_hash_;
std::map<int, std::shared_ptr<BornPoint>> born_point_hash_; std::map<int, std::shared_ptr<BornPoint>> born_point_hash_;
std::map<int, ITask*> task_hash_; std::map<int, std::shared_ptr<a8::CommonCbProcEx>> task_hash_;
std::map<int, CarObject> car_hash_; std::map<int, CarObject> car_hash_;
std::map<int, Human*> removed_robot_hash_; std::map<int, Human*> removed_robot_hash_;

View File

@ -103,3 +103,9 @@ typedef std::weak_ptr<struct AttrRuducePtr> AttrRuduceHandle;
typedef std::weak_ptr<struct AttrAbsPtr> AttrAbsHandle; typedef std::weak_ptr<struct AttrAbsPtr> AttrAbsHandle;
typedef std::weak_ptr<struct AttrRatePtr> AttrRateHandle; typedef std::weak_ptr<struct AttrRatePtr> AttrRateHandle;
typedef std::weak_ptr<struct AttrDirectPtr> AttrDirectHandle; typedef std::weak_ptr<struct AttrDirectPtr> AttrDirectHandle;
namespace a8
{
class Args;
typedef std::function<void(const a8::Args*)> CommonCbProcEx;
}

View File

@ -124,6 +124,17 @@ void VirtualBullet::ForceRemove()
{ {
if (!later_removed_) { if (!later_removed_) {
later_removed_ = true; 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_
);
} }
} }

View File

@ -4,7 +4,7 @@ struct GridCell;
class Entity; class Entity;
class Room; class Room;
class Obstacle; class Obstacle;
class VirtualBullet : public IBullet, public ITask class VirtualBullet : public IBullet
{ {
public: public:
int bullet_uniid = 0; 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 void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) override;
virtual bool NoAdjustPos() override; virtual bool NoAdjustPos() override;
virtual void Update(int delta_time) override; virtual void Update(int delta_time);
virtual bool IsDone() override; virtual bool IsDone();
void Init(); void Init();
void SetPos(Position pos) { pos_ = pos; }; void SetPos(Position pos) { pos_ = pos; };