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 
35  } ;
36 
37  cDelayedFluidSimulatorChunkData(int a_TickDelay);
39 
42 } ;
43 
44 
45 
46 
47 
49  public cFluidSimulator
50 {
52 
53 public:
54  cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay);
55 
56  // cSimulator overrides:
57  virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override;
58  virtual void Simulate(float a_Dt) override;
59  virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override;
60  virtual cFluidSimulatorData * CreateChunkData(void) override { return new cDelayedFluidSimulatorChunkData(m_TickDelay); }
61 
62 protected:
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:42
bool HasBlock(int a_RelX, int a_RelY, int a_RelZ)
Returns true if the specified block is stored.
Definition: Chunk.h:49
cSlot * m_Slots
Slots, one for each delay tick, each containing the blocks to simulate.
virtual cFluidSimulatorData * CreateChunkData(void) override
Creates a ChunkData object for the simulator to use.
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...
Definition: World.h:65
This is a base class for all fluid simulator data classes.
cCoordWithIntVector m_Blocks[16]
Array of block containers, each item stores blocks for one Z coord Int param is the block index (for ...
std::vector< cCoordWithInt > cCoordWithIntVector
Definition: ChunkDef.h:669