CRM32Pro_Main Class Reference
[MODULE 1: CRM32Pro main and generic functions (v2.3).]

CRM32Pro. More...


Detailed Description

CRM32Pro.

Main library interface.

List of all members.

Classes

struct  sConfig
 Main config struct.
You can manually fill it or using CRM32Pro.LoadConfig() loading an external XML. More...

Public Member Functions

void AudioInfo ()
 Uses ILogSystem to dump audio subsystem information.
int Blit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
 Perform a fast blit from source surface to the destination surface.
void CleanUp (void)
 Clean up update systems to avoid events and timing propagation.
unsigned int CRC32 (char *filename)
 Calculate CRC32 of given file.
unsigned int CRC32 (char *buffer, int Size)
 Calculate CRC32 of given buffer with given size.
void FreeSurface (SDL_Surface *&)
 Frees a SDL_Surface on a safe way. Use it instead SDL_FreeSurface() to avoid and to be aware of attempts to free a freed surface.
char * GetCopyright ()
 Get copyright string.
int GetKeystate (int keysym)
 Get current state of the given key.
float GetLogicTime ()
 Get current logic time.
char * GetVersion ()
 Get version string.
int Init (unsigned int flags)
 Initialize all internal systems and call to SDL_Init(flags)
Select optimized path depending on the CPU.
int IsGL ()
 Check if glSDL is enabled and running.
int LoadConfig (char *fileDPF, char *fileXML, sConfig *conf=NULL)
 Load the config stored on given XML.
int MakeDirectory (char *fullpath)
 Create a directory.
void PrintVersion ()
 Print version and compiled date to log system(ILogSystem).
void Quit (void)
 Close all internal systems and call to SDL_Quit().
Uint32 Rand ()
 Generates a random 32bits integer.
double RandReal ()
 Generates a random 32bits real number.
void RandSeed (unsigned int seed)
 Initializes random number generator with a seed.
int SaveConfig (char *fileDPF, char *fileXML, sConfig *conf=NULL)
 Save the given config to a DPF/XML.
void SetRenderCallback (void(*myRenderFunc)(int bLogicUpdate))
 Set a callback function to blit your graphics at Rendering Frame Rate.
int SetVideoMode (void)
 Setup selected video mode given by Config struct. It also try to assign an icon and a title.
int Surface2Texture (SDL_Surface *surf)
 Convert a surface into a texture. For OpenGL modes (glSDL).
void SurfaceInfo (SDL_Surface *surface)
 Uses ILogSystem to dump surface information.
int Update (SDL_Event *ev=NULL)
 Update all systems: graphics,events,timing...
void VideoInfo ()
 Uses ILogSystem to dump video subsystem information.
int XMLAttributeGet (int id, char *name, double *value)
 Get the double value of the given attribute.
int XMLAttributeGet (int id, char *name, int *value)
 Get the integer value of the given attribute.
int XMLAttributeGet (int id, char *name, char **value)
 Get the string value of the given attribute.
int XMLAttributeRemove (int id, char *name)
 Remove an attribute.
int XMLAttributeSet (int id, char *name, double value)
 Set a double value of a given attribute. If that attribute does not exist, a new one is created.
int XMLAttributeSet (int id, char *name, int value)
 Set an integer value of a given attribute. If that attribute does not exist, a new one is created.
int XMLAttributeSet (int id, char *name, char *value)
 Set a string value of a given attribute. If that attribute does not exist, a new one is created.
void XMLClose (int id)
 Close a given XML.
char * XMLCommentGet (int id)
 Return the first comment of current node(if any).
int XMLCommentRemove (int id)
 Remove the first comment contained on current node.
int XMLCommentSet (int id, char *value)
 Add a new comment to current node.
int XMLCreate (char *mainnode)
 Create a new XML document.
int XMLNodeChild (int id)
 Point to the first child node of the XML.
int XMLNodeCreate (int id, char *name)
 Create a new node on current pointer and set it as new current.
int XMLNodeFirst (int id)
 Point to the first node of the XML (the root node).
char * XMLNodeGetName (int id)
 Get the name of current node.
int XMLNodeNext (int id)
 Point to the next node of the XML.
int XMLNodeParent (int id)
 Point to the parent node of the XML.
int XMLNodePointTo (int id, int nparam, char *,...)
 Search and point to a given node or subnode of any level.
