mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r17727) -Codechange: some coding style and documentation fixes
This commit is contained in:
parent
7a8a97e68a
commit
1e2dc25582
@ -18,6 +18,9 @@
|
|||||||
CargoPacketPool _cargopacket_pool("CargoPacket");
|
CargoPacketPool _cargopacket_pool("CargoPacket");
|
||||||
INSTANTIATE_POOL_METHODS(CargoPacket)
|
INSTANTIATE_POOL_METHODS(CargoPacket)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize, i.e. clean, the pool with cargo packets.
|
||||||
|
*/
|
||||||
void InitializeCargoPackets()
|
void InitializeCargoPackets()
|
||||||
{
|
{
|
||||||
_cargopacket_pool.CleanPool();
|
_cargopacket_pool.CleanPool();
|
||||||
@ -28,7 +31,7 @@ CargoPacket::CargoPacket(StationID source, uint16 count, SourceType source_type,
|
|||||||
source(source),
|
source(source),
|
||||||
source_id(source_id)
|
source_id(source_id)
|
||||||
{
|
{
|
||||||
this->source_type = source_type;
|
this->source_type = source_type;
|
||||||
|
|
||||||
if (source != INVALID_STATION) {
|
if (source != INVALID_STATION) {
|
||||||
assert(count != 0);
|
assert(count != 0);
|
||||||
@ -67,48 +70,48 @@ CargoPacket::CargoPacket(uint16 count, byte days_in_transit, Money feeder_share,
|
|||||||
|
|
||||||
CargoList::~CargoList()
|
CargoList::~CargoList()
|
||||||
{
|
{
|
||||||
while (!packets.empty()) {
|
while (!this->packets.empty()) {
|
||||||
delete packets.front();
|
delete this->packets.front();
|
||||||
packets.pop_front();
|
this->packets.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CargoList::AgeCargo()
|
void CargoList::AgeCargo()
|
||||||
{
|
{
|
||||||
if (empty) return;
|
if (this->empty) return;
|
||||||
|
|
||||||
uint dit = 0;
|
uint dit = 0;
|
||||||
for (List::const_iterator it = packets.begin(); it != packets.end(); it++) {
|
for (List::const_iterator it = this->packets.begin(); it != this->packets.end(); it++) {
|
||||||
if ((*it)->days_in_transit != 0xFF) (*it)->days_in_transit++;
|
if ((*it)->days_in_transit != 0xFF) (*it)->days_in_transit++;
|
||||||
dit += (*it)->days_in_transit * (*it)->count;
|
dit += (*it)->days_in_transit * (*it)->count;
|
||||||
}
|
}
|
||||||
days_in_transit = dit / count;
|
this->days_in_transit = dit / count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CargoList::Append(CargoPacket *cp)
|
void CargoList::Append(CargoPacket *cp)
|
||||||
{
|
{
|
||||||
assert(cp != NULL);
|
assert(cp != NULL);
|
||||||
|
|
||||||
for (List::iterator it = packets.begin(); it != packets.end(); it++) {
|
for (List::iterator it = this->packets.begin(); it != this->packets.end(); it++) {
|
||||||
if ((*it)->SameSource(cp) && (*it)->count + cp->count <= CargoPacket::MAX_COUNT) {
|
if ((*it)->SameSource(cp) && (*it)->count + cp->count <= CargoPacket::MAX_COUNT) {
|
||||||
(*it)->count += cp->count;
|
(*it)->count += cp->count;
|
||||||
(*it)->feeder_share += cp->feeder_share;
|
(*it)->feeder_share += cp->feeder_share;
|
||||||
delete cp;
|
delete cp;
|
||||||
|
|
||||||
InvalidateCache();
|
this->InvalidateCache();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The packet could not be merged with another one */
|
/* The packet could not be merged with another one */
|
||||||
packets.push_back(cp);
|
this->packets.push_back(cp);
|
||||||
InvalidateCache();
|
this->InvalidateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CargoList::Truncate(uint count)
|
void CargoList::Truncate(uint count)
|
||||||
{
|
{
|
||||||
for (List::iterator it = packets.begin(); it != packets.end(); it++) {
|
for (List::iterator it = this->packets.begin(); it != this->packets.end(); it++) {
|
||||||
uint local_count = (*it)->count;
|
uint local_count = (*it)->count;
|
||||||
if (local_count <= count) {
|
if (local_count <= count) {
|
||||||
count -= local_count;
|
count -= local_count;
|
||||||
@ -119,14 +122,14 @@ void CargoList::Truncate(uint count)
|
|||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!packets.empty()) {
|
while (!this->packets.empty()) {
|
||||||
CargoPacket *cp = packets.back();
|
CargoPacket *cp = this->packets.back();
|
||||||
if (cp->count != 0) break;
|
if (cp->count != 0) break;
|
||||||
delete cp;
|
delete cp;
|
||||||
packets.pop_back();
|
this->packets.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidateCache();
|
this->InvalidateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta, CargoPayment *payment, uint data)
|
bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta, CargoPayment *payment, uint data)
|
||||||
@ -135,11 +138,11 @@ bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta,
|
|||||||
assert(mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL);
|
assert(mta == MTA_UNLOAD || mta == MTA_CARGO_LOAD || payment != NULL);
|
||||||
CargoList tmp;
|
CargoList tmp;
|
||||||
|
|
||||||
while (!packets.empty() && count > 0) {
|
while (!this->packets.empty() && count > 0) {
|
||||||
CargoPacket *cp = *packets.begin();
|
CargoPacket *cp = *packets.begin();
|
||||||
if (cp->count <= count) {
|
if (cp->count <= count) {
|
||||||
/* Can move the complete packet */
|
/* Can move the complete packet */
|
||||||
packets.remove(cp);
|
this->packets.remove(cp);
|
||||||
switch (mta) {
|
switch (mta) {
|
||||||
case MTA_FINAL_DELIVERY:
|
case MTA_FINAL_DELIVERY:
|
||||||
if (cp->source == data) {
|
if (cp->source == data) {
|
||||||
@ -195,7 +198,7 @@ bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool remaining = !packets.empty();
|
bool remaining = !this->packets.empty();
|
||||||
|
|
||||||
if (mta == MTA_FINAL_DELIVERY && !tmp.Empty()) {
|
if (mta == MTA_FINAL_DELIVERY && !tmp.Empty()) {
|
||||||
/* There are some packets that could not be delivered at the station, put them back */
|
/* There are some packets that could not be delivered at the station, put them back */
|
||||||
@ -204,28 +207,27 @@ bool CargoList::MoveTo(CargoList *dest, uint count, CargoList::MoveToAction mta,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dest != NULL) dest->InvalidateCache();
|
if (dest != NULL) dest->InvalidateCache();
|
||||||
InvalidateCache();
|
this->InvalidateCache();
|
||||||
|
|
||||||
return remaining;
|
return remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CargoList::InvalidateCache()
|
void CargoList::InvalidateCache()
|
||||||
{
|
{
|
||||||
empty = packets.empty();
|
this->empty = this->packets.empty();
|
||||||
count = 0;
|
this->count = 0;
|
||||||
feeder_share = 0;
|
this->feeder_share = 0;
|
||||||
source = INVALID_STATION;
|
this->source = INVALID_STATION;
|
||||||
days_in_transit = 0;
|
this->days_in_transit = 0;
|
||||||
|
|
||||||
if (empty) return;
|
if (this->empty) return;
|
||||||
|
|
||||||
uint dit = 0;
|
uint dit = 0;
|
||||||
for (List::const_iterator it = packets.begin(); it != packets.end(); it++) {
|
for (List::const_iterator it = this->packets.begin(); it != this->packets.end(); it++) {
|
||||||
count += (*it)->count;
|
this->count += (*it)->count;
|
||||||
dit += (*it)->days_in_transit * (*it)->count;
|
dit += (*it)->days_in_transit * (*it)->count;
|
||||||
feeder_share += (*it)->feeder_share;
|
this->feeder_share += (*it)->feeder_share;
|
||||||
}
|
}
|
||||||
days_in_transit = dit / count;
|
this->days_in_transit = dit / count;
|
||||||
source = (*packets.begin())->source;
|
this->source = (*packets.begin())->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,11 +19,13 @@
|
|||||||
#include "cargo_type.h"
|
#include "cargo_type.h"
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
/** Unique identifier for a single cargo packet. */
|
||||||
typedef uint32 CargoPacketID;
|
typedef uint32 CargoPacketID;
|
||||||
struct CargoPacket;
|
struct CargoPacket;
|
||||||
|
|
||||||
/** We want to use a pool */
|
/** Type of the pool for cargo packets. */
|
||||||
typedef Pool<CargoPacket, CargoPacketID, 1024, 1048576> CargoPacketPool;
|
typedef Pool<CargoPacket, CargoPacketID, 1024, 1048576> CargoPacketPool;
|
||||||
|
/** The actual pool with cargo packets */
|
||||||
extern CargoPacketPool _cargopacket_pool;
|
extern CargoPacketPool _cargopacket_pool;
|
||||||
|
|
||||||
class CargoList;
|
class CargoList;
|
||||||
@ -51,7 +53,7 @@ public:
|
|||||||
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)
|
||||||
TileIndex 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
|
||||||
StationID source; ///< The station where the cargo came from first
|
StationID source; ///< The station where the cargo came from first
|
||||||
SourceTypeByte source_type; ///< Type of #source_id
|
SourceTypeByte source_type; ///< Type of \c source_id
|
||||||
SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid
|
SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,8 +120,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
FORCEINLINE bool SameSource(const CargoPacket *cp) const
|
FORCEINLINE bool SameSource(const CargoPacket *cp) const
|
||||||
{
|
{
|
||||||
return this->source_xy == cp->source_xy && this->days_in_transit == cp->days_in_transit &&
|
return this->source_xy == cp->source_xy &&
|
||||||
this->source_type == cp->source_type && this->source_id == cp->source_id;
|
this->days_in_transit == cp->days_in_transit &&
|
||||||
|
this->source_type == cp->source_type &&
|
||||||
|
this->source_id == cp->source_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InvalidateAllFrom(SourceType src_type, SourceID src);
|
static void InvalidateAllFrom(SourceType src_type, SourceID src);
|
||||||
@ -166,6 +170,7 @@ private:
|
|||||||
uint days_in_transit; ///< Cache for the number of days in transit
|
uint days_in_transit; ///< Cache for the number of days in transit
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** The GoodsEntry has a CargoList. */
|
||||||
friend const struct SaveLoad *GetGoodsDesc();
|
friend const struct SaveLoad *GetGoodsDesc();
|
||||||
|
|
||||||
/** Create the cargo list */
|
/** Create the cargo list */
|
||||||
@ -177,7 +182,10 @@ public:
|
|||||||
* Returns a pointer to the cargo packet list (so you can iterate over it etc).
|
* Returns a pointer to the cargo packet list (so you can iterate over it etc).
|
||||||
* @return pointer to the packet list
|
* @return pointer to the packet list
|
||||||
*/
|
*/
|
||||||
FORCEINLINE const CargoList::List *Packets() const { return &this->packets; }
|
FORCEINLINE const CargoList::List *Packets() const
|
||||||
|
{
|
||||||
|
return &this->packets;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ages the all cargo in this list
|
* Ages the all cargo in this list
|
||||||
@ -188,31 +196,46 @@ public:
|
|||||||
* Checks whether this list is empty
|
* Checks whether this list is empty
|
||||||
* @return true if and only if the list is empty
|
* @return true if and only if the list is empty
|
||||||
*/
|
*/
|
||||||
FORCEINLINE bool Empty() const { return this->empty; }
|
FORCEINLINE bool Empty() const
|
||||||
|
{
|
||||||
|
return this->empty;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of cargo entities in this list
|
* Returns the number of cargo entities in this list
|
||||||
* @return the before mentioned number
|
* @return the before mentioned number
|
||||||
*/
|
*/
|
||||||
FORCEINLINE uint Count() const { return this->count; }
|
FORCEINLINE uint Count() const
|
||||||
|
{
|
||||||
|
return this->count;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns total sum of the feeder share for all packets
|
* Returns total sum of the feeder share for all packets
|
||||||
* @return the before mentioned number
|
* @return the before mentioned number
|
||||||
*/
|
*/
|
||||||
FORCEINLINE Money FeederShare() const { return this->feeder_share; }
|
FORCEINLINE Money FeederShare() const
|
||||||
|
{
|
||||||
|
return this->feeder_share;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns source of the first cargo packet in this list
|
* Returns source of the first cargo packet in this list
|
||||||
* @return the before mentioned source
|
* @return the before mentioned source
|
||||||
*/
|
*/
|
||||||
FORCEINLINE StationID Source() const { return this->source; }
|
FORCEINLINE StationID Source() const
|
||||||
|
{
|
||||||
|
return this->source;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns average number of days in transit for a cargo entity
|
* Returns average number of days in transit for a cargo entity
|
||||||
* @return the before mentioned number
|
* @return the before mentioned number
|
||||||
*/
|
*/
|
||||||
FORCEINLINE uint DaysInTransit() const { return this->days_in_transit; }
|
FORCEINLINE uint DaysInTransit() const
|
||||||
|
{
|
||||||
|
return this->days_in_transit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,6 +196,11 @@ static const SaveLoad _station_speclist_desc[] = {
|
|||||||
SLE_END()
|
SLE_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper function to get the GoodsEntry's internal structure while
|
||||||
|
* some of the variables itself are private.
|
||||||
|
* @return the saveload description for GoodsEntry.
|
||||||
|
*/
|
||||||
const SaveLoad *GetGoodsDesc()
|
const SaveLoad *GetGoodsDesc()
|
||||||
{
|
{
|
||||||
static const SaveLoad goods_desc[] = {
|
static const SaveLoad goods_desc[] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user