v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
Public Member Functions | Static Public Member Functions | List of all members
Sifteo::TileBuffer< tW, tH, tF > Struct Template Reference

A drawable that's backed by plain memory, instead of by a VideoBuffer. More...

#include <sifteo/video/tilebuffer.h>

Public Member Functions

CubeID cube () const
 Return the CubeID associated with this drawable.
 
void erase (uint16_t index=0)
 Erase the buffer, filling it with the specified absolute tile index value.
 
void erase (const PinnedAssetImage &image)
 Erase the buffer, filling it with the first tile from the specified PinnedAssetImage.
 
void fill (UInt2 topLeft, UInt2 size, unsigned tileIndex, unsigned frame=0)
 Fill a rectangle of identical tiles, specified as a top-left corner location and a size. More...
 
void fill (UInt2 topLeft, UInt2 size, const PinnedAssetImage &image, unsigned frame=0)
 Fill a rectangle of identical tiles, using the first tile of a pinned asset. More...
 
void image (UInt2 pos, const AssetImage &image, unsigned srcFrame=0, unsigned destFrame=0)
 Draw a full AssetImage frame, with its top-left corner at the specified location. More...
 
void image (UInt2 destXY, UInt2 size, const AssetImage &image, UInt2 srcXY, unsigned srcFrame=0, unsigned destFrame=0)
 Draw part of an AssetImage frame, with its top-left corner at the specified location. More...
 
void init ()
 Initialize the TileBuffer's AssetImage header.
 
void plot (unsigned i, uint16_t tileIndex)
 Plot a single tile, by absolute tile index, at linear position 'i'. More...
 
void plot (UInt2 pos, uint16_t tileIndex, unsigned frame=0)
 Plot a single tile, by absolute tile index, at location 'pos' in tile units, on the given frame. More...
 
void setCube (CubeID cube)
 Change the CubeID associated with this drawable. More...
 
void span (UInt2 pos, unsigned width, unsigned tileIndex, unsigned frame=0)
 Plot a horizontal span of tiles, by absolute tile index, given the position of the leftmost tile and the number of tiles to plot. More...
 
void span (UInt2 pos, unsigned width, const PinnedAssetImage &image, unsigned frame=0)
 Plot a horizontal span of tiles, using the first tile of a pinned asset. More...
 
void text (Int2 topLeft, const AssetImage &font, const char *str, unsigned destFrame=0, char firstChar= ' ')
 Draw text, using an AssetImage as a fixed width font. More...
 
uint16_t tile (unsigned i) const
 Returns the index of the tile at linear position 'i' in the image.
 
uint16_t tile (UInt2 pos, unsigned frame=0) const
 Return the index of the tile at the specified (x, y) tile coordinates, and optionally on the specified frame number.
 
uint16_t tileAddr (UInt2 pos, unsigned frame=0) const
 Calculate the video buffer address of a particular tile. More...
 
 TileBuffer ()
 Initialize a TileBuffer. More...
 
 TileBuffer (CubeID cube)
 Initialize a TileBuffer for use. More...
 

Static Public Member Functions

static int numFrames ()
 Return the number of frames in this image.
 
static int numTiles ()
 Return the total number of tiles in every frame of the image.
 
static int numTilesPerFrame ()
 Return the number of tiles in each frame of the image.
 
static unsigned pixelHeight ()
 Return the height, in pixel, of this mode.
 
static UInt2 pixelSize ()
 Return the size of this mode as a vector, in pixels.
 
static unsigned pixelWidth ()
 Return the width, in pixels, of this mode.
 
static unsigned sizeInBytes ()
 Returns the size of this drawable's tile data, in bytes.
 
static unsigned sizeInWords ()
 Returns the size of this drawable's tile data, in 16-bit words.
 
static unsigned tileHeight ()
 Return the height, in tiles, of this mode.
 
static UInt2 tileSize ()
 Return the size of this mode as a vector, in tiles.
 
static unsigned tileWidth ()
 Return the width, in tiles, of this mode.
 

Detailed Description

template<unsigned tW, unsigned tH, unsigned tF = 1>
struct Sifteo::TileBuffer< tW, tH, tF >

A drawable that's backed by plain memory, instead of by a VideoBuffer.

Template parameters specify the width and height of the buffer, in tiles, and optionally the number of frames.

You can draw on a TileBuffer in the same manner you'd draw on BG0, for example.

In memory, we store a flat array of 16-bit relocated tile indices.

