Codechange: simplify the type of loaded_at_xy / next_station (#11182)
It was TileOrStationID, most likely to make sure both types in
the union are identical. But as TileIndex is a StrongTypeDef
that becomes a bit weird. So instead, still make sure they are
of equal size, but define their individual types better.
(cherry picked from commit c9c9cfa4fd
)
This commit is contained in:

committed by
Jonathan G Rennison

parent
e0e4d7c07e
commit
d17c949c22
@@ -745,7 +745,7 @@ void VehicleCargoList::InvalidateCache()
|
|||||||
* @return Amount of cargo actually reassigned.
|
* @return Amount of cargo actually reassigned.
|
||||||
*/
|
*/
|
||||||
template<VehicleCargoList::MoveToAction Tfrom, VehicleCargoList::MoveToAction Tto>
|
template<VehicleCargoList::MoveToAction Tfrom, VehicleCargoList::MoveToAction Tto>
|
||||||
uint VehicleCargoList::Reassign(uint max_move, TileOrStationID)
|
uint VehicleCargoList::Reassign(uint max_move, StationID)
|
||||||
{
|
{
|
||||||
static_assert(Tfrom != MTA_TRANSFER && Tto != MTA_TRANSFER);
|
static_assert(Tfrom != MTA_TRANSFER && Tto != MTA_TRANSFER);
|
||||||
static_assert(Tfrom - Tto == 1 || Tto - Tfrom == 1);
|
static_assert(Tfrom - Tto == 1 || Tto - Tfrom == 1);
|
||||||
@@ -763,7 +763,7 @@ uint VehicleCargoList::Reassign(uint max_move, TileOrStationID)
|
|||||||
* @return Amount of cargo actually reassigned.
|
* @return Amount of cargo actually reassigned.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
uint VehicleCargoList::Reassign<VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_TRANSFER>(uint max_move, TileOrStationID next_station)
|
uint VehicleCargoList::Reassign<VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_TRANSFER>(uint max_move, StationID next_station)
|
||||||
{
|
{
|
||||||
max_move = std::min(this->action_counts[MTA_DELIVER], max_move);
|
max_move = std::min(this->action_counts[MTA_DELIVER], max_move);
|
||||||
|
|
||||||
@@ -1161,4 +1161,4 @@ uint StationCargoList::RerouteFromSource(uint max_move, StationCargoList *dest,
|
|||||||
*/
|
*/
|
||||||
template class CargoList<VehicleCargoList, CargoPacketList>;
|
template class CargoList<VehicleCargoList, CargoPacketList>;
|
||||||
template class CargoList<StationCargoList, StationCargoPacketMap>;
|
template class CargoList<StationCargoList, StationCargoPacketMap>;
|
||||||
template uint VehicleCargoList::Reassign<VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_KEEP>(uint, TileOrStationID);
|
template uint VehicleCargoList::Reassign<VehicleCargoList::MTA_DELIVER, VehicleCargoList::MTA_KEEP>(uint, StationID);
|
||||||
|
@@ -43,11 +43,16 @@ namespace upstream_sl {
|
|||||||
class SlStationGoods;
|
class SlStationGoods;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef uint32 TileOrStationID;
|
|
||||||
|
|
||||||
void ClearCargoPacketDeferredPayments();
|
void ClearCargoPacketDeferredPayments();
|
||||||
void ChangeOwnershipOfCargoPacketDeferredPayments(Owner old_owner, Owner new_owner);
|
void ChangeOwnershipOfCargoPacketDeferredPayments(Owner old_owner, Owner new_owner);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To make alignment in the union in CargoPacket a bit easier, create a new type
|
||||||
|
* that is a StationID, but stored as 32bit.
|
||||||
|
*/
|
||||||
|
typedef uint32_t StationID_32bit;
|
||||||
|
static_assert(sizeof(TileIndex) == sizeof(StationID_32bit));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for cargo from the same location and time.
|
* Container for cargo from the same location and time.
|
||||||
*/
|
*/
|
||||||
@@ -59,8 +64,8 @@ private:
|
|||||||
SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid.
|
SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid.
|
||||||
TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain).
|
TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain).
|
||||||
union {
|
union {
|
||||||
TileOrStationID loaded_at_xy; ///< Location where this cargo has been loaded into the vehicle.
|
TileIndex loaded_at_xy; ///< Location where this cargo has been loaded into the vehicle.
|
||||||
TileOrStationID next_station; ///< Station where the cargo wants to go next.
|
StationID_32bit next_station; ///< Station where the cargo wants to go next.
|
||||||
};
|
};
|
||||||
StationID source; ///< The station where the cargo came from first.
|
StationID source; ///< The station where the cargo came from first.
|
||||||
SourceType source_type; ///< Type of \c source_id.
|
SourceType source_type; ///< Type of \c source_id.
|
||||||
@@ -467,7 +472,7 @@ public:
|
|||||||
* applicable), return value is amount of cargo actually moved. */
|
* applicable), return value is amount of cargo actually moved. */
|
||||||
|
|
||||||
template<MoveToAction Tfrom, MoveToAction Tto>
|
template<MoveToAction Tfrom, MoveToAction Tto>
|
||||||
uint Reassign(uint max_move, TileOrStationID update = INVALID_TILE);
|
uint Reassign(uint max_move, StationID update = INVALID_STATION);
|
||||||
uint Return(uint max_move, StationCargoList *dest, StationID next_station);
|
uint Return(uint max_move, StationCargoList *dest, StationID next_station);
|
||||||
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment);
|
uint Unload(uint max_move, StationCargoList *dest, CargoPayment *payment);
|
||||||
uint Shift(uint max_move, VehicleCargoList *dest);
|
uint Shift(uint max_move, VehicleCargoList *dest);
|
||||||
|
Reference in New Issue
Block a user