MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateVehicleTileHash

Function UpdateVehicleTileHash

src/vehicle.cpp:592–621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590}
591
592static void UpdateVehicleTileHash(Vehicle *v, bool remove)
593{
594 Vehicle **old_hash = v->hash_tile_current;
595 Vehicle **new_hash;
596
597 if (remove) {
598 new_hash = nullptr;
599 } else {
600 new_hash = &_vehicle_tile_hash[GetTileHash(TileX(v->tile), TileY(v->tile))];
601 }
602
603 if (old_hash == new_hash) return;
604
605 /* Remove from the old position in the hash table */
606 if (old_hash != nullptr) {
607 if (v->hash_tile_next != nullptr) v->hash_tile_next->hash_tile_prev = v->hash_tile_prev;
608 *v->hash_tile_prev = v->hash_tile_next;
609 }
610
611 /* Insert vehicle at beginning of the new position in the hash table */
612 if (new_hash != nullptr) {
613 v->hash_tile_next = *new_hash;
614 if (v->hash_tile_next != nullptr) v->hash_tile_next->hash_tile_prev = &v->hash_tile_next;
615 v->hash_tile_prev = new_hash;
616 *new_hash = v;
617 }
618
619 /* Remember current hash position */
620 v->hash_tile_current = new_hash;
621}
622
623static std::array<Vehicle *, 1 << (GEN_HASHX_BITS + GEN_HASHY_BITS)> _vehicle_viewport_hash{};
624

Callers 2

~VehicleMethod · 0.85
UpdatePositionMethod · 0.85

Calls 3

GetTileHashFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85

Tested by

no test coverage detected