OpenTTD
Public Member Functions | Data Fields | Static Private Attributes
NewGRFSpriteLayout Struct Reference

NewGRF supplied spritelayout. More...

#include <newgrf_commons.h>

Inheritance diagram for NewGRFSpriteLayout:
ZeroedMemoryAllocator DrawTileSprites

Public Member Functions

void Allocate (uint num_sprites)
 Allocate a spritelayout for num_sprites building sprites.
void AllocateRegisters ()
 Allocate memory for register modifiers.
void Clone (const DrawTileSeqStruct *source)
 Clone the building sprites of a spritelayout.
void Clone (const NewGRFSpriteLayout *source)
 Clone a spritelayout.
void Clone (const DrawTileSprites *source)
 Clone a spritelayout.
bool NeedsPreprocessing () const
 Tests whether this spritelayout needs preprocessing by PrepareLayout() and ProcessRegisters(), or whether it can be used directly.
uint32 PrepareLayout (uint32 orig_offset, uint32 newgrf_ground_offset, uint32 newgrf_offset, uint constr_stage, bool separate_ground) const
 Prepares a sprite layout before resolving action-1-2-3 chains.
void ProcessRegisters (uint8 resolved_var10, uint32 resolved_sprite, bool separate_ground) const
 Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
const DrawTileSeqStructGetLayout (PalSpriteID *ground) const
 Returns the result spritelayout after preprocessing.
- Public Member Functions inherited from ZeroedMemoryAllocator
void * operator new (size_t size)
 Memory allocator for a single class instance.
void * operator new[] (size_t size)
 Memory allocator for an array of class instances.
void operator delete (void *ptr)
 Memory release for a single class instance.
void operator delete[] (void *ptr)
 Memory release for an array of class instances.

Data Fields

const TileLayoutRegistersregisters
uint consistent_max_offset
 Number of sprites in all referenced spritesets.
- Data Fields inherited from DrawTileSprites
PalSpriteID ground
 Palette and sprite for the ground.
const DrawTileSeqStructseq
 Array of child sprites. Terminated with a terminator entry.

Static Private Attributes

static SmallVector
< DrawTileSeqStruct, 8 > 
result_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 115 of file newgrf_commons.h.

Member Function Documentation

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 626 of file newgrf_commons.cpp.

References DrawTileSeqStruct::MakeTerminator(), and DrawTileSprites::seq.

Referenced by ReadSpriteLayout().

void NewGRFSpriteLayout::Clone ( const DrawTileSeqStruct source)

Clone the building sprites of a spritelayout.

Parameters
sourceThe building sprites to copy.

Definition at line 588 of file newgrf_commons.cpp.

References foreach_draw_tile_seq, MemCpyT(), and DrawTileSprites::seq.

Referenced by Clone(), and StationChangeInfo().

void NewGRFSpriteLayout::Clone ( const NewGRFSpriteLayout source)

Clone a spritelayout.

Parameters
sourceThe spritelayout to copy.

Definition at line 606 of file newgrf_commons.cpp.

References Clone(), foreach_draw_tile_seq, MemCpyT(), and DrawTileSprites::seq.

void NewGRFSpriteLayout::Clone ( const DrawTileSprites source)
inline

Clone a spritelayout.

Parameters
sourceThe spritelayout to copy.

Definition at line 133 of file newgrf_commons.h.

References Clone(), DrawTileSprites::ground, and DrawTileSprites::seq.

const 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 165 of file newgrf_commons.h.

References SmallVector< T, S >::Begin(), and result_seq.

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

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 152 of file newgrf_commons.h.

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

uint32 NewGRFSpriteLayout::PrepareLayout ( uint32  orig_offset,
uint32  newgrf_ground_offset,
uint32  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 everytime 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 662 of file newgrf_commons.cpp.

References SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), SmallVector< T, S >::Clear(), DrawTileSeqStruct::delta_x, DrawTileSeqStruct::delta_z, TileLayoutRegisters::flags, foreach_draw_tile_seq, GetConstructionStageOffset(), DrawTileSprites::ground, HasBit(), DrawTileSeqStruct::MakeTerminator(), TileLayoutRegisters::max_palette_offset, TileLayoutRegisters::max_sprite_offset, PalSpriteID::pal, TileLayoutRegisters::palette_var10, result_seq, DrawTileSprites::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().

void NewGRFSpriteLayout::ProcessRegisters ( uint8  resolved_var10,
uint32  resolved_sprite,
bool  separate_ground 
) const

Field Documentation

uint NewGRFSpriteLayout::consistent_max_offset

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 122 of file newgrf_commons.h.

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


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