OpenTTD Source 20250312-master-gcdcc6b491d
NewGRFSpriteLayout Struct Reference

NewGRF supplied spritelayout. More...

#include <newgrf_commons.h>

Inheritance diagram for NewGRFSpriteLayout:
DrawTileSprites

Public Member Functions

void Allocate (uint num_sprites)
 Allocate a spritelayout for num_sprites building sprites.
 
void AllocateRegisters ()
 Allocate memory for register modifiers.
 
bool NeedsPreprocessing () const
 Tests whether this spritelayout needs preprocessing by PrepareLayout() and ProcessRegisters(), or whether it can be used directly.
 
uint32_t PrepareLayout (uint32_t orig_offset, uint32_t newgrf_ground_offset, uint32_t newgrf_offset, uint constr_stage, bool separate_ground) const
 Prepares a sprite layout before resolving action-1-2-3 chains.
 
void ProcessRegisters (uint8_t resolved_var10, uint32_t resolved_sprite, bool separate_ground) const
 Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
 
std::span< DrawTileSeqStructGetLayout (PalSpriteID *ground) const
 Returns the result spritelayout after preprocessing.
 
std::span< const DrawTileSeqStructGetSequence () const override
 
- Public Member Functions inherited from DrawTileSprites
 DrawTileSprites (PalSpriteID ground)
 

Data Fields

std::vector< DrawTileSeqStructseq {}
 
std::vector< TileLayoutRegistersregisters {}
 
uint consistent_max_offset = 0
 Number of sprites in all referenced spritesets.
 
- Data Fields inherited from DrawTileSprites
PalSpriteID ground {}
 Palette and sprite for the ground.
 

Static Private Attributes

static std::vector< DrawTileSeqStructresult_seq
 Temporary storage when preprocessing spritelayouts.
 

Detailed Description

NewGRF supplied spritelayout.

In contrast to DrawTileSprites this struct is for allocated layouts on the heap. It allocates data and frees them on destruction.

Definition at line 112 of file newgrf_commons.h.

Member Function Documentation

◆ Allocate()

void NewGRFSpriteLayout::Allocate ( uint  num_sprites)

Allocate a spritelayout for num_sprites building sprites.

Parameters
num_spritesNumber of building sprites to allocate memory for. (not counting the terminator)

Definition at line 573 of file newgrf_commons.cpp.

Referenced by ReadSpriteLayout().

◆ AllocateRegisters()

void NewGRFSpriteLayout::AllocateRegisters ( )

Allocate memory for register modifiers.

Definition at line 583 of file newgrf_commons.cpp.

Referenced by ReadSpriteLayout(), and ReadSpriteLayoutRegisters().

◆ GetLayout()

std::span< DrawTileSeqStruct > NewGRFSpriteLayout::GetLayout ( PalSpriteID ground) const
inline

Returns the result spritelayout after preprocessing.

Precondition
PrepareLayout() and ProcessRegisters() need calling first.
Returns
result spritelayout

Definition at line 144 of file newgrf_commons.h.

References DrawTileSprites::ground, and result_seq.

Referenced by DrawStationTile(), and TileLayoutSpriteGroup::ProcessRegisters().

◆ GetSequence()

std::span< const DrawTileSeqStruct > NewGRFSpriteLayout::GetSequence ( ) const
inlineoverridevirtual

Implements DrawTileSprites.

Definition at line 150 of file newgrf_commons.h.

◆ NeedsPreprocessing()

bool NewGRFSpriteLayout::NeedsPreprocessing ( ) const
inline

Tests whether this spritelayout needs preprocessing by PrepareLayout() and ProcessRegisters(), or whether it can be used directly.

Returns
true if preprocessing is needed

Definition at line 131 of file newgrf_commons.h.

Referenced by DrawStationTile(), and TileLayoutSpriteGroup::ProcessRegisters().

◆ PrepareLayout()

uint32_t NewGRFSpriteLayout::PrepareLayout ( uint32_t  orig_offset,
uint32_t  newgrf_ground_offset,
uint32_t  newgrf_offset,
uint  constr_stage,
bool  separate_ground 
) const

Prepares a sprite layout before resolving action-1-2-3 chains.

Integrates offsets into the layout and determines which chains to resolve.

Note
The function uses statically allocated temporary storage, which is reused every time when calling the function. That means, you have to use the sprite layout before calling PrepareLayout() the next time.
Parameters
orig_offsetOffset to apply to non-action-1 sprites.
newgrf_ground_offsetOffset to apply to action-1 ground sprites.
newgrf_offsetOffset to apply to action-1 non-ground sprites.
constr_stageConstruction stage (0-3) to apply to all action-1 sprites.
separate_groundWhether the ground sprite shall be resolved by a separate action-1-2-3 chain by default.
Returns
Bitmask of values for variable 10 to resolve action-1-2-3 chains for.

Definition at line 602 of file newgrf_commons.cpp.

References DrawTileSeqStruct::delta_z, TileLayoutRegisters::flags, GetConstructionStageOffset(), DrawTileSprites::ground, HasBit(), TileLayoutRegisters::max_palette_offset, TileLayoutRegisters::max_sprite_offset, TileLayoutRegisters::palette_var10, result_seq, SetBit(), PalSpriteID::sprite, SPRITE_MODIFIER_CUSTOM_SPRITE, TileLayoutRegisters::sprite_var10, TLF_PALETTE, TLF_PALETTE_REG_FLAGS, TLF_PALETTE_VAR10, TLF_SPRITE, TLF_SPRITE_REG_FLAGS, and TLF_SPRITE_VAR10.

Referenced by DrawStationTile(), and TileLayoutSpriteGroup::ProcessRegisters().

◆ ProcessRegisters()

void NewGRFSpriteLayout::ProcessRegisters ( uint8_t  resolved_var10,
uint32_t  resolved_sprite,
bool  separate_ground 
) const

Evaluates the register modifiers and integrates them into the preprocessed sprite layout.

Precondition
PrepareLayout() needs calling first.
Parameters
resolved_var10The value of var10 the action-1-2-3 chain was evaluated for.
resolved_spriteResult sprite of the action-1-2-3 chain.
separate_groundWhether the ground sprite is resolved by a separate action-1-2-3 chain.
Returns
Resulting spritelayout after processing the registers.

Definition at line 669 of file newgrf_commons.cpp.

References TileLayoutRegisters::child, TileLayoutRegisters::dodraw, TileLayoutRegisters::flags, GetRegister(), DrawTileSprites::ground, HasBit(), TileLayoutRegisters::max_palette_offset, TileLayoutRegisters::max_sprite_offset, TileLayoutRegisters::palette, TileLayoutRegisters::palette_var10, TileLayoutRegisters::parent, result_seq, TileLayoutRegisters::sprite, SPRITE_MODIFIER_CUSTOM_SPRITE, TileLayoutRegisters::sprite_var10, TLF_BB_XY_OFFSET, TLF_BB_Z_OFFSET, TLF_CHILD_X_OFFSET, TLF_CHILD_Y_OFFSET, TLF_DODRAW, TLF_PALETTE, TLF_PALETTE_REG_FLAGS, TLF_PALETTE_VAR10, TLF_SPRITE, TLF_SPRITE_REG_FLAGS, and TLF_SPRITE_VAR10.

Referenced by DrawStationTile(), and TileLayoutSpriteGroup::ProcessRegisters().

Field Documentation

◆ consistent_max_offset

uint NewGRFSpriteLayout::consistent_max_offset = 0

Number of sprites in all referenced spritesets.

If these numbers are inconsistent, then this is 0 and the real values are in registers.

Definition at line 120 of file newgrf_commons.h.

Referenced by TileLayoutSpriteGroup::ProcessRegisters(), ReadSpriteLayout(), and StationChangeInfo().

◆ registers

std::vector<TileLayoutRegisters> NewGRFSpriteLayout::registers {}

Definition at line 114 of file newgrf_commons.h.

◆ result_seq

std::vector< DrawTileSeqStruct > NewGRFSpriteLayout::result_seq
staticprivate

Temporary storage when preprocessing spritelayouts.

Definition at line 154 of file newgrf_commons.h.

Referenced by GetLayout(), PrepareLayout(), and ProcessRegisters().

◆ seq

std::vector<DrawTileSeqStruct> NewGRFSpriteLayout::seq {}

Definition at line 113 of file newgrf_commons.h.


The documentation for this struct was generated from the following files: