diff --git a/source/Simulator/ClassicFluidSimulator.cpp b/source/Simulator/ClassicFluidSimulator.cpp index e005e7381..d96c863c1 100644 --- a/source/Simulator/ClassicFluidSimulator.cpp +++ b/source/Simulator/ClassicFluidSimulator.cpp @@ -32,7 +32,7 @@ class cClassicFluidSimulator::FluidData { public: - FluidData(cWorld * a_World, cClassicFluidSimulator * a_Simulator ) + FluidData(cWorld & a_World, cClassicFluidSimulator * a_Simulator ) : m_ActiveFluid( new std::set < Vector3i >() ) , m_Simulator (a_Simulator) , m_Buffer( new std::set< Vector3i >() ) @@ -109,8 +109,8 @@ public: { for (int z = 0; z < AREA_WIDTH; z++) { - char UpperBlock = m_World->GetBlock(CornerGlobal.x + x, CornerGlobal.y, CornerGlobal.z + z); - char DownBlock = m_World->GetBlock(CornerGlobal.x + x, CornerGlobal.y - 1, CornerGlobal.z + z); + BLOCKTYPE UpperBlock = m_World.GetBlock(CornerGlobal.x + x, CornerGlobal.y, CornerGlobal.z + z); + BLOCKTYPE DownBlock = m_World.GetBlock(CornerGlobal.x + x, CornerGlobal.y - 1, CornerGlobal.z + z); if (m_Simulator->IsSolidBlock(UpperBlock) || (m_Simulator->IsStationaryFluidBlock(UpperBlock))) { @@ -214,7 +214,7 @@ public: }; for (int i = 0; i < 4; ++i) { - char Block = m_World->GetBlock(LevelPoints[i].x, a_BlockY, LevelPoints[i].z); + char Block = m_World.GetBlock(LevelPoints[i].x, a_BlockY, LevelPoints[i].z); if (m_Simulator->IsPassableForFluid(Block)) { Points.push_back(LevelPoints[i]); @@ -227,7 +227,7 @@ public: std::set< Vector3i > * m_ActiveFluid; std::set< Vector3i > * m_Buffer; - cWorld * m_World; + cWorld & m_World; cClassicFluidSimulator * m_Simulator; const static int AREA_WIDTH = 11; @@ -262,7 +262,7 @@ public: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cClassicFluidSimulator: -cClassicFluidSimulator::cClassicFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff) : +cClassicFluidSimulator::cClassicFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff) : cFluidSimulator(a_World, a_Fluid, a_StationaryFluid), m_Data(NULL), m_MaxHeight(a_MaxHeight), @@ -287,7 +287,7 @@ cClassicFluidSimulator::~cClassicFluidSimulator() void cClassicFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) { // TODO: This can be optimized - BLOCKTYPE BlockType = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + BLOCKTYPE BlockType = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); if (!IsAllowedBlock(BlockType)) // This should save very much time because it doesn´t have to iterate through all blocks { return; @@ -306,10 +306,10 @@ NIBBLETYPE cClassicFluidSimulator::GetHighestLevelAround(int a_BlockX, int a_Blo NIBBLETYPE Max = m_MaxHeight + m_Falloff; #define __HIGHLEVEL_CHECK__( x, y, z ) \ - if (IsAllowedBlock(m_World->GetBlock( x, y, z ) ) ) \ + if (IsAllowedBlock(m_World.GetBlock( x, y, z ) ) ) \ { \ NIBBLETYPE Meta; \ - if ((Meta = m_World->GetBlockMeta( x, y, z ) ) < Max ) Max = Meta; \ + if ((Meta = m_World.GetBlockMeta( x, y, z ) ) < Max ) Max = Meta; \ else if (Meta == m_MaxHeight + m_Falloff) Max = 0; \ if (Max == 0) return 0; \ } @@ -348,16 +348,16 @@ void cClassicFluidSimulator::Simulate(float a_Dt) continue; } - char BlockID = m_World->GetBlock( pos.x, pos.y, pos.z ); + char BlockID = m_World.GetBlock( pos.x, pos.y, pos.z ); if( IsAllowedBlock( BlockID ) ) // only care about own fluid { bool bIsFed = false; - NIBBLETYPE Meta = m_World->GetBlockMeta( pos.x, pos.y, pos.z ); + NIBBLETYPE Meta = m_World.GetBlockMeta( pos.x, pos.y, pos.z ); NIBBLETYPE Feed = Meta; if (BlockID == m_StationaryFluidBlock) Meta = 0; if (Meta == 8 ) // Falling fluid { - if (IsAllowedBlock( m_World->GetBlock(pos.x, pos.y+1, pos.z) ) ) // Block above is fluid + if (IsAllowedBlock( m_World.GetBlock(pos.x, pos.y+1, pos.z) ) ) // Block above is fluid { bIsFed = true; Meta = 0; // Make it a full block @@ -376,7 +376,7 @@ void cClassicFluidSimulator::Simulate(float a_Dt) if( bIsFed ) { - char DownID = m_World->GetBlock(pos.x, pos.y - 1, pos.z); + char DownID = m_World.GetBlock(pos.x, pos.y - 1, pos.z); bool bWashedAwayItem = CanWashAway(DownID); if ((IsPassableForFluid(DownID) || bWashedAwayItem) && !IsStationaryFluidBlock(DownID) ) // free for fluid { @@ -385,12 +385,12 @@ void cClassicFluidSimulator::Simulate(float a_Dt) cBlockHandler * Handler = BlockHandler(DownID); if (Handler->DoesDropOnUnsuitable()) { - Handler->DropBlock(m_World, NULL, pos.x, pos.y - 1, pos.z); + Handler->DropBlock(&m_World, NULL, pos.x, pos.y - 1, pos.z); } } if (pos.y > 0) { - m_World->SetBlock(pos.x, pos.y - 1, pos.z, m_FluidBlock, 8); // falling + m_World.SetBlock(pos.x, pos.y - 1, pos.z, m_FluidBlock, 8); // falling ApplyUniqueToNearest(pos - Vector3i(0, 1, 0)); } } @@ -398,7 +398,7 @@ void cClassicFluidSimulator::Simulate(float a_Dt) { if (Feed + m_Falloff < Meta) { - m_World->SetBlock(pos.x, pos.y, pos.z, m_FluidBlock, Feed + m_Falloff); + m_World.SetBlock(pos.x, pos.y, pos.z, m_FluidBlock, Feed + m_Falloff); ApplyUniqueToNearest(pos); } else if ((Meta < m_MaxHeight ) || (BlockID == m_StationaryFluidBlock)) // max is the lowest, so it cannot spread @@ -407,7 +407,7 @@ void cClassicFluidSimulator::Simulate(float a_Dt) for( std::vector< Vector3i >::iterator itr = Points.begin(); itr != Points.end(); ++itr ) { Vector3i & p = *itr; - char BlockID = m_World->GetBlock( p.x, p.y, p.z ); + char BlockID = m_World.GetBlock( p.x, p.y, p.z ); bool bWashedAwayItem = CanWashAway( BlockID ); if (!IsPassableForFluid(BlockID)) continue; @@ -419,23 +419,23 @@ void cClassicFluidSimulator::Simulate(float a_Dt) cBlockHandler * Handler = BlockHandler(DownID); if (Handler->DoesDropOnUnsuitable()) { - Handler->DropBlock(m_World, NULL, p.x, p.y, p.z); + Handler->DropBlock(&m_World, NULL, p.x, p.y, p.z); } } if (p.y == pos.y) { - m_World->SetBlock(p.x, p.y, p.z, m_FluidBlock, Meta + m_Falloff); + m_World.SetBlock(p.x, p.y, p.z, m_FluidBlock, Meta + m_Falloff); } else { - m_World->SetBlock(p.x, p.y, p.z, m_FluidBlock, 8); + m_World.SetBlock(p.x, p.y, p.z, m_FluidBlock, 8); } ApplyUniqueToNearest(p); } else // it's fluid { - NIBBLETYPE PointMeta = m_World->GetBlockMeta(p.x, p.y, p.z); + NIBBLETYPE PointMeta = m_World.GetBlockMeta(p.x, p.y, p.z); if (PointMeta > Meta + m_Falloff) { // TODO: AddBlock(p.x, p.y, p.z); @@ -448,7 +448,7 @@ void cClassicFluidSimulator::Simulate(float a_Dt) } else // not fed { - m_World->SetBlock(pos.x, pos.y, pos.z, E_BLOCK_AIR, 0); + m_World.SetBlock(pos.x, pos.y, pos.z, E_BLOCK_AIR, 0); } } } @@ -462,22 +462,22 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos) { bool result = false; - char BlockId = m_World->GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); - char Meta = m_World->GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z ); + char BlockId = m_World.GetBlock( a_Pos.x, a_Pos.y, a_Pos.z ); + char Meta = m_World.GetBlockMeta( a_Pos.x, a_Pos.y, a_Pos.z ); if(IsBlockWater(BlockId)) { - char UpperBlock = m_World->GetBlock( a_Pos.x, a_Pos.y + 1, a_Pos.z ); + char UpperBlock = m_World.GetBlock( a_Pos.x, a_Pos.y + 1, a_Pos.z ); if(IsBlockLava(UpperBlock)) { - m_World->SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_STONE, 0); + m_World.SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_STONE, 0); } if(BlockId != E_BLOCK_STATIONARY_WATER) { - char DownBlockId = m_World->GetBlock( a_Pos.x, a_Pos.y-1, a_Pos.z ); + char DownBlockId = m_World.GetBlock( a_Pos.x, a_Pos.y-1, a_Pos.z ); if(IsSolidBlock(DownBlockId)) { Vector3i LevelPoints [] = { @@ -489,14 +489,14 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos) int SourceBlocksCount = 0; for(int i=0; i<4; i++) { - if (m_World->GetBlock(LevelPoints[i].x, LevelPoints[i].y, LevelPoints[i].z)==E_BLOCK_STATIONARY_WATER) + if (m_World.GetBlock(LevelPoints[i].x, LevelPoints[i].y, LevelPoints[i].z)==E_BLOCK_STATIONARY_WATER) { SourceBlocksCount++; } } if(SourceBlocksCount>=2) { - m_World->SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_STATIONARY_WATER, 0); + m_World.SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_STATIONARY_WATER, 0); } } @@ -507,7 +507,7 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos) { bool bWater = false; - char UpperBlock = m_World->GetBlock( a_Pos.x, a_Pos.y + 1, a_Pos.z ); + char UpperBlock = m_World.GetBlock( a_Pos.x, a_Pos.y + 1, a_Pos.z ); if (IsBlockWater(UpperBlock)) { bWater = true; @@ -523,7 +523,7 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos) for(int i=0; i<4; i++) { - if (IsBlockWater(m_World->GetBlock(LevelPoints[i].x, LevelPoints[i].y, LevelPoints[i].z))) + if (IsBlockWater(m_World.GetBlock(LevelPoints[i].x, LevelPoints[i].y, LevelPoints[i].z))) { bWater = true; } @@ -535,11 +535,11 @@ bool cClassicFluidSimulator::UniqueSituation(Vector3i a_Pos) { if (BlockId == E_BLOCK_STATIONARY_LAVA) { - m_World->SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_OBSIDIAN, 0); + m_World.SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_OBSIDIAN, 0); } else if (MetaSetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_COBBLESTONE, 0); + m_World.SetBlock(a_Pos.x, a_Pos.y, a_Pos.z, E_BLOCK_COBBLESTONE, 0); } } } diff --git a/source/Simulator/ClassicFluidSimulator.h b/source/Simulator/ClassicFluidSimulator.h index 95dfd9e4a..330946bff 100644 --- a/source/Simulator/ClassicFluidSimulator.h +++ b/source/Simulator/ClassicFluidSimulator.h @@ -19,7 +19,7 @@ class cClassicFluidSimulator : public cFluidSimulator { public: - cClassicFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff); + cClassicFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff); ~cClassicFluidSimulator(); // cSimulator overrides: diff --git a/source/Simulator/DelayedFluidSimulator.cpp b/source/Simulator/DelayedFluidSimulator.cpp index e0faf5b18..d6d9a8793 100644 --- a/source/Simulator/DelayedFluidSimulator.cpp +++ b/source/Simulator/DelayedFluidSimulator.cpp @@ -13,7 +13,7 @@ -cDelayedFluidSimulator::cDelayedFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay) : +cDelayedFluidSimulator::cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay) : super(a_World, a_Fluid, a_StationaryFluid), m_TickDelay(a_TickDelay), m_Slots(NULL), @@ -45,7 +45,7 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, } // TODO: This can be optimized: - BLOCKTYPE BlockType = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + BLOCKTYPE BlockType = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); if (BlockType != m_FluidBlock) { return; diff --git a/source/Simulator/DelayedFluidSimulator.h b/source/Simulator/DelayedFluidSimulator.h index d8ba3f858..7a5967235 100644 --- a/source/Simulator/DelayedFluidSimulator.h +++ b/source/Simulator/DelayedFluidSimulator.h @@ -21,7 +21,7 @@ class cDelayedFluidSimulator : typedef cFluidSimulator super; public: - cDelayedFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay); + cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay); virtual ~cDelayedFluidSimulator(); // cSimulator overrides: diff --git a/source/Simulator/FireSimulator.cpp b/source/Simulator/FireSimulator.cpp index 0ebac74b3..277ac0700 100644 --- a/source/Simulator/FireSimulator.cpp +++ b/source/Simulator/FireSimulator.cpp @@ -10,7 +10,7 @@ -cFireSimulator::cFireSimulator( cWorld* a_World ) +cFireSimulator::cFireSimulator(cWorld & a_World) : cSimulator(a_World) , m_Blocks(new BlockList) , m_Buffer(new BlockList) @@ -33,30 +33,34 @@ cFireSimulator::~cFireSimulator() -void cFireSimulator::Simulate( float a_Dt ) +void cFireSimulator::Simulate(float a_Dt) { m_Buffer->clear(); - std::swap( m_Blocks, m_Buffer ); + std::swap(m_Blocks, m_Buffer); - for( BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr ) + for (BlockList::iterator itr = m_Buffer->begin(); itr != m_Buffer->end(); ++itr) { Vector3i Pos = *itr; - char BlockID = m_World->GetBlock(Pos.x, Pos.y, Pos.z); + BLOCKTYPE BlockID = m_World.GetBlock(Pos.x, Pos.y, Pos.z); - if(!IsAllowedBlock(BlockID)) //Check wheather the block is still burning + 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 { 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); - - } - + { + 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); + } + } + } // for itr - m_Buffer[] } @@ -75,7 +79,7 @@ bool cFireSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType) void cFireSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) { // TODO: This can be optimized - BLOCKTYPE BlockType = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); + BLOCKTYPE BlockType = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ); if (!IsAllowedBlock(BlockType)) { return; @@ -148,18 +152,18 @@ bool cFireSimulator::BurnBlockAround(int a_X, int a_Y, int a_Z) bool cFireSimulator::BurnBlock(int a_X, int a_Y, int a_Z) { - char BlockID = m_World->GetBlock(a_X, a_Y, a_Z); - if(IsBurnable(BlockID)) + BLOCKTYPE BlockID = m_World.GetBlock(a_X, a_Y, a_Z); + if (IsBurnable(BlockID)) { - m_World->SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0); + m_World.SetBlock(a_X, a_Y, a_Z, E_BLOCK_FIRE, 0); return true; } - if(IsForeverBurnable(BlockID)) + if (IsForeverBurnable(BlockID)) { - char BlockAbove = m_World->GetBlock(a_X, a_Y + 1, a_Z); - if(BlockAbove == E_BLOCK_AIR) + BLOCKTYPE BlockAbove = m_World.GetBlock(a_X, a_Y + 1, a_Z); + if (BlockAbove == E_BLOCK_AIR) { - m_World->SetBlock(a_X, a_Y + 1, a_Z, E_BLOCK_FIRE, 0); //Doesn´t notify the simulator so it won´t go off + m_World.SetBlock(a_X, a_Y + 1, a_Z, E_BLOCK_FIRE, 0); //Doesn´t notify the simulator so it won´t go off return true; } return false; diff --git a/source/Simulator/FireSimulator.h b/source/Simulator/FireSimulator.h index d95ecf4f0..2a510d276 100644 --- a/source/Simulator/FireSimulator.h +++ b/source/Simulator/FireSimulator.h @@ -11,7 +11,7 @@ class cFireSimulator : public cSimulator { public: - cFireSimulator( cWorld* a_World ); + cFireSimulator(cWorld & a_World); ~cFireSimulator(); virtual void Simulate( float a_Dt ) override; diff --git a/source/Simulator/FloodyFluidSimulator.cpp b/source/Simulator/FloodyFluidSimulator.cpp index 9d4cda2fc..eaf16fff4 100644 --- a/source/Simulator/FloodyFluidSimulator.cpp +++ b/source/Simulator/FloodyFluidSimulator.cpp @@ -27,7 +27,7 @@ cFloodyFluidSimulator::cFloodyFluidSimulator( - cWorld * a_World, + cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_Falloff, @@ -51,7 +51,7 @@ void cFloodyFluidSimulator::SimulateBlock(int a_BlockX, int a_BlockY, int a_Bloc cBlockArea Area; int MinBlockY = std::max(0, a_BlockY - 1); int MaxBlockY = std::min(+cChunkDef::Height, a_BlockY + 1); - if (!Area.Read(m_World, a_BlockX - 1, a_BlockX + 1, MinBlockY, MaxBlockY, a_BlockZ - 1, a_BlockZ + 1)) + if (!Area.Read(&m_World, a_BlockX - 1, a_BlockX + 1, MinBlockY, MaxBlockY, a_BlockZ - 1, a_BlockZ + 1)) { // Cannot read the immediate neighborhood, probably too close to an unloaded chunk. Bail out. // TODO: Shouldn't we re-schedule? @@ -112,7 +112,7 @@ void cFloodyFluidSimulator::SimulateBlock(int a_BlockX, int a_BlockY, int a_Bloc } // Mark as processed: - m_World->FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, MyMeta); + m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, MyMeta); } @@ -147,7 +147,7 @@ bool cFloodyFluidSimulator::CheckTributaries(int a_BlockX, int a_BlockY, int a_B if (a_MyMeta >= 8) { FLOG(" Not fed and downwards, turning into non-downwards meta %d", m_Falloff); - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, m_Falloff); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, m_Falloff); } else { @@ -155,12 +155,12 @@ bool cFloodyFluidSimulator::CheckTributaries(int a_BlockX, int a_BlockY, int a_B if (a_MyMeta < 8) { FLOG(" Not fed, decreasing from %d to %d", a_MyMeta, a_MyMeta + m_Falloff); - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, a_MyMeta); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_StationaryFluidBlock, a_MyMeta); } else { FLOG(" Not fed, meta %d, erasing altogether", a_MyMeta); - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); } } return true; @@ -200,7 +200,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(int a_BlockX, int a_BlockY, int a_B a_BlockX, a_BlockY, a_BlockZ, ItemTypeToString(NewBlock).c_str() ); - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, NewBlock, 0); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, NewBlock, 0); // TODO: Sound effect @@ -216,7 +216,7 @@ void cFloodyFluidSimulator::SpreadToNeighbor(int a_BlockX, int a_BlockY, int a_B FLOG(" Water flowing into lava, turning lava at {%d, %d, %d} into %s", a_BlockX, a_BlockY, a_BlockZ, ItemTypeToString(NewBlock).c_str() ); - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, NewBlock, 0); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, NewBlock, 0); // TODO: Sound effect @@ -240,13 +240,13 @@ void cFloodyFluidSimulator::SpreadToNeighbor(int a_BlockX, int a_BlockY, int a_B cBlockHandler * Handler = BlockHandler(Block); if (Handler->DoesDropOnUnsuitable()) { - Handler->DropBlock(m_World, NULL, a_BlockX, a_BlockY, a_BlockZ); + Handler->DropBlock(&m_World, NULL, a_BlockX, a_BlockY, a_BlockZ); } } // Spread: FLOG(" Spreading to {%d, %d, %d} with meta %d", a_BlockX, a_BlockY, a_BlockZ, a_NewMeta); - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_FluidBlock, a_NewMeta); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_FluidBlock, a_NewMeta); } @@ -283,7 +283,7 @@ bool cFloodyFluidSimulator::CheckNeighborsForSource(int a_BlockX, int a_BlockY, { // Found enough, turn into a source and bail out FLOG(" Found enough neighbor sources, turning into a source"); - m_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_FluidBlock, 0); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, m_FluidBlock, 0); return true; } } diff --git a/source/Simulator/FloodyFluidSimulator.h b/source/Simulator/FloodyFluidSimulator.h index dc9ff2557..ec3ab044a 100644 --- a/source/Simulator/FloodyFluidSimulator.h +++ b/source/Simulator/FloodyFluidSimulator.h @@ -29,7 +29,7 @@ class cFloodyFluidSimulator : typedef cDelayedFluidSimulator super; public: - cFloodyFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_Falloff, int a_TickDelay, int a_NumNeighborsForSource); + cFloodyFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_Falloff, int a_TickDelay, int a_NumNeighborsForSource); protected: NIBBLETYPE m_Falloff; diff --git a/source/Simulator/FluidSimulator.cpp b/source/Simulator/FluidSimulator.cpp index 66ba40941..4648c4cde 100644 --- a/source/Simulator/FluidSimulator.cpp +++ b/source/Simulator/FluidSimulator.cpp @@ -8,7 +8,7 @@ -cFluidSimulator::cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid) : +cFluidSimulator::cFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid) : super(a_World), m_FluidBlock(a_Fluid), m_StationaryFluidBlock(a_StationaryFluid) @@ -119,7 +119,7 @@ bool cFluidSimulator::IsHigherMeta(NIBBLETYPE a_Meta1, NIBBLETYPE a_Meta2) // TODO Not working very well yet :s Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over) { - char BlockID = m_World->GetBlock(a_X, a_Y, a_Z); + char BlockID = m_World.GetBlock(a_X, a_Y, a_Z); if (!IsAllowedBlock(BlockID)) // No Fluid -> No Flowing direction :D { return NONE; @@ -128,15 +128,15 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a /* Disabled because of causing problems and being useless atm - char BlockBelow = m_World->GetBlock(a_X, a_Y - 1, a_Z); //If there is nothing or fluid below it -> dominating flow is down :D + char BlockBelow = m_World.GetBlock(a_X, a_Y - 1, a_Z); //If there is nothing or fluid below it -> dominating flow is down :D if (BlockBelow == E_BLOCK_AIR || IsAllowedBlock(BlockBelow)) return Y_MINUS; */ - NIBBLETYPE LowestPoint = m_World->GetBlockMeta(a_X, a_Y, a_Z); //Current Block Meta so only lower points will be counted + NIBBLETYPE LowestPoint = m_World.GetBlockMeta(a_X, a_Y, a_Z); //Current Block Meta so only lower points will be counted int X = 0, Y = 0, Z = 0; //Lowest Pos will be stored here - if (IsAllowedBlock(m_World->GetBlock(a_X, a_Y + 1, a_Z)) && a_Over) //check for upper block to flow because this also affects the flowing direction + if (IsAllowedBlock(m_World.GetBlock(a_X, a_Y + 1, a_Z)) && a_Over) //check for upper block to flow because this also affects the flowing direction { return GetFlowingDirection(a_X, a_Y + 1, a_Z, false); } @@ -154,10 +154,10 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a for (std::vector::iterator it = Points.begin(); it < Points.end(); it++) { Vector3i *Pos = (*it); - char BlockID = m_World->GetBlock(Pos->x, Pos->y, Pos->z); + char BlockID = m_World.GetBlock(Pos->x, Pos->y, Pos->z); if(IsAllowedBlock(BlockID)) { - char Meta = m_World->GetBlockMeta(Pos->x, Pos->y, Pos->z); + char Meta = m_World.GetBlockMeta(Pos->x, Pos->y, Pos->z); if(Meta > LowestPoint) { @@ -177,7 +177,7 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a delete Pos; } - if (LowestPoint == m_World->GetBlockMeta(a_X, a_Y, a_Z)) + if (LowestPoint == m_World.GetBlockMeta(a_X, a_Y, a_Z)) return NONE; if (a_X - X > 0) diff --git a/source/Simulator/FluidSimulator.h b/source/Simulator/FluidSimulator.h index ec225728e..fce18522f 100644 --- a/source/Simulator/FluidSimulator.h +++ b/source/Simulator/FluidSimulator.h @@ -28,7 +28,7 @@ class cFluidSimulator : typedef cSimulator super; public: - cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid); + cFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid); // cSimulator overrides: virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override; diff --git a/source/Simulator/RedstoneSimulator.cpp b/source/Simulator/RedstoneSimulator.cpp index d6afda413..976c2a978 100644 --- a/source/Simulator/RedstoneSimulator.cpp +++ b/source/Simulator/RedstoneSimulator.cpp @@ -12,7 +12,7 @@ -cRedstoneSimulator::cRedstoneSimulator( cWorld* a_World ) +cRedstoneSimulator::cRedstoneSimulator(cWorld & a_World ) : super(a_World) { } @@ -60,15 +60,15 @@ void cRedstoneSimulator::Simulate( float a_Dt ) } BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - m_World->GetBlockTypeMeta(itr->Position.x, itr->Position.y, itr->Position.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(itr->Position.x, itr->Position.y, itr->Position.z, BlockType, BlockMeta); if (itr->bPowerOn && (BlockType == E_BLOCK_REDSTONE_REPEATER_OFF)) { - m_World->FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_ON, BlockMeta); + m_World.FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_ON, BlockMeta); m_Blocks.push_back(itr->Position); } else if (!itr->bPowerOn && (BlockType == E_BLOCK_REDSTONE_REPEATER_ON)) { - m_World->FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_OFF, BlockMeta); + m_World.FastSetBlock(itr->Position.x, itr->Position.y, itr->Position.z, E_BLOCK_REDSTONE_REPEATER_OFF, BlockMeta); m_Blocks.push_back(itr->Position); } @@ -116,16 +116,16 @@ void cRedstoneSimulator::RefreshTorchesAround( const Vector3i & a_BlockPos ) { TargetBlockType = E_BLOCK_REDSTONE_TORCH_OFF; TargetRepeaterType = E_BLOCK_REDSTONE_REPEATER_ON; - //if( m_World->GetBlock( a_BlockPos ) == E_BLOCK_DIRT ) + //if( m_World.GetBlock( a_BlockPos ) == E_BLOCK_DIRT ) //{ - // m_World->FastSetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_STONE, 0 ); + // m_World.FastSetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_STONE, 0 ); //} } else { - //if( m_World->GetBlock( a_BlockPos ) == E_BLOCK_STONE ) + //if( m_World.GetBlock( a_BlockPos ) == E_BLOCK_STONE ) //{ - // m_World->FastSetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_DIRT, 0 ); + // m_World.FastSetBlock( a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, E_BLOCK_DIRT, 0 ); //} } @@ -134,7 +134,7 @@ void cRedstoneSimulator::RefreshTorchesAround( const Vector3i & a_BlockPos ) Vector3i TorchPos = a_BlockPos + Surroundings[i]; BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - m_World->GetBlockTypeMeta(TorchPos.x, TorchPos.y, TorchPos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(TorchPos.x, TorchPos.y, TorchPos.z, BlockType, BlockMeta); switch (BlockType) { case E_BLOCK_REDSTONE_TORCH_ON: @@ -144,7 +144,7 @@ void cRedstoneSimulator::RefreshTorchesAround( const Vector3i & a_BlockPos ) { if (cTorch::IsAttachedTo(TorchPos, BlockMeta, a_BlockPos)) { - m_World->FastSetBlock(TorchPos.x, TorchPos.y, TorchPos.z, TargetBlockType, BlockMeta); + m_World.FastSetBlock(TorchPos.x, TorchPos.y, TorchPos.z, TargetBlockType, BlockMeta); m_Blocks.push_back(TorchPos); } } @@ -189,7 +189,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); // First check whether torch should be on or off switch (BlockType) @@ -207,7 +207,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) for( unsigned int i = 0; i < ARRAYCOUNT( Surroundings ); ++i ) { Vector3i pos = a_BlockPos + Surroundings[i]; - BLOCKTYPE OtherBlock = m_World->GetBlock( pos ); + BLOCKTYPE OtherBlock = m_World.GetBlock( pos ); if ( (OtherBlock != E_BLOCK_AIR) && (OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) && @@ -217,7 +217,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) RefreshTorchesAround( pos ); } } - m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); break; } // case "torches" @@ -227,7 +227,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) // Check if repeater is powered by a 'powered block' (not wires/torch) Vector3i Direction = GetRepeaterDirection(BlockMeta); Vector3i pos = a_BlockPos - Direction; // NOTE: It's minus Direction - BLOCKTYPE OtherBlock = m_World->GetBlock(pos); + BLOCKTYPE OtherBlock = m_World.GetBlock(pos); if ( (OtherBlock != E_BLOCK_AIR) && (OtherBlock != E_BLOCK_REDSTONE_TORCH_ON) && @@ -241,7 +241,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) { SetRepeater(a_BlockPos, 10, IsPowered(a_BlockPos, false)); } - m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); break; } } // switch (BlockType) @@ -298,7 +298,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - m_World->GetBlockTypeMeta(SourcePos.x, SourcePos.y, SourcePos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(SourcePos.x, SourcePos.y, SourcePos.z, BlockType, BlockMeta); switch (BlockType) { case E_BLOCK_LEVER: // Treating lever as a torch @@ -349,7 +349,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) { Vector3i pos = SpreadStack.back(); SpreadStack.pop_back(); - NIBBLETYPE Meta = m_World->GetBlockMeta(pos); + NIBBLETYPE Meta = m_World.GetBlockMeta(pos); for (unsigned int i = 0; i < ARRAYCOUNT(Surroundings); ++i) { @@ -367,7 +367,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) Vector3i pos = m_RefreshPistons.back(); m_RefreshPistons.pop_back(); - BLOCKTYPE BlockType = m_World->GetBlock(pos); + BLOCKTYPE BlockType = m_World.GetBlock(pos); switch (BlockType) { case E_BLOCK_PISTON: @@ -375,12 +375,12 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) { if (IsPowered(pos)) { - cPiston Piston(m_World); + cPiston Piston(&m_World); Piston.ExtendPiston(pos.x, pos.y, pos.z); } else { - cPiston Piston(m_World); + cPiston Piston(&m_World); Piston.RetractPiston(pos.x, pos.y, pos.z); } break; @@ -393,7 +393,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) Vector3i pos = m_RefreshDispensers.back(); m_RefreshDispensers.pop_back(); - BLOCKTYPE BlockType = m_World->GetBlock(pos); + BLOCKTYPE BlockType = m_World.GetBlock(pos); if (BlockType == E_BLOCK_DISPENSER) { if (IsPowered(pos)) @@ -413,7 +413,7 @@ void cRedstoneSimulator::HandleChange( const Vector3i & a_BlockPos ) } } ; cActivateDispenser DispAct; - m_World->DoWithDispenserAt(pos.x, pos.y, pos.z, DispAct); + m_World.DoWithDispenserAt(pos.x, pos.y, pos.z, DispAct); } } } @@ -427,14 +427,14 @@ bool cRedstoneSimulator::PowerBlock(const Vector3i & a_BlockPos, const Vector3i { BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); switch (BlockType) { case E_BLOCK_REDSTONE_WIRE: { if (BlockMeta < a_Power) { - m_World->SetBlockMeta(a_BlockPos, a_Power); + m_World.SetBlockMeta(a_BlockPos, a_Power); return true; } break; @@ -496,14 +496,14 @@ int cRedstoneSimulator::UnPowerBlock( const Vector3i & a_BlockPos, const Vector3 { return 0; } - m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); switch (BlockType) { case E_BLOCK_REDSTONE_WIRE: { if (BlockMeta > 0 ) { - m_World->SetBlockMeta(a_BlockPos, 0); + m_World.SetBlockMeta(a_BlockPos, 0); return 1; } break; @@ -609,7 +609,7 @@ cRedstoneSimulator::BlockList cRedstoneSimulator::RemoveCurrent( const Vector3i BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); switch (BlockType) { case E_BLOCK_REDSTONE_REPEATER_ON: @@ -704,7 +704,7 @@ bool cRedstoneSimulator::IsPowering(const Vector3i & a_PowerPos, const Vector3i { BLOCKTYPE PowerBlock; NIBBLETYPE PowerMeta; - m_World->GetBlockTypeMeta(a_PowerPos.x, a_PowerPos.y, a_PowerPos.z, PowerBlock, PowerMeta); + m_World.GetBlockTypeMeta(a_PowerPos.x, a_PowerPos.y, a_PowerPos.z, PowerBlock, PowerMeta); // Filter out powering blocks for a_bOnlyByWire if ( @@ -753,13 +753,13 @@ bool cRedstoneSimulator::IsPowered( const Vector3i & a_BlockPos, bool a_bOnlyByW { BLOCKTYPE BlockType; NIBBLETYPE BlockMeta; - m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); + m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, BlockType, BlockMeta); if ((BlockType == E_BLOCK_REDSTONE_REPEATER_OFF) || (BlockType == E_BLOCK_REDSTONE_REPEATER_ON)) { Vector3i Behind = a_BlockPos - GetRepeaterDirection(BlockMeta); BLOCKTYPE BehindBlock; NIBBLETYPE BehindMeta; - m_World->GetBlockTypeMeta(Behind.x, Behind.y, Behind.z, BehindBlock, BehindMeta); + m_World.GetBlockTypeMeta(Behind.x, Behind.y, Behind.z, BehindBlock, BehindMeta); switch (BehindBlock) { case E_BLOCK_REDSTONE_TORCH_ON: @@ -800,7 +800,7 @@ bool cRedstoneSimulator::IsPowered( const Vector3i & a_BlockPos, bool a_bOnlyByW // Only wires can power the bottom block BLOCKTYPE PosYType; NIBBLETYPE PosYMeta; - m_World->GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y + 1, a_BlockPos.z, PosYType, PosYMeta); + m_World.GetBlockTypeMeta(a_BlockPos.x, a_BlockPos.y + 1, a_BlockPos.z, PosYType, PosYMeta); if (PosYType == E_BLOCK_REDSTONE_WIRE) { return (PosYMeta > 0); @@ -817,7 +817,7 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int { int Dir = REDSTONE_NONE; - BLOCKTYPE NegX = m_World->GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ); + BLOCKTYPE NegX = m_World.GetBlock(a_BlockX - 1, a_BlockY, a_BlockZ); if ( (NegX == E_BLOCK_REDSTONE_WIRE) || (NegX == E_BLOCK_REDSTONE_TORCH_ON) || @@ -827,7 +827,7 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int Dir |= (REDSTONE_X_POS); } - BLOCKTYPE PosX = m_World->GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ); + BLOCKTYPE PosX = m_World.GetBlock(a_BlockX + 1, a_BlockY, a_BlockZ); if ( (PosX == E_BLOCK_REDSTONE_WIRE) || (PosX == E_BLOCK_REDSTONE_TORCH_ON) || @@ -837,7 +837,7 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int Dir |= (REDSTONE_X_NEG); } - BLOCKTYPE NegZ = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1); + BLOCKTYPE NegZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ - 1); if ( (NegZ == E_BLOCK_REDSTONE_WIRE) || (NegZ == E_BLOCK_REDSTONE_TORCH_ON) || @@ -857,7 +857,7 @@ cRedstoneSimulator::eRedstoneDirection cRedstoneSimulator::GetWireDirection(int Dir |= REDSTONE_Z_POS; } - BLOCKTYPE PosZ = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1); + BLOCKTYPE PosZ = m_World.GetBlock(a_BlockX, a_BlockY, a_BlockZ + 1); if ( (PosZ == E_BLOCK_REDSTONE_WIRE) || (PosZ == E_BLOCK_REDSTONE_TORCH_ON) || diff --git a/source/Simulator/RedstoneSimulator.h b/source/Simulator/RedstoneSimulator.h index df5874d07..7d869fae1 100644 --- a/source/Simulator/RedstoneSimulator.h +++ b/source/Simulator/RedstoneSimulator.h @@ -12,7 +12,7 @@ class cRedstoneSimulator : { typedef cSimulator super; public: - cRedstoneSimulator( cWorld* a_World ); + cRedstoneSimulator(cWorld & a_World); ~cRedstoneSimulator(); virtual void Simulate( float a_Dt ) override; diff --git a/source/Simulator/SandSimulator.cpp b/source/Simulator/SandSimulator.cpp index f9d58f030..04bcc498c 100644 --- a/source/Simulator/SandSimulator.cpp +++ b/source/Simulator/SandSimulator.cpp @@ -12,7 +12,7 @@ -cSandSimulator::cSandSimulator( cWorld* a_World ) +cSandSimulator::cSandSimulator(cWorld & a_World) : cSimulator(a_World) , m_Blocks(new BlockList) , m_Buffer(new BlockList) @@ -34,7 +34,7 @@ cSandSimulator::~cSandSimulator() -void cSandSimulator::Simulate( float a_Dt ) +void cSandSimulator::Simulate(float a_Dt) { m_Buffer->clear(); std::swap( m_Blocks, m_Buffer ); @@ -42,17 +42,17 @@ void cSandSimulator::Simulate( float a_Dt ) 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); + 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 ); + 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 ); + cFallingBlock * FallingBlock = new cFallingBlock(Pos, BlockID); + FallingBlock->Initialize(&m_World); + m_World.SetBlock( Pos.x, Pos.y, Pos.z, E_BLOCK_AIR, 0 ); } } diff --git a/source/Simulator/SandSimulator.h b/source/Simulator/SandSimulator.h index 4b786678c..ebd154f2d 100644 --- a/source/Simulator/SandSimulator.h +++ b/source/Simulator/SandSimulator.h @@ -12,7 +12,7 @@ class cSandSimulator : public cSimulator { public: - cSandSimulator( cWorld* a_World ); + cSandSimulator(cWorld & a_World); ~cSandSimulator(); virtual void Simulate( float a_Dt ) override; diff --git a/source/Simulator/Simulator.cpp b/source/Simulator/Simulator.cpp index 8560163c5..07ed31b52 100644 --- a/source/Simulator/Simulator.cpp +++ b/source/Simulator/Simulator.cpp @@ -12,7 +12,7 @@ -cSimulator::cSimulator( cWorld* a_World ) +cSimulator::cSimulator(cWorld & a_World) : m_World(a_World) { } diff --git a/source/Simulator/Simulator.h b/source/Simulator/Simulator.h index ee3489b02..1f31bc2e8 100644 --- a/source/Simulator/Simulator.h +++ b/source/Simulator/Simulator.h @@ -17,12 +17,15 @@ class cChunk; class cSimulator { public: - cSimulator(cWorld * a_World); + cSimulator(cWorld & a_World); virtual ~cSimulator(); /// Called in each tick, a_Dt is the time passed since the last tick, in msec virtual void Simulate(float a_Dt) = 0; + /// Called in each tick for each chunk, a_Dt is the time passed since the last tick, in msec; direct access to chunk data available + virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) {}; + /// Called when a block changes virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk); @@ -32,7 +35,7 @@ protected: /// Called to simulate a new block virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) = 0; - cWorld * m_World; + cWorld & m_World; } ; diff --git a/source/Simulator/SimulatorManager.cpp b/source/Simulator/SimulatorManager.cpp index ceebc2d8f..2bc483cbd 100644 --- a/source/Simulator/SimulatorManager.cpp +++ b/source/Simulator/SimulatorManager.cpp @@ -2,12 +2,14 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "SimulatorManager.h" +#include "../World.h" -cSimulatorManager::cSimulatorManager(void) : +cSimulatorManager::cSimulatorManager(cWorld & a_World) : + m_World(a_World), m_Ticks(0) { } @@ -24,7 +26,7 @@ cSimulatorManager::~cSimulatorManager() -void cSimulatorManager::Simulate( float a_Dt ) +void cSimulatorManager::Simulate(float a_Dt) { m_Ticks++; for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr ) @@ -40,6 +42,22 @@ void cSimulatorManager::Simulate( float a_Dt ) +void cSimulatorManager::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) +{ + // m_Ticks has already been increased in Simulate() + for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr ) + { + if ((m_Ticks % itr->second) == 0) + { + itr->first->SimulateChunk(a_Dt, a_ChunkX, a_ChunkZ, a_Chunk); + } + } +} + + + + + void cSimulatorManager::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) { for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr ) diff --git a/source/Simulator/SimulatorManager.h b/source/Simulator/SimulatorManager.h index 989831b03..31a709316 100644 --- a/source/Simulator/SimulatorManager.h +++ b/source/Simulator/SimulatorManager.h @@ -18,6 +18,9 @@ // fwd: Chunk.h class cChunk; +// fwd: World.h +class cWorld; + @@ -25,18 +28,21 @@ class cChunk; class cSimulatorManager { public: - cSimulatorManager(void); + cSimulatorManager(cWorld & a_World); ~cSimulatorManager(); void Simulate(float a_Dt); + + void SimulateChunk(float a_DT, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk); + void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk); void RegisterSimulator(cSimulator * a_Simulator, int a_Rate); // Takes ownership of the simulator object! protected: - typedef std::vector > cSimulators; + cWorld & m_World; cSimulators m_Simulators; long long m_Ticks; }; diff --git a/source/World.cpp b/source/World.cpp index 0236a456b..3097e5029 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -250,12 +250,12 @@ cWorld::cWorld(const AString & a_WorldName) : m_BlockTickQueueCopy.reserve(1000); // Simulators: - m_SimulatorManager = new cSimulatorManager(); + m_SimulatorManager = new cSimulatorManager(*this); m_WaterSimulator = InitializeFluidSimulator(IniFile, "Water", E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER); m_LavaSimulator = InitializeFluidSimulator(IniFile, "Lava", E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA); - m_SandSimulator = new cSandSimulator(this); - m_FireSimulator = new cFireSimulator(this); - m_RedstoneSimulator = new cRedstoneSimulator(this); + m_SandSimulator = new cSandSimulator(*this); + m_FireSimulator = new cFireSimulator(*this); + m_RedstoneSimulator = new cRedstoneSimulator(*this); // Water and Lava simulators get registered in InitializeFluidSimulator() m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1); @@ -2217,7 +2217,7 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", IsWater ? 1 : 2); int TickDelay = a_IniFile.GetValueSetI(SimulatorSectionName, "TickDelay", IsWater ? 5 : 30); int NumNeighborsForSource = a_IniFile.GetValueSetI(SimulatorSectionName, "NumNeighborsForSource", IsWater ? 2 : -1); - res = new cFloodyFluidSimulator(this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource); + res = new cFloodyFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, Falloff, TickDelay, NumNeighborsForSource); } else { @@ -2230,7 +2230,7 @@ cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const c int DefaultMaxHeight = IsWater ? 7 : 6; int Falloff = a_IniFile.GetValueSetI(SimulatorSectionName, "Falloff", DefaultFalloff); int MaxHeight = a_IniFile.GetValueSetI(SimulatorSectionName, "MaxHeight", DefaultMaxHeight); - res = new cClassicFluidSimulator(this, a_SimulateBlock, a_StationaryBlock, MaxHeight, Falloff); + res = new cClassicFluidSimulator(*this, a_SimulateBlock, a_StationaryBlock, MaxHeight, Falloff); Rate = IsWater ? 6 : 12; }