mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use (better) named constants for the bridge sprite table
parent
2176d49a39
commit
54d58a08f3
|
@ -27,12 +27,13 @@ enum BridgePieces {
|
|||
BRIDGE_PIECE_MIDDLE_ODD,
|
||||
BRIDGE_PIECE_MIDDLE_EVEN,
|
||||
BRIDGE_PIECE_HEAD,
|
||||
BRIDGE_PIECE_INVALID,
|
||||
NUM_BRIDGE_PIECES,
|
||||
};
|
||||
|
||||
DECLARE_POSTFIX_INCREMENT(BridgePieces)
|
||||
|
||||
static const uint MAX_BRIDGES = 13; ///< Maximal number of available bridge specs.
|
||||
constexpr uint SPRITES_PER_BRIDGE_PIECE = 32; ///< Number of sprites there are per bridge piece.
|
||||
|
||||
typedef uint BridgeType; ///< Bridge spec number.
|
||||
|
||||
|
|
|
@ -2292,21 +2292,21 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteR
|
|||
|
||||
if (bridge->sprite_table == nullptr) {
|
||||
/* Allocate memory for sprite table pointers and zero out */
|
||||
bridge->sprite_table = CallocT<PalSpriteID*>(7);
|
||||
bridge->sprite_table = CallocT<PalSpriteID*>(NUM_BRIDGE_PIECES);
|
||||
}
|
||||
|
||||
for (; numtables-- != 0; tableid++) {
|
||||
if (tableid >= 7) { // skip invalid data
|
||||
GrfMsg(1, "BridgeChangeInfo: Table {} >= 7, skipping", tableid);
|
||||
for (uint8_t sprite = 0; sprite < 32; sprite++) buf.ReadDWord();
|
||||
if (tableid >= NUM_BRIDGE_PIECES) { // skip invalid data
|
||||
GrfMsg(1, "BridgeChangeInfo: Table {} >= {}, skipping", tableid, NUM_BRIDGE_PIECES);
|
||||
for (uint8_t sprite = 0; sprite < SPRITES_PER_BRIDGE_PIECE; sprite++) buf.ReadDWord();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bridge->sprite_table[tableid] == nullptr) {
|
||||
bridge->sprite_table[tableid] = MallocT<PalSpriteID>(32);
|
||||
bridge->sprite_table[tableid] = MallocT<PalSpriteID>(SPRITES_PER_BRIDGE_PIECE);
|
||||
}
|
||||
|
||||
for (uint8_t sprite = 0; sprite < 32; sprite++) {
|
||||
for (uint8_t sprite = 0; sprite < SPRITES_PER_BRIDGE_PIECE; sprite++) {
|
||||
SpriteID image = buf.ReadWord();
|
||||
PaletteID pal = buf.ReadWord();
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ void ResetBridges()
|
|||
/* First, free sprite table data */
|
||||
for (BridgeType i = 0; i < MAX_BRIDGES; i++) {
|
||||
if (_bridge[i].sprite_table != nullptr) {
|
||||
for (BridgePieces j = BRIDGE_PIECE_NORTH; j < BRIDGE_PIECE_INVALID; j++) free(_bridge[i].sprite_table[j]);
|
||||
for (BridgePieces j = BRIDGE_PIECE_NORTH; j < NUM_BRIDGE_PIECES; j++) free(_bridge[i].sprite_table[j]);
|
||||
free(_bridge[i].sprite_table);
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ bool HasBridgeFlatRamp(Slope tileh, Axis axis)
|
|||
static inline const PalSpriteID *GetBridgeSpriteTable(int index, BridgePieces table)
|
||||
{
|
||||
const BridgeSpec *bridge = GetBridgeSpec(index);
|
||||
assert(table < BRIDGE_PIECE_INVALID);
|
||||
assert(table < NUM_BRIDGE_PIECES);
|
||||
if (bridge->sprite_table == nullptr || bridge->sprite_table[table] == nullptr) {
|
||||
return _bridge_sprite_table[index][table];
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue