Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Member Functions | Static Public Member Functions | Static Public Attributes | 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 ~cSimulator ()
 

Static Public Member Functions

static std::array< Vector3i, 5 > GetLinkedOffsets (Vector3i Offset)
 For a given offset from a position, return the offsets that represent the adjacents of the newly offset position, excluding the old position. More...
 

Static Public Attributes

static constexpr std::array< Vector3i, 6 > AdjacentOffsets
 Contains offsets for direct adjacents of any position. More...
 

Protected Member Functions

virtual void AddBlock (cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block)=0
 Called to simulate a new block. More...
 
virtual void Simulate (float a_Dt)
 
virtual void SimulateChunk (std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk *a_Chunk)=0
 
virtual void WakeUp (cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block)
 Called to simulate a single new block, typically as a result of a single block break or change. More...
 
virtual void WakeUp (cChunk &a_Chunk, Vector3i a_Position, Vector3i a_Offset, BLOCKTYPE a_Block)
 Called to simulate a single block, synthesised by the simulator manager. More...
 

Protected Attributes

cWorldm_World
 

Friends

class cChunk
 
class cSimulatorManager
 

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() functions are called to notify all simulators by the simulator manager. The functions are invoked to add all affected blocks and their direct neighbors using the AddBlock() function. The simulator may update its internal state based on this call.

Definition at line 21 of file Simulator.h.

Constructor & Destructor Documentation

◆ cSimulator()

cSimulator::cSimulator ( cWorld a_World)
inline

Definition at line 25 of file Simulator.h.

◆ ~cSimulator()

virtual cSimulator::~cSimulator ( )
inlinevirtual

Definition at line 30 of file Simulator.h.

Member Function Documentation

◆ AddBlock()

virtual void cSimulator::AddBlock ( cChunk a_Chunk,
Vector3i  a_Position,
BLOCKTYPE  a_Block 
)
protectedpure virtual

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, suitable for area wakeups.

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

◆ GetLinkedOffsets()

std::array< Vector3i, 5 > cSimulator::GetLinkedOffsets ( Vector3i  Offset)
static

For a given offset from a position, return the offsets that represent the adjacents of the newly offset position, excluding the old position.

Definition at line 12 of file Simulator.cpp.

◆ Simulate()

void cSimulator::Simulate ( float  a_Dt)
protectedvirtual

Reimplemented in cDelayedFluidSimulator.

Definition at line 96 of file Simulator.cpp.

◆ SimulateChunk()

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

◆ WakeUp() [1/2]

void cSimulator::WakeUp ( cChunk a_Chunk,
Vector3i  a_Position,
BLOCKTYPE  a_Block 
)
protectedvirtual

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.

Reimplemented in cIncrementalRedstoneSimulator.

Definition at line 105 of file Simulator.cpp.

◆ WakeUp() [2/2]

void cSimulator::WakeUp ( cChunk a_Chunk,
Vector3i  a_Position,
Vector3i  a_Offset,
BLOCKTYPE  a_Block 
)
protectedvirtual

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.

Reimplemented in cIncrementalRedstoneSimulator.

Definition at line 116 of file Simulator.cpp.

Friends And Related Function Documentation

◆ cChunk

friend class cChunk
friend

Definition at line 50 of file Simulator.h.

◆ cSimulatorManager

friend class cSimulatorManager
friend

Definition at line 51 of file Simulator.h.

Member Data Documentation

◆ AdjacentOffsets

constexpr std::array<Vector3i, 6> cSimulator::AdjacentOffsets
staticconstexpr
Initial value:
{
{
{ 1, 0, 0 },
{ -1, 0, 0 },
{ 0, 1, 0 },
{ 0, -1, 0 },
{ 0, 0, 1 },
{ 0, 0, -1 },
}
}

Contains offsets for direct adjacents of any position.

Definition at line 33 of file Simulator.h.

◆ m_World

cWorld& cSimulator::m_World
protected

Definition at line 71 of file Simulator.h.


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