Added Mersenne Twister pseudo-random number generator ( really usefull and fast for some type of games if you want a deterministic random number generator ).

Reimplemented the tResourceManager, now uses std::list instead of std::map, and added some new methods.
cShapeGroupManager and cShapeGroup now inherits from tResourceManager.
Rolled back eeUint and eeInt, now are fine again ( it was changed for testing ).
This commit is contained in:
spartanj
2010-08-01 18:16:27 -03:00
parent 0a3d6e0728
commit 74e6eacd15
16 changed files with 463 additions and 271 deletions

View File

@@ -2,20 +2,13 @@
namespace EE { namespace Graphics {
cShapeGroup::cShapeGroup( const std::string& name, const Uint32& Allocate ) :
mCount(0)
cShapeGroup::cShapeGroup( const std::string& name ) :
tResourceManager<cShape> ( true )
{
Name( name );
this->Allocate( Allocate );
}
cShapeGroup::~cShapeGroup() {
Destroy();
}
void cShapeGroup::Destroy() {
for ( Uint32 i = 0; i < mShapes.size(); i++ )
RemoveAt(i);
}
const std::string& cShapeGroup::Name() const {
@@ -31,100 +24,8 @@ const Uint32& cShapeGroup::Id() const {
return mId;
}
void cShapeGroup::Allocate( const Uint32& Size ) {
if ( Size > mShapes.size() ) {
mShapes.resize( Size, NULL );
for ( eeUint i = 0; i < mShapes.size(); i++ )
mVectorFreeSlots.push( i );
}
}
Uint32 cShapeGroup::FindFreeSlot() {
if ( mVectorFreeSlots.size() ) {
Uint32 Pos = mVectorFreeSlots.front();
mVectorFreeSlots.pop();
return Pos;
}
mShapes.push_back( NULL );
return mShapes.size() - 1;
}
Uint32 cShapeGroup::GetIndex( const Uint32& Hash ) {
if ( 0 != Hash ) {
for ( Uint32 i = 0; i < mShapes.size(); i++ ) {
if ( NULL != mShapes[i] && mShapes[i]->Id() == Hash )
return i;
}
}
return SHAPE_NONE;
}
Uint32 cShapeGroup::GetIndex( const std::string& Name ) {
return GetIndex( MakeHash( Name ) );
}
cShape * cShapeGroup::GetAt( const Uint32& Index ) {
// assert here
return mShapes[ Index ];
}
cShape * cShapeGroup::GetById( const Uint32& Hash ) {
if ( 0 != Hash ) {
for ( Uint32 i = mShapes.size() - 1; i >= 0; i-- ) {
if ( NULL != mShapes[i] && mShapes[i]->Id() == Hash )
return mShapes[i];
}
}
return NULL;
}
cShape * cShapeGroup::GetByName( const std::string& Name ) {
return GetById( MakeHash( Name ) );
}
bool cShapeGroup::RemoveById( const Uint32& Hash ) {
Uint32 Pos = GetIndex( Hash );
if ( Pos != SHAPE_NONE )
return RemoveAt( Pos );
return false;
}
bool cShapeGroup::RemoveAt( const Uint32& Index ) {
if ( Index < mShapes.size() ) {
eeSAFE_DELETE( mShapes[ Index ] );
mVectorFreeSlots.push( Index );
mCount--;
return true;
}
return false;
}
bool cShapeGroup::RemoveByName( const std::string& Name ) {
return RemoveById( MakeHash( Name ) );
}
cShape * cShapeGroup::Add( cShape * Shape ) {
if ( NULL != Shape ) {
mShapes[ FindFreeSlot() ] = Shape;
mCount++;
}
return Shape;
return tResourceManager<cShape>::Add( Shape );
}
cShape * cShapeGroup::Add( const Uint32& TexId, const std::string& Name ) {
@@ -143,13 +44,4 @@ cShape * cShapeGroup::Add( const Uint32& TexId, const eeRecti& SrcRect, const ee
return Add( new cShape( TexId, SrcRect, DestWidth, DestHeight, OffsetX, OffsetY, Name ) );
}
void cShapeGroup::Clear() {
for ( Uint32 i = 0; i < mShapes.size(); i++ )
RemoveAt(i);
}
const Int32& cShapeGroup::Count() const {
return mCount;
}
}}