(svn r22976) -Codechange: Split group statistics into separate struct.

This commit is contained in:
frosch
2011-10-03 17:20:26 +00:00
parent 7133887ed6
commit b6766c2ed5
5 changed files with 48 additions and 23 deletions

View File

@@ -21,16 +21,25 @@
typedef Pool<Group, GroupID, 16, 64000> GroupPool;
extern GroupPool _group_pool; ///< Pool of groups.
/** Statistics and caches on the vehicles in a group. */
struct GroupStatistics {
uint16 num_vehicle; ///< Number of vehicles.
uint16 *num_engines; ///< Caches the number of engines of each type the company owns.
GroupStatistics();
~GroupStatistics();
void Clear();
};
/** Group data. */
struct Group : GroupPool::PoolItem<&_group_pool> {
char *name; ///< Group Name
uint16 num_vehicle; ///< Number of vehicles in the group
OwnerByte owner; ///< Group Owner
VehicleTypeByte vehicle_type; ///< Vehicle type of the group
bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group
uint16 *num_engines; ///< Caches the number of engines of each type the company owns (no need to save this)
GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group.
Group(CompanyID owner = INVALID_COMPANY);
~Group();
@@ -77,7 +86,7 @@ uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
static inline void IncreaseGroupNumVehicle(GroupID id_g)
{
Group *g = Group::GetIfValid(id_g);
if (g != NULL) g->num_vehicle++;
if (g != NULL) g->statistics.num_vehicle++;
}
/**
@@ -87,7 +96,7 @@ static inline void IncreaseGroupNumVehicle(GroupID id_g)
static inline void DecreaseGroupNumVehicle(GroupID id_g)
{
Group *g = Group::GetIfValid(id_g);
if (g != NULL) g->num_vehicle--;
if (g != NULL) g->statistics.num_vehicle--;
}