int XMLNodeRemove (int id)
 Remove current node pointed to and all its nodes and attributes.
int XMLNodeRename (int id, char *name)
 Rename current node pointed to.
int XMLOpen (int idDPF, char *blockname)
 Open a XML file stored on a DPF(idDPF).
int XMLOpen (char *fileDPF, char *blockname)
 Open a XML file stored on a DPF(using filename).
int XMLOpen (char *filename)
 Open a XML file.
int XMLSave (int id, int idDPF, char *blockname)
 Save a given XML to a DPF(using idDPF).
int XMLSave (int id, char *fileDPF, char *blockname)
 Save a given XML to a DPF(using filename).
int XMLSave (int id, char *filename)
 Save a given XML to external file.
char * XMLTextGet (int id)
 Return text contained on current node.
int XMLTextRemove (int id)
 Remove text contained on current node.
int XMLTextSet (int id, char *value)
 Add a new text to the existing text node(if any).

Public Attributes

struct CRM32Pro_Main::sConfig Config
 Main config struct.
You can manually fill it or using CRM32Pro.LoadConfig() loading an external XML.
Uint8 iAutoSurfRecovery
 Flag to set on/off auto surface recovery.It is automatically setup in DirectX hardware mode.
Uint32 iStartTime
 Store the start ticks(SDL_GetTicks()) when CRM32Pro was initialized.
Uint8 mouse_buttons
 Current state of mouse's buttons. Updated automatically in CRM32Pro.Update().
Used as a mask when testing mouse buttons, usually as follow:
-Left mouse button (CRM32PRO_BUTTON_LEFT)
-Middle mouse button (CRM32PRO_BUTTON_MIDDLE)
-Right mouse button (CRM32PRO_BUTTON_RIGHT)
It also stores buttons combinations.
Uint8 mouse_prevbuttons
 Previous state of mouse's buttons. Updated automatically in CRM32Pro.Update().
int mouse_x
 Mouse X position. Updated automatically.
int mouse_y
 Mouse Y position. Updated automatically.
SDL_Surface * screen
 Main screen surface. You always have to use it to blit your graphics.

Member Function Documentation

int CRM32Pro_Main::Blit ( SDL_Surface *  src,
SDL_Rect *  srcrect,
SDL_Surface *  dst,
SDL_Rect *  dstrect 
)

Perform a fast blit from source surface to the destination surface.

It can be used instead of SDL_BlitSurface() when your destination surface is CRM32Pro.screen as it supports built-in cursor system.

Parameters:
src source surface.
srcrect pointer to source rect or NULL to copy the entire surface.
dst destination surface.
dstrect pointer to destination rect or NULL to copy at (0,0).
Returns:
0 Error
Other values mean OK. See SDL_BlitSurface() return values to extend info.
Examples:
SpacePong.cpp.
unsigned int CRM32Pro_Main::CRC32 ( char *  fname  ) 

Calculate CRC32 of given file.

Parameters:
fname path and filename of the file to calculate its CRC32
Returns:
CRC32 of given file
unsigned int CRM32Pro_Main::CRC32 ( char *  buffer,
int  size 
)

Calculate CRC32 of given buffer with given size.

Parameters:
buffer pointer to buffer to calculate its CRC32
size size in bytes of given buffer
Returns:
CRC32 of given buffer
void CRM32Pro_Main::FreeSurface ( SDL_Surface *&  srf  ) 

Frees a SDL_Surface on a safe way. Use it instead SDL_FreeSurface() to avoid and to be aware of attempts to free a freed surface.

Parameters:
srf pointer to surface to be deleted.
Examples:
Example01_BasicCode.cpp, Example03_GUI.cpp, Example08_SpriteCollision.cpp, and Example09_LogicRenderRates.cpp.
int CRM32Pro_Main::GetKeystate ( int  keysym  ) 

Get current state of the given key.

Update() will automatically get a snapshot of the current keyboard state, and to access to that snapshot you can use this method.

Parameters:
keysym Desired key to get its state. Use the SDLK_xxx symbols defined on SDL_keysym.h.
Returns:
0 Key not pressed
1 Key pressed
Examples:
SpacePong.cpp.
float CRM32Pro_Main::GetLogicTime (  ) 

Get current logic time.

Internal setting.

int CRM32Pro_Main::IsGL (  ) 

