2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// DelayedFluidSimulator.h
|
|
|
|
|
|
|
|
// Interfaces to the cDelayedFluidSimulator class representing a fluid simulator that has a configurable delay
|
|
|
|
// before simulating a block. Each tick it takes a consecutive delay "slot" and simulates only blocks in that slot.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "FluidSimulator.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cDelayedFluidSimulatorChunkData :
|
|
|
|
public cFluidSimulatorData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class cSlot
|
|
|
|
{
|
|
|
|
public:
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Returns true if the specified block is stored */
|
2013-07-29 07:13:03 -04:00
|
|
|
bool HasBlock(int a_RelX, int a_RelY, int a_RelZ);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Adds the specified block unless already present; returns true if added, false if the block was already present */
|
2013-07-29 07:13:03 -04:00
|
|
|
bool Add(int a_RelX, int a_RelY, int a_RelZ);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
/** Array of block containers, each item stores blocks for one Z coord
|
|
|
|
Int param is the block index (for faster duplicate comparison in Add())
|
|
|
|
*/
|
|
|
|
cCoordWithIntVector m_Blocks[16];
|
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
cDelayedFluidSimulatorChunkData(int a_TickDelay);
|
|
|
|
virtual ~cDelayedFluidSimulatorChunkData();
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Slots, one for each delay tick, each containing the blocks to simulate */
|
2013-07-29 07:13:03 -04:00
|
|
|
cSlot * m_Slots;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cDelayedFluidSimulator :
|
|
|
|
public cFluidSimulator
|
|
|
|
{
|
|
|
|
typedef cFluidSimulator super;
|
|
|
|
|
2014-07-17 16:50:58 -04:00
|
|
|
public:
|
2013-07-29 07:13:03 -04:00
|
|
|
cDelayedFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid, int a_TickDelay);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
// cSimulator overrides:
|
2017-08-17 09:48:38 -04:00
|
|
|
virtual void AddBlock(Vector3i a_Block, cChunk * a_Chunk) override;
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual void Simulate(float a_Dt) override;
|
2015-01-11 16:12:26 -05:00
|
|
|
virtual void SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override;
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual cFluidSimulatorData * CreateChunkData(void) override { return new cDelayedFluidSimulatorChunkData(m_TickDelay); }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
int m_TickDelay; // Count of the m_Slots array in each ChunkData
|
|
|
|
int m_AddSlotNum; // Index into m_Slots[] where to add new blocks in each ChunkData
|
|
|
|
int m_SimSlotNum; // Index into m_Slots[] where to simulate blocks in each ChunkData
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
int m_TotalBlocks; // Statistics only: the total number of blocks currently queued
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/* Slots:
|
2013-07-29 07:13:03 -04:00
|
|
|
| 0 | 1 | ... | m_AddSlotNum | m_SimSlotNum | ... | m_TickDelay - 1 |
|
2015-07-31 10:49:10 -04:00
|
|
|
| adding blocks here ^ | ^ simulating here */
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Called from SimulateChunk() to simulate each block in one slot of blocks. Descendants override this method to provide custom simulation. */
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual void SimulateBlock(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ) = 0;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|