mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::vector for NewGRFSpriteLayout registers
parent
e7595c6c85
commit
faa845398f
|
@ -818,7 +818,7 @@ static void ReadSpriteLayoutRegisters(ByteReader &buf, TileLayoutFlags flags, bo
|
|||
{
|
||||
if (!(flags & TLF_DRAWING_FLAGS)) return;
|
||||
|
||||
if (dts->registers == nullptr) dts->AllocateRegisters();
|
||||
if (dts->registers.empty()) dts->AllocateRegisters();
|
||||
TileLayoutRegisters ®s = const_cast<TileLayoutRegisters&>(dts->registers[index]);
|
||||
regs.flags = flags & TLF_DRAWING_FLAGS;
|
||||
|
||||
|
@ -943,9 +943,9 @@ static bool ReadSpriteLayout(ByteReader &buf, uint num_building_sprites, bool us
|
|||
/* When the Action1 sets are unknown, everything should be 0 (no spriteset usage) or UINT16_MAX (some spriteset usage) */
|
||||
assert(use_cur_spritesets || (is_consistent && (dts->consistent_max_offset == 0 || dts->consistent_max_offset == UINT16_MAX)));
|
||||
|
||||
if (!is_consistent || dts->registers != nullptr) {
|
||||
if (!is_consistent || !dts->registers.empty()) {
|
||||
dts->consistent_max_offset = 0;
|
||||
if (dts->registers == nullptr) dts->AllocateRegisters();
|
||||
if (dts->registers.empty()) dts->AllocateRegisters();
|
||||
|
||||
for (uint i = 0; i < num_building_sprites + 1; i++) {
|
||||
TileLayoutRegisters ®s = const_cast<TileLayoutRegisters&>(dts->registers[i]);
|
||||
|
|
|
@ -573,14 +573,7 @@ bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t
|
|||
void NewGRFSpriteLayout::Clone(const NewGRFSpriteLayout *source)
|
||||
{
|
||||
this->Clone((const DrawTileSprites*)source);
|
||||
|
||||
if (source->registers != nullptr) {
|
||||
size_t count = 1 + source->seq.size(); // 1 for the ground sprite
|
||||
|
||||
TileLayoutRegisters *regs = MallocT<TileLayoutRegisters>(count);
|
||||
MemCpyT(regs, source->registers, count);
|
||||
this->registers = regs;
|
||||
}
|
||||
this->registers = source->registers;
|
||||
}
|
||||
|
||||
|
||||
|
@ -601,10 +594,9 @@ void NewGRFSpriteLayout::Allocate(uint num_sprites)
|
|||
void NewGRFSpriteLayout::AllocateRegisters()
|
||||
{
|
||||
assert(!this->seq.empty());
|
||||
assert(this->registers == nullptr);
|
||||
assert(this->registers.empty());
|
||||
|
||||
size_t count = 1 + this->seq.size(); // 1 for the ground sprite
|
||||
this->registers = CallocT<TileLayoutRegisters>(count);
|
||||
this->registers.resize(1 + this->seq.size(), {}); // 1 for the ground sprite
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -635,7 +627,7 @@ uint32_t NewGRFSpriteLayout::PrepareLayout(uint32_t orig_offset, uint32_t newgrf
|
|||
}
|
||||
/* Determine the var10 values the action-1-2-3 chains needs to be resolved for,
|
||||
* and apply the default sprite offsets (unless disabled). */
|
||||
const TileLayoutRegisters *regs = this->registers;
|
||||
const TileLayoutRegisters *regs = this->registers.empty() ? nullptr : this->registers.data();
|
||||
bool ground = true;
|
||||
for (DrawTileSeqStruct result : result_seq) {
|
||||
TileLayoutFlags flags = TLF_NOTHING;
|
||||
|
@ -688,7 +680,7 @@ uint32_t NewGRFSpriteLayout::PrepareLayout(uint32_t orig_offset, uint32_t newgrf
|
|||
*/
|
||||
void NewGRFSpriteLayout::ProcessRegisters(uint8_t resolved_var10, uint32_t resolved_sprite, bool separate_ground) const
|
||||
{
|
||||
const TileLayoutRegisters *regs = this->registers;
|
||||
const TileLayoutRegisters *regs = this->registers.empty() ? nullptr : this->registers.data();
|
||||
bool ground = true;
|
||||
for (DrawTileSeqStruct &result : result_seq) {
|
||||
TileLayoutFlags flags = TLF_NOTHING;
|
||||
|
|
|
@ -111,7 +111,7 @@ static const uint TLR_MAX_VAR10 = 7; ///< Maximum value for var 10.
|
|||
*/
|
||||
struct NewGRFSpriteLayout : ZeroedMemoryAllocator, DrawTileSprites {
|
||||
std::vector<DrawTileSeqStruct> seq;
|
||||
const TileLayoutRegisters *registers;
|
||||
std::vector<TileLayoutRegisters> registers;
|
||||
|
||||
/**
|
||||
* Number of sprites in all referenced spritesets.
|
||||
|
@ -137,11 +137,6 @@ struct NewGRFSpriteLayout : ZeroedMemoryAllocator, DrawTileSprites {
|
|||
this->seq.insert(this->seq.end(), source_sequence.begin(), source_sequence.end());
|
||||
}
|
||||
|
||||
virtual ~NewGRFSpriteLayout()
|
||||
{
|
||||
free(this->registers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this spritelayout needs preprocessing by
|
||||
* #PrepareLayout() and #ProcessRegisters(), or whether it can be
|
||||
|
@ -150,7 +145,7 @@ struct NewGRFSpriteLayout : ZeroedMemoryAllocator, DrawTileSprites {
|
|||
*/
|
||||
bool NeedsPreprocessing() const
|
||||
{
|
||||
return this->registers != nullptr;
|
||||
return !this->registers.empty();
|
||||
}
|
||||
|
||||
uint32_t PrepareLayout(uint32_t orig_offset, uint32_t newgrf_ground_offset, uint32_t newgrf_offset, uint constr_stage, bool separate_ground) const;
|
||||
|
|
Loading…
Reference in New Issue