Codechange: use std::vector/std::span for DrawTileSprites over malloc-ed table

This commit is contained in:
Rubidium
2025-01-12 19:20:44 +01:00
committed by rubidium42
parent 6cf7a899e9
commit 069ff846e4
16 changed files with 93 additions and 87 deletions

View File

@@ -561,24 +561,6 @@ bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t
/* static */ std::vector<DrawTileSeqStruct> NewGRFSpriteLayout::result_seq;
/**
* Clone the building sprites of a spritelayout.
* @param source The building sprites to copy.
*/
void NewGRFSpriteLayout::Clone(const DrawTileSeqStruct *source)
{
assert(this->seq == nullptr);
assert(source != nullptr);
size_t count = 1; // 1 for the terminator
const DrawTileSeqStruct *element;
foreach_draw_tile_seq(element, source) count++;
DrawTileSeqStruct *sprites = MallocT<DrawTileSeqStruct>(count);
MemCpyT(sprites, source, count);
this->seq = sprites;
}
/**
* Clone a spritelayout.
* @param source The spritelayout to copy.
@@ -605,11 +587,10 @@ void NewGRFSpriteLayout::Clone(const NewGRFSpriteLayout *source)
*/
void NewGRFSpriteLayout::Allocate(uint num_sprites)
{
assert(this->seq == nullptr);
assert(this->seq.empty());
DrawTileSeqStruct *sprites = CallocT<DrawTileSeqStruct>(num_sprites + 1);
sprites[num_sprites].MakeTerminator();
this->seq = sprites;
this->seq.resize(num_sprites + 1, {});
this->seq[num_sprites].MakeTerminator();
}
/**
@@ -617,7 +598,7 @@ void NewGRFSpriteLayout::Allocate(uint num_sprites)
*/
void NewGRFSpriteLayout::AllocateRegisters()
{
assert(this->seq != nullptr);
assert(!this->seq.empty());
assert(this->registers == nullptr);
size_t count = 1; // 1 for the ground sprite
@@ -661,7 +642,7 @@ uint32_t NewGRFSpriteLayout::PrepareLayout(uint32_t orig_offset, uint32_t newgrf
* and apply the default sprite offsets (unless disabled). */
const TileLayoutRegisters *regs = this->registers;
bool ground = true;
foreach_draw_tile_seq(result, result_seq.data()) {
foreach_draw_tile_seq(result, result_seq) {
TileLayoutFlags flags = TLF_NOTHING;
if (regs != nullptr) flags = regs->flags;
@@ -715,7 +696,7 @@ void NewGRFSpriteLayout::ProcessRegisters(uint8_t resolved_var10, uint32_t resol
DrawTileSeqStruct *result;
const TileLayoutRegisters *regs = this->registers;
bool ground = true;
foreach_draw_tile_seq(result, result_seq.data()) {
foreach_draw_tile_seq(result, result_seq) {
TileLayoutFlags flags = TLF_NOTHING;
if (regs != nullptr) flags = regs->flags;