2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "SimulatorManager.h"
|
2013-02-28 08:39:20 -05:00
|
|
|
#include "../World.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
cSimulatorManager::cSimulatorManager(cWorld & a_World) :
|
|
|
|
m_World(a_World),
|
2012-10-27 03:51:01 -04:00
|
|
|
m_Ticks(0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cSimulatorManager::~cSimulatorManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
void cSimulatorManager::Simulate(float a_Dt)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
m_Ticks++;
|
2014-07-21 09:19:48 -04:00
|
|
|
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-10-27 03:51:01 -04:00
|
|
|
if ((m_Ticks % itr->second) == 0)
|
|
|
|
{
|
|
|
|
itr->first->Simulate(a_Dt);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
void cSimulatorManager::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk)
|
2013-02-28 08:39:20 -05:00
|
|
|
{
|
|
|
|
// m_Ticks has already been increased in Simulate()
|
2014-07-21 09:19:48 -04:00
|
|
|
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr)
|
2013-02-28 08:39:20 -05:00
|
|
|
{
|
|
|
|
if ((m_Ticks % itr->second) == 0)
|
|
|
|
{
|
|
|
|
itr->first->SimulateChunk(a_Dt, a_ChunkX, a_ChunkZ, a_Chunk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 02:42:45 -05:00
|
|
|
void cSimulatorManager::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-07-21 09:19:48 -04:00
|
|
|
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-02-28 02:42:45 -05:00
|
|
|
itr->first->WakeUp(a_BlockX, a_BlockY, a_BlockZ, a_Chunk);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-25 16:54:00 -04:00
|
|
|
void cSimulatorManager::RegisterSimulator(cSimulator * a_Simulator, int a_Rate)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-10-27 03:51:01 -04:00
|
|
|
m_Simulators.push_back(std::make_pair(a_Simulator, a_Rate));
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|