mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: use std::vector for _sorted_railtypes
This commit is contained in:
parent
0797de06be
commit
25e534f3cf
|
@ -464,14 +464,13 @@ void ResetRailTypes();
|
||||||
void InitRailTypes();
|
void InitRailTypes();
|
||||||
RailType AllocateRailType(RailTypeLabel label);
|
RailType AllocateRailType(RailTypeLabel label);
|
||||||
|
|
||||||
extern RailType _sorted_railtypes[RAILTYPE_END];
|
extern std::vector<RailType> _sorted_railtypes;
|
||||||
extern uint8 _sorted_railtypes_size;
|
|
||||||
extern RailTypes _railtypes_hidden_mask;
|
extern RailTypes _railtypes_hidden_mask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loop header for iterating over railtypes, sorted by sortorder.
|
* Loop header for iterating over railtypes, sorted by sortorder.
|
||||||
* @param var Railtype.
|
* @param var Railtype.
|
||||||
*/
|
*/
|
||||||
#define FOR_ALL_SORTED_RAILTYPES(var) for (uint8 index = 0; index < _sorted_railtypes_size && (var = _sorted_railtypes[index], true) ; index++)
|
#define FOR_ALL_SORTED_RAILTYPES(var) for (uint8 index = 0; index < _sorted_railtypes.size() && (var = _sorted_railtypes[index], true) ; index++)
|
||||||
|
|
||||||
#endif /* RAIL_H */
|
#endif /* RAIL_H */
|
||||||
|
|
|
@ -44,8 +44,7 @@
|
||||||
typedef std::vector<Train *> TrainList;
|
typedef std::vector<Train *> TrainList;
|
||||||
|
|
||||||
RailtypeInfo _railtypes[RAILTYPE_END];
|
RailtypeInfo _railtypes[RAILTYPE_END];
|
||||||
RailType _sorted_railtypes[RAILTYPE_END];
|
std::vector<RailType> _sorted_railtypes;
|
||||||
uint8 _sorted_railtypes_size;
|
|
||||||
RailTypes _railtypes_hidden_mask;
|
RailTypes _railtypes_hidden_mask;
|
||||||
|
|
||||||
/** Enum holding the signal offset in the sprite sheet according to the side it is representing. */
|
/** Enum holding the signal offset in the sprite sheet according to the side it is representing. */
|
||||||
|
@ -130,9 +129,9 @@ void ResolveRailTypeGUISprites(RailtypeInfo *rti)
|
||||||
* @param second The railtype to compare.
|
* @param second The railtype to compare.
|
||||||
* @return True iff the first should be sorted before the second.
|
* @return True iff the first should be sorted before the second.
|
||||||
*/
|
*/
|
||||||
static int CDECL CompareRailTypes(const RailType *first, const RailType *second)
|
static bool CompareRailTypes(const RailType &first, const RailType &second)
|
||||||
{
|
{
|
||||||
return GetRailTypeInfo(*first)->sorting_order - GetRailTypeInfo(*second)->sorting_order;
|
return GetRailTypeInfo(first)->sorting_order < GetRailTypeInfo(second)->sorting_order;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,13 +145,13 @@ void InitRailTypes()
|
||||||
if (HasBit(rti->flags, RTF_HIDDEN)) SetBit(_railtypes_hidden_mask, rt);
|
if (HasBit(rti->flags, RTF_HIDDEN)) SetBit(_railtypes_hidden_mask, rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
_sorted_railtypes_size = 0;
|
_sorted_railtypes.clear();
|
||||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||||
if (_railtypes[rt].label != 0 && !HasBit(_railtypes_hidden_mask, rt)) {
|
if (_railtypes[rt].label != 0 && !HasBit(_railtypes_hidden_mask, rt)) {
|
||||||
_sorted_railtypes[_sorted_railtypes_size++] = rt;
|
_sorted_railtypes.push_back(rt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QSortT(_sorted_railtypes, _sorted_railtypes_size, CompareRailTypes);
|
std::sort(_sorted_railtypes.begin(), _sorted_railtypes.end(), CompareRailTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue