mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Remove unused FindVehicleOnPosXY/HasVehicleOnPosXY.
parent
2241476aee
commit
ceaf488313
|
@ -425,83 +425,6 @@ static inline uint GetTileHash(uint x, uint y)
|
|||
|
||||
static std::array<Vehicle *, TOTAL_TILE_HASH_SIZE> _vehicle_tile_hash{};
|
||||
|
||||
static Vehicle *VehicleFromTileHash(uint xl, uint yl, uint xu, uint yu, void *data, VehicleFromPosProc *proc, bool find_first)
|
||||
{
|
||||
for (uint y = yl; ; y = IncTileHash1D(y)) {
|
||||
for (uint x = xl; ; x = IncTileHash1D(x)) {
|
||||
Vehicle *v = _vehicle_tile_hash[ComposeTileHash(x, y)];
|
||||
for (; v != nullptr; v = v->hash_tile_next) {
|
||||
Vehicle *a = proc(v, data);
|
||||
if (find_first && a != nullptr) return a;
|
||||
}
|
||||
if (x == xu) break;
|
||||
}
|
||||
if (y == yu) break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function for FindVehicleOnPos/HasVehicleOnPos.
|
||||
* @note Do not call this function directly!
|
||||
* @param x The X location on the map
|
||||
* @param y The Y location on the map
|
||||
* @param data Arbitrary data passed to proc
|
||||
* @param proc The proc that determines whether a vehicle will be "found".
|
||||
* @param find_first Whether to return on the first found or iterate over
|
||||
* all vehicles
|
||||
* @return the best matching or first vehicle (depending on find_first).
|
||||
*/
|
||||
static Vehicle *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc, bool find_first)
|
||||
{
|
||||
const int COLL_DIST = 6;
|
||||
|
||||
/* Hash area to scan is from xl,yl to xu,yu */
|
||||
uint xl = GetTileHash1D((x - COLL_DIST) / TILE_SIZE);
|
||||
uint xu = GetTileHash1D((x + COLL_DIST) / TILE_SIZE);
|
||||
uint yl = GetTileHash1D((y - COLL_DIST) / TILE_SIZE);
|
||||
uint yu = GetTileHash1D((y + COLL_DIST) / TILE_SIZE);
|
||||
|
||||
return VehicleFromTileHash(xl, yl, xu, yu, data, proc, find_first);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a vehicle from a specific location. It will call proc for ALL vehicles
|
||||
* on the tile and YOU must make SURE that the "best one" is stored in the
|
||||
* data value and is ALWAYS the same regardless of the order of the vehicles
|
||||
* where proc was called on!
|
||||
* When you fail to do this properly you create an almost untraceable DESYNC!
|
||||
* @note The return value of proc will be ignored.
|
||||
* @note Use this when you have the intention that all vehicles
|
||||
* should be iterated over.
|
||||
* @param x The X location on the map
|
||||
* @param y The Y location on the map
|
||||
* @param data Arbitrary data passed to proc
|
||||
* @param proc The proc that determines whether a vehicle will be "found".
|
||||
*/
|
||||
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
|
||||
{
|
||||
VehicleFromPosXY(x, y, data, proc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a vehicle in on a specific location. It will call proc for
|
||||
* vehicles until it returns non-nullptr.
|
||||
* @note Use FindVehicleOnPosXY when you have the intention that all vehicles
|
||||
* should be iterated over.
|
||||
* @param x The X location on the map
|
||||
* @param y The Y location on the map
|
||||
* @param data Arbitrary data passed to proc
|
||||
* @param proc The proc that determines whether a vehicle will be "found".
|
||||
* @return True if proc returned non-nullptr.
|
||||
*/
|
||||
bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
|
||||
{
|
||||
return VehicleFromPosXY(x, y, data, proc, true) != nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator constructor.
|
||||
* Find first vehicle near (x, y).
|
||||
|
|
|
@ -178,12 +178,8 @@ bool HasVehicleNearTileXY(int32_t x, int32_t y, UnaryPred &&predicate)
|
|||
return false;
|
||||
}
|
||||
|
||||
typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
|
||||
|
||||
void VehicleServiceInDepot(Vehicle *v);
|
||||
uint CountVehiclesInChain(const Vehicle *v);
|
||||
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||
bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||
void CallVehicleTicks();
|
||||
uint8_t CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
|
||||
|
||||
|
|
Loading…
Reference in New Issue