Contents
[ hide ]
This page describes KGE coding style that every developers have to know these rules and obey them.
Const
Use const keyword right.
For more info about const read this or this
Working with memory
You have to use KGE_NEW and KGE_DELETE macros instead of new and delete. When you use these macros KGE can track memory for memory leakage and it uses nedmalloc to allocate memory which is very faster than normal new and delete.
Example
class test
{
public:
test(int i) {kge::io::Logger::Debug("test constructor %d", i);}
~test() {kge::io::Logger::Debug("test destructor");}
int a,b,c,d,r;
};
int main()
{
kge::io::Logger log;
test* t = KGE_NEW(test)(5);
test* r = KGE_NEW(test)(57);
KGE_DELETE(t, test);
KGE_DELETE(r, test);
getchar();
return 0;
}
A class declaration sample
#ifndef KGE_DEVICE_H
#define KGE_DEVICE_H
#include "kgedef.h"
namespace kge
{
class KGE_API Device
{
public:
//! Constructor
Device();
//! Destructor
~Device();
//! Returns the Device object pointer.
static Device* GetSingletonPtr();
/** Initialize KGE with given parameters.
return: Returns true on success
param params: Initialize parameters
*/
bool Init(InitParameters params);
//! Run the KGE
bool Run();
}; // Device
} // kge
#endif // KGE_DEVICE_H
A class implementation sample
#include "../include/Device.h"
namespace kge
{
//------------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------------
Device::Device()
{
} // Constructor
//------------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------------
Device::~Device()
{
} // Destructor
//------------------------------------------------------------------------------------
// Returns the Device object pointer.
//------------------------------------------------------------------------------------
Device* Device::GetSingletonPtr()
{
static Device me;
return &me;
} // GetSingletonPtr
//------------------------------------------------------------------------------------
// Initialize KGE with given parameters
//------------------------------------------------------------------------------------
bool Device::Init(InitParameters params)
{
return false;
} // Init
//------------------------------------------------------------------------------------
// Run the KGE
//------------------------------------------------------------------------------------
bool Device::Run()
{
return false;
} // Run
} // kge