From d1e2cc438f19967bb21bafc57bd75c5b08e38088 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 10 Apr 2019 19:02:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90room=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/human.cc | 10 +++++---- server/gameserver/player.cc | 42 ++++++++++++++----------------------- server/gameserver/room.cc | 31 +++++++++++++++++++++++---- server/gameserver/room.h | 13 ++++++++---- 4 files changed, 58 insertions(+), 38 deletions(-) diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 7df8666..11d85f4 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -278,9 +278,11 @@ void Human::UpdatePoisoning() void Human::SyncAroundPlayers() { - for (auto& pair : room->human_hash_) { - pair.second->new_objects.insert(this); - } + room->TouchHumanList(a8::XParams(), + [this] (Human* hum, a8::XParams& param) + { + hum->new_objects.insert(this); + }); } void Human::AutoLoadingBullet(bool manual) @@ -359,7 +361,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name) health = 0.0f; dead_frameno = room->frame_no; send_gameover = true; - --room->alive_count_; + room->OnHumanDie(this); SyncAroundPlayers(); } } diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 5ac235b..da3c340 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -138,9 +138,7 @@ void Player::UpdateSelectWeapon() curr_weapon = weapon; ResetAction(); need_sync_active_player = true; - for (auto& pair : room->human_hash_) { - pair.second->new_objects.insert(this); - } + SyncAroundPlayers(); AutoLoadingBullet(); } } @@ -404,15 +402,17 @@ void Player::ObstacleInteraction(Obstacle* entity) entity->building->pos.y + entity->door_state0->y() - entity->building->meta->i->tileheight() / 2.0); } entity->RecalcSelfCollider(); - for (auto& pair : room->human_hash_) { - pair.second->new_objects.insert(entity); - pair.second->part_objects.insert(entity); - if (entity->TestCollision(pair.second)) { - pair.second->last_collision_door = entity; - } else if (pair.second->last_collision_door == entity) { - pair.second->last_collision_door = nullptr; - } - } + room->TouchHumanList(a8::XParams(), + [entity] (Human* hum, a8::XParams& param) + { + hum->new_objects.insert(entity); + hum->part_objects.insert(entity); + if (entity->TestCollision(hum)) { + hum->last_collision_door = entity; + } else if (hum->last_collision_door == entity) { + hum->last_collision_door = nullptr; + } + }); } else { } } @@ -445,9 +445,7 @@ void Player::LootInteraction(Loot* entity) need_sync_active_player = true; } need_sync_active_player = true; - for (auto& pair : room->human_hash_) { - pair.second->new_objects.insert(this); - } + SyncAroundPlayers(); } else { Weapon* weapon = nullptr; if (weapons[GUN_SLOT1].weapon_id == 0) { @@ -475,9 +473,7 @@ void Player::LootInteraction(Loot* entity) weapon->meta = item_meta; AutoLoadingBullet(); need_sync_active_player = true; - for (auto& pair : room->human_hash_) { - pair.second->new_objects.insert(this); - } + SyncAroundPlayers(); } } break; @@ -688,9 +684,7 @@ void Player::UpdateDropWeapon() room->CreateLoot(weapon_id, pos + dir * (25 + rand() % 50), std::max(1, weapon_ammo)); } need_sync_active_player = true; - for (auto& pair : room->human_hash_) { - pair.second->new_objects.insert(this); - } + SyncAroundPlayers(); } } } @@ -810,11 +804,7 @@ void Player::MakeUpdateMsg() } } if (updated_times == 0) { - for (auto& pair : room->uniid_hash_) { - if (pair.second->entity_type == ET_Building) { - new_objects.insert(pair.second); - } - } + room->FetchBuilding(this); } for (auto& itr : new_objects) { itr->FillMFObjectFull(update_msg->add_full_objects()); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 6a92e6b..e2a1e5e 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -488,6 +488,20 @@ void Room::CreateLoot(int equip_id, Vector2D pos, int count) } } +void Room::FetchBuilding(Human* hum) +{ + for (auto& pair : uniid_hash_) { + if (pair.second->entity_type == ET_Building) { + hum->new_objects.insert(pair.second); + } + } +} + +void Room::OnHumanDie(Human* hum) +{ + --alive_count_; +} + void Room::ClearDeletedObjects() { for (auto& obj_uniid : frame_data.deleted_objects) { @@ -519,6 +533,19 @@ void Room::TouchPlayerList(a8::XParams param, } } +void Room::TouchHumanList(a8::XParams param, + std::function func) +{ + if (!func) { + return; + } + for (auto& pair : human_hash_) { + if (pair.second) { + func(pair.second, param); + } + } +} + void Room::ProcAddedObjects() { if (!be_added_hash_.empty()) { @@ -647,11 +674,7 @@ void Room::UpdateGas() continue; } bool b1 = CircleContainCircle(gas_data.pos_old, - #if 1 gas_data.gas_progress, - #else - gas_data.rad_old, - #endif pair.second->pos, pair.second->GetRadius() ); diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 6388724..b232a7e 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -59,6 +59,8 @@ public: void ResetFrameData(); void TouchPlayerList(a8::XParams param, std::function func); + void TouchHumanList(a8::XParams param, + std::function func); void BeAddedObject(Entity* entity); void ProcDrop(Vector2D center, int drop_id); void CreateThings(); @@ -67,6 +69,8 @@ public: void CreateDoor(Building* building, int door_idx); void CreateHouseObstacle(Building* building, int id, float x, float y); void CreateLoot(int equip_id, Vector2D pos, int count); + void FetchBuilding(Human* hum); + void OnHumanDie(Human* hum); private: void ClearDeletedObjects(); @@ -75,15 +79,16 @@ private: bool GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float small_circle_rad, Vector2D& out_pos); -public: - unsigned short current_uniid = 0; - RoomState_e state_ = RS_Inactive; +private: int elapsed_time_ = 0; int alive_count_ = 0; + unsigned short current_uniid = 0; + RoomState_e state_ = RS_Inactive; + std::map accountid_hash_; - std::map uniid_hash_; std::map moveable_hash_; + std::map uniid_hash_; std::map human_hash_; std::map be_added_hash_; };