2012-01-29 11:28:19 -08:00
|
|
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
2011-12-26 12:57:12 -08:00
|
|
|
|
#include "cSandSimulator.h"
|
|
|
|
|
#include "cWorld.h"
|
|
|
|
|
#include "Vector3i.h"
|
|
|
|
|
#include "BlockID.h"
|
|
|
|
|
#include "Defines.h"
|
2012-01-29 11:28:19 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-26 12:57:12 -08:00
|
|
|
|
|
|
|
|
|
cSandSimulator::cSandSimulator( cWorld* a_World )
|
|
|
|
|
: cSimulator(a_World)
|
2012-02-14 04:23:02 -08:00
|
|
|
|
, m_Blocks(new BlockList)
|
|
|
|
|
, m_Buffer(new BlockList)
|
2011-12-26 12:57:12 -08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cSandSimulator::~cSandSimulator()
|
|
|
|
|
{
|
|
|
|
|
delete m_Buffer;
|
|
|
|
|
delete m_Blocks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cSandSimulator::Simulate( float a_Dt )
|
|
|
|
|
{
|
|
|
|
|
m_Buffer->clear();
|
|
|
|
|
std::swap( m_Blocks, m_Buffer );
|
|
|
|
|
|
2012-02-14 04:23:02 -08:00
|
|
|
|
for( BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
|
2011-12-26 12:57:12 -08:00
|
|
|
|
{
|
2012-02-14 04:23:02 -08:00
|
|
|
|
Vector3i Pos = *itr;
|
|
|
|
|
char BlockID = m_World->GetBlock(Pos.x, Pos.y, Pos.z);
|
2011-12-26 12:57:12 -08:00
|
|
|
|
if(!IsAllowedBlock(BlockID))
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-02-14 04:23:02 -08:00
|
|
|
|
char BottomBlock = m_World->GetBlock( Pos.x, Pos.y - 1, Pos.z );
|
2011-12-26 12:57:12 -08:00
|
|
|
|
|
|
|
|
|
if( IsPassable(BottomBlock) )
|
|
|
|
|
{
|
2012-02-14 04:23:02 -08:00
|
|
|
|
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 );
|
2011-12-26 12:57:12 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cSandSimulator::IsAllowedBlock( char a_BlockID )
|
|
|
|
|
{
|
|
|
|
|
return a_BlockID == E_BLOCK_SAND
|
|
|
|
|
|| a_BlockID == E_BLOCK_GRAVEL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z)
|
|
|
|
|
{
|
2011-12-27 18:38:00 -08:00
|
|
|
|
if(!IsAllowedBlock(m_World->GetBlock(a_X, a_Y, a_Z))) //This should save very much time because it doesn<73>t have to iterate through all blocks
|
|
|
|
|
return;
|
|
|
|
|
|
2012-02-14 04:23:02 -08:00
|
|
|
|
Vector3i Block(a_X, a_Y, a_Z);
|
2011-12-26 12:57:12 -08:00
|
|
|
|
|
|
|
|
|
//check for duplicates
|
2012-02-14 04:23:02 -08:00
|
|
|
|
for( BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr )
|
2011-12-26 12:57:12 -08:00
|
|
|
|
{
|
2012-02-14 04:23:02 -08:00
|
|
|
|
Vector3i Pos = *itr;
|
|
|
|
|
if( Pos.x == a_X && Pos.y == a_Y && Pos.z == a_Z )
|
2011-12-26 12:57:12 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_Blocks->push_back(Block);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool cSandSimulator::IsPassable( char a_BlockID )
|
|
|
|
|
{
|
|
|
|
|
return a_BlockID == E_BLOCK_AIR
|
|
|
|
|
|| IsBlockWater(a_BlockID)
|
2011-12-29 14:55:25 -08:00
|
|
|
|
|| IsBlockLava(a_BlockID)
|
|
|
|
|
|| a_BlockID == E_BLOCK_FIRE;
|
2011-12-26 12:57:12 -08:00
|
|
|
|
|
2011-12-28 13:35:43 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cSandSimulator::WakeUp( int a_X, int a_Y, int a_Z )
|
|
|
|
|
{
|
|
|
|
|
//Nothing else needs to be simulated :D (Bugs not included :s)
|
|
|
|
|
AddBlock( a_X, a_Y+1, a_Z );
|
|
|
|
|
AddBlock( a_X, a_Y, a_Z );
|
|
|
|
|
}
|