Cuberite
A lightweight, fast and extensible game server for Minecraft
Simulator.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ChunkDef.h"
5 
6 class cWorld;
7 class cChunk;
8 class cCuboid;
9 
10 
11 
12 
13 
22 {
23 public:
24 
25  cSimulator(cWorld & a_World)
26  : m_World(a_World)
27  {
28  }
29 
30  virtual ~cSimulator() {}
31 
33  static constexpr std::array<Vector3i, 6> AdjacentOffsets
34  {
35  {
36  { 1, 0, 0 },
37  { -1, 0, 0 },
38  { 0, 1, 0 },
39  { 0, -1, 0 },
40  { 0, 0, 1 },
41  { 0, 0, -1 },
42  }
43  };
44 
46  static std::array<Vector3i, 5> GetLinkedOffsets(Vector3i Offset);
47 
48 protected:
49 
50  friend class cChunk; // Calls AddBlock() in its WakeUpSimulators() function, to speed things up
51  friend class cSimulatorManager; // Class reponsible for dispatching calls to the various slave Simulators
52 
53  virtual void Simulate(float a_Dt);
54  virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) = 0;
55 
58  virtual void AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) = 0;
59 
63  virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block);
64 
69  virtual void WakeUp(cChunk & a_Chunk, Vector3i a_Position, Vector3i a_Offset, BLOCKTYPE a_Block);
70 
72 } ;
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
Definition: Chunk.h:36
Definition: Cuboid.h:10
Base class for all block-based physics simulators (such as fluid, fire, falling blocks etc....
Definition: Simulator.h:22
virtual void Simulate(float a_Dt)
Definition: Simulator.cpp:96
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.
Definition: Simulator.cpp:105
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 offs...
Definition: Simulator.cpp:12
static constexpr std::array< Vector3i, 6 > AdjacentOffsets
Contains offsets for direct adjacents of any position.
Definition: Simulator.h:34
virtual void AddBlock(cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block)=0
Called to simulate a new block.
cSimulator(cWorld &a_World)
Definition: Simulator.h:25
virtual ~cSimulator()
Definition: Simulator.h:30
cWorld & m_World
Definition: Simulator.h:71
Definition: World.h:53