37 if ((
m_Ticks % itr->second) == 0)
39 itr->first->Simulate(a_Dt);
54 if ((
m_Ticks % itr->second) == 0)
56 itr->first->SimulateChunk(a_Dt, a_ChunkX, a_ChunkZ, a_Chunk);
71 Item.first->WakeUp(a_Chunk, a_Position, a_Chunk.
GetBlock(a_Position));
76 auto Relative = a_Position + Offset;
85 if ((Chunk ==
nullptr) || !Chunk->IsValid())
92 const auto Block = Chunk->GetBlock(Relative);
96 Item.first->WakeUp(*Chunk, Relative, Offset,
Block);
109 area.
Expand(1, 1, 1, 1, 1, 1);
129 const auto Simulator =
Item.first;
131 for (
int y = area.
p1.
y; y <= area.
p2.
y; ++y)
133 for (
int z = startZ; z <= endZ; ++z)
135 for (
int x = startX; x <= endX; ++x)
138 Simulator->WakeUp(a_CBChunk, Position, a_CBChunk.
GetBlock(Position));
155 m_Simulators.push_back(std::make_pair(a_Simulator, a_Rate));
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
bool IsValid(void) const
Returns true iff the chunk block data is valid (loaded / generated)
Wraps the chunk coords into a single structure.
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
Expands the cuboid by the specified amount in each direction.
void ClampY(int a_MinY, int a_MaxY)
Clamps both Y coords to the specified range.
Base class for all block-based physics simulators (such as fluid, fire, falling blocks etc....
static constexpr std::array< Vector3i, 6 > AdjacentOffsets
Contains offsets for direct adjacents of any position.
void RegisterSimulator(cSimulator *a_Simulator, int a_Rate)
cSimulatorManager(cWorld &a_World)
void SimulateChunk(std::chrono::milliseconds a_DT, int a_ChunkX, int a_ChunkZ, cChunk *a_Chunk)
Called in each tick for each chunk, a_Dt is the time passed since the last tick, in msec; direct acce...
void Simulate(float a_Dt)
Called in each tick, a_Dt is the time passed since the last tick, in msec.
void WakeUp(cChunk &a_Chunk, Vector3i a_Position)
bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
Calls the callback for the chunk specified, with ChunkMapCS locked.