summaryrefslogtreecommitdiffstats
path: root/source/Simulator
diff options
context:
space:
mode:
Diffstat (limited to 'source/Simulator')
-rw-r--r--source/Simulator/ClassicFluidSimulator.cpp27
-rw-r--r--source/Simulator/ClassicFluidSimulator.h2
-rw-r--r--source/Simulator/DelayedFluidSimulator.cpp3
-rw-r--r--source/Simulator/DelayedFluidSimulator.h2
-rw-r--r--source/Simulator/FireSimulator.cpp3
-rw-r--r--source/Simulator/FireSimulator.h2
-rw-r--r--source/Simulator/RedstoneSimulator.cpp5
-rw-r--r--source/Simulator/RedstoneSimulator.h5
-rw-r--r--source/Simulator/SandSimulator.cpp28
-rw-r--r--source/Simulator/SandSimulator.h2
-rw-r--r--source/Simulator/Simulator.cpp17
-rw-r--r--source/Simulator/Simulator.h9
-rw-r--r--source/Simulator/SimulatorManager.cpp4
-rw-r--r--source/Simulator/SimulatorManager.h9
14 files changed, 69 insertions, 49 deletions
diff --git a/source/Simulator/ClassicFluidSimulator.cpp b/source/Simulator/ClassicFluidSimulator.cpp
index e195ffdc5..e005e7381 100644
--- a/source/Simulator/ClassicFluidSimulator.cpp
+++ b/source/Simulator/ClassicFluidSimulator.cpp
@@ -284,8 +284,9 @@ cClassicFluidSimulator::~cClassicFluidSimulator()
-void cClassicFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
+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);
if (!IsAllowedBlock(BlockType)) // This should save very much time because it doesn´t have to iterate through all blocks
{
@@ -389,17 +390,15 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
}
if (pos.y > 0)
{
- m_World->FastSetBlock( pos.x, pos.y-1, pos.z, m_FluidBlock, 8 ); // falling
- AddBlock( pos.x, pos.y-1, pos.z );
+ m_World->SetBlock(pos.x, pos.y - 1, pos.z, m_FluidBlock, 8); // falling
ApplyUniqueToNearest(pos - Vector3i(0, 1, 0));
}
}
- if (IsSolidBlock(DownID)||( BlockID == m_StationaryFluidBlock)) // Not falling
+ if (IsSolidBlock(DownID) || (BlockID == m_StationaryFluidBlock)) // Not falling
{
if (Feed + m_Falloff < Meta)
{
- m_World->FastSetBlock( pos.x, pos.y, pos.z, m_FluidBlock, Feed + m_Falloff);
- AddBlock( pos.x, pos.y, pos.z );
+ 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
@@ -426,21 +425,20 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
if (p.y == pos.y)
{
- m_World->FastSetBlock(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->FastSetBlock(p.x, p.y, p.z, m_FluidBlock, 8);
+ m_World->SetBlock(p.x, p.y, p.z, m_FluidBlock, 8);
}
- AddBlock( p.x, p.y, p.z );
ApplyUniqueToNearest(p);
}
else // it's fluid
{
- char PointMeta = m_World->GetBlockMeta( p.x, p.y, p.z );
- if( PointMeta > Meta + m_Falloff)
+ NIBBLETYPE PointMeta = m_World->GetBlockMeta(p.x, p.y, p.z);
+ if (PointMeta > Meta + m_Falloff)
{
- AddBlock( p.x, p.y, p.z );
+ // TODO: AddBlock(p.x, p.y, p.z);
ApplyUniqueToNearest(p);
}
}
@@ -448,10 +446,9 @@ void cClassicFluidSimulator::Simulate(float a_Dt)
}
}
}
- else// not fed
+ else // not fed
{
- m_World->FastSetBlock( pos.x, pos.y, pos.z, E_BLOCK_AIR, 0 );
- WakeUp( pos.x, pos.y, pos.z );
+ m_World->SetBlock(pos.x, pos.y, pos.z, E_BLOCK_AIR, 0);
}
}
}
diff --git a/source/Simulator/ClassicFluidSimulator.h b/source/Simulator/ClassicFluidSimulator.h
index 4198f16de..95dfd9e4a 100644
--- a/source/Simulator/ClassicFluidSimulator.h
+++ b/source/Simulator/ClassicFluidSimulator.h
@@ -24,7 +24,7 @@ public:
// cSimulator overrides:
virtual void Simulate(float a_Dt) override;
- virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
protected:
NIBBLETYPE GetHighestLevelAround(int a_BlockX, int a_BlockY, int a_BlockZ);
diff --git a/source/Simulator/DelayedFluidSimulator.cpp b/source/Simulator/DelayedFluidSimulator.cpp
index 317452c57..e0faf5b18 100644
--- a/source/Simulator/DelayedFluidSimulator.cpp
+++ b/source/Simulator/DelayedFluidSimulator.cpp
@@ -36,7 +36,7 @@ cDelayedFluidSimulator::~cDelayedFluidSimulator()
-void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
+void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
{
if ((a_BlockY < 0) || (a_BlockY >= cChunkDef::Height))
{
@@ -44,6 +44,7 @@ void cDelayedFluidSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
return;
}
+ // TODO: This can be optimized:
BLOCKTYPE BlockType = m_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
if (BlockType != m_FluidBlock)
{
diff --git a/source/Simulator/DelayedFluidSimulator.h b/source/Simulator/DelayedFluidSimulator.h
index 51fe2a514..d8ba3f858 100644
--- a/source/Simulator/DelayedFluidSimulator.h
+++ b/source/Simulator/DelayedFluidSimulator.h
@@ -25,7 +25,7 @@ public:
virtual ~cDelayedFluidSimulator();
// cSimulator overrides:
- virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
virtual void Simulate(float a_Dt) override;
protected:
diff --git a/source/Simulator/FireSimulator.cpp b/source/Simulator/FireSimulator.cpp
index 8579c2c17..0ebac74b3 100644
--- a/source/Simulator/FireSimulator.cpp
+++ b/source/Simulator/FireSimulator.cpp
@@ -72,8 +72,9 @@ bool cFireSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType)
-void cFireSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
+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);
if (!IsAllowedBlock(BlockType))
{
diff --git a/source/Simulator/FireSimulator.h b/source/Simulator/FireSimulator.h
index 826d24340..d95ecf4f0 100644
--- a/source/Simulator/FireSimulator.h
+++ b/source/Simulator/FireSimulator.h
@@ -23,7 +23,7 @@ public:
virtual bool FiresForever( BLOCKTYPE a_BlockType );
protected:
- virtual void AddBlock(int a_X, int a_Y, int a_Z) override;
+ virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
virtual bool BurnBlockAround(int a_X, int a_Y, int a_Z);
virtual bool BurnBlock(int a_X, int a_Y, int a_Z);
diff --git a/source/Simulator/RedstoneSimulator.cpp b/source/Simulator/RedstoneSimulator.cpp
index 1862537e0..d6afda413 100644
--- a/source/Simulator/RedstoneSimulator.cpp
+++ b/source/Simulator/RedstoneSimulator.cpp
@@ -29,10 +29,9 @@ cRedstoneSimulator::~cRedstoneSimulator()
-void cRedstoneSimulator::WakeUp( int a_X, int a_Y, int a_Z )
+void cRedstoneSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
{
- cCSLock Lock( m_CS );
- m_Blocks.push_back( Vector3i( a_X, a_Y, a_Z ) );
+ m_Blocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
}
diff --git a/source/Simulator/RedstoneSimulator.h b/source/Simulator/RedstoneSimulator.h
index 0b0333164..df5874d07 100644
--- a/source/Simulator/RedstoneSimulator.h
+++ b/source/Simulator/RedstoneSimulator.h
@@ -18,7 +18,7 @@ public:
virtual void Simulate( float a_Dt ) override;
virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return true; }
- virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
enum eRedstoneDirection
{
@@ -56,7 +56,7 @@ private:
void SetRepeater(const Vector3i & a_Position, int a_Ticks, bool a_bPowerOn);
- virtual void AddBlock(int a_X, int a_Y, int a_Z) {}
+ virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override {}
void HandleChange( const Vector3i & a_BlockPos );
BlockList RemoveCurrent( const Vector3i & a_BlockPos );
@@ -77,6 +77,7 @@ private:
void RefreshTorchesAround( const Vector3i & a_BlockPos );
+ // TODO: The entire simulator is synchronized, no need to lock data structures; remove this
cCriticalSection m_CS;
};
diff --git a/source/Simulator/SandSimulator.cpp b/source/Simulator/SandSimulator.cpp
index 69513afef..f9d58f030 100644
--- a/source/Simulator/SandSimulator.cpp
+++ b/source/Simulator/SandSimulator.cpp
@@ -6,6 +6,8 @@
#include "../BlockID.h"
#include "../Defines.h"
#include "../FallingBlock.h"
+#include "../Chunk.h"
+
@@ -70,19 +72,29 @@ bool cSandSimulator::IsAllowedBlock( BLOCKTYPE a_BlockType )
-void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z)
+void cSandSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
{
- if(!IsAllowedBlock(m_World->GetBlock(a_X, a_Y, a_Z)))
+ // TODO: Optimize this by passing the block type along
+ int RelX = a_BlockX;
+ int RelY = a_BlockY;
+ int RelZ = a_BlockZ;
+ int ChunkX, ChunkZ;
+ cChunkDef::AbsoluteToRelative(RelX, RelY, RelZ, ChunkX, ChunkZ);
+ if (!IsAllowedBlock(a_Chunk->GetBlock(RelX, RelY, RelZ)))
+ {
return;
+ }
- Vector3i Block(a_X, a_Y, a_Z);
+ Vector3i Block(a_BlockX, a_BlockY, a_BlockZ);
//check for duplicates
- for( BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr )
+ 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;
+ }
}
m_Blocks->push_back(Block);
@@ -92,10 +104,10 @@ void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z)
-bool cSandSimulator::IsPassable( BLOCKTYPE a_BlockType )
+bool cSandSimulator::IsPassable(BLOCKTYPE a_BlockType)
{
- return a_BlockType == E_BLOCK_AIR
+ return (a_BlockType == E_BLOCK_AIR)
|| IsBlockWater(a_BlockType)
|| IsBlockLava(a_BlockType)
- || a_BlockType == E_BLOCK_FIRE;
+ || (a_BlockType == E_BLOCK_FIRE);
}
diff --git a/source/Simulator/SandSimulator.h b/source/Simulator/SandSimulator.h
index 928ea63fc..4b786678c 100644
--- a/source/Simulator/SandSimulator.h
+++ b/source/Simulator/SandSimulator.h
@@ -21,7 +21,7 @@ public:
virtual bool IsPassable( BLOCKTYPE a_BlockType );
protected:
- virtual void AddBlock(int a_X, int a_Y, int a_Z) override;
+ virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
typedef std::list <Vector3i> BlockList;
BlockList * m_Blocks;
diff --git a/source/Simulator/Simulator.cpp b/source/Simulator/Simulator.cpp
index 86b37e989..8560163c5 100644
--- a/source/Simulator/Simulator.cpp
+++ b/source/Simulator/Simulator.cpp
@@ -6,6 +6,7 @@
#include "../Vector3i.h"
#include "../BlockID.h"
#include "../Defines.h"
+#include "../Chunk.h"
@@ -28,15 +29,15 @@ cSimulator::~cSimulator()
-void cSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ)
+void cSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
{
- AddBlock(a_BlockX, a_BlockY, a_BlockZ);
- AddBlock(a_BlockX - 1, a_BlockY, a_BlockZ);
- AddBlock(a_BlockX + 1, a_BlockY, a_BlockZ);
- AddBlock(a_BlockX, a_BlockY - 1, a_BlockZ);
- AddBlock(a_BlockX, a_BlockY + 1, a_BlockZ);
- AddBlock(a_BlockX, a_BlockY, a_BlockZ - 1);
- AddBlock(a_BlockX, a_BlockY, a_BlockZ + 1);
+ AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk);
+ AddBlock(a_BlockX, a_BlockY - 1, a_BlockZ, a_Chunk);
+ AddBlock(a_BlockX, a_BlockY + 1, a_BlockZ, a_Chunk);
+ AddBlock(a_BlockX - 1, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 1, a_BlockY, a_BlockZ));
+ AddBlock(a_BlockX + 1, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 1, a_BlockY, a_BlockZ));
+ AddBlock(a_BlockX, a_BlockY, a_BlockZ - 1, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockY, a_BlockZ - 1));
+ AddBlock(a_BlockX, a_BlockY, a_BlockZ + 1, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockY, a_BlockZ + 1));
}
diff --git a/source/Simulator/Simulator.h b/source/Simulator/Simulator.h
index 1fecb0c96..ee3489b02 100644
--- a/source/Simulator/Simulator.h
+++ b/source/Simulator/Simulator.h
@@ -8,6 +8,7 @@
class cWorld;
+class cChunk;
@@ -19,17 +20,17 @@ public:
cSimulator(cWorld * a_World);
virtual ~cSimulator();
- /// Called in each tick, a_Dt is the time passed since the last tick
+ /// Called in each tick, a_Dt is the time passed since the last tick, in msec
virtual void Simulate(float a_Dt) = 0;
- /// Called when a block changes via cWorld::SetBlock()
- virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ);
+ /// Called when a block changes
+ virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) = 0;
protected:
/// Called to simulate a new block
- virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
+ virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) = 0;
cWorld * m_World;
} ;
diff --git a/source/Simulator/SimulatorManager.cpp b/source/Simulator/SimulatorManager.cpp
index c74b273f7..ceebc2d8f 100644
--- a/source/Simulator/SimulatorManager.cpp
+++ b/source/Simulator/SimulatorManager.cpp
@@ -40,11 +40,11 @@ void cSimulatorManager::Simulate( float a_Dt )
-void cSimulatorManager::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ)
+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 )
{
- itr->first->WakeUp(a_BlockX, a_BlockY, a_BlockZ);
+ itr->first->WakeUp(a_BlockX, a_BlockY, a_BlockZ, a_Chunk);
}
}
diff --git a/source/Simulator/SimulatorManager.h b/source/Simulator/SimulatorManager.h
index fbd97b8fa..989831b03 100644
--- a/source/Simulator/SimulatorManager.h
+++ b/source/Simulator/SimulatorManager.h
@@ -15,6 +15,13 @@
+// fwd: Chunk.h
+class cChunk;
+
+
+
+
+
class cSimulatorManager
{
public:
@@ -22,7 +29,7 @@ public:
~cSimulatorManager();
void Simulate(float a_Dt);
- void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ);
+ 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!