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

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

 CRM64Pro::SceneLayerTile::SceneLayerTile (const string &sName, Sint32 height, Sint32 width)
 Constructor.
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 size)
 Set cell width.
bool CRM64Pro::SceneLayerTile::setCellHeight (Sint32 size)
 Set tile height.
bool CRM64Pro::SceneLayerTile::allocateCells (Sint32 height, Sint32 width, Uint32 value=0)
 Allocate the 2D array for the cells.
bool CRM64Pro::SceneLayerTile::freeCells ()
 Free the 2D array of cells.
bool CRM64Pro::SceneLayerTile::setCellValue (Sint32 y, Sint32 x, Uint32 value)
 Set arbitrary values on 2D array of cells.
bool CRM64Pro::SceneLayerTile::clone (SceneLayerTile *dest)
 Copy the current values of the 2D array iCellMap to the given TileLayer.
bool CRM64Pro::SceneLayerTile::isValid ()
 Map validation.
Sint32 CRM64Pro::SceneLayerTile::info (Sint8 iTilesetReady, eLogLevel eLL)
 Request TileLayer object information.
VisibleRange CRM64Pro::SceneLayerTile::calculateVisibleRange (const SDL_Rect &viewport, float fOffsetX, float fOffsetY)
 Calculate visible range of tiles for a given viewport and offset.
Sint32 CRM64Pro::SceneLayerTile::update (Scene *pEngine, SceneLayerContext &context) override
 Update tile layer logic.
Sint32 CRM64Pro::SceneLayerTile::render (Scene *pEngine, SceneLayerContext &context) override
 Render tile layer content.
Sint32 CRM64Pro::SceneLayerTile::cellRender (Sint32 x_cell, Sint32 y_cell, float x_dst, float y_dst, 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.
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

◆ SceneLayerTile()

CRM64Pro::SceneLayerTile::SceneLayerTile ( const string & sName,
Sint32 height,
Sint32 width )

Constructor.

Parameters
sNameLayer name.
heightMap height (in cells).
widthMap width (in cells).

◆ 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 size)

Set cell width.

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

◆ setCellHeight()

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

Set tile height.

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

◆ allocateCells()

bool CRM64Pro::SceneLayerTile::allocateCells ( Sint32 height,
Sint32 width,
Uint32 value = 0 )

Allocate the 2D array for the cells.

Each element on this 2D array is a cell.

Parameters
heightSelected height of your map.
widthSelected width of your map.
valueDefault 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 y,
Sint32 x,
Uint32 value )

Set arbitrary values on 2D array of cells.

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

Parameters
ySelected Y position. Use -1 to affect all rows (Y axis).
xSelected 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
valueThe value to be set on the given position.
Returns
true on success or false on failure.

◆ clone()

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

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
destPointer to destination SceneLayerTile or derivated object.
Returns
true on success or false on failure.

◆ isValid()

bool CRM64Pro::SceneLayerTile::isValid ( )

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 & viewport,
float fOffsetX,
float fOffsetY )

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

Parameters
viewportViewport 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 & context )
overrideprotectedvirtual

Update tile layer logic.

Parameters
pEnginePointer to the Scene instance.
contextLayer 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 & context )
overrideprotectedvirtual

Render tile layer content.

Parameters
pEnginePointer to the Scene instance.
contextLayer 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 x_cell,
Sint32 y_cell,
float x_dst,
float y_dst,
Sint32 iAlpha,
Sint32 idTileset,
Uint32 idTile,
Sint32 idRes )

Render a cell.

Parameters
x_cellCell X coordinate to be rendered.
y_cellCell y coordinate to be rendered.
x_dstDestination surface X coordinate to start to render in case you wish to.
y_dstDestination 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
The assigned Global ID or a negative error code.

◆ 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
The assigned Global ID or a negative error code.

◆ 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
The assigned Global ID or a negative error code.

◆ 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 ITileMgr() to modify tile attributes (animations, collision, etc.) directly.

Parameters
iTNGlobal Tile ID (from the map data).
Returns
The CRM64Pro Tile Resource ID on success, or a negative error code if not found.

◆ getTileSetType()

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

Get the TileSet type.

Parameters
iTNGlobal ID or any tile of the TileSet.
Returns
check eSceneTileSetType for further information.

◆ 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.