MSTE - MegaStorm Tile-based Engine  v1.10
 All Classes Functions Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
cMSTE_MapBase Class Reference

MapBase derivated class. More...

Inheritance diagram for cMSTE_MapBase:
cMSTE_MapData

Public Member Functions

int CellRender (int, int, int, int, cMSTE *TE, int)
 Render a cell. More...
 
int CellUpdate (int, int, cMSTE *TE, void *, void *)
 Update a cell. More...
 
int CheckMap ()
 Map validation. More...
 
int CloneMapBase (cMSTE_MapBase *)
 Copy the current values of the 2D array iTilemap to the given MapBase. More...
 
 cMSTE_MapBase ()
 MapBase default constructor.
 
 cMSTE_MapBase (int height, int width)
 MapBase mandatory constructor. More...
 
int CreateMapBase (int height, int width, short int value=-1)
 Create the 2D array for the tiles allocation(mapbase). More...
 
int DeleteMapBase ()
 Delete the 2D array(mapbase) More...
 
int LoadMapdataNode (int i, int iInput)
 Load the mapdata base type from a node inside a MSM or TMX file. More...
 
int PrintInfo (char, int)
 Print using ILogSystem some details of this mapdata. More...
 
int SaveMapdataNode (int i, int iOutput)
 Save the mapdata base type to a XML node of a MSM or TMX file. More...
 
int SetMapBaseValue (int y, int x, short int value)
 Set arbitrary values on 2D array(mapbase) More...
 
 ~cMSTE_MapBase ()
 MapBase destructor.
 
- Public Member Functions inherited from cMSTE_MapData
 cMSTE_MapData ()
 MapData constructor.
 
template<typename T >
T ** Create2DArray (int height, int width)
 Create a dynamic 2D array of a given data type. More...
 
template<typename T >
void Delete2DArray (T **Array)
 Delete a dynamic 2D array.
 
int GetCellHeight ()
 Get cell height. More...
 
int GetCellWidth ()
 Get cell width. More...
 
int GetMapHeight ()
 Get map height. More...
 
char * GetMapType ()
 Get map type. More...
 
int GetMapWidth ()
 Get map width. More...
 
void SetCellHeight (int size)
 Set tile height. More...
 
void SetCellWidth (int size)
 Set cell width. More...
 
virtual ~cMSTE_MapData ()
 MapData destructor.
 

Static Public Member Functions

static cMSTE_MapBasecreateInstance (int height, int width)
 Create an instance of this class. More...
 

Protected Member Functions

int A2DtoCSV (unsigned int **Array2D, int w, int h, char *&szOutput)
 Convert a 2D integers array to a CSV formatted string (SerializeOut) More...
 
int CSVtoA2D (unsigned int **Array2D, int w, int h, char *&szInput)
 Convert a CSV formatted string to a 2D integers array (SerializeIn) More...
 
int StringtoA2D (unsigned int **Array2D, int w, int h, char *&szInput)
 Convert a string to a 2D integers array (SerializeIn) More...
 

Detailed Description

MapBase derivated class.

This is a valid mapdata to be used with MSTE.
Inherit from it your own custom MapData class definition.

Examples:
Example01_Init.cpp, and Example04_Custom.cpp.

Constructor & Destructor Documentation

cMSTE_MapBase::cMSTE_MapBase ( int  height,
int  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 cMSTE_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.

Member Function Documentation

int cMSTE_MapBase::A2DtoCSV ( unsigned int **  Array2D,
int  w,
int  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 Failed
1 Succeed
int cMSTE_MapBase::CellRender ( int  x_cell,
int  y_cell,
int  x_dst,
int  y_dst,
cMSTE TE,
int  iAlpha 
)
virtual

Render a cell.

When you inherit from cMSTE_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
TEPointer to the TileEngine instance
iAlphaAlpha per-surface value for this layer. With 255, it will use the alpha per-surface of the used tilesets.
Returns
0 Failed
1 Succeed

Implements cMSTE_MapData.

Examples:
Example04_Custom.cpp.
int cMSTE_MapBase::CellUpdate ( int  x_cell,
int  y_cell,
cMSTE TE,
void *  v1,
void *  v2 
)
virtual

Update a cell.

When you inherit from cMSTE_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
TEPointer to the TileEngine instance
v1Pointer to an user defined data value or structure
v2Pointer to an user defined data value or structure
Returns
0 Failed
1 Succeed

Implements cMSTE_MapData.

int cMSTE_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 cMSTE_MapBase), you can overload this method to check your custom mapdata but you must call first this method.

Returns
0 Failed
1 Succeed

Implements cMSTE_MapData.

Examples:
Example01_Init.cpp, and Example04_Custom.cpp.
int cMSTE_MapBase::CloneMapBase ( cMSTE_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 cMSTE_MapBase or derivated object
Returns
0 Failed
1 Succeed
cMSTE_MapBase * cMSTE_MapBase::createInstance ( int  y,
int  x 
)
static

Create an instance of this class.

When you inherit from cMSTE_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 cMSTE_MapBase pointer to the created instance
Examples:
Example04_Custom.cpp.
int cMSTE_MapBase::CreateMapBase ( int  height,
int  width,
short int  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 Failed
1 Succeed
int cMSTE_MapBase::CSVtoA2D ( unsigned int **  Array2D,
int  w,
int  h,
char *&  szInput 
)
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
szInputPointer to the input string with the integers in CSV format.
Returns
0 Failed
1 Succeed
int cMSTE_MapBase::DeleteMapBase ( )

Delete the 2D array(mapbase)

Returns
0 Failed
1 Succeed
int cMSTE_MapBase::LoadMapdataNode ( int  idXML,
int  iInput 
)
virtual

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

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

Parameters
idXMLid of an opened XML file with the pointer inside a mapdata/data subnode
iInputinteger with 0 for MSM or 1 for TMX files.
Returns
0 Failed
1 Succeed

Implements cMSTE_MapData.

Examples:
Example04_Custom.cpp.
int cMSTE_MapBase::PrintInfo ( char  bTilesetReady,
int  iLogLevel 
)
virtual

Print using ILogSystem some details of this mapdata.

When you use custom mapdata (inherit from cMSTE_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
iLogLevelMSTE verbosity level
Returns
0 Failed
1 Succeed

Implements cMSTE_MapData.

Examples:
Example04_Custom.cpp.
int cMSTE_MapBase::SaveMapdataNode ( int  idXML,
int  iOutput 
)
virtual

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

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

Parameters
idXMLid of an opened XML file with the pointer inside a layer subnode
iOutputinteger with 0 for MSM or 1 for TMX files.
Returns
0 Failed
1 Succeed

Implements cMSTE_MapData.

Examples:
Example04_Custom.cpp.
int cMSTE_MapBase::SetMapBaseValue ( int  y,
int  x,
short int  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 Failed
1 Succeed
Examples:
Example01_Init.cpp.
int cMSTE_MapBase::StringtoA2D ( unsigned int **  Array2D,
int  w,
int  h,
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 Failed
1 Succeed

The documentation for this class was generated from the following files: