修复gridservice越界问题
This commit is contained in:
parent
07535d954f
commit
6d77ee37d8
@ -97,4 +97,11 @@ void Entity::BroadcastFullState()
|
||||
|
||||
void Entity::BroadcastDeleteState()
|
||||
{
|
||||
std::set<GridCell*> grid_list;
|
||||
room->grid_service.Get123456789(grid_id, grid_list);
|
||||
for (auto& grid : grid_list) {
|
||||
for (Human* hum : grid->human_list) {
|
||||
hum->RemoveObjects(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ void FrameEvent::AddExplosion(Bullet* bullet, int item_id, Vector2D bomb_pos)
|
||||
void FrameEvent::AddSmoke(Bullet* bullet, int item_id, Vector2D pos)
|
||||
{
|
||||
{
|
||||
auto& tuple = a8::FastAppend(explosions_);
|
||||
auto& tuple = a8::FastAppend(smokes_);
|
||||
std::get<0>(tuple) = bullet->player;
|
||||
auto& p = std::get<1>(tuple);
|
||||
|
||||
@ -113,10 +113,10 @@ void FrameEvent::AddSmoke(Bullet* bullet, int item_id, Vector2D pos)
|
||||
p.set_player_id(bullet->player->entity_uniid);
|
||||
}
|
||||
{
|
||||
int explosion_idx = smokes_.size() - 1;
|
||||
int idx = smokes_.size() - 1;
|
||||
for (auto& cell : bullet->player->grid_list) {
|
||||
for (auto& hum : cell->human_list) {
|
||||
hum->explosions_.push_back(explosion_idx);
|
||||
hum->smokes_.push_back(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -174,8 +174,15 @@ void GridService::MoveBullet(Bullet* bullet)
|
||||
}
|
||||
}
|
||||
|
||||
void GridService::DelBullet(Bullet* bullet)
|
||||
{
|
||||
GridCell& cell = cells_[bullet->grid_id];
|
||||
cell.bullet_list.erase(bullet);
|
||||
}
|
||||
|
||||
void GridService::AddEntity(Entity* entity)
|
||||
{
|
||||
assert(entity->entity_type != ET_Player);
|
||||
int x = (int)entity->pos.x + cell_width_;
|
||||
int y = (int)entity->pos.y + cell_width_;
|
||||
if (BroderOverFlow(x, y)) {
|
||||
@ -188,6 +195,12 @@ void GridService::AddEntity(Entity* entity)
|
||||
cells_[entity->grid_id].entity_list.insert(entity);
|
||||
}
|
||||
|
||||
void GridService::DelEntity(Entity* entity)
|
||||
{
|
||||
GridCell& cell = cells_[entity->grid_id];
|
||||
cell.entity_list.erase(entity);
|
||||
}
|
||||
|
||||
bool GridService::HumanInGridList(Human* hum, std::set<GridCell*>& grid_list)
|
||||
{
|
||||
for (auto& cell : grid_list) {
|
||||
|
@ -41,8 +41,10 @@ class GridService
|
||||
|
||||
void AddBullet(Bullet* bullet);
|
||||
void MoveBullet(Bullet* bullet);
|
||||
void DelBullet(Bullet* bullet);
|
||||
|
||||
void AddEntity(Entity* entity);
|
||||
void DelEntity(Entity* entity);
|
||||
|
||||
bool HumanInGridList(Human* hum, std::set<GridCell*>& grid_list);
|
||||
bool EntityInGridList(Entity* entity, std::set<GridCell*>& grid_list);
|
||||
|
@ -41,6 +41,7 @@ Human::~Human()
|
||||
void Human::Initialize()
|
||||
{
|
||||
Entity::Initialize();
|
||||
RecalcSelfCollider();
|
||||
}
|
||||
|
||||
float Human::GetSpeed()
|
||||
|
@ -27,7 +27,6 @@ void Player::Initialize()
|
||||
Human::Initialize();
|
||||
health = meta->i->health();
|
||||
max_energy_shield = energy_shield;
|
||||
RecalcSelfCollider();
|
||||
}
|
||||
|
||||
void Player::Update(int delta_time)
|
||||
|
@ -419,6 +419,7 @@ void Room::CreateLoot(int equip_id, Vector2D pos, int count)
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
grid_service.AddEntity(entity);
|
||||
entity->BroadcastFullState();
|
||||
}
|
||||
}
|
||||
|
||||
@ -450,16 +451,18 @@ void Room::RemoveObjectLater(Entity* entity)
|
||||
case ET_Bullet:
|
||||
{
|
||||
entity->room->moveable_hash_.erase(entity->entity_uniid);
|
||||
entity->room->grid_service.DelBullet((Bullet*)entity);
|
||||
}
|
||||
break;
|
||||
case ET_Loot:
|
||||
{
|
||||
entity->BroadcastDeleteState();
|
||||
entity->room->grid_service.DelEntity(entity);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
||||
abort();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user