CRM64Pro GDK v0.11.0
A free cross-platform game development kit built on top of SDL 3.0
Loading...
Searching...
No Matches
Classes | Functions
TileEngine MapData extension

Detailed Description

v1.00 (24 February 2017)
Data definition used by the TileEngine objects as the way of updating and rendering the layers.

TE_MapData is the abstract class that define base components of a layer. TE_MapBase is a derivated class from TE_MapData that implements all required methods for creating a layer.
It could be further derivated to a custom class for representing customized layers.

Todo:
an example?

Classes

class  CRM64Pro::TE_MapData
 MapData abstract class definition. More...
 
class  CRM64Pro::TE_MapBase
 MapBase class. Minimum mapdata to be used with the TileEngine. Inherit from it your own custom MapData. More...
 

Functions

template<typename T >
T ** CRM64Pro::TE_MapData::create2DArray (Sint32 height, Sint32 width)
 Template: dynamic 2D array of a given data type.
 
template<typename T >
Sint32 CRM64Pro::TE_MapData::delete2DArray (T **Array)
 Template: delete a dynamic 2D array.
 
Sint32 CRM64Pro::TE_MapData::getMapType (string &sMT)
 Get map type.
 
Sint32 CRM64Pro::TE_MapData::getCellWidth ()
 Get cell width.
 
Sint32 CRM64Pro::TE_MapData::setCellWidth (Sint32 size)
 Set cell width.
 
Sint32 CRM64Pro::TE_MapData::getCellHeight ()
 Get cell height.
 
Sint32 CRM64Pro::TE_MapData::setCellHeight (Sint32 size)
 Set tile height.
 
Sint32 CRM64Pro::TE_MapData::getMapWidth ()
 Get map width.
 
Sint32 CRM64Pro::TE_MapData::getMapHeight ()
 Get map height.
 
 CRM64Pro::TE_MapBase::TE_MapBase ()
 MapBase default constructor.
 
 CRM64Pro::TE_MapBase::TE_MapBase (Sint32 height, Sint32 width)
 MapBase mandatory constructor.
 
 CRM64Pro::TE_MapBase::~TE_MapBase ()
 MapBase destructor.
 
static TE_MapBaseCRM64Pro::TE_MapBase::createInstance (Sint32 height, Sint32 width)
 Create an instance of this class.
 
Sint32 CRM64Pro::TE_MapBase::checkMap ()
 Map validation.
 
Sint32 CRM64Pro::TE_MapBase::info (Sint8, eLogMessageLevel eLML)
 Request MapBase object information.
 
Sint32 CRM64Pro::TE_MapBase::cellUpdate (Sint32, Sint32, void *, void *)
 Update a cell.
 
Sint32 CRM64Pro::TE_MapBase::cellRender (Sint32, Sint32, Sint32, Sint32, Sint32, Sint32, Sint32, Sint32)
 Render a cell.
 
Sint32 CRM64Pro::TE_MapBase::saveMapdataNode (Sint32 idXML, Sint32 iOutput)
 Save the mapdata base type to a XML node of a TEL or TMX file.
 
Sint32 CRM64Pro::TE_MapBase::loadMapdataNode (Sint32 idXML, Sint32 iInput)
 Load the mapdata base type from a node inside a TEL or TMX file.
 
Sint32 CRM64Pro::TE_MapBase::createMapBase (Sint32 height, Sint32 width, Sint16 value=-1)
 Create the 2D array for the tiles allocation(mapbase).
 
Sint32 CRM64Pro::TE_MapBase::deleteMapBase ()
 Delete the 2D array(mapbase).
 
Sint32 CRM64Pro::TE_MapBase::setMapBaseValue (Sint32 y, Sint32 x, Sint16 value)
 Set arbitrary values on 2D array(mapbase).
 
Sint32 CRM64Pro::TE_MapBase::cloneMapBase (TE_MapBase *)
 Copy the current values of the 2D array iTilemap to the given MapBase.
 
Sint32 CRM64Pro::TE_MapBase::A2DtoCSV (Uint32 **Array2D, Sint32 w, Sint32 h, char *&szOutput)
 Convert a 2D integers array to a CSV formatted string (SerializeOut).
 
Sint32 CRM64Pro::TE_MapBase::CSVtoA2D (Uint32 **Array2D, Sint32 w, Sint32 h, const string &sInput)
 Convert a CSV formatted string to a 2D integers array (SerializeIn).
 
Sint32 CRM64Pro::TE_MapBase::stringtoA2D (Uint32 **Array2D, Sint32 w, Sint32 h, const char *szInput)
 Convert a string to a 2D integers array (SerializeIn).
 

