summaryrefslogtreecommitdiffstats
path: root/source/cSandSimulator.cpp
diff options
context:
space:
mode:
authorlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-26 21:57:12 +0100
committerlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-26 21:57:12 +0100
commit9f77572fb0d045229556314ba9d7aa0f52ad5635 (patch)
tree67bf3cfaf013be8566e0d541c1a1b571719816f7 /source/cSandSimulator.cpp
parent- improved ClosestPlayerDetection (Really the closest now ;)) (diff)
downloadcuberite-9f77572fb0d045229556314ba9d7aa0f52ad5635.tar
cuberite-9f77572fb0d045229556314ba9d7aa0f52ad5635.tar.gz
cuberite-9f77572fb0d045229556314ba9d7aa0f52ad5635.tar.bz2
cuberite-9f77572fb0d045229556314ba9d7aa0f52ad5635.tar.lz
cuberite-9f77572fb0d045229556314ba9d7aa0f52ad5635.tar.xz
cuberite-9f77572fb0d045229556314ba9d7aa0f52ad5635.tar.zst
cuberite-9f77572fb0d045229556314ba9d7aa0f52ad5635.zip
Diffstat (limited to 'source/cSandSimulator.cpp')
-rw-r--r--source/cSandSimulator.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/source/cSandSimulator.cpp b/source/cSandSimulator.cpp
new file mode 100644
index 000000000..b25b498c5
--- /dev/null
+++ b/source/cSandSimulator.cpp
@@ -0,0 +1,74 @@
+#include "cSandSimulator.h"
+#include "cWorld.h"
+#include "Vector3i.h"
+#include "BlockID.h"
+#include "Defines.h"
+#include <vector>
+
+cSandSimulator::cSandSimulator( cWorld* a_World )
+ : cSimulator(a_World)
+ , m_Blocks(new std::vector <Vector3i *>)
+ , m_Buffer(new std::vector <Vector3i *>)
+{
+
+}
+
+cSandSimulator::~cSandSimulator()
+{
+ delete m_Buffer;
+ delete m_Blocks;
+}
+
+void cSandSimulator::Simulate( float a_Dt )
+{
+ m_Buffer->clear();
+ std::swap( m_Blocks, m_Buffer );
+
+ for( std::vector<Vector3i *>::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr )
+ {
+ Vector3i *Pos = *itr;
+ char BlockID = m_World->GetBlock(Pos->x, Pos->y, Pos->z);
+ if(!IsAllowedBlock(BlockID))
+ continue;
+
+ char BottomBlock = m_World->GetBlock( Pos->x, Pos->y - 1, Pos->z );
+
+ if( IsPassable(BottomBlock) )
+ {
+ 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 );
+ }
+ }
+
+}
+
+
+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)
+{
+ Vector3i *Block = new Vector3i(a_X, a_Y, a_Z);
+
+ //check for duplicates
+ for( std::vector<Vector3i *>::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( char a_BlockID )
+{
+ return a_BlockID == E_BLOCK_AIR
+ || IsBlockWater(a_BlockID)
+ || IsBlockLava(a_BlockID);
+
+} \ No newline at end of file