1
0

Fixed a (pretty big) memory leak in cSandSimulator

git-svn-id: http://mc-server.googlecode.com/svn/trunk@252 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
faketruth 2012-02-14 12:23:02 +00:00
parent 4f17362aeb
commit eaa17b6a84
2 changed files with 16 additions and 15 deletions

View File

@ -13,8 +13,8 @@
cSandSimulator::cSandSimulator( cWorld* a_World ) cSandSimulator::cSandSimulator( cWorld* a_World )
: cSimulator(a_World) : cSimulator(a_World)
, m_Blocks(new std::list <Vector3i *>) , m_Blocks(new BlockList)
, m_Buffer(new std::list <Vector3i *>) , m_Buffer(new BlockList)
{ {
} }
@ -30,19 +30,19 @@ void cSandSimulator::Simulate( float a_Dt )
m_Buffer->clear(); m_Buffer->clear();
std::swap( m_Blocks, m_Buffer ); std::swap( m_Blocks, m_Buffer );
for( std::list<Vector3i *>::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr ) for( BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
{ {
Vector3i *Pos = *itr; Vector3i Pos = *itr;
char BlockID = m_World->GetBlock(Pos->x, Pos->y, Pos->z); char BlockID = m_World->GetBlock(Pos.x, Pos.y, Pos.z);
if(!IsAllowedBlock(BlockID)) if(!IsAllowedBlock(BlockID))
continue; continue;
char BottomBlock = m_World->GetBlock( Pos->x, Pos->y - 1, Pos->z ); char BottomBlock = m_World->GetBlock( Pos.x, Pos.y - 1, Pos.z );
if( IsPassable(BottomBlock) ) if( IsPassable(BottomBlock) )
{ {
m_World->SetBlock( Pos->x, Pos->y, Pos->z, E_BLOCK_AIR, 0 ); m_World->SetBlock( Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0 );
m_World->SetBlock( Pos->x, Pos->y - 1, Pos->z, BlockID, 0 ); m_World->SetBlock( Pos.x, Pos.y - 1, Pos.z, BlockID, 0 );
} }
} }
@ -60,13 +60,13 @@ void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z)
if(!IsAllowedBlock(m_World->GetBlock(a_X, a_Y, a_Z))) //This should save very much time because it doesn´t have to iterate through all blocks if(!IsAllowedBlock(m_World->GetBlock(a_X, a_Y, a_Z))) //This should save very much time because it doesn´t have to iterate through all blocks
return; return;
Vector3i *Block = new Vector3i(a_X, a_Y, a_Z); Vector3i Block(a_X, a_Y, a_Z);
//check for duplicates //check for duplicates
for( std::list<Vector3i *>::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr ) for( BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr )
{ {
Vector3i *Pos = *itr; Vector3i Pos = *itr;
if( Pos->x == a_X && Pos->y == a_Y && Pos->z == a_Z ) if( Pos.x == a_X && Pos.y == a_Y && Pos.z == a_Z )
return; return;
} }

View File

@ -2,8 +2,8 @@
#include "cSimulator.h" #include "cSimulator.h"
#include "cBlockEntity.h" #include "cBlockEntity.h"
#include <list> #include <list>
#include "Vector3i.h"
class Vector3i;
class cWorld; class cWorld;
class cSandSimulator : public cSimulator class cSandSimulator : public cSimulator
{ {
@ -20,6 +20,7 @@ public:
protected: protected:
virtual void AddBlock(int a_X, int a_Y, int a_Z); virtual void AddBlock(int a_X, int a_Y, int a_Z);
std::list <Vector3i *> *m_Blocks; typedef std::list <Vector3i> BlockList;
std::list <Vector3i *> *m_Buffer; BlockList * m_Blocks;
BlockList * m_Buffer;
}; };