Function Documentation

◆ create2DArray()

template<typename T >
T ** CRM64Pro::TE_MapData::create2DArray ( Sint32  height,
Sint32  width 
)

Template: dynamic 2D array of a given data type.

Parameters
heightSelected height of your 2D array
widthSelected width of your 2D array
Returns
A Pointer to the dynamic 2D array

◆ delete2DArray()

template<typename T >
Sint32 CRM64Pro::TE_MapData::delete2DArray ( T **  Array)

Template: delete a dynamic 2D array.

Parameters
Arraypointer to 2D array.
Returns
0 on success.

◆ getMapType()

Sint32 CRM64Pro::TE_MapData::getMapType ( string &  sMT)

Get map type.

Parameters
sMTstring to be filled in with the map type.
Returns
0 on success or a negative error code on failure.

◆ getCellWidth()

Sint32 CRM64Pro::TE_MapData::getCellWidth ( )

Get cell width.

Returns
integer with the cell width (in pixels).

◆ setCellWidth()

Sint32 CRM64Pro::TE_MapData::setCellWidth ( Sint32  size)

Set cell width.

Parameters
sizeinteger with cell width (in pixels).
Returns
0 on success or a negative error code on failure.

◆ getCellHeight()

Sint32 CRM64Pro::TE_MapData::getCellHeight ( )

Get cell height.

Returns
integer with the cell height (in pixels).

◆ setCellHeight()

Sint32 CRM64Pro::TE_MapData::setCellHeight ( Sint32  size)

Set tile height.

Parameters
sizeinteger with cell height (in pixels).
Returns
0 on success or a negative error code on failure.

◆ getMapWidth()

Sint32 CRM64Pro::TE_MapData::getMapWidth ( )

Get map width.

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

◆ getMapHeight()

Sint32 CRM64Pro::TE_MapData::getMapHeight ( )

Get map height.

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

◆ TE_MapBase()

CRM64Pro::TE_MapBase::TE_MapBase ( Sint32  height,
Sint32  width 
)

MapBase mandatory constructor.

It will create a 2D array for the cells allocation. Each element on this 2D array is a cell.
When you inherit from TE_MapBase to create a custom map you HAVE TO create a constructor to overload
this one but do not forget to call this mandatory constructor from your own constructor.

Parameters
heightSelected height of your map. 0 avoid the iTilemap creation.
widthSelected width of your map. 0 avoid the iTilemap creation.

◆ createInstance()

TE_MapBase * CRM64Pro::TE_MapBase::createInstance ( Sint32  y,
Sint32  x 
)
static

Create an instance of this class.

When you inherit from TE_MapBase to create a custom map you HAVE TO create a method to overload
this one creating an instance of your own derivated class. This is mandatory.

Parameters
yValue to be passed to the mandatory constructor.
xValue to be passed to the mandatory constructor.
Returns
A TE_MapBase pointer to the created instance.

◆ checkMap()

Sint32 CRM64Pro::TE_MapBase::checkMap ( )
virtual

Map validation.

It validates the iTilemap 2D array(mapbase):

  • If there is any <0, it will print info with the error
  • Check the mapbase width and height
  • Check the mapbase cell width and height

When you use custom mapdata (inherit from TE_MapBase), you can overload this method to check your custom mapdata but you must call first this method.

Returns
0 on success or a negative error code on failure.

Implements CRM64Pro::TE_MapData.

◆ info()

Sint32 CRM64Pro::TE_MapBase::info ( Sint8  bTilesetReady,
eLogMessageLevel  eLML 
)
virtual

Request MapBase object information.

For displaying the information, it uses the default log.
When you use custom mapdata (inherit from TE_MapBase), you can overload this method to show your custom information but you should call first this method.

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

Implements CRM64Pro::TE_MapData.

◆ cellUpdate()

Sint32 CRM64Pro::TE_MapBase::cellUpdate ( Sint32  x_cell,
Sint32  y_cell,
void *  v1,
void *  v2 
)
inlinevirtual

Update a cell.

When you inherit from TE_MapBase to create a custom mapdata you could overload this method to execute your own updating code.
This method does not perform any action in the base mapdata level.

Parameters
x_cellCell X coordinate to be updated.
y_cellCell y coordinate to be updated.
v1Pointer to an user defined data value or structure.
v2Pointer to an user defined data value or structure.
Returns
0 on success or a negative error code on failure.

Implements CRM64Pro::TE_MapData.

◆ cellRender()