TileBuffers can be used as assets. In particular, they can be freely converted to FlatAssetImage or AssetImage instances. This means you can use them to do off-screen rendering, and then draw that rendering to any other drawable.

Note that TileBuffers are not POD types. The underlying AssetImage header we build in RAM needs to be initialized by the constructor, and you must attach the TileBuffer to a specific CubeID so we can relocate assets.

Constructor & Destructor Documentation

template<unsigned tW, unsigned tH, unsigned tF = 1>
Sifteo::TileBuffer< tW, tH, tF >::TileBuffer ( )
inline

Initialize a TileBuffer.

You must call setCube() on this instance before using it, due to the potentially different memory layout on each individual cube.

template<unsigned tW, unsigned tH, unsigned tF = 1>
Sifteo::TileBuffer< tW, tH, tF >::TileBuffer ( CubeID  cube)
inline

Initialize a TileBuffer for use.

You must pass in a CubeID which represents the cube that this buffer will be drawn to. Each cube may have assets loaded at different addresses, so we need to know this in order to relocate tile indices when drawing to this buffer.

This does not write anything to the tile buffer memory itself. If you want to initialize the buffer to a known value, call erase().

Member Function Documentation

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::fill ( UInt2  topLeft,
UInt2  size,
unsigned  tileIndex,
unsigned  frame = 0 
)
inline

Fill a rectangle of identical tiles, specified as a top-left corner location and a size.

All coordinates must be in range. This function performs no clipping.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::fill ( UInt2  topLeft,
UInt2  size,
const PinnedAssetImage image,
unsigned  frame = 0 
)
inline

Fill a rectangle of identical tiles, using the first tile of a pinned asset.

All coordinates must be in range. This function performs no clipping.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::image ( UInt2  pos,
const AssetImage image,
unsigned  srcFrame = 0,
unsigned  destFrame = 0 
)
inline

Draw a full AssetImage frame, with its top-left corner at the specified location.

Locations are specified in tile units, relative to the top-left of the 18x18 grid.

All coordinates must be in range. This function performs no clipping.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::image ( UInt2  destXY,
UInt2  size,
const AssetImage image,
UInt2  srcXY,
unsigned  srcFrame = 0,
unsigned  destFrame = 0 
)
inline

Draw part of an AssetImage frame, with its top-left corner at the specified location.

Locations are specified in tile units, relative to the top-left of the 18x18 grid.

All coordinates must be in range. This function performs no clipping.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::plot ( unsigned  i,
uint16_t  tileIndex 
)
inline

Plot a single tile, by absolute tile index, at linear position 'i'.

All coordinates must be in range. This function performs no clipping.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::plot ( UInt2  pos,
uint16_t  tileIndex,
unsigned  frame = 0 
)
inline

Plot a single tile, by absolute tile index, at location 'pos' in tile units, on the given frame.

All coordinates must be in range. This function performs no clipping.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::setCube ( CubeID  cube)
inline

Change the CubeID associated with this drawable.

Note that this buffer holds relocated tile indices, and there is no way to efficiently retarget an already-rendered TileBuffer from one cube to another. So, this will effectively render any existing contents of this buffer meaningless.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::span ( UInt2  pos,
unsigned  width,
unsigned  tileIndex,
unsigned  frame = 0 
)
inline

Plot a horizontal span of tiles, by absolute tile index, given the position of the leftmost tile and the number of tiles to plot.

All coordinates must be in range. This function performs no clipping.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::span ( UInt2  pos,
unsigned  width,
const PinnedAssetImage image,
unsigned  frame = 0 
)
inline

Plot a horizontal span of tiles, using the first tile of a pinned asset.

All coordinates must be in range. This function performs no clipping.

template<unsigned tW, unsigned tH, unsigned tF = 1>
void Sifteo::TileBuffer< tW, tH, tF >::text ( Int2  topLeft,
const AssetImage font,
const char *  str,
unsigned  destFrame = 0,
char  firstChar = ' ' 
)
inline

Draw text, using an AssetImage as a fixed width font.

Each character is represented by a consecutive 'frame' in the image. Characters not present in the font will be skipped.

template<unsigned tW, unsigned tH, unsigned tF = 1>
uint16_t Sifteo::TileBuffer< tW, tH, tF >::tileAddr ( UInt2  pos,
unsigned  frame = 0 
) const
inline

Calculate the video buffer address of a particular tile.

All coordinates must be in range. This function performs no clipping.


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