I compiled all my new 'safer' media commands into a single header, I hope somebody will find them useful! You can now say...
myObj = dbExLoadObject( "Graphics\myObj.dbo" );
And dbExLoadObject will auto fetch a free id for your object, AND warn you (via a popup window) if the object has trouble loading. There is a similar function for loading images, and a 'GetFreeId' function for most all the media types.
I also included my performance timer functions, since dbTimer() is the devil!
Enjoy!
//dbEx.h
/*
Extended dark sdk functions
*/
//common data types
#include <string>
//*****************
//PERFORMANCE TIMER
//*****************
bool perfAvailable;
double perfTimeFactor; //time scaling factor
//============
//INITIALIZE()
//============
//this must be called once to initialize dbExPerfTimer()
void initdbExPerfTimer( void ) {
LONGLONG perfFrq;
//determine if the performance timer is available
if ( QueryPerformanceFrequency( (LARGE_INTEGER*) &perfFrq ) ) {
perfAvailable = true;
perfTimeFactor = 1.0/perfFrq;
} else {
perfAvailable = false;
perfTimeFactor = 0.001;
}
} //end initdbExPerfTimer()
//===================
//PERFORMANCE TIMER()
//===================
//returns the current time (raw)
LONGLONG dbExPerfTimer( void ) {
LONGLONG currentTime;
//read the appropriate counter
if ( perfAvailable )
QueryPerformanceCounter( (LARGE_INTEGER*) ¤tTime );
else
currentTime = timeGetTime();
return currentTime;
} //end dbExPerfTimer()
//==========================
//PERFORMANCE TIMER SECOND()
//==========================
//returns the current time in seconds
double dbExPerfTimerSec( void ) {
LONGLONG currentTime;
//read the appropriate counter
if ( perfAvailable )
QueryPerformanceCounter( (LARGE_INTEGER*) ¤tTime );
else
currentTime = timeGetTime();
return currentTime*perfTimeFactor;
} //end dbExPerfTimerSec()
//=============================
//GET PERFORMANCE TIME FACTOR()
//=============================
double dbExGetPerfTimeFactor( void ) {
return perfTimeFactor;
} //end dbExGetPerfTimeFactor()
//***************
//MEDIA FUNCTIONS
//***************
//========
//OBJECT()
//========
int dbExGetFreeObj ( void ) {
for (int i = 1; i < 10000; i++) { if ( !dbObjectExist(i) ) return i; }
MessageBox(NULL,"dbExGetFreeObj() - no free objects!","Fatal Error!",MB_OK);
return 0;
} //end dbExGetFreeObj()
int dbExLoadObject ( std::string fileName ) {
int mediaId = dbExGetFreeObj();
if ( mediaId > 0 ) {
dbLoadObject( const_cast<char*>(fileName.c_str()), mediaId );
if ( !dbObjectExist( mediaId ) ) {
MessageBox(NULL,"dbExLoadObject() - load fail!","Fatal Error!",MB_OK);
} else {
return mediaId;
} //end if
} //end if
return 0;
} //end dbExLoadObject()
//=======
//IMAGE()
//=======
int dbExGetFreeImg ( void ) {
for (int i = 10; i < 10000; i++) { if ( !dbImageExist(i) ) return i; }
MessageBox(NULL,"dbExGetFreeImg() - no free images!","Fatal Error!",MB_OK);
return 0;
} //end dbExGetFreeImg()
int dbExLoadImage ( std::string fileName ) {
int mediaId = dbExGetFreeImg();
if ( mediaId > 0 ) {
dbLoadImage( const_cast<char*>(fileName.c_str()), mediaId );
if ( !dbImageExist( mediaId ) ) {
MessageBox(NULL,"dbExLoadImage() - load fail!","Fatal Error!",MB_OK);
} else {
return mediaId;
} //end if
} //end if
return 0;
} //end dbExLoadImage()
//========
//SPRITE()
//========
int dbExGetFreeSpr ( void ) {
for (int i = 1; i < 10000; i++) { if ( !dbSpriteExist(i) ) return i; }
MessageBox(NULL,"dbExGetFreeSpr() - no free sprites!","Fatal Error!",MB_OK);
return 0;
} //end dbExGetFreeSpr()
//======
//MESH()
//======
int dbExGetFreeMsh ( void ) {
for (int i = 1; i < 10000; i++) { if ( !dbMeshExist(i) ) return i; }
MessageBox(NULL,"dbExGetFreeMsh() - no free meshes!","Fatal Error!",MB_OK);
return 0;
} //end dbExGetFreeMsh()
//========
//MEMORY()
//========
int dbExGetFreeMem ( void ) {
for (int i = 1; i < 10000; i++) { if ( !dbMemblockExist(i) ) return i; }
MessageBox(NULL,"dbExGetFreeMem() - no free memblocks!","Fatal Error!",MB_OK);
return 0;
} //end dbExGetFreeMem()
//========
//CAMERA()
//========
//in the new patch well get a camera exists command, but this works ok
int dbExGetFreeCam ( void ) {
static int camCount = 0;
camCount++;
if ( camCount > 31 )
MessageBox(NULL,"dbExGetFreeCam() - no free cameras!","Fatal Error!",MB_OK);
else
return camCount;
return 0;
} //end dbExGetFreeCam()
All you need is zeal