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"
|
2020-07-28 19:12:45 -04:00
|
|
|
#include "../Chunk.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 19:12:45 -04:00
|
|
|
void cSimulatorManager::WakeUp(cChunk & a_Chunk, Vector3i a_Position)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2020-07-28 19:12:45 -04:00
|
|
|
ASSERT(a_Chunk.IsValid());
|
|
|
|
|
2020-07-29 15:15:09 -04:00
|
|
|
for (const auto Item : m_Simulators)
|
|
|
|
{
|
|
|
|
Item.first->WakeUp(a_Chunk, a_Position, a_Chunk.GetBlock(a_Position));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto Offset : cSimulator::AdjacentOffsets)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2020-07-29 15:15:09 -04:00
|
|
|
auto Relative = a_Position + Offset;
|
2020-08-05 03:35:10 -04:00
|
|
|
if (!cChunkDef::IsValidHeight(Relative.y))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-29 15:15:09 -04:00
|
|
|
|
2020-08-05 03:35:10 -04:00
|
|
|
auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(Relative);
|
2020-07-29 15:15:09 -04:00
|
|
|
if ((Chunk == nullptr) || !Chunk->IsValid())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stored block to give to simulators for performance
|
|
|
|
// Since they all need this we save them querying it themselves
|
|
|
|
const auto Block = Chunk->GetBlock(Relative);
|
|
|
|
|
|
|
|
for (const auto Item : m_Simulators)
|
|
|
|
{
|
|
|
|
Item.first->WakeUp(*Chunk, Relative, Offset, Block);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 19:12:45 -04:00
|
|
|
void cSimulatorManager::WakeUp(const cCuboid & a_Area)
|
2017-07-14 10:18:33 -04:00
|
|
|
{
|
2020-07-28 19:12:45 -04:00
|
|
|
for (const auto Item : m_Simulators)
|
2017-07-14 10:18:33 -04:00
|
|
|
{
|
2020-07-28 19:12:45 -04:00
|
|
|
Item.first->WakeUp(a_Area);
|
2017-07-14 10:18:33 -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
|
|
|
}
|