Sint32 CRM64Pro::TE_MapBase::cellRender ( Sint32  x_cell,
Sint32  y_cell,
Sint32  x_dst,
Sint32  y_dst,
Sint32  iAlpha,
Sint32  idTileset,
Sint32  idTile,
Sint32  idRes 
)
inlinevirtual

Render a cell.

When you inherit from TE_MapBase to create a custom mapdata you could overload this method to execute your own rendering code. Additionally, you must call this method in order to render the base mapdata
We support rendering tiles with different size to the underlying cells: larger tiles will extend at the top and right.

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.

Implements CRM64Pro::TE_MapData.

◆ saveMapdataNode()

Sint32 CRM64Pro::TE_MapBase::saveMapdataNode ( Sint32  idXML,
Sint32  iOutput 
)
virtual

Save the mapdata base type to a XML node of a TEL or TMX file.

When you use custom mapdata (inherit from TE_MapBase), you can overload this method to save your custom mapdata but you must call first this method.

Parameters
idXMLid of an opened XML with the pointer inside a layer subnode.
iOutputinteger with 0 for TEL or 1 for TMX files.
Returns
0 on success or a negative error code on failure.

Implements CRM64Pro::TE_MapData.

◆ loadMapdataNode()

Sint32 CRM64Pro::TE_MapBase::loadMapdataNode ( Sint32  idXML,
Sint32  iInput 
)
virtual

Load the mapdata base type from a node inside a TEL or TMX file.

When you use custom mapdata (inherit from TE_MapBase), you can overload this method to load your custom mapdata and you must not call this method.

Parameters
idXMLid of an opened XML with the pointer inside a mapdata/data subnode.
iInputinteger with 0 for TEL or 1 for TMX files.
Returns
0 on success or a negative error code on failure.

Implements CRM64Pro::TE_MapData.

◆ createMapBase()

Sint32 CRM64Pro::TE_MapBase::createMapBase ( Sint32  height,
Sint32  width,
Sint16  value = -1 
)

Create the 2D array for the tiles allocation(mapbase).

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
0 on success or a negative error code on failure.

◆ deleteMapBase()

Sint32 CRM64Pro::TE_MapBase::deleteMapBase ( )

Delete the 2D array(mapbase).

Returns
0 on success or a negative error code on failure.

◆ setMapBaseValue()

Sint32 CRM64Pro::TE_MapBase::setMapBaseValue ( Sint32  y,
Sint32  x,
Sint16  value 
)

Set arbitrary values on 2D array(mapbase).

It is mainly used creating manual maps

Parameters
ySelected Y position. -1 to affect the whole axis.
xSelected X position. -1 to affect the whole axis.
valueThe value to be set on the given position.
Returns
0 on success or a negative error code on failure.

◆ cloneMapBase()

Sint32 CRM64Pro::TE_MapBase::cloneMapBase ( TE_MapBase dest)

Copy the current values of the 2D array iTilemap to the given MapBase.

The destination must have identical attributes (iMapWidth and iMapHeight). If the destination has not an iTilemap we will create one identical to the source

Parameters
destPointer to destination TE_MapBase or derivated object.
Returns
0 on success or a negative error code on failure.

◆ A2DtoCSV()

Sint32 CRM64Pro::TE_MapBase::A2DtoCSV ( Uint32 **  Array2D,
Sint32  w,
Sint32  h,
char *&  szOutput 
)
protected

Convert a 2D integers array to a CSV formatted string (SerializeOut).

Parameters
Array2D2D array to be parsed.
wwidth of the 2D array.
hheight of the 2D array.
szOutputPointer to the output string with the integers in CSV format.
Returns
0 on success or a negative error code on failure.
Note
On successfully calls to this method, a memory allocation for szOutput is done, so once you finish, please remove it using _C64_FREE macro.

◆ CSVtoA2D()

Sint32 CRM64Pro::TE_MapBase::CSVtoA2D ( Uint32 **  Array2D,
Sint32  w,
Sint32  h,
const string &  sInput 
)
protected

Convert a CSV formatted string to a 2D integers array (SerializeIn).

Parameters
Array2Ddestination 2D array of the parsed integers.
wwidth of the 2D array.
hheight of the 2D array.
sInputstring with the the integers in CSV format.
Returns
0 on success or a negative error code on failure.

◆ stringtoA2D()

Sint32 CRM64Pro::TE_MapBase::stringtoA2D ( Uint32 **  Array2D,
Sint32  w,
Sint32  h,
const char *  szInput 
)
protected

Convert a string to a 2D integers array (SerializeIn).

Parameters
Array2Ddestination 2D array of the parsed integers.
wwidth of the 2D array.
hheight of the 2D array.
szInputPointer to the input string.
Returns
0 on success or a negative error code on failure.