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

Function UpdateVehicleViewportHash

src/vehicle.cpp:625–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

623static std::array<Vehicle *, 1 << (GEN_HASHX_BITS + GEN_HASHY_BITS)> _vehicle_viewport_hash{};
624
625static void UpdateVehicleViewportHash(Vehicle *v, int x, int y, int old_x, int old_y)
626{
627 Vehicle **old_hash, **new_hash;
628
629 new_hash = (x == INVALID_COORD) ? nullptr : &_vehicle_viewport_hash[GetViewportHash(x, y)];
630 old_hash = (old_x == INVALID_COORD) ? nullptr : &_vehicle_viewport_hash[GetViewportHash(old_x, old_y)];
631
632 if (old_hash == new_hash) return;
633
634 /* remove from hash table? */
635 if (old_hash != nullptr) {
636 if (v->hash_viewport_next != nullptr) v->hash_viewport_next->hash_viewport_prev = v->hash_viewport_prev;
637 *v->hash_viewport_prev = v->hash_viewport_next;
638 }
639
640 /* insert into hash table? */
641 if (new_hash != nullptr) {
642 v->hash_viewport_next = *new_hash;
643 if (v->hash_viewport_next != nullptr) v->hash_viewport_next->hash_viewport_prev = &v->hash_viewport_next;
644 v->hash_viewport_prev = new_hash;
645 *new_hash = v;
646 }
647}
648
649void ResetVehicleHash()
650{

Callers 2

~VehicleMethod · 0.85
UpdateViewportMethod · 0.85

Calls 1

GetViewportHashFunction · 0.85

Tested by

no test coverage detected