| 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
Scene module » Scene Layer base

## 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

  sName | Layer name.
  height | Map height (in cells).
  width | Map width (in cells).

## ◆ getType()

eSceneLayerType CRM64Pro::SceneLayerTile::getType | ( |  | ) | const
| override virtual

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
| override virtual

Get layer total width in pixels.

Returns
  Width = cell width * map width.

Reimplemented from CRM64Pro::SceneLayer.

## ◆ getTotalHeight()

float CRM64Pro::SceneLayerTile::getTotalHeight | ( |  | ) | const
| override virtual

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

  size | integer with cell width (in pixels).

Returns
  true on success or false on failure.

## ◆ setCellHeight()

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

Set tile height.

Parameters

  size | integer 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

  height | Selected height of your map.
  width | Selected width of your map.
  value | Default 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

  y | Selected Y position. Use -1 to affect all rows (Y axis).
  x | Selected 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

  value | The 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

  dest | Pointer 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.
  eLL | importance 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

  viewport | Viewport rectangle.
  fOffsetX | Layer X offset.
  fOffsetY | Layer Y offset.

Returns
  A VisibleRange struct containing start/end indices and pixel offsets.

## ◆ update()

Sint32 CRM64Pro::SceneLayerTile::update | ( | Scene * | pEngine,
|  | SceneLayerContext & | context )
| override protected virtual

Update tile layer logic.

Parameters

  pEngine | Pointer to the Scene instance.
  context | Layer 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 )
| override protected virtual

Render tile layer content.

Parameters

  pEngine | Pointer to the Scene instance.
  context | Layer 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_cell | Cell X coordinate to be rendered.
  y_cell | Cell y coordinate to be rendered.
  x_dst | Destination surface X coordinate to start to render in case you wish to.
  y_dst | Destination surface Y coordinate to start to render in case you wish to.
  iAlpha | Alpha modulation for this layer. This value overwrites the own tileset alpha modulation.
  idTileset | tileset id.
  idTile | which tile inside the tileset must be rendered.
  idRes | a 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

  idRes | ID of the resource (Image or Tile) loaded in memory.
  globalID | Initial 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

  sCDCFile | Path to the CDC archive.
  sResourceName | Name of the resource inside the CDC.
  globalID | Initial 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

  sPath | Path to the image file.
  globalID | Initial Global ID for this TileSet. Use -1 to auto-assign the first available ID.
  iTileWidth | Optional tile width override.
  iTileHeight | Optional 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

  iTN | Global 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

  iTN | Global 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

  iTN | Global 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

  iTN | Global ID of the TileSet.
  eMode | Output storage mode (Disk, CDC, or Internal).
  sPath | Output path or CDC archive name.
  sFilename | Output 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

  iTN | Global ID of the TileSet.
  eMode | Storage mode (Disk, CDC, or Internal).
  sPath | Path or CDC archive name.
  sFilename | TSX or image filename.

Returns
  true on success or false on failure.