1
0
Fork 0

Codechange: Clamp the search area to valid values for the hash bucket selection.

The bucket selection uses a truncating division instead of a flooring division, so it does not work for negative positions.
Anyhow, there are no negative tile coordinates, so just clamp the search area.
pull/14116/head
frosch 2025-04-26 15:19:57 +02:00 committed by frosch
parent 0f76ba122c
commit 2df1233f1f
1 changed files with 5 additions and 4 deletions

View File

@ -432,10 +432,11 @@ static std::array<Vehicle *, TOTAL_TILE_HASH_SIZE> _vehicle_tile_hash{};
VehiclesNearTileXY::Iterator::Iterator(int32_t x, int32_t y) VehiclesNearTileXY::Iterator::Iterator(int32_t x, int32_t y)
{ {
const int COLL_DIST = 6; const int COLL_DIST = 6;
pos_rect.left = x - COLL_DIST; /* There are no negative tile coordinates */
pos_rect.right = x + COLL_DIST; pos_rect.left = std::max<int>(0, x - COLL_DIST);
pos_rect.top = y - COLL_DIST; pos_rect.right = std::max<int>(0, x + COLL_DIST);
pos_rect.bottom = y + COLL_DIST; pos_rect.top = std::max<int>(0, y - COLL_DIST);
pos_rect.bottom = std::max<int>(0, y + COLL_DIST);
/* Hash area to scan */ /* Hash area to scan */
this->hxmin = this->hx = GetTileHash1D(pos_rect.left / TILE_SIZE); this->hxmin = this->hx = GetTileHash1D(pos_rect.left / TILE_SIZE);