From a2dd2d675e4c2c88c94bd08d3185ad0e21d5b719 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 26 Oct 2022 14:37:03 +0800 Subject: [PATCH] 1 --- server/gameserver/room.cc | 16 ++++++++++++++++ server/gameserver/room.h | 3 +++ server/gameserver/types.h | 7 +++++++ server/gameserver/virtualbullet.cc | 10 ++++++++++ server/gameserver/virtualbullet.h | 6 +++++- 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index cd5b6c9b..d15dc6af 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -161,6 +161,9 @@ void Room::Update(int delta_time) for (auto& pair : moveable_hash_) { pair.second->Update(50); } + for (auto& pair : task_hash_) { + pair.second->Update(50); + } #ifdef DEBUG1 end_tick = a8::XGetTickCount(); if (a8::XGetTickCount() - begin_tick > 1000) { @@ -4142,3 +4145,16 @@ bool Room::IsAllRealDead() ); return is_all_dead; } + +void Room::AddTask(int task_uniid, ITask* task) +{ + if (task_hash_.find(task_uniid) != task_hash_.end()) { + abort(); + } + task_hash_[task_uniid] = task; +} + +void Room::RemoveTask(int task_uniid) +{ + task_hash_.erase(task_uniid); +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index e8cab542..4d723f91 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -326,6 +326,8 @@ private: void InternalRemoveObjectLater(Entity* entity, a8::XTimerAttacher& entity_xtimer_attacher); void OnBattleStart(); void ClearPostBattleAutoFreeList(); + void AddTask(int task_uniid, ITask* task); + void RemoveTask(int task_uniid); #ifdef DEBUG void InitDebugInfo(); @@ -390,6 +392,7 @@ private: std::map alive_player_hash_; std::map last_human_hash_; std::map born_point_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 d13155c2..605c0842 100644 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -39,3 +39,10 @@ class IBullet virtual bool IsPreBattleBullet() = 0; virtual Room* GetRoom() = 0; }; + +class ITask +{ + public: + virtual void Update(int delta_time) = 0; + virtual bool IsDone() = 0; +}; diff --git a/server/gameserver/virtualbullet.cc b/server/gameserver/virtualbullet.cc index e997ea76..74570210 100644 --- a/server/gameserver/virtualbullet.cc +++ b/server/gameserver/virtualbullet.cc @@ -50,3 +50,13 @@ Room* VirtualBullet::GetRoom() { return room; } + +void VirtualBullet::Update(int delta_time) +{ + +} + +bool VirtualBullet::IsDone() +{ + return false; +} diff --git a/server/gameserver/virtualbullet.h b/server/gameserver/virtualbullet.h index edd31850..735ac387 100644 --- a/server/gameserver/virtualbullet.h +++ b/server/gameserver/virtualbullet.h @@ -7,7 +7,7 @@ namespace MetaData } class Room; -class VirtualBullet : public IBullet +class VirtualBullet : public IBullet, public ITask { public: long long weapon_uniid = 0; @@ -29,4 +29,8 @@ class VirtualBullet : public IBullet virtual bool IsBomb() override; virtual bool IsPreBattleBullet() override; virtual Room* GetRoom() override; + + virtual void Update(int delta_time) override; + virtual bool IsDone() override; + };