Developing CNep game is going to finished. so recently I decide to rewrite some part of engine which may cause to rewrite whole source code. at the first step I rewrite containers library. in this new version I change container structures to decrease template<> usage which make code ugly. use sampler to decrease allocation. implementing memory allocator is more easy and in some cases changeable during the code and finally implementing new memory allocator which uses stack memory and also some algorithms are changed to increase speed in some container.
Note that some new features are not designed for general purpose. there are many limitations to use them and must used with care. because those features are designed to develop game and most of capabilities are depend on needs of a game engine.
Here are some highlights :
Added math base functions to the library with some fast functions like :
float sx_sqrt_fast( const float x );
// return sine( x ) from table. maximum absolute error is 0.001f
float sx_sin_fast( const float x );
// return cosine( x ) from table. maximum absolute error is 0.001f
float sx_cos_fast( const float x );
// compute sine and cosine of the angle x in same time. maximum absolute error is 0.001f
void sx_sin_cos_fast( const float IN x, float& OUT s, float& OUT c);
and some useful conventional functions
MemManFixed::SetBuffer(void* buffer);
I can change the memory buffer of allocator by setting a new buffer. this feature is available only on fixed memory manager. it means that it’s suitable just for arrays and strings.
For example example I wanna change/fill an string in an structure. in this example when I set members of structure to the allocator, all string functions can be applied easily.
wchar path[256];
wchar name[64];
wchar type[32];
}
FileIfo fileInfo;
MemManFixed memTmp;
String strTmp( 0, &memTmp );
// extract file path from file name and copy that to fileInfo.path
memTmp.SetBuffer( &fileInfo.path );
strTmp = fileName;
strTmp.ExtractFilePath();
// extract name of the file and copy that to fileInfo.name
memTmp.SetBuffer( &fileInfo.name );
strTmp = fileName;
strTmp.ExtractFileName();
// extract file type and copy that to the fileInfo.type
memTmp.SetBuffer( &fileInfo.type );
strTmp = fileName;
strTmp.ExtractFileExtension();
MemManFixed_inline<memSizeInByte>
This memory manager use memory stack of functions. by the way this feature is available only on fixed memory manager. this means that it’s suitable just for arrays and strings.
In this example I try to collect some nodes from the scene manager. this will happens at each frame more that once at renderer , AI system & etc. implementing new Array class cause to calling allocation/deallocation. the other solution is declaring static array. the other solution is using memory stack with some limitation but fast and easy memory management.
example :
Array<Node*> nodes( 0, &tmpMem );
// collect nodes from the scene manager
g_engine->m_scene->GetNodesByFrustum( cameraFrustum, nodes );
for ( int i = 0; i < nodes.Count(); i++ )
{
// ... do something !
}
Finally although there are some changes like adding new functions, changing algorithms in the other stuff to increase performance and capabilities. but those still need optimize more and more. oh I forgot to say that I put away namespaces in c++. those things are not suitable for game programming and maybe not suitable at all !







