CRM64Pro GDK v0.11.0
A free cross-platform game development kit built on top of SDL 3.0
|
v2.00 (23 June 2023)
The Tool interface provides some generic and useful methods.
Useful methods:
Only a single instance of the Tool interface exists which is created once Main is instantiated.
You can get a reference to this interface using Main::ITool() method.
Classes | |
class | CRM64Pro::Tool |
Tool class. More... | |
Macros | |
#define | TMBB_OK 1 |
#define | TMBB_CANCEL 2 |
#define | TMBB_YES 4 |
#define | TMBB_NO 8 |
Enumerations | |
enum | CRM64Pro::eToolMBT { CRM64Pro::TMBT_EMPTY = 0 , CRM64Pro::TMBT_ERROR = 1 , CRM64Pro::TMBT_WARNING = 2 , CRM64Pro::TMBT_INFO = 4 } |
Tool MessageBox type. More... | |
Functions | |
Sint32 | CRM64Pro::Tool::info (Sint32 iMode=0) |
Request Tool Interface information. | |
Uint32 | CRM64Pro::Tool::CRC32 (const void *pBuffer, size_t iSize, Uint32 iPreviousCRC32=0) |
CRC32 checksum of a memory buffer. | |
Uint32 | CRM64Pro::Tool::CRC32 (const string &sFile) |
CRC32 checksum of a file. | |
Uint32 | CRM64Pro::Tool::xxHash (const void *pBuffer, size_t iSize, Uint32 iSeed) |
xxHash 32bits checksum of a memory buffer. | |
void * | CRM64Pro::Tool::xxHashInit (Uint32 iSeed) |
Initialize xxHash 32bits for being used in multiple memory buffers. | |
Sint32 | CRM64Pro::Tool::xxHashUpdate (void *pState, const void *pBuffer, size_t iSize) |
Feed with a new memory buffer the xxHash 32bits. | |
Uint32 | CRM64Pro::Tool::xxHashDigest (void *pState) |
Get current xxHash 32bits checksum for the accumulative memory buffers. | |
Sint32 | CRM64Pro::Tool::xxHashEnd (void *pState) |
Finalize xxHash 32bits used in multiple memory buffers. | |
Sint32 | CRM64Pro::Tool::XOR (void *pSrc, size_t iSize, Uint8 cKey) |
XOR of a memory buffer by a key(8bits). | |
Sint32 | CRM64Pro::Tool::decodeBase64 (const string &sInput, string &sOutput, Uint32 iCleanInput=0) |
Decode a base64 string. | |
Sint32 | CRM64Pro::Tool::decompressZlib (const void *pCompressed, Sint32 iCompressedSize, void *pUncompressed, Sint32 iUncompressedSize) |
Decompress a zlib compressed data block. | |
void | CRM64Pro::Tool::randSeedMWC (Uint32 iSeed) |
Initializes the Multiply-with-carry(MWC) random number generator with a seed. | |
Uint32 | CRM64Pro::Tool::randMWC () |
Generates a random 32bits integer using Multiply-with-carry(MWC) algorithm. | |
double | CRM64Pro::Tool::randRealMWC () |
Generates a random 64bits real number using Multiply-with-carry(MWC) algorithm. | |
void | CRM64Pro::Tool::randSeedWELL (Uint32 iSeed, Uint32 *pSeedTable=nullptr) |
Initializes the WELL512 random number generator with a seed. | |
Uint32 | CRM64Pro::Tool::randWELL (Uint32 *pSeedState=nullptr, Uint32 *pSeedTable=nullptr) |
Generates a random 32bits integer using WELL512 algorithm. | |
double | CRM64Pro::Tool::randRealWELL (Uint32 *pSeedState=nullptr, Uint32 *pSeedTable=nullptr) |
Generates a random 64bits real number using WELL512 algorithm. | |
float | CRM64Pro::Tool::round (const float fNum) |
Round a float value. | |
double | CRM64Pro::Tool::round (const double dNum) |
Round a double value. | |
Sint32 | CRM64Pro::Tool::dirExists (const string &sPath) |
Check if a directory exists. | |
Sint32 | CRM64Pro::Tool::dirCreate (const string &sPath) |
Create a directory. | |
Sint32 | CRM64Pro::Tool::fileExists (const string &sPath) |
Check if a file exists. | |
Sint32 | CRM64Pro::Tool::fileRemove (const string &sPath) |
Remove a file. | |
Sint32 | CRM64Pro::Tool::fileGetAbsolutePath (const string &sPath, string &sAbsolutePath) |
Get the absolute path of a given relative path. | |
Sint32 | CRM64Pro::Tool::fileGetExePath (string &sPath) |
Get the executable path. | |
Sint32 | CRM64Pro::Tool::fileGetName (const string &sPath, string &sFileName) |
Get the filename. | |
Sint32 | CRM64Pro::Tool::fileGetDir (const string &sPath, string &sDirName) |
Get the directory. | |
Sint32 | CRM64Pro::Tool::fileGetExtension (const string &sPath, string &sExtensionName) |
Get the extension. | |
Sint32 | CRM64Pro::Tool::fileCheckExtension (const string &sPath, const string &sExt) |
Check if a filename contains a given extension. | |
Sint32 | CRM64Pro::Tool::fileOpenDialog (const string &sTitle, const char *szFilter, string &sSelectedFile) |
Create a native file open dialog. | |
Sint32 | CRM64Pro::Tool::fileSaveDialog (const string &sTitle, const char *szFilter, string &sSelectedFile) |
Create a native file save dialog. | |
Sint32 | CRM64Pro::Tool::messageBox (const string &sTitle, const string &sMsg, Uint32 iButtons=TMBB_OK, eToolMBT eTMBT=TMBT_INFO, Sint32 iTTL=0, Sint32 idCustomPanel=-1, Sint32 idScreen=-1) |
Create a messagebox. | |
Sint32 | CRM64Pro::Tool::szCopy (char *szDst, const char *szSrc, size_t iSize) |
Copy a string-zero avoiding buffer overflow. | |
Sint32 | CRM64Pro::Tool::getDateStamp (string &sString) |
Get current date+time stamp. | |
Sint32 | CRM64Pro::Tool::strCompare (const string &sOne, const string &sTwo) |
Case insensitive string comparation. | |
Sint32 | CRM64Pro::Tool::strToLowerCase (string &sString) |
Convert the string to lower case. | |
Sint32 | CRM64Pro::Tool::strToUpperCase (string &sString) |
Convert the string to upper case. | |
Sint32 | CRM64Pro::Tool::strTovStr (const string sString, const string sSplit, vector< string > &vString) |
Split a string into a vector of string given a split string. | |
Sint32 | CRM64Pro::Tool::strDecToInt (const string sString) |
Convert a given string with a number in decimal format to a Sint32 number. | |
Sint32 | CRM64Pro::Tool::intToStrDec (Sint32 iNum, string &sString) |
Convert a 32bits signed integer to a string in decimal format. | |
Sint32 | CRM64Pro::Tool::strHexToInt (const string sString) |
Convert a given string with a number in hexdecimal format to a Sint32 number. | |
Sint32 | CRM64Pro::Tool::intToStrHex (Sint32 iNum, string &sString) |
Convert a 32bits signed integer to a string in hexadecimal format. | |
Sint32 | CRM64Pro::Tool::vStrToFile (const vector< string > &vString, const string &sFileName) |
Save a vector<string> to a filename. | |
Sint32 | CRM64Pro::Tool::fileTovStr (vector< string > &vString, const string &sFileName) |
Load lines of a filename into a vector<string>. | |
#define TMBB_OK 1 |
MessageBox Button OK. 'iButtons' parameter in Tools::messageBox().
#define TMBB_CANCEL 2 |
MessageBox Button Cancel. 'iButtons' parameter in Tools::messageBox().
#define TMBB_YES 4 |
MessageBox Button Yes. 'iButtons' parameter in Tools::messageBox().
#define TMBB_NO 8 |
MessageBox Button No. 'iButtons' parameter in Tools::messageBox().
enum CRM64Pro::eToolMBT |
Tool MessageBox type.
Sint32 CRM64Pro::Tool::info | ( | Sint32 | iMode = 0 | ) |
Request Tool Interface information.
For displaying the information, it uses the default log.
iMode | unused for the time being. |
Uint32 CRM64Pro::Tool::CRC32 | ( | const void * | pBuffer, |
size_t | iSize, | ||
Uint32 | iPreviousCRC32 = 0 |
||
) |
CRC32 checksum of a memory buffer.
This algorithm take +-8 CPU cycles per byte.
pBuffer | pointer to the memory buffer. |
iSize | size in bytes of the memory buffer. |
iPreviousCRC32 | support for rolling mechanism: if you already have a memory buffer and its CRC32 checksum, then you can append new data and calculate the updated CRC32 but using your original value as a seed and just scanning through the appended data. By default, it is set to 0. |
Uint32 CRM64Pro::Tool::CRC32 | ( | const string & | sFile | ) |
CRC32 checksum of a file.
Internally, it calls to memory buffer CRC32() method.
sFile | string containing the [directory]+filename+[extension]. |
Uint32 CRM64Pro::Tool::xxHash | ( | const void * | pBuffer, |
size_t | iSize, | ||
Uint32 | iSeed | ||
) |
xxHash 32bits checksum of a memory buffer.
This algorithm is very fast(16x faster than CRC32) and close to the memory bandwidth limit.
pBuffer | pointer to the memory buffer. |
iSize | size in bytes of the memory buffer. |
iSeed | can be used to alter the result predictably. |
void * CRM64Pro::Tool::xxHashInit | ( | Uint32 | iSeed | ) |
Initialize xxHash 32bits for being used in multiple memory buffers.
iSeed | can be used to alter the result predictably. |
Sint32 CRM64Pro::Tool::xxHashUpdate | ( | void * | pState, |
const void * | pBuffer, | ||
size_t | iSize | ||
) |
Feed with a new memory buffer the xxHash 32bits.
pState | a void* state previously created by xxHashInit(). |
pBuffer | pointer to the memory buffer. |
iSize | size in bytes of the memory buffer. |
Uint32 CRM64Pro::Tool::xxHashDigest | ( | void * | pState | ) |
Get current xxHash 32bits checksum for the accumulative memory buffers.
pState | a void* state created by xxHashInit() and used on xxHashUpdate(). |
Sint32 CRM64Pro::Tool::xxHashEnd | ( | void * | pState | ) |
Finalize xxHash 32bits used in multiple memory buffers.
pState | a void* state created by xxHashInit(). |
Sint32 CRM64Pro::Tool::XOR | ( | void * | pSrc, |
size_t | iSize, | ||
Uint8 | cKey | ||
) |
XOR of a memory buffer by a key(8bits).
It can be used for simple encryption/decryption tasks.
pSrc | pointer to the memory buffer. |
iSize | size in bytes of the memory buffer. |
cKey | unsigned char value representing the key. |
Sint32 CRM64Pro::Tool::decodeBase64 | ( | const string & | sInput, |
string & | sOutput, | ||
Uint32 | iCleanInput = 0 |
||
) |
Decode a base64 string.
sInput | string containing the base64 encoded string. |
sOutput | string containing the decoded base64 string. |
iCleanInput | set to 1 for cleaning the sInput string of non base64 characters before to try to decode it. By default it is set to 0. |
Sint32 CRM64Pro::Tool::decompressZlib | ( | const void * | pCompressed, |
Sint32 | iCompressedSize, | ||
void * | pUncompressed, | ||
Sint32 | iUncompressedSize | ||
) |
Decompress a zlib compressed data block.
pCompressed | pointer to compressed data. |
iCompressedSize | compressed data buffer size. |
pUncompressed | pointer to the decompressed data. You must create this buffer and once done with it, free it. |
iUncompressedSize | uncompressed data buffer size. |
void CRM64Pro::Tool::randSeedMWC | ( | Uint32 | iSeed | ) |
Initializes the Multiply-with-carry(MWC) random number generator with a seed.
For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.
iSeed | any Uint32 from [0,4294967295] interval. |
Uint32 CRM64Pro::Tool::randMWC | ( | ) |
Generates a random 32bits integer using Multiply-with-carry(MWC) algorithm.
For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.
double CRM64Pro::Tool::randRealMWC | ( | ) |
Generates a random 64bits real number using Multiply-with-carry(MWC) algorithm.
For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.
void CRM64Pro::Tool::randSeedWELL | ( | Uint32 | iSeed, |
Uint32 * | pSeed = nullptr |
||
) |
Initializes the WELL512 random number generator with a seed.
For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.
iSeed | any Uint32 from [0,4294967295] interval. |
pSeed | pointer to an array of 16 Uint32 for storing the seed output. By default it is set to nullptr for using an internal array. |
Uint32 CRM64Pro::Tool::randWELL | ( | Uint32 * | pState = nullptr , |
Uint32 * | pSeed = nullptr |
||
) |
Generates a random 32bits integer using WELL512 algorithm.
For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.
pState | pointer to an Uint32 containing the WELL512 algorithm state. By default it is set to nullptr for using an internal Uint32. |
pSeed | pointer to an array of 16 Uint32 containing the seed current status. By default it is set to nullptr for using an internal array. |
double CRM64Pro::Tool::randRealWELL | ( | Uint32 * | pState = nullptr , |
Uint32 * | pSeed = nullptr |
||
) |
Generates a random 64bits real number using WELL512 algorithm.
For further information, you can check the development blog entry on http://www.megastormsystems.com about PRNG algorithms.
pState | pointer to an Uint32 containing the WELL512 algorithm state. By default it is set to nullptr for using an internal Uint32. |
pSeed | pointer to an array of 16 Uint32 containing the seed current status. By default it is set to nullptr for using an internal array. |
float CRM64Pro::Tool::round | ( | const float | fNum | ) |
Round a float value.
fNum | float to be rounded |
double CRM64Pro::Tool::round | ( | const double | dNum | ) |
Round a double value.
dNum | double to be rounded |
Sint32 CRM64Pro::Tool::dirExists | ( | const string & | sPath | ) |
Check if a directory exists.
sPath | string containing the directory. Directory separators '\' and '/' are supported. |
Sint32 CRM64Pro::Tool::dirCreate | ( | const string & | sPath | ) |
Create a directory.
It extracts the directory, discards the filename and extension and try to create the directory.
Directory separators '\' and '/' are supported.
sPath | string containing the directory (e.g. myDir/, myDir/mySubDir). |
Sint32 CRM64Pro::Tool::fileExists | ( | const string & | sPath | ) |
Check if a file exists.
sPath | string containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
Sint32 CRM64Pro::Tool::fileRemove | ( | const string & | sPath | ) |
Remove a file.
sPath | string containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
Sint32 CRM64Pro::Tool::fileGetAbsolutePath | ( | const string & | sPath, |
string & | sAbsolutePath | ||
) |
Get the absolute path of a given relative path.
sPath | string containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
sAbsolutePath | a string variable with the absolute path. Will not be modified on error. |
Sint32 CRM64Pro::Tool::fileGetExePath | ( | string & | sPath | ) |
Get the executable path.
sPath | a string variable containing the full executable path. Will not be modified on error. |
Sint32 CRM64Pro::Tool::fileGetName | ( | const string & | sPath, |
string & | sFileName | ||
) |
Get the filename.
It removes the directory and extension if present and get only the filename.
sPath | string containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
sFileName | a string variable. Will not be modified on error. |
Sint32 CRM64Pro::Tool::fileGetDir | ( | const string & | sPath, |
string & | sDirName | ||
) |
Get the directory.
It removes the name and extension if present and get only the directory.
sPath | string containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
sDirName | a string variable. Will not be modified on error. |
Sint32 CRM64Pro::Tool::fileGetExtension | ( | const string & | sPath, |
string & | sExtensionName | ||
) |
Get the extension.
It removes the directory and name if present and get only the extension.
sPath | string containing the [directory]+filename+[extension]. |
sExtensionName | a string variable. Will not be modified on error. |
Sint32 CRM64Pro::Tool::fileCheckExtension | ( | const string & | sPath, |
const string & | sExt | ||
) |
Check if a filename contains a given extension.
sPath | string containing the [directory]+filename+[extension]. |
sExt | the extension to be checked. |
Sint32 CRM64Pro::Tool::fileOpenDialog | ( | const string & | sTitle, |
const char * | szFilter, | ||
string & | sSelectedFile | ||
) |
Create a native file open dialog.
sTitle | string containing dialog title. |
szFilter | pointer to a buffer containing pairs of nullptr-terminated filter strings. The first string in each pair is a display string that describes the filter (for example, "PNG Files"), and the second string specifies the filter pattern (for example, "*.png"). |
sSelectedFile | string to contain the directory+filename+extension of the selected file. |
Sint32 CRM64Pro::Tool::fileSaveDialog | ( | const string & | sTitle, |
const char * | szFilter, | ||
string & | sSelectedFile | ||
) |
Create a native file save dialog.
sTitle | string containing dialog title. |
szFilter | pointer to a buffer containing pairs of nullptr-terminated filter strings. The first string in each pair is a display string that describes the filter (for example, "PNG Files"), and the second string specifies the filter pattern (for example, "*.png"). |
sSelectedFile | string to contain the directory+filename+extension of the selected file. |
Sint32 CRM64Pro::Tool::messageBox | ( | const string & | sTitle, |
const string & | sMsg, | ||
Uint32 | iButtons = TMBB_OK , |
||
eToolMBT | eTMBT = TMBT_INFO , |
||
Sint32 | iTTL = 0 , |
||
Sint32 | idCustomPanel = -1 , |
||
Sint32 | idScreen = -1 |
||
) |
Create a messagebox.
sTitle | string containing the messagebox title. It can be an empty string. |
sMsg | string containing the messagebox body text. It can be an empty string. |
iButtons | Check TMBB_OK, TMBB_CANCEL, TMBB_YES and TMBB_NO for further information. You can OR'ed them. By default is set to TMBB_OK. |
eTMBT | messagebox type. Check eToolMBT enum for further information. By default is set to TMBT_INFO. |
iTTL | Time to live of this messagebox. If set to 0, it is a modal panel, otherwise, it is a modeless one that will last for the specified time in milliseconds. By default is set to 0. |
idCustomPanel | custom panel id to be used as the messagebox. By default is set to -1 for using an internal crafted messagebox panel. |
idScreen | screen id to attach the panel used when using the default internal messagebox panel. By default is set to -1 for using "default" screen. |
Sint32 CRM64Pro::Tool::szCopy | ( | char * | szDst, |
const char * | szSrc, | ||
size_t | iSize | ||
) |
Copy a string-zero avoiding buffer overflow.
It avoids buffer overflow and always appends a nullptr string termination.
szDst | destination char array of at least iSize size. |
szSrc | source char array of at least iSize size. |
iSize | maximum size of characters to copy. |
Sint32 CRM64Pro::Tool::getDateStamp | ( | string & | sString | ) |
Get current date+time stamp.
sString | string reference with the date+time stamp. |
Sint32 CRM64Pro::Tool::strCompare | ( | const string & | sOne, |
const string & | sTwo | ||
) |
Case insensitive string comparation.
sOne | string one. |
sTwo | string two. |
Sint32 CRM64Pro::Tool::strToLowerCase | ( | string & | sString | ) |
Convert the string to lower case.
sString | string to be converted. |
Sint32 CRM64Pro::Tool::strToUpperCase | ( | string & | sString | ) |
Convert the string to upper case.
sString | string to be converted. |
Sint32 CRM64Pro::Tool::strTovStr | ( | const string | sString, |
const string | sSplit, | ||
vector< string > & | vString | ||
) |
Split a string into a vector of string given a split string.
sString | original string to be split. |
sSplit | split string. |
vString | vector<string> to store split strings. |
Sint32 CRM64Pro::Tool::strDecToInt | ( | const string | sString | ) |
Convert a given string with a number in decimal format to a Sint32 number.
sString | string containing the number in decimal format. |
Sint32 CRM64Pro::Tool::intToStrDec | ( | Sint32 | iNum, |
string & | sString | ||
) |
Convert a 32bits signed integer to a string in decimal format.
iNum | integer number. |
sString | string to store the result. |
Sint32 CRM64Pro::Tool::strHexToInt | ( | const string | sString | ) |
Convert a given string with a number in hexdecimal format to a Sint32 number.
sString | string containing the number in hexadecimal format. It supports string starting with '0x', '#' or without any prefix. |
Sint32 CRM64Pro::Tool::intToStrHex | ( | Sint32 | iNum, |
string & | sString | ||
) |
Convert a 32bits signed integer to a string in hexadecimal format.
iNum | integer number. |
sString | string to store the result. |
Sint32 CRM64Pro::Tool::vStrToFile | ( | const vector< string > & | vString, |
const string & | sFileName | ||
) |
Save a vector<string> to a filename.
vString | vector<string> to be dumped into an external filename. Each string will be saved in a line. |
sFileName | a string variable with the output file name. |
Sint32 CRM64Pro::Tool::fileTovStr | ( | vector< string > & | vString, |
const string & | sFileName | ||
) |
Load lines of a filename into a vector<string>.
vString | vector<string> to be loaded with lines of the filename. |
sFileName | a string variable with the input file name. |