修复活跃人数问题

This commit is contained in:
aozhiwei 2020-05-25 14:40:40 +08:00
parent e01382beac
commit 4372d054fb
6 changed files with 30 additions and 18 deletions

View File

@ -45,9 +45,6 @@ void Android::Update(int delta_time)
if (room->frame_no % 2 == 0) { if (room->frame_no % 2 == 0) {
SendUpdateMsg(); SendUpdateMsg();
} }
if (!real_dead) {
room->IncRealAliveCount();
}
++updated_times_; ++updated_times_;
} }

View File

@ -2971,7 +2971,6 @@ void Human::DropItems(Obstacle* obstacle)
}, },
&xtimer_attacher.timer_list_ &xtimer_attacher.timer_list_
); );
room->ShuaNewBieAndroid(this);
} }
drop_id = MetaMgr::Instance()->newbie_drop[normal_drop_times_]; drop_id = MetaMgr::Instance()->newbie_drop[normal_drop_times_];
} }

View File

@ -48,9 +48,6 @@ void Player::Update(int delta_time)
if (room->frame_no % 2 == 0) { if (room->frame_no % 2 == 0) {
SendUpdateMsg(); SendUpdateMsg();
} }
if (!real_dead) {
room->IncRealAliveCount();
}
++updated_times_; ++updated_times_;
} }

View File