Check if glSDL is enabled and running.

Returns:
0 glSDL disabled
1 glSDL enabled
Examples:
Example05_VideoPlayer.cpp, Example08_SpriteCollision.cpp, and Example09_LogicRenderRates.cpp.
int CRM32Pro_Main::LoadConfig ( char *  fileDPF,
char *  fileXML,
sConfig conf = NULL 
)

Load the config stored on given XML.

Parameters:
fileDPF DPF with the stored XML. NULL if it is not stored on a DPF(it is an external XML file). Supports optional paths.
fileXML External XML file name or name of the XML inside the DPF. Supports optional paths with the config settings.
conf Pointer to sConfig struct to store the settings. By default it is pointed to CRM32Pro.Config.
Returns:
0 Failed
1 Ok
Examples:
SpacePong.cpp.
int CRM32Pro_Main::MakeDirectory ( char *  fullpath  ) 

Create a directory.

It extract the path discarding the filename and extension.
Supports subdirectories using '\' or '/' as separators.

Parameters:
fullpath 
Returns:
0 Failed
1 Created or already existing
Uint32 CRM32Pro_Main::Rand (  ) 

Generates a random 32bits integer.

Returns:
randon integer from [0,4294967295] interval
double CRM32Pro_Main::RandReal (  ) 

Generates a random 32bits real number.

Returns:
random real from [0,1] interval
void CRM32Pro_Main::RandSeed ( unsigned int  seed  ) 

Initializes random number generator with a seed.

Parameters:
seed any unsigned integer from [0,4294967295] interval
int CRM32Pro_Main::SaveConfig ( char *  fileDPF,
char *  fileXML,
sConfig conf = NULL 
)

Save the given config to a DPF/XML.

Parameters:
fileDPF DPF filename to store the XML. NULL if it will store on an external XML file. Supports optional paths.
fileXML External XML file name or name of the XML to be stored on a DPF. Supports optional paths with the config settings.
conf Pointer to sConfig struct to read its settings. By default it is pointed to CRM32Pro.Config.
Returns:
0 Failed
1 Ok
void CRM32Pro_Main::SetRenderCallback ( void(*)(int bLogicUpdate)  myRenderFunc  ) 

Set a callback function to blit your graphics at Rendering Frame Rate.

Use NULL if you want to remove a previous callback function.
Instead of use this callback,you can also call to your graphics blitting function from loop events when you get an EVENT_LOGICWAIT type.
But you will get the best results using a callback function.

Parameters:
myRenderFunc pointer to your graphics blitting function. bLogicUpdate will be 1 after a logic update.
Examples:
Example08_SpriteCollision.cpp, Example09_LogicRenderRates.cpp, and SpacePong.cpp.
int CRM32Pro_Main::SetVideoMode ( void   ) 

Setup selected video mode given by Config struct. It also try to assign an icon and a title.

Note that the icon surface used will be internally removed.

Returns:
0 Error
1 OK and CRM32Pro.screen ready to use.
Examples:
Example01_BasicCode.cpp, Example03_GUI.cpp, Example05_VideoPlayer.cpp, Example08_SpriteCollision.cpp, Example09_LogicRenderRates.cpp, and SpacePong.cpp.
int CRM32Pro_Main::Surface2Texture ( SDL_Surface *  surf  ) 

Convert a surface into a texture. For OpenGL modes (glSDL).

If an arbitrary surface is loaded using external methods to CRM32Pro or the colorkey is modified, a good practice is to convert it to a texture at the loading time. Before to call to this method, a call to SDL_DisplayFormat() it is needed.

Returns:
0 No glSDL mode
1 Surface converted successfully
void CRM32Pro_Main::SurfaceInfo ( SDL_Surface *  surface  ) 

Uses ILogSystem to dump surface information.

Parameters:
surface surface to gather and print information
int CRM32Pro_Main::Update ( SDL_Event *  ev = NULL  ) 

Update all systems: graphics,events,timing...


It replaces to SDL_Flip() and SDL_PollEvent(). It updates cursor,buttons and all internal variables.
You can set Logical and Rendering frames rates using ITimeSystem. This method will delay the program execution to fit the Logical Frame Rate,
in addition, if you want to use the Rendering Frame Rate, you have to use SetRenderCallback() to set your graphics update function.
The right way to use in your code is:

