CRM64Pro GDK v0.18.0
A free cross-platform game development kit built on top of SDL 3.0
Loading...
Searching...
No Matches
Scene Layer Tile

Description

TileLayer class for tile-based map layers.

SceneLayerTile manages a 2D grid of tile indices (Global IDs) that reference tiles from loaded TileSets. Supports variable cell sizes and provides methods for tile manipulation and rendering.

Classes

class  CRM64Pro::SceneLayerTile
 TileLayer class for tile-based map layers. More...

Functions

eSceneLayerType CRM64Pro::SceneLayerTile::getType () const override
 Get the layer type.
Sint32 CRM64Pro::SceneLayerTile::getCellWidth () const
 Get cell width.
Sint32 CRM64Pro::SceneLayerTile::getCellHeight () const
 Get cell height.
Sint32 CRM64Pro::SceneLayerTile::getWidth () const
 Get map width.
Sint32 CRM64Pro::SceneLayerTile::getHeight () const
 Get map height.
float CRM64Pro::SceneLayerTile::getTotalWidth () const override
 Get layer total width in pixels.
float CRM64Pro::SceneLayerTile::getTotalHeight () const override
 Get layer total height in pixels.
bool CRM64Pro::SceneLayerTile::setCellWidth (Sint32 iSize)
 Set cell width.
bool CRM64Pro::SceneLayerTile::setCellHeight (Sint32 iSize)
 Set cell height.
bool CRM64Pro::SceneLayerTile::allocateCells (Sint32 iHeight, Sint32 iWidth, Uint32 iValue=0)
 Allocate the 2D array for the cells.
bool CRM64Pro::SceneLayerTile::freeCells ()
 Free the 2D array of cells.
bool CRM64Pro::SceneLayerTile::setCellValue (Sint32 iY, Sint32 iX, Uint32 iValue)
 Set arbitrary values on 2D array of cells.
bool CRM64Pro::SceneLayerTile::clone (SceneLayerTile *pDest)
 Copy the current values of the 2D array iCellMap to the given TileLayer.
bool CRM64Pro::SceneLayerTile::isValid () const
 Map validation.
Sint32 CRM64Pro::SceneLayerTile::info (Sint8 iTilesetReady, eLogLevel eLL)
 Request TileLayer object information.
VisibleRange CRM64Pro::SceneLayerTile::calculateVisibleRange (const SDL_Rect &rViewport, float fOffsetX, float fOffsetY)
 Calculate visible range of tiles for a given viewport and offset.
Sint32 CRM64Pro::SceneLayerTile::update (Scene *pEngine, SceneLayerContext &rContext) override
 Update tile layer logic.
Sint32 CRM64Pro::SceneLayerTile::render (Scene *pEngine, SceneLayerContext &rContext) override
 Render tile layer content.
Sint32 CRM64Pro::SceneLayerTile::cellRender (Sint32 iCellX, Sint32 iCellY, float fDstX, float fDstY, Sint32 iAlpha, Sint32 idTileset, Uint32 idTile, Sint32 idRes)
 Render a cell.
Sint32 CRM64Pro::Scene::createTileSet (Sint32 idRes, Sint32 globalID=-1)
 Create a TileSet from a memory resource (Image or Tile).
Sint32 CRM64Pro::Scene::createTileSet (const string &sCDCFile, const string &sResourceName, Sint32 globalID=-1)
 Create a TileSet from a CDC archive resource.
Sint32 CRM64Pro::Scene::createTileSetFromFile (const string &sPath, Sint32 globalID=-1, Sint32 iTileWidth=-1, Sint32 iTileHeight=-1)
 Create a TileSet from a file on disk.
Sint32 CRM64Pro::Scene::setTileAnimation (Uint32 iTileGID, const vector< Uint32 > &vFrameGID, const vector< Sint32 > &vDuration)
 Set a TileSet animation for a tile.
