From 4372d054fbc12523e601456c1139d0f29b1a94d3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 25 May 2020 14:40:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B4=BB=E8=B7=83=E4=BA=BA?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/android.cc | 3 --- server/gameserver/human.cc | 1 - server/gameserver/player.cc | 3 --- server/gameserver/room.cc | 9 +++++++-- server/gameserver/room.h | 6 ++---- server/gameserver/roommgr.cc | 26 +++++++++++++++++++++----- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/server/gameserver/android.cc b/server/gameserver/android.cc index f9f101b..251d1b6 100644 --- a/server/gameserver/android.cc +++ b/server/gameserver/android.cc @@ -45,9 +45,6 @@ void Android::Update(int delta_time) if (room->frame_no % 2 == 0) { SendUpdateMsg(); } - if (!real_dead) { - room->IncRealAliveCount(); - } ++updated_times_; } diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 3b0d8be..ea8e5c3 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -2971,7 +2971,6 @@ void Human::DropItems(Obstacle* obstacle) }, &xtimer_attacher.timer_list_ ); - room->ShuaNewBieAndroid(this); } drop_id = MetaMgr::Instance()->newbie_drop[normal_drop_times_]; } diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index c77e82f..11f0eca 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -48,9 +48,6 @@ void Player::Update(int delta_time) if (room->frame_no % 2 == 0) { SendUpdateMsg(); } - if (!real_dead) { - room->IncRealAliveCount(); - } ++updated_times_; } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index c71c797..4ec97c9 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -89,7 +89,6 @@ void Room::Update(int delta_time) return; } - real_alive_count_stat_ = 0; elapsed_time_ += delta_time; while (elapsed_time_ >= 50) { if (frame_no % 2 == 0) { @@ -104,7 +103,6 @@ void Room::Update(int delta_time) ++frame_no; elapsed_time_ -= 50; } - real_alive_count_ = real_alive_count_stat_; } int Room::GetPlayerNum() @@ -173,6 +171,7 @@ void Room::AddPlayer(Player* hum) moveable_hash_[hum->entity_uniid] = hum; accountid_hash_[hum->account_id] = hum; human_hash_[hum->entity_uniid] = hum; + alive_human_hash_[hum->entity_uniid] = hum; last_add_player_tick = a8::XGetTickCount(); ++alive_count_; ++App::Instance()->perf.alive_count; @@ -348,6 +347,7 @@ DEFAULT_BORN_POINT_Y + rand() % 1500) if (room_type == RT_NewBrid) { a8::SetBitFlag(hum->status, HS_Disable); } else { + alive_human_hash_[hum->entity_uniid] = hum; moveable_hash_[hum->entity_uniid] = hum; grid_service->AddHuman(hum); hum->FindLocation(); @@ -548,6 +548,7 @@ void Room::OnHumanDie(Human* hum) { --alive_count_; --App::Instance()->perf.alive_count; + alive_human_hash_.erase(hum->entity_uniid); NotifyUiUpdate(); } @@ -1713,6 +1714,9 @@ void Room::EnableHuman(Human* target) grid_service->AddHuman(target); target->FindLocation(); target->RefreshView(); + if (!target->real_dead) { + alive_human_hash_[target->entity_uniid] = target; + } } } @@ -1721,6 +1725,7 @@ void Room::DisableHuman(Human* target) if (!a8::HasBitFlag(target->status, HS_Disable)) { a8::SetBitFlag(target->status, HS_Disable); moveable_hash_.erase(target->entity_uniid); + alive_human_hash_.erase(target->entity_uniid); for (auto& cell : target->grid_list) { bool has_target = false; for (Human* hum : cell->human_list[room_idx]) { diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 1a93a1c..647d944 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -73,8 +73,7 @@ public: void Update(int delta_time); int GetPlayerNum(); int AliveCount(); - inline int RealAliveCount() { return real_alive_count_; } - inline void IncRealAliveCount() { ++real_alive_count_stat_; } + inline int RealAliveCount() { return alive_human_hash_.size(); } Player* GetPlayerByAccountId(const std::string& accountid); Player* GetPlayerByUniId(int uniid); Entity* GetEntityByUniId(int uniid); @@ -167,8 +166,6 @@ private: private: int elapsed_time_ = 0; int alive_count_ = 0; - int real_alive_count_ = 0; - int real_alive_count_stat_ = 0; int force_shua_android_times_ = 0; MetaData::AirLine* airline_ = nullptr; a8::XTimerAttacher xtimer_attacher_; @@ -185,6 +182,7 @@ private: std::map uniid_hash_; std::map later_add_hash_; std::map human_hash_; + std::map alive_human_hash_; std::map born_point_hash_; std::map car_hash_; diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 82b0d7d..3458c19 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -33,6 +33,9 @@ static RoomType_e GetHumanRoomType(const cs::CMJoin& msg) int game_times = a8::XValue(tmp_strings[0]); if (!f8::IsOnlineEnv()) { game_times = 0; + if (!msg.team_uuid().empty()) { + game_times = 1; + } } #if 0 int win_times = a8::XValue(tmp_strings[1]); @@ -40,7 +43,7 @@ static RoomType_e GetHumanRoomType(const cs::CMJoin& msg) #endif if (game_times <= MetaMgr::Instance()->newbie_game_times) { return RT_NewBrid; - } else if (game_times == 2) { + } else if (game_times == 1) { return RT_MidBrid; } return RT_OldBrid; @@ -65,11 +68,24 @@ void RoomMgr::UnInit() void RoomMgr::Update(int delta_time) { + #ifdef DEBUG + static long long last_tick = 0; + #endif long long real_alive_count = 0; for (auto& pair : room_hash_) { Room* room = pair.second; room->Update(delta_time); real_alive_count += room->RealAliveCount(); + #ifdef DEBUG + if (a8::XGetTickCount() - last_tick > 1000 *1) { + last_tick = a8::XGetTickCount(); + a8::UdpLog::Instance()->Debug("room %d real_alive_count:%d", + { + room->room_idx, + room->RealAliveCount() + }); + } + #endif } App::Instance()->perf.real_alive_count = real_alive_count; } @@ -314,11 +330,11 @@ bool RoomMgr::IsLimitJoin() int RoomMgr::AllocRoomIdx() { do { - if (current_room_idx_ <= 0) { - current_room_idx_ = 1; + if (current_room_idx_ < 0) { + current_room_idx_ = 0; } if (current_room_idx_ >= (MAX_ROOM_IDX - 1)) { - current_room_idx_ = 1; + current_room_idx_ = 0; } } while (GetRoomByIdx(++current_room_idx_)); return current_room_idx_; @@ -333,7 +349,7 @@ Room* RoomMgr::CreateRoom(RoomType_e room_type) Room* room = new Room(); room->room_type = room_type; room->room_uuid = App::Instance()->NewUuid(); - room->room_idx = AllocRoomIdx(); + room->room_idx = room_idx; MapMgr::Instance()->AttachRoom(room); if (GetRoomByUuid(room->room_uuid)) { abort();