15#include "../safeguards.h"
17std::map<GRFLocation, std::pair<SpriteID, uint16_t>> _grm_sprites;
18GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
36 size_t pos = file.
GetPos();
42 GrfMsg(2,
"CfgApply: Ignoring (next sprite is real, unsupported)");
45 file.
SeekTo(pos, SEEK_SET);
51 std::vector<uint8_t> &preload_sprite = _grf_line_to_action6_sprite_override[location];
54 if (preload_sprite.empty()) {
55 preload_sprite.resize(num);
56 file.
ReadBlock(preload_sprite.data(), num);
60 file.
SeekTo(pos, SEEK_SET);
72 if (param_num == 0xFF)
break;
80 add_value =
HasBit(param_size, 7);
81 param_size =
GB(param_size, 0, 7);
88 if (param_num < 0x80 && (param_num + (param_size - 1) / 4) >= std::size(_cur.
grffile->param)) {
89 GrfMsg(2,
"CfgApply: Ignoring (param {} not set)", (param_num + (param_size - 1) / 4));
93 GrfMsg(8,
"CfgApply: Applying {} bytes from parameter 0x{:02X} at offset 0x{:04X}", param_size, param_num, offset);
96 for (i = 0; i < param_size && offset + i < num; i++) {
97 uint32_t value = GetParamVal(param_num + i / 4,
nullptr);
100 if (i % 4 == 0) carry =
false;
103 uint new_value = preload_sprite[offset + i] +
GB(value, (i % 4) * 8, 8) + (carry ? 1 : 0);
104 preload_sprite[offset + i] =
GB(new_value, 0, 8);
106 carry = new_value >= 256;
108 preload_sprite[offset + i] =
GB(value, (i % 4) * 8, 8);
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Class to read from a NewGRF file.
uint16_t ReadExtendedByte()
Read a single Extended Byte (8 or 16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
void ReadBlock(void *ptr, size_t size)
Read a block.
size_t GetPos() const
Get position in the file.
void SeekTo(size_t pos, int mode)
Seek in the current file.
uint8_t ReadByte()
Read a byte from the file.
uint32_t ReadDword()
Read a double word (32 bits) from the file (in low endian format).
uint16_t ReadWord()
Read a word (16 bits) from the file (in low endian format).
RandomAccessFile with some extra information specific for sprite files.
uint8_t GetContainerVersion() const
Get the version number of container type used by the file.
NewGRF buffer reader definition.
NewGRF internal processing state.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
uint32_t grfid
GRF ID (defined by Action 0x08)
SpriteFile * file
File of currently processed GRF file.
GRFFile * grffile
Currently processed GRF file.
uint32_t nfo_line
Currently processed pseudo sprite number in the GRF.
GRFConfig * grfconfig
Config of the currently processed GRF file.