From 5b7de82a79e3f18affcffd686484a681d187942a Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 14 Oct 2012 17:06:21 +0000 Subject: Initial Floody fluid simulator. Can spread, cannot dry. git-svn-id: http://mc-server.googlecode.com/svn/trunk@963 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Simulator/FireSimulator.cpp | 40 ++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'source/Simulator/FireSimulator.cpp') diff --git a/source/Simulator/FireSimulator.cpp b/source/Simulator/FireSimulator.cpp index c2f22668b..1f20b0497 100644 --- a/source/Simulator/FireSimulator.cpp +++ b/source/Simulator/FireSimulator.cpp @@ -47,8 +47,10 @@ void cFireSimulator::Simulate( float a_Dt ) if(!IsAllowedBlock(BlockID)) //Check wheather the block is still burning continue; - if(BurnBlockAround(Pos.x, Pos.y, Pos.z)) //Burn single block and if there was one -> next time again - _AddBlock(Pos.x, Pos.y, Pos.z); + if (BurnBlockAround(Pos.x, Pos.y, Pos.z)) //Burn single block and if there was one -> next time again + { + m_Blocks->push_back(Pos); + } else if(!IsForeverBurnable(m_World->GetBlock(Pos.x, Pos.y - 1, Pos.z)) && !FiresForever(BlockID)) m_World->SetBlock(Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0); @@ -61,42 +63,34 @@ void cFireSimulator::Simulate( float a_Dt ) -bool cFireSimulator::IsAllowedBlock( BLOCKTYPE a_BlockType ) +bool cFireSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType) { - return a_BlockType == E_BLOCK_FIRE - || IsBlockLava(a_BlockType); + return (a_BlockType == E_BLOCK_FIRE) || IsBlockLava(a_BlockType); } -void cFireSimulator::AddBlock(int a_X, int a_Y, int a_Z) +void cFireSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ) { - char BlockID = m_World->GetBlock(a_X, a_Y, a_Z); - if(!IsAllowedBlock(BlockID)) //This should save very much time because it doesn´t have to iterate through all blocks + BLOCKTYPE BlockType = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + if (!IsAllowedBlock(BlockType)) + { return; + } - //check for duplicates - for( BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr ) + // 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 ) + if ((Pos.x == a_BlockX) && (Pos.y == a_BlockY) && (Pos.z == a_BlockZ)) + { return; + } } - _AddBlock(a_X, a_Y, a_Z); - -} - - - - - -void cFireSimulator::_AddBlock(int a_X, int a_Y, int a_Z) -{ - m_Blocks->push_back( Vector3i(a_X, a_Y, a_Z) ); - + m_Blocks->push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ)); } -- cgit v1.2.3