gridservice AddEntity ok
This commit is contained in:
parent
281f725ccf
commit
a047b17d29
@ -139,19 +139,38 @@ void GridService::MoveHuman(Human* hum)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridService::AddEntity(Entity* entity, std::set<GridCell*>& inc_grid_list)
|
void GridService::AddEntity(Entity* entity)
|
||||||
{
|
{
|
||||||
|
int x = (int)entity->pos.x + cell_width_;
|
||||||
|
int y = (int)entity->pos.y + cell_width_;
|
||||||
|
if (BroderOverFlow(x, y)) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
entity->grid_id = x/cell_width_ + (y/cell_width_) * cell_count_per_row_;
|
||||||
|
if (entity->grid_id == 0 || entity->grid_id > max_grid_id_) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
cells_[entity->grid_id].entity_list.insert(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GridService::HumanInGridList(Human* hum, std::set<GridCell*>& grid_list)
|
bool GridService::HumanInGridList(Human* hum, std::set<GridCell*>& grid_list)
|
||||||
{
|
{
|
||||||
|
for (auto& cell : grid_list) {
|
||||||
|
if (cell->human_list.find(hum) != cell->human_list.end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GridService::EntityInGridList(Entity* entity, std::set<GridCell*>& grid_list)
|
bool GridService::EntityInGridList(Entity* entity, std::set<GridCell*>& grid_list)
|
||||||
{
|
{
|
||||||
|
for (auto& cell : grid_list) {
|
||||||
|
if (cell->entity_list.find(entity) != cell->entity_list.end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridService::GetGridList(int grid_id, int offset,
|
void GridService::GetGridList(int grid_id, int offset,
|
||||||
|
@ -37,7 +37,7 @@ class GridService
|
|||||||
void AddHuman(Human* hum);
|
void AddHuman(Human* hum);
|
||||||
void MoveHuman(Human* hum);
|
void MoveHuman(Human* hum);
|
||||||
|
|
||||||
void AddEntity(Entity* entity, std::set<GridCell*>& inc_grid_list);
|
void AddEntity(Entity* entity);
|
||||||
|
|
||||||
bool HumanInGridList(Human* hum, std::set<GridCell*>& grid_list);
|
bool HumanInGridList(Human* hum, std::set<GridCell*>& grid_list);
|
||||||
bool EntityInGridList(Entity* entity, std::set<GridCell*>& grid_list);
|
bool EntityInGridList(Entity* entity, std::set<GridCell*>& grid_list);
|
||||||
|
@ -403,10 +403,7 @@ void Room::CreateBuilding(int thing_id, float building_x, float building_y)
|
|||||||
building->pos = Vector2D(building_x, building_y);
|
building->pos = Vector2D(building_x, building_y);
|
||||||
building->Initialize();
|
building->Initialize();
|
||||||
uniid_hash_[building->entity_uniid] = building;
|
uniid_hash_[building->entity_uniid] = building;
|
||||||
{
|
grid_service.AddEntity(building);
|
||||||
std::set<GridCell*> inc_grid_list;
|
|
||||||
grid_service.AddEntity(building, inc_grid_list);
|
|
||||||
}
|
|
||||||
for (size_t door_idx = 0; door_idx < building_meta->doors.size(); ++door_idx) {
|
for (size_t door_idx = 0; door_idx < building_meta->doors.size(); ++door_idx) {
|
||||||
if (door_idx >= 0 && door_idx < building->meta->doors.size()) {
|
if (door_idx >= 0 && door_idx < building->meta->doors.size()) {
|
||||||
MetaData::Building::Door* door_meta = &building->meta->doors[door_idx];
|
MetaData::Building::Door* door_meta = &building->meta->doors[door_idx];
|
||||||
@ -468,10 +465,7 @@ void Room::CreateLoot(int equip_id, Vector2D pos, int count)
|
|||||||
entity->count = count;
|
entity->count = count;
|
||||||
entity->Initialize();
|
entity->Initialize();
|
||||||
uniid_hash_[entity->entity_uniid] = entity;
|
uniid_hash_[entity->entity_uniid] = entity;
|
||||||
{
|
grid_service.AddEntity(entity);
|
||||||
std::set<GridCell*> inc_grid_list;
|
|
||||||
grid_service.AddEntity(entity, inc_grid_list);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -953,10 +947,7 @@ Obstacle* Room::InternalCreateObstacle(int id, float x, float y,
|
|||||||
on_precreate(entity);
|
on_precreate(entity);
|
||||||
}
|
}
|
||||||
uniid_hash_[entity->entity_uniid] = entity;
|
uniid_hash_[entity->entity_uniid] = entity;
|
||||||
{
|
grid_service.AddEntity(entity);
|
||||||
std::set<GridCell*> inc_grid_list;
|
|
||||||
grid_service.AddEntity(entity, inc_grid_list);
|
|
||||||
}
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user