2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "SandSimulator.h"
|
|
|
|
#include "World.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
#include "Vector3i.h"
|
|
|
|
#include "BlockID.h"
|
|
|
|
#include "Defines.h"
|
2012-09-30 12:37:44 -04:00
|
|
|
#include "FallingBlock.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cSandSimulator::cSandSimulator( cWorld* a_World )
|
|
|
|
: cSimulator(a_World)
|
|
|
|
, m_Blocks(new BlockList)
|
|
|
|
, m_Buffer(new BlockList)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cSandSimulator::~cSandSimulator()
|
|
|
|
{
|
|
|
|
delete m_Buffer;
|
|
|
|
delete m_Blocks;
|
|
|
|
}
|
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
void cSandSimulator::Simulate( float a_Dt )
|
|
|
|
{
|
|
|
|
m_Buffer->clear();
|
|
|
|
std::swap( m_Blocks, m_Buffer );
|
|
|
|
|
|
|
|
for( BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
|
|
|
|
{
|
|
|
|
Vector3i Pos = *itr;
|
2012-09-30 12:37:44 -04:00
|
|
|
BLOCKTYPE BlockID = m_World->GetBlock(Pos.x, Pos.y, Pos.z);
|
2012-06-14 09:06:06 -04:00
|
|
|
if(!IsAllowedBlock(BlockID))
|
|
|
|
continue;
|
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
BLOCKTYPE BottomBlock = m_World->GetBlock( Pos.x, Pos.y - 1, Pos.z );
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
if( IsPassable(BottomBlock) )
|
|
|
|
{
|
2012-09-30 12:37:44 -04:00
|
|
|
cFallingBlock * FallingBlock = new cFallingBlock( Pos, BlockID );
|
|
|
|
FallingBlock->Initialize( m_World );
|
|
|
|
m_World->SetBlock( Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0 );
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cSandSimulator::IsAllowedBlock( BLOCKTYPE a_BlockID )
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return a_BlockID == E_BLOCK_SAND
|
|
|
|
|| a_BlockID == E_BLOCK_GRAVEL;
|
|
|
|
}
|
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z)
|
|
|
|
{
|
2012-09-30 12:37:44 -04:00
|
|
|
if(!IsAllowedBlock(m_World->GetBlock(a_X, a_Y, a_Z)))
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
Vector3i Block(a_X, a_Y, a_Z);
|
|
|
|
|
|
|
|
//check for duplicates
|
|
|
|
for( BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr )
|
|
|
|
{
|
|
|
|
Vector3i Pos = *itr;
|
|
|
|
if( Pos.x == a_X && Pos.y == a_Y && Pos.z == a_Z )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Blocks->push_back(Block);
|
|
|
|
}
|
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cSandSimulator::IsPassable( BLOCKTYPE a_BlockID )
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return a_BlockID == E_BLOCK_AIR
|
|
|
|
|| IsBlockWater(a_BlockID)
|
|
|
|
|| IsBlockLava(a_BlockID)
|
|
|
|
|| a_BlockID == E_BLOCK_FIRE;
|
|
|
|
}
|