- without events control: while(CRM32Pro.Update());

- with events control: while(CRM32Pro.Update(&event)) { your events handling code }

Parameters:
ev pointer to SDL_Event struct, by default is NULL.
Returns:
1 if there is a pending event
0 if there is not a pending event.
Examples:
Example01_BasicCode.cpp, Example03_GUI.cpp, Example08_SpriteCollision.cpp, Example09_LogicRenderRates.cpp, and SpacePong.cpp.
int CRM32Pro_Main::XMLAttributeGet ( int  id,
char *  name,
double *  value 
)

Get the double value of the given attribute.

Parameters:
id ID of the XML
name name of attribute
value pointer to double to get the value. Null if does not exist.
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLAttributeGet ( int  id,
char *  name,
int *  value 
)

Get the integer value of the given attribute.

Parameters:
id ID of the XML
name name of attribute
value pointer to int to get the value. Null if does not exist.
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLAttributeGet ( int  id,
char *  name,
char **  value 
)

Get the string value of the given attribute.

Parameters:
id ID of the XML
name name of attribute
value pointer to string to get the value. Null if does not exist.
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLAttributeRemove ( int  id,
char *  name 
)

Remove an attribute.

Parameters:
id ID of the XML
name name of attribute
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLAttributeSet ( int  id,
char *  name,
double  value 
)

Set a double value of a given attribute. If that attribute does not exist, a new one is created.

Parameters:
id ID of the XML
name name of attribute
value new double value of given attribute
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLAttributeSet ( int  id,
char *  name,
int  value 
)

Set an integer value of a given attribute. If that attribute does not exist, a new one is created.

Parameters:
id ID of the XML
name name of attribute
value new integer value of given attribute
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLAttributeSet ( int  id,
char *  name,
char *  value 
)

Set a string value of a given attribute. If that attribute does not exist, a new one is created.

Parameters:
id ID of the XML
name name of attribute
value new string value of given attribute
Returns:
0 Failed
1 Ok
void CRM32Pro_Main::XMLClose ( int  id  ) 

Close a given XML.

Parameters:
id ID of the XML
char * CRM32Pro_Main::XMLCommentGet ( int  id  ) 

Return the first comment of current node(if any).

Parameters:
id ID of the XML
Returns:
pointer to the comment or null if there is not any.
int CRM32Pro_Main::XMLCommentRemove ( int  id  ) 

Remove the first comment contained on current node.

If you want to remove all comments on a given node, call this method while you get 1 as returned value.

Parameters:
id ID of the XML
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLCommentSet ( int  id,
char *  value 
)

Add a new comment to current node.

If a comment already exists, it will be pushed down and the new comment will be the first one.

Parameters:
id ID of the XML
value string with desired comment
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLCreate ( char *  mainnode  ) 

Create a new XML document.

Parameters:
mainnode string with the name of the main node
Returns:
0 Error
any other value, the ID of the created XML
int CRM32Pro_Main::XMLNodeChild ( int  id  ) 

Point to the first child node of the XML.

It only changes the pointer if it can found a valid node.

Parameters:
id ID of the XML
Returns:
0 Failed
1 OK
int CRM32Pro_Main::XMLNodeCreate ( int  id,
char *  name 
)

Create a new node on current pointer and set it as new current.

Parameters:
id ID of the XML
name string with the name
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLNodeFirst ( int  id  ) 

Point to the first node of the XML (the root node).

It only changes the pointer if it can found a valid node.

Parameters:
id ID of the XML
Returns:
0 Failed
1 OK
char * CRM32Pro_Main::XMLNodeGetName ( int  id  ) 

Get the name of current node.

Parameters:
id ID of the XML
Returns:
name or null if there is not node selected.
int CRM32Pro_Main::XMLNodeNext ( int  id  ) 

Point to the next node of the XML.

It only changes the pointer if it can found a valid node.

Parameters:
id ID of the XML
Returns:
0 Failed
1 OK
int CRM32Pro_Main::XMLNodeParent ( int  id  ) 

Point to the parent node of the XML.

It only changes the pointer if it can found a valid node.

Parameters:
id ID of the XML
Returns:
0 Failed
1 OK
int CRM32Pro_Main::XMLNodePointTo ( int  id,
int  deep,
char *  element,
  ... 
)

