diff --git a/server/gameserver/gridservice.cc b/server/gameserver/gridservice.cc index d0618b9..93ccec7 100644 --- a/server/gameserver/gridservice.cc +++ b/server/gameserver/gridservice.cc @@ -1,6 +1,7 @@ #include "precompile.h" #include "gridservice.h" +#include "human.h" GridService::GridService() { @@ -103,9 +104,19 @@ void GridService::Get369(int grid_id, std::set& grid_list) GetGridList(grid_id, 9, grid_list); } -void GridService::AddHuman(Human* hum, std::set& inc_grid_list) +void GridService::AddHuman(Human* hum) { - + int x = (int)hum->pos.x + cell_width_; + int y = (int)hum->pos.y + cell_width_; + if (BroderOverFlow(x, y)) { + abort(); + } + hum->grid_id = x/cell_width_ + (y/cell_width_) * cell_count_per_row_; + if (hum->grid_id == 0 || hum->grid_id > max_grid_id_) { + abort(); + } + cells_[hum->grid_id].human_list.insert(hum); + Get123456789(hum->grid_id, hum->grid_list); } void GridService::MoveHuman(Human* hum, float x, float y, diff --git a/server/gameserver/gridservice.h b/server/gameserver/gridservice.h index 61e43c2..d194217 100644 --- a/server/gameserver/gridservice.h +++ b/server/gameserver/gridservice.h @@ -34,7 +34,7 @@ class GridService void Get258(int grid_id, std::set& grid_list); void Get369(int grid_id, std::set& grid_list); - void AddHuman(Human* hum, std::set& inc_grid_list); + void AddHuman(Human* hum); void MoveHuman(Human* hum, float x, float y, std::set& inc_grid_list, std::set& dec_grid_list diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 8a3defa..18a1244 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -169,11 +169,8 @@ void Room::AddPlayer(Player* hum) accountid_hash_[hum->account_id] = hum; human_hash_[hum->entity_uniid] = hum; ++alive_count_; - { - std::set inc_grid_list; - grid_service.AddHuman(hum, inc_grid_list); - hum->RefreshView(); - } + grid_service.AddHuman(hum); + hum->RefreshView(); MatchTeam(hum); } @@ -211,11 +208,8 @@ void Room::ShuaAndroid() moveable_hash_[hum->entity_uniid] = hum; human_hash_[hum->entity_uniid] = hum; ++alive_count_; - { - std::set inc_grid_list; - grid_service.AddHuman(hum, inc_grid_list); - hum->RefreshView(); - } + grid_service.AddHuman(hum); + hum->RefreshView(); } }