1
0
Fork 0

Codechange: use (better) named constants for the bridge sprite table

pull/12288/head
Rubidium 2024-12-22 12:50:10 +01:00 committed by rubidium42
parent 2176d49a39
commit 54d58a08f3
3 changed files with 10 additions and 9 deletions

View File

@ -27,12 +27,13 @@ enum BridgePieces {
BRIDGE_PIECE_MIDDLE_ODD, BRIDGE_PIECE_MIDDLE_ODD,
BRIDGE_PIECE_MIDDLE_EVEN, BRIDGE_PIECE_MIDDLE_EVEN,
BRIDGE_PIECE_HEAD, BRIDGE_PIECE_HEAD,
BRIDGE_PIECE_INVALID, NUM_BRIDGE_PIECES,
}; };
DECLARE_POSTFIX_INCREMENT(BridgePieces) DECLARE_POSTFIX_INCREMENT(BridgePieces)
static const uint MAX_BRIDGES = 13; ///< Maximal number of available bridge specs. 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. typedef uint BridgeType; ///< Bridge spec number.

View File

@ -2292,21 +2292,21 @@ static ChangeInfoResult BridgeChangeInfo(uint brid, int numinfo, int prop, ByteR
if (bridge->sprite_table == nullptr) { if (bridge->sprite_table == nullptr) {
/* Allocate memory for sprite table pointers and zero out */ /* 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++) { for (; numtables-- != 0; tableid++) {
if (tableid >= 7) { // skip invalid data if (tableid >= NUM_BRIDGE_PIECES) { // skip invalid data
GrfMsg(1, "BridgeChangeInfo: Table {} >= 7, skipping", tableid); GrfMsg(1, "BridgeChangeInfo: Table {} >= {}, skipping", tableid, NUM_BRIDGE_PIECES);
for (uint8_t sprite = 0; sprite < 32; sprite++) buf.ReadDWord(); for (uint8_t sprite = 0; sprite < SPRITES_PER_BRIDGE_PIECE; sprite++) buf.ReadDWord();
continue; continue;
} }
if (bridge->sprite_table[tableid] == nullptr) { 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(); SpriteID image = buf.ReadWord();
PaletteID pal = buf.ReadWord(); PaletteID pal = buf.ReadWord();

View File

@ -88,7 +88,7 @@ void ResetBridges()
/* First, free sprite table data */ /* First, free sprite table data */
for (BridgeType i = 0; i < MAX_BRIDGES; i++) { for (BridgeType i = 0; i < MAX_BRIDGES; i++) {
if (_bridge[i].sprite_table != nullptr) { 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); free(_bridge[i].sprite_table);
} }
} }
@ -152,7 +152,7 @@ bool HasBridgeFlatRamp(Slope tileh, Axis axis)
static inline const PalSpriteID *GetBridgeSpriteTable(int index, BridgePieces table) static inline const PalSpriteID *GetBridgeSpriteTable(int index, BridgePieces table)
{ {
const BridgeSpec *bridge = GetBridgeSpec(index); 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) { if (bridge->sprite_table == nullptr || bridge->sprite_table[table] == nullptr) {
return _bridge_sprite_table[index][table]; return _bridge_sprite_table[index][table];
} else { } else {