This commit is contained in:
aozhiwei 2019-06-17 10:19:43 +08:00
parent d665f43a8d
commit a23e11bb66
2 changed files with 7 additions and 12 deletions

View File

@ -90,10 +90,17 @@ void MapService::AddCollider(ColliderComponent* collider)
float min_y = (collider->owner->pos + aabb._min).y - 2;
float max_x = (collider->owner->pos + aabb._max).x + 2;
float max_y = (collider->owner->pos + aabb._max).y + 2;
#if 1
int min_grid_x = floor(min_x / cell_width_);
int min_grid_y = floor(min_y / cell_width_);
int max_grid_x = ceil(max_x / cell_width_);
int max_grid_y = ceil(max_y / cell_width_);
#else
int min_grid_x = ceil(min_x / cell_width_) - 1;
int min_grid_y = ceil(min_y / cell_width_) - 1;
int max_grid_x = ceil(max_x / cell_width_) - 1;
int max_grid_y = ceil(max_y / cell_width_) - 1;
#endif
if (min_grid_x < 0 || max_grid_x >= map_width_) {
abort();
}
@ -148,17 +155,6 @@ void MapService::RemoveCollider(ColliderComponent* collider)
}
}
bool MapService::Walkable(float world_x, float world_y)
{
int grid_id = GetGridId(world_x, world_y);
if (grid_id < 0 || grid_id >= max_grid_id_) {
return false;
}
list_head& node = map_cells_[grid_id];
return (node.next == nullptr && node.prev == nullptr) ||
list_empty(&node);
}
void MapService::GetColliders(float world_x, float world_y, std::set<ColliderComponent*>& colliders)
{
int center_grid_id = GetGridId(world_x, world_y);

View File

@ -20,7 +20,6 @@ class MapService
void AddCollider(ColliderComponent* collider);
void RemoveCollider(ColliderComponent* collider);
bool Walkable(float world_x, float world_y);
void GetColliders(float world_x, float world_y, std::set<ColliderComponent*>& colliders);
private: