From 97fb7cd9d493389de3c98f2e2a198d9d5f7d17f6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 3 Feb 2024 13:24:27 +0800 Subject: [PATCH] 1 --- server/gameserver/room.cc | 34 ++++++++++++++++++++-------------- server/gameserver/room.h | 2 ++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 90eaed37..4e3b313e 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -234,7 +234,7 @@ void Room::UnInit() room_agent_ = nullptr; team_hash_.clear(); frame_event_data = nullptr; - PerfMonitor::Instance()->alive_count -= alive_count_; + PerfMonitor::Instance()->alive_count -= AliveCount(); ob_->UnInit(); ob_ = nullptr; } @@ -418,9 +418,7 @@ void Room::AddPlayer(Player* hum, std::shared_ptr init_born_point, bo } hum->PushJoinRoomMsg(); if (!hum->IsOb()) { - ++alive_count_; - alive_count_chged_frameno_ = GetFrameNo(); - ++PerfMonitor::Instance()->alive_count; + IncAliveCount(); } grid_service->AddCreature(hum); hum->FindLocation(); @@ -520,9 +518,7 @@ void Room::CreateAndroid(int robot_num, std::shared_ptr team) MatchTeam(hum); } if (!hum->IsOb()) { - ++alive_count_; - alive_count_chged_frameno_ = GetFrameNo(); - ++PerfMonitor::Instance()->alive_count; + IncAliveCount(); } refreshed_robot_set_.insert(robot_meta->id()); if (!CanAddToScene(hum)) { @@ -932,9 +928,7 @@ void Room::InternalRemoveObjectLater(Entity* entity, a8::Attacher& xtimer_attach void Room::OnHumanDie(Human* hum) { if (!hum->IsOb()) { - --alive_count_; - alive_count_chged_frameno_ = GetFrameNo(); - --PerfMonitor::Instance()->alive_count; + DecAliveCount(); RemoveFromAliveHumanHash(hum); NotifyUiUpdate(); } @@ -1342,7 +1336,7 @@ void Room::UpdateGas() } } else { if (!IsGameOver() && - alive_count_ <= GetMaxTeamNum() && + AliveCount() <= GetMaxTeamNum() && GetAliveTeamNum() <= 1) { game_over_ = true; game_over_frameno_ = GetFrameNo(); @@ -2199,9 +2193,7 @@ void Room::RandRemoveAndroid() RemoveFromAliveHumanHash(hum); AddToRemovedRobotHash(hum); if (!hum->IsOb()) { - --alive_count_; - alive_count_chged_frameno_ = GetFrameNo(); - --PerfMonitor::Instance()->alive_count; + DecAliveCount(); } TraverseRawHumanList ( @@ -3614,3 +3606,17 @@ std::shared_ptr Room::GetRoomOb() { return ob_; } + +void Room::IncAliveCount() +{ + ++alive_count_; + alive_count_chged_frameno_ = GetFrameNo(); + ++PerfMonitor::Instance()->alive_count; +} + +void Room::DecAliveCount() +{ + --alive_count_; + alive_count_chged_frameno_ = GetFrameNo(); + --PerfMonitor::Instance()->alive_count; +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index be4acf2a..12c5f9ad 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -352,6 +352,8 @@ private: bool IsAllRealDead(); void AutoJump(); + void IncAliveCount(); + void DecAliveCount(); private: bool destorying_ = false;