summaryrefslogtreecommitdiffstats
path: root/src/Simulator/Simulator.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Simulator/Simulator.h')
-rw-r--r--src/Simulator/Simulator.h44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/Simulator/Simulator.h b/src/Simulator/Simulator.h
index 669680693..5bd5d8f30 100644
--- a/src/Simulator/Simulator.h
+++ b/src/Simulator/Simulator.h
@@ -19,6 +19,7 @@ may update its internal state based on this call. */
class cSimulator
{
public:
+
cSimulator(cWorld & a_World)
: m_World(a_World)
{
@@ -26,10 +27,13 @@ public:
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;
+ virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block);
- /** 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 */
+protected:
+
+ friend class cChunk; // Calls AddBlock() in its WakeUpSimulators() function, to speed things up
+
+ virtual void Simulate(float a_Dt) = 0;
virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk)
{
UNUSED(a_Dt);
@@ -38,28 +42,26 @@ public:
UNUSED(a_Chunk);
}
- /** Called when a block changes */
- void WakeUp(Vector3i a_Block, cChunk * a_Chunk);
-
- /** Does the same processing as WakeUp, but for all blocks within the specified area.
- Has better performance than calling WakeUp for each block individually, due to neighbor-checking.
- All chunks intersected by the area should be valid (outputs a warning if not).
- Note that, unlike WakeUp(), this call adds blocks not only face-neighboring, but also edge-neighboring and
- corner-neighboring the specified area. So far none of the simulators care about that. */
- void WakeUpArea(const cCuboid & a_Area);
-
/** Returns true if the specified block type is "interesting" for this simulator. */
virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) = 0;
-protected:
- friend class cChunk; // Calls AddBlock() in its WakeUpSimulators() function, to speed things up
-
- /** Called to simulate a new block */
- virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) = 0;
-
- cWorld & m_World;
-} ;
+ /** Called to simulate a new block. Unlike WakeUp this function will perform minimal checking.
+ It queues the block to be simulated as fast as possible, only making sure that the block type IsAllowedBlock. */
+ virtual void AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) = 0;
+ /** Called to simulate a single new block, typically as a result of a single block break or change.
+ The simulator implementation may decide to perform additional checks or maintain consistency of internal state
+ before the block is added to the simulate queue. */
+ virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block);
+ /** Called to simulate a single block, synthesised by the simulator manager.
+ The position represents the adjacents of the block that was actually changed, with the offset used given.
+ Simulators may use this information to update additional blocks that were affected by the change, or queue
+ farther, extra-adjacents blocks to be updated. The simulator manager calls this overload after the 3-argument WakeUp. */
+ virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, Vector3i a_Offset, BLOCKTYPE a_Block);
+ /** Called to simulate an area by the manager, delegated to cSimulator to avoid virtual calls in tight loops. */
+ void WakeUp(const cCuboid & a_Area);
+ cWorld & m_World;
+} ;