Cuberite
A lightweight, fast and extensible game server for Minecraft
DelayedFluidSimulator.h
Go to the documentation of this file.
1 
2 // DelayedFluidSimulator.h
3 
4 // Interfaces to the cDelayedFluidSimulator class representing a fluid simulator that has a configurable delay
5 // before simulating a block. Each tick it takes a consecutive delay "slot" and simulates only blocks in that slot.
6 
7 
8 
9 
10 #pragma once
11 
12 #include "FluidSimulator.h"
13 
14 
15 
16 
17 
19  public cFluidSimulatorData
20 {
21 public:
22  class cSlot
23  {
24  public:
26  bool HasBlock(int a_RelX, int a_RelY, int a_RelZ);
27 
29  bool Add(int a_RelX, int a_RelY, int a_RelZ);
30 
34  std::vector<cCoordWithData<size_t>> m_Blocks[16];
35  } ;
36 
37  cDelayedFluidSimulatorChunkData(int a_TickDelay);
38  virtual ~cDelayedFluidSimulatorChunkData() override;
39 
42 } ;
43 
44 
45 
46 
47 
49  public cFluidSimulator
50 {
52 
53 public:
54 
55  cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay);
56 
57 protected:
58 
59  virtual void Simulate(float a_Dt) override;
60  virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override;
61  virtual void AddBlock(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override;
63 
64  int m_TickDelay; // Count of the m_Slots array in each ChunkData
65  int m_AddSlotNum; // Index into m_Slots[] where to add new blocks in each ChunkData
66  int m_SimSlotNum; // Index into m_Slots[] where to simulate blocks in each ChunkData
67 
68  int m_TotalBlocks; // Statistics only: the total number of blocks currently queued
69 
70  /* Slots:
71  | 0 | 1 | ... | m_AddSlotNum | m_SimSlotNum | ... | m_TickDelay - 1 |
72  | adding blocks here ^ | ^ simulating here */
73 
75  virtual void SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ) = 0;
76 } ;
77 
78 
79 
80 
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
Definition: Chunk.h:36
cSlot * m_Slots
Slots, one for each delay tick, each containing the blocks to simulate.
virtual ~cDelayedFluidSimulatorChunkData() override
bool HasBlock(int a_RelX, int a_RelY, int a_RelZ)
Returns true if the specified block is stored.
std::vector< cCoordWithData< size_t > > m_Blocks[16]
Array of block containers, each item stores blocks for one Z coord size_t param is the block index (f...
bool Add(int a_RelX, int a_RelY, int a_RelZ)
Adds the specified block unless already present; returns true if added, false if the block was alread...
virtual void AddBlock(cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_Block) override
Called to simulate a new block.
virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk *a_Chunk) override
virtual void SimulateBlock(cChunk *a_Chunk, int a_RelX, int a_RelY, int a_RelZ)=0
Called from SimulateChunk() to simulate each block in one slot of blocks.
cDelayedFluidSimulator(cWorld &a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay)
virtual void Simulate(float a_Dt) override
virtual cFluidSimulatorData * CreateChunkData(void) override
Creates a ChunkData object for the simulator to use.
This is a base class for all fluid simulator data classes.
cFluidSimulator(cWorld &a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid)
Definition: World.h:53