Search and point to a given node or subnode of any level.

It only changes the pointer when all element given point to valid node.

Parameters:
id ID of the XML
deep number of parameters of 'element' given
element variable number of node/subnode
Returns:
0 Failed
1 OK
int CRM32Pro_Main::XMLNodeRemove ( int  id  ) 

Remove current node pointed to and all its nodes and attributes.

Parameters:
id ID of the XML
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLNodeRename ( int  id,
char *  name 
)

Rename current node pointed to.

Parameters:
id ID of the XML
name string with the new name
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLOpen ( int  idDPF,
char *  name 
)

Open a XML file stored on a DPF(idDPF).

To open a XML from a DPF, CRM32Pro must be initialized.

Parameters:
idDPF ID of the opened DPF
name name of the stored XML
Returns:
0 Error
any other value, the ID of the opened XML
int CRM32Pro_Main::XMLOpen ( char *  fileDPF,
char *  name 
)

Open a XML file stored on a DPF(using filename).

To open a XML from a DPF, CRM32Pro must be initialized.

Parameters:
fileDPF name of DPF file that contains to the XML
name name of the stored XML
Returns:
0 Error
any other value, the ID of the opened XML
int CRM32Pro_Main::XMLOpen ( char *  filename  ) 

Open a XML file.

Parameters:
filename name of XML file
Returns:
0 Error
any other value, the ID of the opened XML
int CRM32Pro_Main::XMLSave ( int  id,
int  idDPF,
char *  blockname 
)

Save a given XML to a DPF(using idDPF).

To save a XML in to a DPF, CRM32Pro must be initialized.
If an XML already exists, it will be replaced with the new one.

Parameters:
id ID of the XML
idDPF ID of the opened DPF
blockname name of the block to store the XML, ideally, it could terminate with .xml
Returns:
-1 XML already exists.
0 Failed.
any other positive value, Ok and packed size of the added XML
int CRM32Pro_Main::XMLSave ( int  id,
char *  fileDPF,
char *  blockname 
)

Save a given XML to a DPF(using filename).

To save a XML in to a DPF, CRM32Pro must be initialized.
If an XML already exists, it will be replaced with the new one.

Parameters:
id ID of the XML
fileDPF name of DPF to store the XML
blockname name of the block to store the XML, ideally, it could terminate with .xml
Returns:
-1 XML already exists.
0 Failed.
any other positive value, Ok and packed size of the added XML
int CRM32Pro_Main::XMLSave ( int  id,
char *  filename 
)

Save a given XML to external file.

Parameters:
id ID of the XML
filename name of file to store the XML
Returns:
0 Error
1 File saved successfully
char * CRM32Pro_Main::XMLTextGet ( int  id  ) 

Return text contained on current node.

Note that it only works in the first text block found:
<mynode>
  Text1 -> First text block
  Text2 -> First text block
  Text3 -> First text block
  <subnode>
    Text1 of Subnode
  </subnode>
  Text4 -> This is a second text block due to exist after a subnode
  Text5 -> This is a second text block due to exist after a subnode
</mynode>

Parameters:
id ID of the XML
Returns:
pointer to text or null if there is not text.
int CRM32Pro_Main::XMLTextRemove ( int  id  ) 

Remove text contained on current node.

Note that it only works in the first text block found:
<mynode>
  Text1 -> First text block
  Text2 -> First text block
  Text3 -> First text block
  <subnode>
    Text1 of Subnode
  </subnode>
  Text4 -> This is a second text block due to exist after a subnode
  Text5 -> This is a second text block due to exist after a subnode
</mynode>

Parameters:
id ID of the XML
Returns:
0 Failed
1 Ok
int CRM32Pro_Main::XMLTextSet ( int  id,
char *  value 
)

Add a new text to the existing text node(if any).

Note that it only works in the first text block found:
<mynode>
  Text1 -> First text block
  Text2 -> First text block
  Text3 -> First text block
  <subnode>
    Text1 of Subnode
  </subnode>
  Text4 -> This is a second text block due to exist after a subnode
  Text5 -> This is a second text block due to exist after a subnode
</mynode>

Parameters:
id ID of the XML
value string with desired text
Returns:
0 Failed
1 Ok

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

Generated on Mon Dec 21 17:04:40 2009 for CRM32Pro SDK v5.00 by  doxygen 1.6.1