Sint32 CRM64Pro::Scene::clearTileAnimation (Uint32 iTileGID)
 Clear a TileSet animation from a tile.
bool CRM64Pro::Scene::closeTileSet (Sint32 iTN)
 Close and destroy a given TileSet.
Sint32 CRM64Pro::Scene::getTileResourceID (Sint32 iTN)
 Resolve a Global Tile ID to its internal CRM64Pro Tile Resource ID.
eSceneTileSetType CRM64Pro::Scene::getTileSetType (Sint32 iTN)
 Get the TileSet type.
bool CRM64Pro::Scene::getTileSetSource (Sint32 iTN, eSceneStorageMode &eMode, string &sPath, string &sFilename)
 Get the storage metadata for a TileSet.
bool CRM64Pro::Scene::setTileSetSource (Sint32 iTN, eSceneStorageMode eMode, const string &sPath, const string &sFilename)
 Set the storage metadata for a TileSet.

Function Documentation

◆ getType()

eSceneLayerType CRM64Pro::SceneLayerTile::getType ( ) const
overridevirtual

Get the layer type.

Returns
SLT_TILE.

Implements CRM64Pro::SceneLayer.

◆ getCellWidth()

Sint32 CRM64Pro::SceneLayerTile::getCellWidth ( ) const

Get cell width.

Returns
integer with the cell width (in pixels).

◆ getCellHeight()

Sint32 CRM64Pro::SceneLayerTile::getCellHeight ( ) const

Get cell height.

Returns
integer with the cell height (in pixels).

◆ getWidth()

Sint32 CRM64Pro::SceneLayerTile::getWidth ( ) const

Get map width.

Returns
width of this map (in number of tiles).

◆ getHeight()

Sint32 CRM64Pro::SceneLayerTile::getHeight ( ) const

Get map height.

Returns
height of this map (in number of tiles).

◆ getTotalWidth()

float CRM64Pro::SceneLayerTile::getTotalWidth ( ) const
overridevirtual

Get layer total width in pixels.

Returns
Width = cell width * map width.

Reimplemented from CRM64Pro::SceneLayer.

◆ getTotalHeight()

float CRM64Pro::SceneLayerTile::getTotalHeight ( ) const
overridevirtual

Get layer total height in pixels.

Returns
Height = cell height * map height.

Reimplemented from CRM64Pro::SceneLayer.

◆ setCellWidth()

bool CRM64Pro::SceneLayerTile::setCellWidth ( Sint32 iSize)

Set cell width.

Parameters
iSizeinteger with cell width (in pixels).
Returns
true on success, or false on failure.

◆ setCellHeight()

bool CRM64Pro::SceneLayerTile::setCellHeight ( Sint32 iSize)

Set cell height.

Parameters
iSizeinteger with cell height (in pixels).
Returns
true on success, or false on failure.

◆ allocateCells()

bool CRM64Pro::SceneLayerTile::allocateCells ( Sint32 iHeight,
Sint32 iWidth,
Uint32 iValue = 0 )

Allocate the 2D array for the cells.

Each element on this 2D array is a cell.

Parameters
iHeightSelected height of your map.
iWidthSelected width of your map.
iValueDefault value to be assigned on each cell.
Returns
true on success, or false on failure.

◆ freeCells()

bool CRM64Pro::SceneLayerTile::freeCells ( )

Free the 2D array of cells.

Returns
true on success, or false on failure.

◆ setCellValue()

bool CRM64Pro::SceneLayerTile::setCellValue ( Sint32 iY,
Sint32 iX,
Uint32 iValue )

Set arbitrary values on 2D array of cells.

It is mainly used for creating maps in a manual way.

Parameters
iYSelected Y position. Use -1 to affect all rows (Y axis).
iXSelected X position. Use -1 to affect all columns (X axis).
Note
Sentinel behavior: y=-1,x=-1 fills the whole map; y=-1,x>=0 fills one column; y>=0,x=-1 fills one row.
Parameters
iValueThe value to be set on the given position.
Returns
true on success, or false on failure.

