2012-06-14 13:06:06 +00:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 22:09:57 +00:00
|
|
|
#include "SimulatorManager.h"
|
2020-07-28 23:12:45 +00:00
|
|
|
#include "../Chunk.h"
|
2013-02-28 13:39:20 +00:00
|
|
|
#include "../World.h"
|
2012-06-14 13:06:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 13:39:20 +00:00
|
|
|
cSimulatorManager::cSimulatorManager(cWorld & a_World) :
|
|
|
|
m_World(a_World),
|
2012-10-27 07:51:01 +00:00
|
|
|
m_Ticks(0)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cSimulatorManager::~cSimulatorManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 13:39:20 +00:00
|
|
|
void cSimulatorManager::Simulate(float a_Dt)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
|
|
|
m_Ticks++;
|
2014-07-21 13:19:48 +00:00
|
|
|
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2012-10-27 07:51:01 +00:00
|
|
|
if ((m_Ticks % itr->second) == 0)
|
|
|
|
{
|
|
|
|
itr->first->Simulate(a_Dt);
|
|
|
|
}
|
2012-06-14 13:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 21:12:26 +00:00
|
|
|
void cSimulatorManager::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk)
|
2013-02-28 13:39:20 +00:00
|
|
|
{
|
|
|
|
// m_Ticks has already been increased in Simulate()
|
2014-07-21 13:19:48 +00:00
|
|
|
for (cSimulators::iterator itr = m_Simulators.begin(); itr != m_Simulators.end(); ++itr)
|
2013-02-28 13:39:20 +00:00
|
|
|
{
|
|
|
|
if ((m_Ticks % itr->second) == 0)
|
|
|
|
{
|
|
|
|
itr->first->SimulateChunk(a_Dt, a_ChunkX, a_ChunkZ, a_Chunk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 23:12:45 +00:00
|
|
|
void cSimulatorManager::WakeUp(cChunk & a_Chunk, Vector3i a_Position)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2020-07-28 23:12:45 +00:00
|
|
|
ASSERT(a_Chunk.IsValid());
|
|
|
|
|
2020-10-05 10:27:14 +00:00
|
|
|
for (const auto & Item : m_Simulators)
|
2020-07-29 19:15:09 +00:00
|
|
|
{
|
|
|
|
Item.first->WakeUp(a_Chunk, a_Position, a_Chunk.GetBlock(a_Position));
|
|
|
|
}
|
|
|
|
|
2020-10-05 10:27:14 +00:00
|
|
|
for (const auto & Offset : cSimulator::AdjacentOffsets)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2020-07-29 19:15:09 +00:00
|
|
|
auto Relative = a_Position + Offset;
|
2020-08-05 07:35:10 +00:00
|
|
|
if (!cChunkDef::IsValidHeight(Relative.y))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-29 19:15:09 +00:00
|
|
|
|
2020-08-05 07:35:10 +00:00
|
|
|
auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(Relative);
|
2020-07-29 19:15:09 +00: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);
|
|
|
|
|
2020-10-05 10:27:14 +00:00
|
|
|
for (const auto & Item : m_Simulators)
|
2020-07-29 19:15:09 +00:00
|
|
|
{
|
|
|
|
Item.first->WakeUp(*Chunk, Relative, Offset, Block);
|
|
|
|
}
|
2012-06-14 13:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-28 23:12:45 +00:00
|
|
|
void cSimulatorManager::WakeUp(const cCuboid & a_Area)
|
2017-07-14 14:18:33 +00:00
|
|
|
{
|
2020-10-05 10:27:14 +00:00
|
|
|
for (const auto & Item : m_Simulators)
|
2017-07-14 14:18:33 +00:00
|
|
|
{
|
2020-07-28 23:12:45 +00:00
|
|
|
Item.first->WakeUp(a_Area);
|
2017-07-14 14:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-25 20:54:00 +00:00
|
|
|
void cSimulatorManager::RegisterSimulator(cSimulator * a_Simulator, int a_Rate)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2012-10-27 07:51:01 +00:00
|
|
|
m_Simulators.push_back(std::make_pair(a_Simulator, a_Rate));
|
2012-06-14 13:06:06 +00:00
|
|
|
}
|