This is a simple definitions file that I use in my game engine, though this version was dumbed down for a 2D game engine I'll be working on.

Definitions.h

#ifndef w_Definitions
#define w_Definitions

#ifndef NULL
#define NULL 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#define NUKE(object)    { if(object)    { delete (object);      (object) = nullptr; } }
#define NUKE_ARRAY(object) { if(object) { delete[] (object);    (object) = nullptr; } }
#define RELEASE(object) { if(object)    { (object)->Release();   (object) = nullptr; } }

namespace _Warp
{
    typedef signed char s8;
    typedef unsigned char u8;
    typedef signed short s16;
    typedef unsigned short u16;
    typedef signed int s32;
    typedef unsigned int u32;
    typedef signed long long s64;
    typedef unsigned long long u64;

    typedef unsigned int Bool;
    typedef u8 Byte;

    typedef float Real32;
    typedef double Real64;
};
#endif

These are the base data types I use everywhere in my game. Instead of using the 1 byte bool, I use a custom defined Bool which is the size of an integer; when compiled for a 32 bit system will coincide with 4 byte alignment, and compiled for a 64bit platform will coincide with 8 byte alignment. For more information on byte alignment, check out this wikipedia article.

Some of the macros are also useful for memory management, specifically NUKE, NUKE_ARRAY, and RELEASE. RELEASE is used on things like DirectX objects: RELEASE(_d3dDevice); basically, if you can't tell, any object that has a function called Release can be used with this macro. It checks to see if the object is valid, releases it, and sets the pointer to NULL. NUKE works on object you create using the 'new' operator, and properly sets the pointer to NULL. For example, cleaning up a Vector3:

Vector3* pVect = new Vector3(0,1,0);
/* other code here */
NUKE(pVect); // pVect gets cleaned up and set to NULL, aka, it is now nuked. ;p

And NUKE_ARRAY is used similarly on an array that was dynamically allocated, using new.

Definitions.zip

Comments

There are no comments yet.

Next Post Previous Post