* Iterator constructor. * Find first vehicle near (x, y). */
| 430 | * Find first vehicle near (x, y). |
| 431 | */ |
| 432 | VehiclesNearTileXY::Iterator::Iterator(int32_t x, int32_t y, uint max_dist) |
| 433 | { |
| 434 | /* There are no negative tile coordinates */ |
| 435 | this->pos_rect.left = std::max<int>(0, x - max_dist); |
| 436 | this->pos_rect.right = std::max<int>(0, x + max_dist); |
| 437 | this->pos_rect.top = std::max<int>(0, y - max_dist); |
| 438 | this->pos_rect.bottom = std::max<int>(0, y + max_dist); |
| 439 | |
| 440 | if (2 * max_dist < TILE_HASH_MASK * TILE_SIZE) { |
| 441 | /* Hash area to scan */ |
| 442 | this->hxmin = this->hx = GetTileHash1D(this->pos_rect.left / TILE_SIZE); |
| 443 | this->hxmax = GetTileHash1D(this->pos_rect.right / TILE_SIZE); |
| 444 | this->hymin = this->hy = GetTileHash1D(this->pos_rect.top / TILE_SIZE); |
| 445 | this->hymax = GetTileHash1D(this->pos_rect.bottom / TILE_SIZE); |
| 446 | } else { |
| 447 | /* Scan all */ |
| 448 | this->hxmin = this->hx = 0; |
| 449 | this->hxmax = TILE_HASH_MASK; |
| 450 | this->hymin = this->hy = 0; |
| 451 | this->hymax = TILE_HASH_MASK; |
| 452 | } |
| 453 | |
| 454 | this->current_veh = _vehicle_tile_hash[ComposeTileHash(this->hx, this->hy)]; |
| 455 | this->SkipEmptyBuckets(); |
| 456 | this->SkipFalseMatches(); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Advance the internal state to the next potential vehicle. |
nothing calls this directly
no test coverage detected