◆ clone()

bool CRM64Pro::SceneLayerTile::clone ( SceneLayerTile * pDest)

Copy the current values of the 2D array iCellMap to the given TileLayer.

The destination must have identical attributes (width and height). If the destination has not an iCellMap, we will create one identical to the source

Parameters
pDestPointer to destination SceneLayerTile or derived object.
Returns
true on success, or false on failure.

◆ isValid()

bool CRM64Pro::SceneLayerTile::isValid ( ) const

Map validation.

Validates iCellMap 2D array: checks tile layer width/height, and checks cell width/height.

Returns
true on success, or false on failure.

◆ info()

Sint32 CRM64Pro::SceneLayerTile::info ( Sint8 iTilesetReady,
eLogLevel eLL )

Request TileLayer object information.

Writes information to the default log.

Parameters
iTilesetReady-1 do not display anything, 0 it is not ready and 1 it is ready.
eLLimportance of the message. Check ::eLogLevel enum for further information.
Returns
0 on success, or a negative error code on failure.

◆ calculateVisibleRange()

SceneLayerTile::VisibleRange CRM64Pro::SceneLayerTile::calculateVisibleRange ( const SDL_Rect & rViewport,
float fOffsetX,
float fOffsetY )

Calculate visible range of tiles for a given viewport and offset.

Parameters
rViewportViewport rectangle.
fOffsetXLayer X offset.
fOffsetYLayer Y offset.
Returns
A VisibleRange struct containing start/end indices and pixel offsets.

◆ update()

Sint32 CRM64Pro::SceneLayerTile::update ( Scene * pEngine,
SceneLayerContext & rContext )
overrideprotectedvirtual

Update tile layer logic.

Parameters
pEnginePointer to the Scene instance.
rContextLayer context structure containing update state.
Returns
0 on success, or a negative error code on failure.

Implements CRM64Pro::SceneLayer.

◆ render()

Sint32 CRM64Pro::SceneLayerTile::render ( Scene * pEngine,
SceneLayerContext & rContext )
overrideprotectedvirtual

Render tile layer content.

Parameters
pEnginePointer to the Scene instance.
rContextLayer context structure containing render state.
Returns
0 on success, or a negative error code on failure.

Implements CRM64Pro::SceneLayer.

◆ cellRender()

Sint32 CRM64Pro::SceneLayerTile::cellRender ( Sint32 iCellX,
Sint32 iCellY,
float fDstX,
float fDstY,
Sint32 iAlpha,
Sint32 idTileset,
Uint32 idTile,
Sint32 idRes )

Render a cell.

Parameters
iCellXCell X coordinate to be rendered.
iCellYCell y coordinate to be rendered.
fDstXDestination surface X coordinate to start to render in case you wish to.
fDstYDestination surface Y coordinate to start to render in case you wish to.
iAlphaAlpha modulation for this layer. This value overwrites the own tileset alpha modulation.
idTilesettileset id.
idTilewhich tile inside the tileset must be rendered.
idResa valid screen or image handle used as rendering target.
Returns
0 on success, or a negative error code on failure.
Note
Tiles with different size to the underlying cells is supported: larger tiles will extend at the top and right.

◆ createTileSet() [1/2]

Sint32 CRM64Pro::Scene::createTileSet ( Sint32 idRes,
Sint32 globalID = -1 )

Create a TileSet from a memory resource (Image or Tile).

Parameters
idResID of the resource (Image or Tile) loaded in memory.
globalIDInitial Global ID for this TileSet. Use -1 to auto-assign the first available ID.
Returns
Greater than 0 on success (the Global TileSet id), or a negative error code on failure.

◆ createTileSet() [2/2]

