1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-28 22:54:29 +01:00

Codechange: Move spritelayout preprocessing to a separate class, which owns the heap allocations involved.

This commit is contained in:
frosch
2025-05-05 18:36:44 +02:00
committed by frosch
parent d9c43e7fda
commit 8bbfbd0347
11 changed files with 90 additions and 68 deletions

View File

@@ -3076,6 +3076,7 @@ bool SplitGroundSpriteForOverlay(const TileInfo *ti, SpriteID *ground, RailTrack
static void DrawTile_Station(TileInfo *ti)
{
const NewGRFSpriteLayout *layout = nullptr;
SpriteLayoutProcessor processor; // owns heap, borrowed by tmp_layout and t
DrawTileSpriteSpan tmp_layout;
const DrawTileSprites *t = nullptr;
int32_t total_offset;
@@ -3268,12 +3269,12 @@ draw_default_foundation:
if (layout != nullptr) {
/* Sprite layout which needs preprocessing */
bool separate_ground = statspec->flags.Test(StationSpecFlag::SeparateGround);
uint32_t var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground);
for (uint8_t var10 : SetBitIterator(var10_values)) {
processor = SpriteLayoutProcessor(*layout, total_offset, rti->fallback_railtype, 0, 0, separate_ground);
for (uint8_t var10 : processor.Var10Values()) {
uint32_t var10_relocation = GetCustomStationRelocation(statspec, st, ti->tile, var10);
layout->ProcessRegisters(var10, var10_relocation, separate_ground);
processor.ProcessRegisters(var10, var10_relocation);
}
tmp_layout = layout->GetLayout();
tmp_layout = processor.GetLayout();
t = &tmp_layout;
total_offset = 0;
} else if (statspec != nullptr) {
@@ -3337,7 +3338,8 @@ draw_default_foundation:
if (type == StationType::RoadWaypoint && stop_draw_mode.Test(RoadStopDrawMode::WaypGround)) {
draw_ground = true;
}
tmp_layout = group->ProcessRegisters(nullptr);
processor = group->ProcessRegisters(nullptr);
tmp_layout = processor.GetLayout();
t = &tmp_layout;
}
}