2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// cSimulatorManager.h
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Simulator.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 02:42:45 -05:00
|
|
|
// fwd: Chunk.h
|
|
|
|
class cChunk;
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
// fwd: World.h
|
|
|
|
class cWorld;
|
|
|
|
|
2013-02-28 02:42:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
class cSimulatorManager
|
|
|
|
{
|
|
|
|
public:
|
2020-07-28 19:12:45 -04:00
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
cSimulatorManager(cWorld & a_World);
|
2012-06-14 09:06:06 -04:00
|
|
|
~cSimulatorManager();
|
|
|
|
|
2020-07-28 19:12:45 -04:00
|
|
|
/** Called in each tick, a_Dt is the time passed since the last tick, in msec. */
|
2012-10-27 03:51:01 -04:00
|
|
|
void Simulate(float a_Dt);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-07-28 19:12:45 -04:00
|
|
|
/** Called in each tick for each chunk, a_Dt is the time passed since the last tick, in msec; direct access to chunk data available. */
|
2015-01-11 16:12:26 -05:00
|
|
|
void SimulateChunk(std::chrono::milliseconds a_DT, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-07-29 15:15:09 -04:00
|
|
|
/* Called when a single block changes, wakes all simulators up for the block and its face-neighbors.
|
|
|
|
The simulator implementation may also decide to wake blocks farther away. */
|
2020-07-28 19:12:45 -04:00
|
|
|
void WakeUp(cChunk & a_Chunk, Vector3i a_Position);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2017-07-14 10:18:33 -04:00
|
|
|
/** Does the same processing as WakeUp, but for all blocks within the specified area.
|
|
|
|
Has better performance than calling WakeUp for each block individually, due to neighbor-checking.
|
|
|
|
All chunks intersected by the area should be valid (outputs a warning if not).
|
2020-07-28 19:12:45 -04:00
|
|
|
Note that, unlike WakeUp(), this call adds blocks not only face-neighboring, but also edge-neighboring and corner-neighboring the specified area. */
|
|
|
|
void WakeUp(const cCuboid & a_Area);
|
2017-07-14 10:18:33 -04:00
|
|
|
|
2014-10-25 16:54:00 -04:00
|
|
|
void RegisterSimulator(cSimulator * a_Simulator, int a_Rate); // Takes ownership of the simulator object!
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
protected:
|
2020-07-28 19:12:45 -04:00
|
|
|
|
2014-10-25 16:54:00 -04:00
|
|
|
typedef std::vector <std::pair<cSimulator *, int> > cSimulators;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
cWorld & m_World;
|
2012-06-14 09:06:06 -04:00
|
|
|
cSimulators m_Simulators;
|
|
|
|
long long m_Ticks;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|