@ -89,7 +89,6 @@ void Room::Update(int delta_time)
return; return;
} }
real_alive_count_stat_ = 0;
elapsed_time_ += delta_time; elapsed_time_ += delta_time;
while (elapsed_time_ >= 50) { while (elapsed_time_ >= 50) {
if (frame_no % 2 == 0) { if (frame_no % 2 == 0) {
@ -104,7 +103,6 @@ void Room::Update(int delta_time)
++frame_no; ++frame_no;
elapsed_time_ -= 50; elapsed_time_ -= 50;
} }
real_alive_count_ = real_alive_count_stat_;
} }
int Room::GetPlayerNum() int Room::GetPlayerNum()
@ -173,6 +171,7 @@ void Room::AddPlayer(Player* hum)
moveable_hash_[hum->entity_uniid] = hum; moveable_hash_[hum->entity_uniid] = hum;
accountid_hash_[hum->account_id] = hum; accountid_hash_[hum->account_id] = hum;
human_hash_[hum->entity_uniid] = hum; human_hash_[hum->entity_uniid] = hum;
alive_human_hash_[hum->entity_uniid] = hum;
last_add_player_tick = a8::XGetTickCount(); last_add_player_tick = a8::XGetTickCount();
++alive_count_; ++alive_count_;
++App::Instance()->perf.alive_count; ++App::Instance()->perf.alive_count;
@ -348,6 +347,7 @@ DEFAULT_BORN_POINT_Y + rand() % 1500)
if (room_type == RT_NewBrid) { if (room_type == RT_NewBrid) {
a8::SetBitFlag(hum->status, HS_Disable); a8::SetBitFlag(hum->status, HS_Disable);
} else { } else {
alive_human_hash_[hum->entity_uniid] = hum;
moveable_hash_[hum->entity_uniid] = hum; moveable_hash_[hum->entity_uniid] = hum;
grid_service->AddHuman(hum); grid_service->AddHuman(hum);
hum->FindLocation(); hum->FindLocation();
@ -548,6 +548,7 @@ void Room::OnHumanDie(Human* hum)
{ {
--alive_count_; --alive_count_;
--App::Instance()->perf.alive_count; --App::Instance()->perf.alive_count;
alive_human_hash_.erase(hum->entity_uniid);
NotifyUiUpdate(); NotifyUiUpdate();
} }
@ -1713,6 +1714,9 @@ void Room::EnableHuman(Human* target)
grid_service->AddHuman(target); grid_service->AddHuman(target);
target->FindLocation(); target->FindLocation();
target->RefreshView(); 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)) { if (!a8::HasBitFlag(target->status, HS_Disable)) {
a8::SetBitFlag(target->status, HS_Disable); a8::SetBitFlag(target->status, HS_Disable);
moveable_hash_.erase(target->entity_uniid); moveable_hash_.erase(target->entity_uniid);
alive_human_hash_.erase(target->entity_uniid);
for (auto& cell : target->grid_list) { for (auto& cell : target->grid_list) {
bool has_target = false; bool has_target = false;
for (Human* hum : cell->human_list[room_idx]) { for (Human* hum : cell->human_list[room_idx]) {

View File

@ -73,8 +73,7 @@ public:
void Update(int delta_time); void Update(int delta_time);
int GetPlayerNum(); int GetPlayerNum();
int AliveCount(); int AliveCount();
inline int RealAliveCount() { return real_alive_count_; } inline int RealAliveCount() { return alive_human_hash_.size(); }
inline void IncRealAliveCount() { ++real_alive_count_stat_; }
Player* GetPlayerByAccountId(const std::string& accountid); Player* GetPlayerByAccountId(const std::string& accountid);
Player* GetPlayerByUniId(int uniid); Player* GetPlayerByUniId(int uniid);
Entity* GetEntityByUniId(int uniid); Entity* GetEntityByUniId(int uniid);
@ -167,8 +166,6 @@ private:
private: private:
int elapsed_time_ = 0; int elapsed_time_ = 0;
int alive_count_ = 0; int alive_count_ = 0;
int real_alive_count_ = 0;
int real_alive_count_stat_ = 0;
int force_shua_android_times_ = 0; int force_shua_android_times_ = 0;
MetaData::AirLine* airline_ = nullptr; MetaData::AirLine* airline_ = nullptr;
a8::XTimerAttacher xtimer_attacher_; a8::XTimerAttacher xtimer_attacher_;
@ -185,6 +182,7 @@ private:
std::map<int, Entity*> uniid_hash_; std::map<int, Entity*> uniid_hash_;
std::map<int, RoomEntity*> later_add_hash_; std::map<int, RoomEntity*> later_add_hash_;
std::map<int, Human*> human_hash_; std::map<int, Human*> human_hash_;
std::map<int, Human*> alive_human_hash_;
std::map<int, BornPoint> born_point_hash_; std::map<int, BornPoint> born_point_hash_;
std::map<int, CarObject> car_hash_; std::map<int, CarObject> car_hash_;

View File

@ -33,6 +33,9 @@ static RoomType_e GetHumanRoomType(const cs::CMJoin& msg)
int game_times = a8::XValue(tmp_strings[0]); int game_times = a8::XValue(tmp_strings[0]);
if (!f8::IsOnlineEnv()) { if (!f8::IsOnlineEnv()) {
game_times = 0; game_times = 0;
if (!msg.team_uuid().empty()) {
game_times = 1;
}
} }
#if 0 #if 0
int win_times = a8::XValue(tmp_strings[1]); int win_times = a8::XValue(tmp_strings[1]);
@ -40,7 +43,7 @@ static RoomType_e GetHumanRoomType(const cs::CMJoin& msg)
#endif #endif
if (game_times <= MetaMgr::Instance()->newbie_game_times) { if (game_times <= MetaMgr::Instance()->newbie_game_times) {
return RT_NewBrid; return RT_NewBrid;
} else if (game_times == 2) { } else if (game_times == 1) {
return RT_MidBrid; return RT_MidBrid;
} }
return RT_OldBrid; return RT_OldBrid;
@ -65,11 +68,24 @@ void RoomMgr::UnInit()
void RoomMgr::Update(int delta_time) void RoomMgr::Update(int delta_time)
{ {
#ifdef DEBUG
static long long last_tick = 0;
#endif
long long real_alive_count = 0; long long real_alive_count = 0;
for (auto& pair : room_hash_) { for (auto& pair : room_hash_) {
Room* room = pair.second; Room* room = pair.second;
room->Update(delta_time); room->Update(delta_time);
real_alive_count += room->RealAliveCount(); 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; App::Instance()->perf.real_alive_count = real_alive_count;
} }
@ -314,11 +330,11 @@ bool RoomMgr::IsLimitJoin()
int RoomMgr::AllocRoomIdx() int RoomMgr::AllocRoomIdx()
{ {
do { do {
if (current_room_idx_ <= 0) { if (current_room_idx_ < 0) {
current_room_idx_ = 1; current_room_idx_ = 0;
} }
if (current_room_idx_ >= (MAX_ROOM_IDX - 1)) { if (current_room_idx_ >= (MAX_ROOM_IDX - 1)) {
current_room_idx_ = 1; current_room_idx_ = 0;
} }
} while (GetRoomByIdx(++current_room_idx_)); } while (GetRoomByIdx(++current_room_idx_));
return current_room_idx_; return current_room_idx_;
@ -333,7 +349,7 @@ Room* RoomMgr::CreateRoom(RoomType_e room_type)
Room* room = new Room(); Room* room = new Room();
room->room_type = room_type; room->room_type = room_type;
room->room_uuid = App::Instance()->NewUuid(); room->room_uuid = App::Instance()->NewUuid();
room->room_idx = AllocRoomIdx(); room->room_idx = room_idx;
MapMgr::Instance()->AttachRoom(room); MapMgr::Instance()->AttachRoom(room);
if (GetRoomByUuid(room->room_uuid)) { if (GetRoomByUuid(room->room_uuid)) {
abort(); abort();