summaryrefslogtreecommitdiffstats
path: root/source/Simulator
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-13 11:53:28 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-13 11:53:28 +0200
commitf7da7c2536b438db92bc28b88c4139d9af15e44f (patch)
tree4710e9e41ebcf2317ebacade2801732ba9184b41 /source/Simulator
parentProtoProxy: Fixed parsing of the PACKET_PLAYER_ABILITIES packet. (diff)
downloadcuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.gz
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.bz2
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.lz
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.xz
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.tar.zst
cuberite-f7da7c2536b438db92bc28b88c4139d9af15e44f.zip
Diffstat (limited to '')
-rw-r--r--source/Simulator.cpp33
-rw-r--r--source/Simulator.h20
-rw-r--r--source/Simulator/ClassicFluidSimulator.h58
-rw-r--r--source/Simulator/FireSimulator.cpp (renamed from source/FireSimulator.cpp)57
-rw-r--r--source/Simulator/FireSimulator.h (renamed from source/FireSimulator.h)11
-rw-r--r--source/Simulator/FluidSimulator.cpp19
-rw-r--r--source/Simulator/FluidSimulator.h47
-rw-r--r--source/Simulator/LavaSimulator.cpp (renamed from source/LavaSimulator.cpp)0
-rw-r--r--source/Simulator/LavaSimulator.h (renamed from source/LavaSimulator.h)0
-rw-r--r--source/Simulator/RedstoneSimulator.cpp (renamed from source/RedstoneSimulator.cpp)8
-rw-r--r--source/Simulator/RedstoneSimulator.h (renamed from source/RedstoneSimulator.h)1
-rw-r--r--source/Simulator/SandSimulator.cpp (renamed from source/SandSimulator.cpp)9
-rw-r--r--source/Simulator/SandSimulator.h (renamed from source/SandSimulator.h)10
-rw-r--r--source/Simulator/Simulator.cpp44
-rw-r--r--source/Simulator/Simulator.h38
-rw-r--r--source/Simulator/SimulatorManager.cpp (renamed from source/SimulatorManager.cpp)4
-rw-r--r--source/Simulator/SimulatorManager.h (renamed from source/SimulatorManager.h)0
-rw-r--r--source/Simulator/WaterSimulator.cpp (renamed from source/WaterSimulator.cpp)0
-rw-r--r--source/Simulator/WaterSimulator.h (renamed from source/WaterSimulator.h)0
19 files changed, 271 insertions, 88 deletions
diff --git a/source/Simulator.cpp b/source/Simulator.cpp
deleted file mode 100644
index e4608e150..000000000
--- a/source/Simulator.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-
-#include "Simulator.h"
-#include "World.h"
-#include "Vector3i.h"
-#include "BlockID.h"
-#include "Defines.h"
-
-
-
-
-
-cSimulator::cSimulator( cWorld* a_World )
- : m_World(a_World)
-{
-
-}
-
-cSimulator::~cSimulator()
-{
-}
-
-void cSimulator::WakeUp( int a_X, int a_Y, int a_Z )
-{
- AddBlock( a_X, a_Y, a_Z );
- AddBlock( a_X-1, a_Y, a_Z );
- AddBlock( a_X+1, a_Y, a_Z );
- AddBlock( a_X, a_Y-1, a_Z );
- AddBlock( a_X, a_Y+1, a_Z );
- AddBlock( a_X, a_Y, a_Z-1 );
- AddBlock( a_X, a_Y, a_Z+1 );
-}
diff --git a/source/Simulator.h b/source/Simulator.h
deleted file mode 100644
index 00e1b5a0c..000000000
--- a/source/Simulator.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-class Vector3i;
-class cWorld;
-class cSimulator
-{
-public:
- cSimulator( cWorld* a_World );
- ~cSimulator();
-
- virtual void Simulate( float a_Dt ) = 0;
- virtual void WakeUp( int a_X, int a_Y, int a_Z );
-
- virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) = 0;
-
-protected:
- virtual void AddBlock(int a_X, int a_Y, int a_Z) = 0;
-
- cWorld * m_World;
-}; \ No newline at end of file
diff --git a/source/Simulator/ClassicFluidSimulator.h b/source/Simulator/ClassicFluidSimulator.h
new file mode 100644
index 000000000..ebccda487
--- /dev/null
+++ b/source/Simulator/ClassicFluidSimulator.h
@@ -0,0 +1,58 @@
+
+// ClassicFluidSimulator.h
+
+// Interfaces to the cClassicFluidSimulator class representing the original MCServer's fluid simulator
+
+
+
+
+
+#pragma once
+
+#include "FluidSimulator.h"
+
+
+
+
+
+class cClassicFluidSimulator :
+ public cFluidSimulator
+{
+public:
+ cClassicFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, NIBBLETYPE a_MaxHeight, NIBBLETYPE a_Falloff);
+ ~cClassicFluidSimulator();
+
+ // cSimulator overrides:
+ virtual void Simulate(float a_Dt) override;
+ virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ) override;
+ virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override;
+
+ // cFluidSimulator overrides:
+ virtual Direction GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over = true) override;
+
+ bool CanWashAway (BLOCKTYPE a_BlockType);
+ bool IsSolidBlock(BLOCKTYPE a_BlockType);
+ bool IsPassableForFluid(BLOCKTYPE a_BlockType);
+
+protected:
+ NIBBLETYPE GetHighestLevelAround(int a_BlockX, int a_BlockY, int a_BlockZ);
+
+ /// Applies special rules such as generation of water between sources, returns false if it is necessary to apply general rules
+ bool UniqueSituation(Vector3i a_Pos);
+
+ void ApplyUniqueToNearest(Vector3i a_Pos);
+
+ float m_Timer;
+
+ // fwd: ClassicFluidSimulator.cpp
+ class FluidData;
+
+ FluidData * m_Data;
+
+ NIBBLETYPE m_MaxHeight;
+ NIBBLETYPE m_Falloff;
+} ;
+
+
+
+
diff --git a/source/FireSimulator.cpp b/source/Simulator/FireSimulator.cpp
index 1dc104d0c..c2f22668b 100644
--- a/source/FireSimulator.cpp
+++ b/source/Simulator/FireSimulator.cpp
@@ -2,10 +2,13 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "FireSimulator.h"
-#include "World.h"
-#include "Vector3i.h"
-#include "BlockID.h"
-#include "Defines.h"
+#include "../World.h"
+#include "../BlockID.h"
+#include "../Defines.h"
+
+
+
+
cFireSimulator::cFireSimulator( cWorld* a_World )
: cSimulator(a_World)
@@ -13,9 +16,12 @@ cFireSimulator::cFireSimulator( cWorld* a_World )
, m_Buffer(new BlockList)
, m_BurningBlocks(new BlockList)
{
-
}
+
+
+
+
cFireSimulator::~cFireSimulator()
{
delete m_Buffer;
@@ -23,6 +29,10 @@ cFireSimulator::~cFireSimulator()
delete m_BurningBlocks;
}
+
+
+
+
void cFireSimulator::Simulate( float a_Dt )
{
m_Buffer->clear();
@@ -48,12 +58,19 @@ void cFireSimulator::Simulate( float a_Dt )
}
+
+
+
bool cFireSimulator::IsAllowedBlock( BLOCKTYPE a_BlockType )
{
return a_BlockType == E_BLOCK_FIRE
|| IsBlockLava(a_BlockType);
}
+
+
+
+
void cFireSimulator::AddBlock(int a_X, int a_Y, int a_Z)
{
char BlockID = m_World->GetBlock(a_X, a_Y, a_Z);
@@ -72,17 +89,29 @@ void cFireSimulator::AddBlock(int a_X, int a_Y, int 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) );
}
+
+
+
+
bool cFireSimulator::IsForeverBurnable( BLOCKTYPE a_BlockType )
{
return a_BlockType == E_BLOCK_BLOODSTONE;
}
+
+
+
+
bool cFireSimulator::IsBurnable( BLOCKTYPE a_BlockType )
{
return a_BlockType == E_BLOCK_PLANKS
@@ -95,11 +124,19 @@ bool cFireSimulator::IsBurnable( BLOCKTYPE a_BlockType )
|| a_BlockType == E_BLOCK_VINES;
}
+
+
+
+
bool cFireSimulator::FiresForever( BLOCKTYPE a_BlockType )
{
return a_BlockType != E_BLOCK_FIRE;
}
+
+
+
+
bool cFireSimulator::BurnBlockAround(int a_X, int a_Y, int a_Z)
{
return BurnBlock(a_X + 1, a_Y, a_Z)
@@ -110,6 +147,10 @@ bool cFireSimulator::BurnBlockAround(int a_X, int a_Y, int a_Z)
|| BurnBlock(a_X, a_Y, a_Z - 1);
}
+
+
+
+
bool cFireSimulator::BurnBlock(int a_X, int a_Y, int a_Z)
{
char BlockID = m_World->GetBlock(a_X, a_Y, a_Z);
@@ -130,4 +171,8 @@ bool cFireSimulator::BurnBlock(int a_X, int a_Y, int a_Z)
}
return false;
-} \ No newline at end of file
+}
+
+
+
+
diff --git a/source/FireSimulator.h b/source/Simulator/FireSimulator.h
index 90e6a6062..753259c2c 100644
--- a/source/FireSimulator.h
+++ b/source/Simulator/FireSimulator.h
@@ -2,14 +2,7 @@
#pragma once
#include "Simulator.h"
-#include "BlockEntity.h"
-
-
-
-
-
-class Vector3i;
-class cWorld;
+#include "../BlockEntity.h"
@@ -31,7 +24,7 @@ public:
protected:
virtual void AddBlock(int a_X, int a_Y, int a_Z) override;
- virtual void _AddBlock(int a_X, int a_Y, int a_Z);
+ virtual void _AddBlock(int a_X, int a_Y, int a_Z); // _X 2012_10_13: WTF? what kind of naming is this? Use proper names!
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/FluidSimulator.cpp b/source/Simulator/FluidSimulator.cpp
new file mode 100644
index 000000000..d352d5d4d
--- /dev/null
+++ b/source/Simulator/FluidSimulator.cpp
@@ -0,0 +1,19 @@
+
+#include "Globals.h"
+
+#include "FluidSimulator.h"
+
+
+
+
+
+cFluidSimulator::cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid) :
+ super(a_World),
+ m_FluidBlock(a_Fluid),
+ m_StationaryFluidBlock(a_StationaryFluid)
+{
+}
+
+
+
+
diff --git a/source/Simulator/FluidSimulator.h b/source/Simulator/FluidSimulator.h
new file mode 100644
index 000000000..f0b2b23ba
--- /dev/null
+++ b/source/Simulator/FluidSimulator.h
@@ -0,0 +1,47 @@
+
+#pragma once
+
+#include "Simulator.h"
+
+
+
+
+
+enum Direction
+{
+ X_PLUS,
+ X_MINUS,
+ Y_PLUS,
+ Y_MINUS,
+ Z_PLUS,
+ Z_MINUS,
+ NONE
+};
+
+
+
+
+
+class cFluidSimulator :
+ public cSimulator
+{
+ typedef cSimulator super;
+
+public:
+ cFluidSimulator(cWorld * a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid);
+
+ // Gets the flowing direction. If a_Over is true also the block over the current block affects the direction (standard)
+ virtual Direction GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a_Over = true) = 0;
+
+ bool IsFluidBlock (BLOCKTYPE a_BlockType) const { return (a_BlockType == m_FluidBlock); }
+ bool IsStationaryFluidBlock(BLOCKTYPE a_BlockType) const { return (a_BlockType == m_StationaryFluidBlock); }
+
+protected:
+ BLOCKTYPE m_FluidBlock; // The fluid block type that needs simulating
+ BLOCKTYPE m_StationaryFluidBlock; // The fluid block type that indicates no simulation is needed
+} ;
+
+
+
+
+
diff --git a/source/LavaSimulator.cpp b/source/Simulator/LavaSimulator.cpp
index 726cc37e4..726cc37e4 100644
--- a/source/LavaSimulator.cpp
+++ b/source/Simulator/LavaSimulator.cpp
diff --git a/source/LavaSimulator.h b/source/Simulator/LavaSimulator.h
index d85b335b7..d85b335b7 100644
--- a/source/LavaSimulator.h
+++ b/source/Simulator/LavaSimulator.h
diff --git a/source/RedstoneSimulator.cpp b/source/Simulator/RedstoneSimulator.cpp
index 6c3e27228..1c30be324 100644
--- a/source/RedstoneSimulator.cpp
+++ b/source/Simulator/RedstoneSimulator.cpp
@@ -2,10 +2,10 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "RedstoneSimulator.h"
-#include "Piston.h"
-#include "World.h"
-#include "BlockID.h"
-#include "Torch.h"
+#include "../Piston.h"
+#include "../World.h"
+#include "../BlockID.h"
+#include "../Torch.h"
diff --git a/source/RedstoneSimulator.h b/source/Simulator/RedstoneSimulator.h
index c1996bb4e..f26b6b46b 100644
--- a/source/RedstoneSimulator.h
+++ b/source/Simulator/RedstoneSimulator.h
@@ -2,7 +2,6 @@
#pragma once
#include "Simulator.h"
-#include "Vector3i.h"
diff --git a/source/SandSimulator.cpp b/source/Simulator/SandSimulator.cpp
index a2e1dc4cb..69513afef 100644
--- a/source/SandSimulator.cpp
+++ b/source/Simulator/SandSimulator.cpp
@@ -2,11 +2,10 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "SandSimulator.h"
-#include "World.h"
-#include "Vector3i.h"
-#include "BlockID.h"
-#include "Defines.h"
-#include "FallingBlock.h"
+#include "../World.h"
+#include "../BlockID.h"
+#include "../Defines.h"
+#include "../FallingBlock.h"
diff --git a/source/SandSimulator.h b/source/Simulator/SandSimulator.h
index ff39d62b2..928ea63fc 100644
--- a/source/SandSimulator.h
+++ b/source/Simulator/SandSimulator.h
@@ -2,14 +2,8 @@
#pragma once
#include "Simulator.h"
-#include "BlockEntity.h"
-#include "Vector3i.h"
-
-
-
-
-
-class cWorld;
+#include "../BlockEntity.h"
+#include "../Vector3i.h"
diff --git a/source/Simulator/Simulator.cpp b/source/Simulator/Simulator.cpp
new file mode 100644
index 000000000..86b37e989
--- /dev/null
+++ b/source/Simulator/Simulator.cpp
@@ -0,0 +1,44 @@
+
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+
+#include "Simulator.h"
+#include "../World.h"
+#include "../Vector3i.h"
+#include "../BlockID.h"
+#include "../Defines.h"
+
+
+
+
+
+cSimulator::cSimulator( cWorld* a_World )
+ : m_World(a_World)
+{
+}
+
+
+
+
+
+cSimulator::~cSimulator()
+{
+}
+
+
+
+
+
+void cSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ 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);
+}
+
+
+
+
diff --git a/source/Simulator/Simulator.h b/source/Simulator/Simulator.h
new file mode 100644
index 000000000..84a1630c2
--- /dev/null
+++ b/source/Simulator/Simulator.h
@@ -0,0 +1,38 @@
+
+#pragma once
+
+#include "../Vector3i.h"
+
+
+
+
+
+class cWorld;
+
+
+
+
+
+class cSimulator
+{
+public:
+ cSimulator(cWorld * a_World);
+ virtual ~cSimulator();
+
+ /// Called in each tick, a_Dt is the time passed since the last tick
+ 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);
+
+ virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) = 0;
+
+protected:
+ virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ) = 0;
+
+ cWorld * m_World;
+} ;
+
+
+
+
diff --git a/source/SimulatorManager.cpp b/source/Simulator/SimulatorManager.cpp
index 0aef1ec6c..1ab7a51b5 100644
--- a/source/SimulatorManager.cpp
+++ b/source/Simulator/SimulatorManager.cpp
@@ -42,11 +42,11 @@ void cSimulatorManager::Simulate( float a_Dt )
-void cSimulatorManager::WakeUp(int a_X, int a_Y, int a_Z)
+void cSimulatorManager::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ)
{
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr )
{
- (*itr)->first->WakeUp(a_X, a_Y, a_Z);
+ (*itr)->first->WakeUp(a_BlockX, a_BlockY, a_BlockZ);
}
}
diff --git a/source/SimulatorManager.h b/source/Simulator/SimulatorManager.h
index e90acffab..e90acffab 100644
--- a/source/SimulatorManager.h
+++ b/source/Simulator/SimulatorManager.h
diff --git a/source/WaterSimulator.cpp b/source/Simulator/WaterSimulator.cpp
index c63135419..c63135419 100644
--- a/source/WaterSimulator.cpp
+++ b/source/Simulator/WaterSimulator.cpp
diff --git a/source/WaterSimulator.h b/source/Simulator/WaterSimulator.h
index 4bc35b8f7..4bc35b8f7 100644
--- a/source/WaterSimulator.h
+++ b/source/Simulator/WaterSimulator.h