From 933a39dfed8bab3ebcb86c3325e382c17859e321 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 16 Mar 2021 13:46:52 +0800 Subject: [PATCH] 1 --- server/gameserver/car.cc | 1 + server/gameserver/gridcell.cc | 1 + server/gameserver/gridservice.cc | 1 + server/gameserver/human.cc | 73 +++++++++++++++++++ server/gameserver/human.h | 7 +- server/gameserver/moveableentity.cc | 107 ++++++++++++---------------- server/gameserver/moveableentity.h | 7 +- server/gameserver/room.cc | 1 + server/gameserver/roommgr.cc | 2 +- 9 files changed, 132 insertions(+), 68 deletions(-) diff --git a/server/gameserver/car.cc b/server/gameserver/car.cc index 6ce4aea..20be5e3 100644 --- a/server/gameserver/car.cc +++ b/server/gameserver/car.cc @@ -175,5 +175,6 @@ void Car::SyncPos() room->grid_service->MoveHuman(hum); } } + room->grid_service->MoveCar(this); } } diff --git a/server/gameserver/gridcell.cc b/server/gameserver/gridcell.cc index 2c4f979..30a9848 100644 --- a/server/gameserver/gridcell.cc +++ b/server/gameserver/gridcell.cc @@ -16,6 +16,7 @@ GridCell::GridCell() human_list_.push_back(std::set()); entity_list_.push_back(std::set()); bullet_list_.push_back(std::set()); + car_list_.push_back(std::set()); } } diff --git a/server/gameserver/gridservice.cc b/server/gameserver/gridservice.cc index 9607a15..9031124 100644 --- a/server/gameserver/gridservice.cc +++ b/server/gameserver/gridservice.cc @@ -231,6 +231,7 @@ void GridService::MoveCar(Car* car) cells_[car->GetGridId()].RemoveCar(car); cells_[new_grid_id].AddCar(car); car->SetGridId(new_grid_id); + car->OnGridListChange(old_grid_list, inc_grid_list, dec_grid_list); } } diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 471a985..f772ac9 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -1497,6 +1497,79 @@ void Human::OnGridListChange(std::set& old_grids, } } +void Human::SyncAroundPlayers(const char* file, int line, const char* func) +{ + #if 0 + if (a8::HasBitFlag(status, HS_Disable)) { + return; + } + #endif + #ifdef DEBUG + #if 0 + room->CheckPartObjects(); + a8::UdpLog::Instance()->Debug("room_idx:%d syncaround begin %s %d %s", + { + room->GetRoomIdx(), + file, + line, + func + }); + #endif + #endif + TouchAllLayerHumanList + ( + [this, file, line, func] (Human* hum, bool& stop) + { + hum->AddToNewObjects(this); +#ifdef DEBUG + #if 0 + { + std::string objs_str; + for (auto& obj : hum->part_objects) { + objs_str += a8::Format("%d ", {(long long)obj}); + } + a8::UdpLog::Instance()->Debug("hum1 %d %s", {(long long)hum, objs_str}); + } + { + std::string objs_str; + for (auto& obj : part_objects) { + objs_str += a8::Format("%d ", {(long long)obj}); + } + a8::UdpLog::Instance()->Debug("hum2 %d %s", {(long long)this, objs_str}); + } + room->CheckPartObjects(hum, this); + hum->InPartObjects(this); + #endif +#endif + assert(hum->InPartObjects(this)); + if (!hum->InPartObjects(this)) { + static long long last_debugout_tick = 0; + if (a8::XGetTickCount() - last_debugout_tick > 1000 * 10) { + last_debugout_tick = a8::XGetTickCount(); + a8::UdpLog::Instance()->Warning + ("SyncAroundPlayers error room_idx:%d, file:%s line:%d func:%s", + { + room->GetRoomIdx(), + file, + line, + func + }); + } + } + }); +#ifdef DEBUG + #if 0 + room->CheckPartObjects(); + a8::UdpLog::Instance()->Debug("syncaround end %s %d %s", + { + file, + line, + func + }); + #endif +#endif +} + void Human::FillMFActivePlayerData(cs::MFActivePlayerData* player_data) { { diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 2e6140c..1c82e6c 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -209,11 +209,12 @@ class Human : public MoveableEntity void DoGetOn(int obj_uniid); void DoGetDown(); void FindLocation(); - void RefreshView(); - void OnGridListChange(std::set& old_grids, + virtual void RefreshView() override; + virtual void OnGridListChange(std::set& old_grids, std::set& inc_grids, std::set& dec_grids - ); + ) override; + virtual void SyncAroundPlayers(const char* file, int line, const char* func) override; void FillMFActivePlayerData(cs::MFActivePlayerData* player_data); void FillMFGasData(cs::MFGasData* gas_data); bool CanSee(const Human* hum) const; diff --git a/server/gameserver/moveableentity.cc b/server/gameserver/moveableentity.cc index ff07256..c615aa0 100644 --- a/server/gameserver/moveableentity.cc +++ b/server/gameserver/moveableentity.cc @@ -23,75 +23,56 @@ void MoveableEntity::TouchAllLayerHumanList(std::function room->grid_service->TouchAllLayerHumanList(room->GetRoomIdx(), grid_list_, func); } +void MoveableEntity::RefreshView() +{ + TouchAllLayerHumanList + ( + [this] (Human* hum, bool& stop) + { + hum->AddToNewObjects(this); + hum->AddToPartObjects(this); + }); +} + +void MoveableEntity::OnGridListChange(std::set& old_grids, + std::set& inc_grids, + std::set& dec_grids + ) +{ + { + room->grid_service->TouchAllLayerHumanList + ( + room->GetRoomIdx(), + inc_grids, + [this, &old_grids] (Human* hum, bool& stop) + { + if (!room->grid_service->HumanInGridList(hum, old_grids)) { + hum->AddToNewObjects(this); + hum->AddToPartObjects(this); + hum->RemoveOutObjects(this); + } + }); + } + { + room->grid_service->TouchAllLayerHumanList + ( + room->GetRoomIdx(), + dec_grids, + [this] (Human* hum, bool& stop) + { + if (!room->grid_service->HumanInGridList(hum, GetGridList())) { + hum->AddOutObjects(this); + } + }); + } +} + void MoveableEntity::SyncAroundPlayers(const char* file, int line, const char* func) { - #if 0 - if (a8::HasBitFlag(status, HS_Disable)) { - return; - } - #endif - #ifdef DEBUG - #if 0 - room->CheckPartObjects(); - a8::UdpLog::Instance()->Debug("room_idx:%d syncaround begin %s %d %s", - { - room->GetRoomIdx(), - file, - line, - func - }); - #endif - #endif TouchAllLayerHumanList ( [this, file, line, func] (Human* hum, bool& stop) { hum->AddToNewObjects(this); -#ifdef DEBUG - #if 0 - { - std::string objs_str; - for (auto& obj : hum->part_objects) { - objs_str += a8::Format("%d ", {(long long)obj}); - } - a8::UdpLog::Instance()->Debug("hum1 %d %s", {(long long)hum, objs_str}); - } - { - std::string objs_str; - for (auto& obj : part_objects) { - objs_str += a8::Format("%d ", {(long long)obj}); - } - a8::UdpLog::Instance()->Debug("hum2 %d %s", {(long long)this, objs_str}); - } - room->CheckPartObjects(hum, this); - hum->InPartObjects(this); - #endif -#endif - assert(hum->InPartObjects(this)); - if (!hum->InPartObjects(this)) { - static long long last_debugout_tick = 0; - if (a8::XGetTickCount() - last_debugout_tick > 1000 * 10) { - last_debugout_tick = a8::XGetTickCount(); - a8::UdpLog::Instance()->Warning - ("SyncAroundPlayers error room_idx:%d, file:%s line:%d func:%s", - { - room->GetRoomIdx(), - file, - line, - func - }); - } - } }); -#ifdef DEBUG - #if 0 - room->CheckPartObjects(); - a8::UdpLog::Instance()->Debug("syncaround end %s %d %s", - { - file, - line, - func - }); - #endif -#endif } diff --git a/server/gameserver/moveableentity.h b/server/gameserver/moveableentity.h index 604c645..fa21ae7 100644 --- a/server/gameserver/moveableentity.h +++ b/server/gameserver/moveableentity.h @@ -15,7 +15,12 @@ class MoveableEntity : public RoomEntity void TouchAllLayerEntityList(std::function func); void TouchAllLayerHumanList(std::function func); - void SyncAroundPlayers(const char* file, int line, const char* func); + virtual void RefreshView(); + virtual void OnGridListChange(std::set& old_grids, + std::set& inc_grids, + std::set& dec_grids + ); + virtual void SyncAroundPlayers(const char* file, int line, const char* func); protected: int updated_times_ = 0; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 841b2a7..da3196e 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -564,6 +564,7 @@ Car* Room::CreateCar(Human* driver, AddToEntityHash(car); grid_service->AddCar(car); car->BroadcastFullState(this); + car->RefreshView(); return car; } diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 54efb19..728b075 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -168,9 +168,9 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) ); hum->meta = MetaMgr::Instance()->human_meta; hum->room = room; + room->AddPlayer(hum); hum->ProcPrepareItems(msg.prepare_items()); hum->ProcPrepareItems2(msg.prepare_items2()); - room->AddPlayer(hum); PlayerMgr::Instance()->IncAccountNum(msg.account_id()); if (JsonDataMgr::Instance()->channel != 0 && JsonDataMgr::Instance()->channel != channel) {