Possibly decoupled IncrementalRedstoneSimulator from the rest of the server
THis wil hopefully allow for unit testing
This commit is contained in:
@@ -10,7 +10,6 @@ SET (SRCS
|
||||
FloodyFluidSimulator.cpp
|
||||
FluidSimulator.cpp
|
||||
IncrementalRedstoneSimulator.cpp
|
||||
RedstoneSimulator.cpp
|
||||
SandSimulator.cpp
|
||||
Simulator.cpp
|
||||
SimulatorManager.cpp
|
||||
|
||||
@@ -16,7 +16,7 @@ it progresses to the next step (blockmeta++). This value is updated if a neighbo
|
||||
The simulator reads its parameters from the ini file given to the constructor.
|
||||
*/
|
||||
class cFireSimulator :
|
||||
public cSimulator
|
||||
public cSimulator<cChunk, cWorld>
|
||||
{
|
||||
public:
|
||||
cFireSimulator(cWorld & a_World, cIniFile & a_IniFile);
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include "Simulator.h"
|
||||
|
||||
|
||||
|
||||
class cChunk;
|
||||
class cWorld;
|
||||
|
||||
|
||||
enum Direction
|
||||
@@ -36,9 +37,9 @@ public:
|
||||
|
||||
|
||||
class cFluidSimulator :
|
||||
public cSimulator
|
||||
public cSimulator<cChunk, cWorld>
|
||||
{
|
||||
typedef cSimulator super;
|
||||
typedef cSimulator<cChunk, cWorld> super;
|
||||
|
||||
public:
|
||||
cFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,23 +6,25 @@
|
||||
/// Per-chunk data for the simulator, specified individual chunks to simulate
|
||||
typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData;
|
||||
|
||||
class cRedstonePoweredEntity;
|
||||
|
||||
typedef cItemCallback<cRedstonePoweredEntity> cRedstonePoweredCallback;
|
||||
|
||||
|
||||
|
||||
|
||||
template<class ChunkType, class WorldType, template <BLOCKTYPE block> class GetHandlerCompileTime, class ChestType>
|
||||
class cIncrementalRedstoneSimulator :
|
||||
public cRedstoneSimulator
|
||||
public cRedstoneSimulator<ChunkType, WorldType>
|
||||
{
|
||||
typedef cRedstoneSimulator super;
|
||||
typedef cRedstoneSimulator<ChunkType, WorldType> super;
|
||||
public:
|
||||
|
||||
cIncrementalRedstoneSimulator(cWorld & a_World);
|
||||
cIncrementalRedstoneSimulator(WorldType & a_World);
|
||||
~cIncrementalRedstoneSimulator();
|
||||
|
||||
virtual void Simulate(float a_Dt) override { UNUSED(a_Dt);} // not used
|
||||
virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, cChunk * a_Chunk) override;
|
||||
virtual void SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, ChunkType * a_Chunk) override;
|
||||
virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) override { return IsRedstone(a_BlockType); }
|
||||
virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
|
||||
virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, ChunkType * a_Chunk) override;
|
||||
|
||||
enum eRedstoneDirection
|
||||
{
|
||||
@@ -82,9 +84,9 @@ private:
|
||||
SimulatedPlayerToggleableList * m_SimulatedPlayerToggleableBlocks;
|
||||
RepeatersDelayList * m_RepeatersDelayList;
|
||||
|
||||
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override { RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); }
|
||||
void RedstoneAddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk, cChunk * a_OtherChunk = NULL);
|
||||
cChunk * m_Chunk;
|
||||
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, ChunkType * a_Chunk) override { RedstoneAddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk); }
|
||||
void RedstoneAddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, ChunkType * a_Chunk, ChunkType * a_OtherChunk = NULL);
|
||||
ChunkType * m_Chunk;
|
||||
|
||||
// We want a_MyState for devices needing a full FastSetBlock (as opposed to meta) because with our simulation model, we cannot keep setting the block if it is already set correctly
|
||||
// In addition to being non-performant, it would stop the player from actually breaking said device
|
||||
@@ -159,12 +161,12 @@ private:
|
||||
/** Removes a block from the Powered and LinkedPowered lists
|
||||
Used for variable sources such as tripwire hooks, daylight sensors, and trapped chests
|
||||
*/
|
||||
void SetSourceUnpowered(int a_RelSourceX, int a_RelSourceY, int a_RelSourceZ, cChunk * a_Chunk, bool a_IsFirstCall = true);
|
||||
void SetSourceUnpowered(int a_RelSourceX, int a_RelSourceY, int a_RelSourceZ, ChunkType * a_Chunk, bool a_IsFirstCall = true);
|
||||
|
||||
/** Returns if a coordinate is powered or linked powered */
|
||||
bool AreCoordsPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ) { return AreCoordsDirectlyPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, m_Chunk) || AreCoordsLinkedPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ); }
|
||||
/** Returns if a coordinate is in the directly powered blocks list */
|
||||
bool AreCoordsDirectlyPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, cChunk * a_Chunk);
|
||||
bool AreCoordsDirectlyPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ, ChunkType * a_Chunk);
|
||||
/** Returns if a coordinate is in the indirectly powered blocks list */
|
||||
bool AreCoordsLinkedPowered(int a_RelBlockX, int a_RelBlockY, int a_RelBlockZ);
|
||||
/** Returns if a coordinate was marked as simulated (for blocks toggleable by players) */
|
||||
@@ -312,5 +314,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef SELF_TEST
|
||||
#include "IncrementalRedstoneSimulator.inc"
|
||||
#endif
|
||||
|
||||
|
||||
2208
src/Simulator/IncrementalRedstoneSimulator.inc
Normal file
2208
src/Simulator/IncrementalRedstoneSimulator.inc
Normal file
File diff suppressed because it is too large
Load Diff
@@ -8,9 +8,9 @@
|
||||
|
||||
|
||||
class cRedstoneNoopSimulator :
|
||||
public cRedstoneSimulator
|
||||
public cRedstoneSimulator<cChunk, cWorld>
|
||||
{
|
||||
typedef cRedstoneSimulator super;
|
||||
typedef cRedstoneSimulator<cChunk, cWorld> super;
|
||||
public:
|
||||
|
||||
cRedstoneNoopSimulator(cWorld & a_World) :
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
#include "RedstoneSimulator.h"
|
||||
#include "../World.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cRedstoneSimulator::cRedstoneSimulator(cWorld & a_World) :
|
||||
super(a_World)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
|
||||
|
||||
|
||||
|
||||
template <class ChunkType, class WorldType>
|
||||
class cRedstoneSimulator :
|
||||
public cSimulator
|
||||
public cSimulator<ChunkType, WorldType>
|
||||
{
|
||||
typedef cSimulator super;
|
||||
typedef cSimulator<ChunkType, WorldType> super;
|
||||
|
||||
public:
|
||||
cRedstoneSimulator(cWorld & a_World);
|
||||
cRedstoneSimulator(WorldType & a_World) :
|
||||
super(a_World)
|
||||
{
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
|
||||
#include "Simulator.h"
|
||||
|
||||
/// Per-chunk data for the simulator, specified individual chunks to simulate; Data is not used
|
||||
typedef cCoordWithIntList cSandSimulatorChunkData;
|
||||
|
||||
|
||||
#include "Chunk.h"
|
||||
|
||||
|
||||
/// Despite the class name, this simulator takes care of all blocks that fall when suspended in the air.
|
||||
class cSandSimulator :
|
||||
public cSimulator
|
||||
public cSimulator<cChunk, cWorld>
|
||||
{
|
||||
public:
|
||||
cSandSimulator(cWorld & a_World, cIniFile & a_IniFile);
|
||||
@@ -55,8 +57,7 @@ protected:
|
||||
|
||||
|
||||
|
||||
/// Per-chunk data for the simulator, specified individual chunks to simulate; Data is not used
|
||||
typedef cCoordWithIntList cSandSimulatorChunkData;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,50 +1,8 @@
|
||||
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "Simulator.h"
|
||||
#include "../World.h"
|
||||
#include "../BlockID.h"
|
||||
#include "../Defines.h"
|
||||
#include "../Chunk.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cSimulator::cSimulator(cWorld & a_World)
|
||||
: m_World(a_World)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cSimulator::~cSimulator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cSimulator::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk)
|
||||
{
|
||||
AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk);
|
||||
AddBlock(a_BlockX - 1, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 1, a_BlockZ));
|
||||
AddBlock(a_BlockX + 1, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 1, a_BlockZ));
|
||||
AddBlock(a_BlockX, a_BlockY, a_BlockZ - 1, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 1));
|
||||
AddBlock(a_BlockX, a_BlockY, a_BlockZ + 1, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ + 1));
|
||||
if (a_BlockY > 0)
|
||||
{
|
||||
AddBlock(a_BlockX, a_BlockY - 1, a_BlockZ, a_Chunk);
|
||||
}
|
||||
if (a_BlockY < cChunkDef::Height - 1)
|
||||
{
|
||||
AddBlock(a_BlockX, a_BlockY + 1, a_BlockZ, a_Chunk);
|
||||
}
|
||||
}
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
#include "Simulator.inc"
|
||||
|
||||
#pragma clang diagnostic ignored "-Wweak-template-vtables"
|
||||
template class cSimulator<cChunk, cWorld>;
|
||||
|
||||
|
||||
@@ -8,17 +8,12 @@
|
||||
|
||||
|
||||
|
||||
class cWorld;
|
||||
class cChunk;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <class ChunkType, class WorldType>
|
||||
class cSimulator
|
||||
{
|
||||
public:
|
||||
cSimulator(cWorld & a_World);
|
||||
cSimulator(WorldType & a_World);
|
||||
virtual ~cSimulator();
|
||||
|
||||
/// Called in each tick, a_Dt is the time passed since the last tick, in msec
|
||||
@@ -26,7 +21,7 @@ public:
|
||||
|
||||
/// 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
|
||||
virtual void SimulateChunk(float a_Dt, int a_ChunkX,
|
||||
int a_ChunkZ, cChunk * a_Chunk)
|
||||
int a_ChunkZ, ChunkType * a_Chunk)
|
||||
{
|
||||
UNUSED(a_Dt);
|
||||
UNUSED(a_ChunkX);
|
||||
@@ -35,7 +30,7 @@ public:
|
||||
}
|
||||
|
||||
/// Called when a block changes
|
||||
virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
|
||||
virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, ChunkType * a_Chunk);
|
||||
|
||||
virtual bool IsAllowedBlock(BLOCKTYPE a_BlockType) = 0;
|
||||
|
||||
@@ -43,9 +38,9 @@ protected:
|
||||
friend class cChunk; // Calls AddBlock() in its WakeUpSimulators() function, to speed things up
|
||||
|
||||
/// Called to simulate a new block
|
||||
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) = 0;
|
||||
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, ChunkType * a_Chunk) = 0;
|
||||
|
||||
cWorld & m_World;
|
||||
WorldType & m_World;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
49
src/Simulator/Simulator.inc
Normal file
49
src/Simulator/Simulator.inc
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
|
||||
#include "Simulator.h"
|
||||
#include "../World.h"
|
||||
#include "../BlockID.h"
|
||||
#include "../Defines.h"
|
||||
#include "../Chunk.h"
|
||||
|
||||
|
||||
|
||||
|
||||
template <class ChunkType, class WorldType>
|
||||
cSimulator<ChunkType, WorldType>::cSimulator(WorldType & a_World)
|
||||
: m_World(a_World)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <class ChunkType, class WorldType>
|
||||
cSimulator<ChunkType, WorldType>::~cSimulator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <class ChunkType, class WorldType>
|
||||
void cSimulator<ChunkType, WorldType>::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, ChunkType * a_Chunk)
|
||||
{
|
||||
AddBlock(a_BlockX, a_BlockY, a_BlockZ, a_Chunk);
|
||||
AddBlock(a_BlockX - 1, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX - 1, a_BlockZ));
|
||||
AddBlock(a_BlockX + 1, a_BlockY, a_BlockZ, a_Chunk->GetNeighborChunk(a_BlockX + 1, a_BlockZ));
|
||||
AddBlock(a_BlockX, a_BlockY, a_BlockZ - 1, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ - 1));
|
||||
AddBlock(a_BlockX, a_BlockY, a_BlockZ + 1, a_Chunk->GetNeighborChunk(a_BlockX, a_BlockZ + 1));
|
||||
if (a_BlockY > 0)
|
||||
{
|
||||
AddBlock(a_BlockX, a_BlockY - 1, a_BlockZ, a_Chunk);
|
||||
}
|
||||
if (a_BlockY < cChunkDef::Height - 1)
|
||||
{
|
||||
AddBlock(a_BlockX, a_BlockY + 1, a_BlockZ, a_Chunk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ void cSimulatorManager::WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk
|
||||
|
||||
|
||||
|
||||
void cSimulatorManager::RegisterSimulator(cSimulator * a_Simulator, int a_Rate)
|
||||
void cSimulatorManager::RegisterSimulator(cSimulator<cChunk, cWorld> * a_Simulator, int a_Rate)
|
||||
{
|
||||
m_Simulators.push_back(std::make_pair(a_Simulator, a_Rate));
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ public:
|
||||
|
||||
void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk);
|
||||
|
||||
void RegisterSimulator(cSimulator * a_Simulator, int a_Rate); // Takes ownership of the simulator object!
|
||||
void RegisterSimulator(cSimulator<cChunk, cWorld> * a_Simulator, int a_Rate); // Takes ownership of the simulator object!
|
||||
|
||||
protected:
|
||||
typedef std::vector <std::pair<cSimulator *, int> > cSimulators;
|
||||
typedef std::vector <std::pair<cSimulator<cChunk, cWorld> *, int> > cSimulators;
|
||||
|
||||
cWorld & m_World;
|
||||
cSimulators m_Simulators;
|
||||
|
||||
Reference in New Issue
Block a user