Sint32 CRM64Pro::Scene::createTileSet ( const string & sCDCFile,
const string & sResourceName,
Sint32 globalID = -1 )

Create a TileSet from a CDC archive resource.

Parameters
sCDCFilePath to the CDC archive.
sResourceNameName of the resource inside the CDC.
globalIDInitial Global ID for this TileSet. Use -1 to auto-assign the first available ID.
Returns
Greater than 0 on success (the Global TileSet id), or a negative error code on failure.

◆ createTileSetFromFile()

Sint32 CRM64Pro::Scene::createTileSetFromFile ( const string & sPath,
Sint32 globalID = -1,
Sint32 iTileWidth = -1,
Sint32 iTileHeight = -1 )

Create a TileSet from a file on disk.

Parameters
sPathPath to the image file.
globalIDInitial Global ID for this TileSet. Use -1 to auto-assign the first available ID.
iTileWidthOptional tile width override.
iTileHeightOptional tile height override.
Returns
Greater than 0 on success (the Global TileSet id), or a negative error code on failure.

◆ setTileAnimation()

Sint32 CRM64Pro::Scene::setTileAnimation ( Uint32 iTileGID,
const vector< Uint32 > & vFrameGID,
const vector< Sint32 > & vDuration )

Set a TileSet animation for a tile.

Parameters
iTileGIDGlobal tile ID that owns the animation.
vFrameGIDList of global tile IDs used as animation frames.
vDurationList of frame durations in milliseconds.
Returns
0 on success, or a negative error code on failure.
Note
All frame tiles must belong to the same TileSet as iTileGID.

◆ clearTileAnimation()

Sint32 CRM64Pro::Scene::clearTileAnimation ( Uint32 iTileGID)

Clear a TileSet animation from a tile.

Parameters
iTileGIDGlobal tile ID that owns the animation.
Returns
0 on success, or a negative error code on failure.

◆ closeTileSet()

bool CRM64Pro::Scene::closeTileSet ( Sint32 iTN)

Close and destroy a given TileSet.

The affected layers (the ones that use any tile of this TileSet) will be disabled.

Parameters
iTNGlobal ID or any tile of the TileSet to be removed.
Returns
true on success, or false on failure.

◆ getTileResourceID()

Sint32 CRM64Pro::Scene::getTileResourceID ( Sint32 iTN)

Resolve a Global Tile ID to its internal CRM64Pro Tile Resource ID.

Retrieves the internal resource handle (ID) for the tile associated with the given Global ID. This ID can be used with tileMgr() to modify tile attributes (animations, collision, etc.) directly.

Parameters
iTNGlobal Tile ID (from the map data).
Returns
Greater than 0 on success (the Tile resource id), or a negative error code on failure.

◆ getTileSetType()

eSceneTileSetType CRM64Pro::Scene::getTileSetType ( Sint32 iTN)

Get the TileSet type.

Parameters
iTNGlobal ID or any tile of the TileSet.
Returns
TileSet type enum value.

◆ getTileSetSource()

bool CRM64Pro::Scene::getTileSetSource ( Sint32 iTN,
eSceneStorageMode & eMode,
string & sPath,
string & sFilename )

Get the storage metadata for a TileSet.

Parameters
iTNGlobal ID of the TileSet.
eModeOutput storage mode (Disk, CDC, or Internal).
sPathOutput path or CDC archive name.
sFilenameOutput TSX or image filename.
Returns
true on success, or false on failure.

◆ setTileSetSource()

bool CRM64Pro::Scene::setTileSetSource ( Sint32 iTN,
eSceneStorageMode eMode,
const string & sPath,
const string & sFilename )

Set the storage metadata for a TileSet.

Used to specify how the TileSet should be referenced when saving the level.

Parameters
iTNGlobal ID of the TileSet.
eModeStorage mode (Disk, CDC, or Internal).
sPathPath or CDC archive name.
sFilenameTSX or image filename.
Returns
true on success, or false on failure.