Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
cSimulator Class Referenceabstract

Base class for all block-based physics simulators (such as fluid, fire, falling blocks etc.). More...

#include <Simulator.h>

Inheritance diagram for cSimulator:
Inheritance graph
[legend]
Collaboration diagram for cSimulator:
Collaboration graph
[legend]

Public Member Functions

 cSimulator (cWorld &a_World)
 
virtual bool IsAllowedBlock (BLOCKTYPE a_BlockType)=0
 Returns true if the specified block type is "interesting" for this simulator. More...
 
virtual void Simulate (float a_Dt)=0
 Called in each tick, a_Dt is the time passed since the last tick, in msec. More...
 
virtual void SimulateChunk (std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk *a_Chunk)
 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. More...
 
void WakeUp (Vector3i a_Block, cChunk *a_Chunk)
 Called when a block changes. More...
 
void WakeUpArea (const cCuboid &a_Area)
 Does the same processing as WakeUp, but for all blocks within the specified area. More...
 
virtual ~cSimulator ()
 

Protected Member Functions

virtual void AddBlock (Vector3i a_Block, cChunk *a_Chunk)=0
 Called to simulate a new block. More...
 

Protected Attributes

cWorldm_World
 

Friends

class cChunk
 

Detailed Description

Base class for all block-based physics simulators (such as fluid, fire, falling blocks etc.).

Each descendant provides an implementation of what needs to be done on each world tick. The descendant may choose to do all processing in a single call for the entire world (Simulate()) or do per-chunk calculations (SimulateChunk()). Whenever a block is changed, the WakeUp() or WakeUpArea() functions are called to notify all simulators. The functions add all affected blocks and all their direct neighbors using the AddBlock() function. The simulator may update its internal state based on this call.

Definition at line 19 of file Simulator.h.

Constructor & Destructor Documentation

cSimulator::cSimulator ( cWorld a_World)
inline

Definition at line 22 of file Simulator.h.

virtual cSimulator::~cSimulator ( )
inlinevirtual

Definition at line 27 of file Simulator.h.

Member Function Documentation

virtual void cSimulator::AddBlock ( Vector3i  a_Block,
cChunk a_Chunk 
)
protectedpure virtual
virtual bool cSimulator::IsAllowedBlock ( BLOCKTYPE  a_BlockType)
pure virtual

Returns true if the specified block type is "interesting" for this simulator.

Implemented in cFluidSimulator, cRedstoneSimulator, cSandSimulator, cIncrementalRedstoneSimulator, cRedstoneNoopSimulator, and cFireSimulator.

virtual void cSimulator::Simulate ( float  a_Dt)
pure virtual

Called in each tick, a_Dt is the time passed since the last tick, in msec.

Implemented in cDelayedFluidSimulator, cNoopFluidSimulator, cRedstoneSimulator, cSandSimulator, cVaporizeFluidSimulator, cFireSimulator, cIncrementalRedstoneSimulator, and cRedstoneNoopSimulator.

virtual void cSimulator::SimulateChunk ( std::chrono::milliseconds  a_Dt,
int  a_ChunkX,
int  a_ChunkZ,
cChunk a_Chunk 
)
inlinevirtual

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.

Reimplemented in cDelayedFluidSimulator, cRedstoneSimulator, cSandSimulator, cFireSimulator, cIncrementalRedstoneSimulator, and cRedstoneNoopSimulator.

Definition at line 33 of file Simulator.h.

void cSimulator::WakeUp ( Vector3i  a_Block,
cChunk a_Chunk 
)

Called when a block changes.

Definition at line 21 of file Simulator.cpp.

void cSimulator::WakeUpArea ( const cCuboid a_Area)

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.

Definition at line 42 of file Simulator.cpp.

Friends And Related Function Documentation

friend class cChunk
friend

Definition at line 55 of file Simulator.h.

Member Data Documentation

cWorld& cSimulator::m_World
protected

Definition at line 60 of file Simulator.h.


The documentation for this class was generated from the following files: