From f7da7c2536b438db92bc28b88c4139d9af15e44f Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 13 Oct 2012 09:53:28 +0000 Subject: Preparation for multiple fluid simulators. Moved all simulators into a subfolder. Replaced cWaterSimulator and cLavaSimulator with a generic cFluidSimulator. Moved original fluid simulation into cClassicFluidSimulator. Fluid simulator parameters (MaxHeight, Falloff) are read from the world.ini file (can have nether-like lava with lower falloff) git-svn-id: http://mc-server.googlecode.com/svn/trunk@956 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Simulator/SandSimulator.cpp | 101 +++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 source/Simulator/SandSimulator.cpp (limited to 'source/Simulator/SandSimulator.cpp') diff --git a/source/Simulator/SandSimulator.cpp b/source/Simulator/SandSimulator.cpp new file mode 100644 index 000000000..69513afef --- /dev/null +++ b/source/Simulator/SandSimulator.cpp @@ -0,0 +1,101 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "SandSimulator.h" +#include "../World.h" +#include "../BlockID.h" +#include "../Defines.h" +#include "../FallingBlock.h" + + + + +cSandSimulator::cSandSimulator( cWorld* a_World ) + : cSimulator(a_World) + , m_Blocks(new BlockList) + , m_Buffer(new BlockList) +{ + +} + + + + + +cSandSimulator::~cSandSimulator() +{ + delete m_Buffer; + delete m_Blocks; +} + + + + + +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; + BLOCKTYPE BlockID = m_World->GetBlock(Pos.x, Pos.y, Pos.z); + if(!IsAllowedBlock(BlockID)) + continue; + + BLOCKTYPE BottomBlock = m_World->GetBlock( Pos.x, Pos.y - 1, Pos.z ); + + if( IsPassable(BottomBlock) ) + { + cFallingBlock * FallingBlock = new cFallingBlock( Pos, BlockID ); + FallingBlock->Initialize( m_World ); + m_World->SetBlock( Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0 ); + } + } + +} + + + + + +bool cSandSimulator::IsAllowedBlock( BLOCKTYPE a_BlockType ) +{ + return a_BlockType == E_BLOCK_SAND + || a_BlockType == E_BLOCK_GRAVEL; +} + + + + + +void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z) +{ + if(!IsAllowedBlock(m_World->GetBlock(a_X, a_Y, a_Z))) + 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); +} + + + + + +bool cSandSimulator::IsPassable( BLOCKTYPE a_BlockType ) +{ + return a_BlockType == E_BLOCK_AIR + || IsBlockWater(a_BlockType) + || IsBlockLava(a_BlockType) + || a_BlockType == E_BLOCK_FIRE; +} -- cgit v1.2.3