Implemented an easy way of adding new redstone simulators.
Also added a "noop" redstone simulator that does the same as the fluid version.
This commit is contained in:
parent
e165da946e
commit
176664810b
40
src/Simulator/NoopRedstoneSimulator.h
Normal file
40
src/Simulator/NoopRedstoneSimulator.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "RedstoneManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cRedstoneNoopSimulator :
|
||||||
|
public cRedstoneManager
|
||||||
|
{
|
||||||
|
typedef cRedstoneManager super;
|
||||||
|
public:
|
||||||
|
|
||||||
|
cRedstoneNoopSimulator(cWorld & a_World) :
|
||||||
|
super(a_World)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//~cRedstoneNoopSimulator();
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
UNUSED(a_Dt);
|
||||||
|
UNUSED(a_ChunkX);
|
||||||
|
UNUSED(a_ChunkZ);
|
||||||
|
UNUSED(a_Chunk);
|
||||||
|
}
|
||||||
|
virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return false; }
|
||||||
|
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override
|
||||||
|
{
|
||||||
|
UNUSED(a_BlockX);
|
||||||
|
UNUSED(a_BlockY);
|
||||||
|
UNUSED(a_BlockZ);
|
||||||
|
UNUSED(a_Chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
} ;
|
19
src/Simulator/RedstoneManager.cpp
Normal file
19
src/Simulator/RedstoneManager.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
#include "Globals.h"
|
||||||
|
|
||||||
|
#include "RedstoneManager.h"
|
||||||
|
#include "../World.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cRedstoneManager::cRedstoneManager(cWorld & a_World) :
|
||||||
|
super(a_World)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
17
src/Simulator/RedstoneManager.h
Normal file
17
src/Simulator/RedstoneManager.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Simulator.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class cRedstoneManager :
|
||||||
|
public cSimulator
|
||||||
|
{
|
||||||
|
typedef cSimulator super;
|
||||||
|
|
||||||
|
public:
|
||||||
|
cRedstoneManager(cWorld & a_World);
|
||||||
|
|
||||||
|
} ;
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Simulator.h"
|
#include "RedstoneManager.h"
|
||||||
|
|
||||||
/// Per-chunk data for the simulator, specified individual chunks to simulate; 'Data' is not used
|
/// Per-chunk data for the simulator, specified individual chunks to simulate; 'Data' is not used
|
||||||
typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData;
|
typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData;
|
||||||
@ -11,9 +11,9 @@ typedef cCoordWithBlockAndBoolVector cRedstoneSimulatorChunkData;
|
|||||||
|
|
||||||
|
|
||||||
class cRedstoneSimulator :
|
class cRedstoneSimulator :
|
||||||
public cSimulator
|
public cRedstoneManager
|
||||||
{
|
{
|
||||||
typedef cSimulator super;
|
typedef cRedstoneManager super;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cRedstoneSimulator(cWorld & a_World);
|
cRedstoneSimulator(cWorld & a_World);
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "Simulator/FluidSimulator.h"
|
#include "Simulator/FluidSimulator.h"
|
||||||
#include "Simulator/FireSimulator.h"
|
#include "Simulator/FireSimulator.h"
|
||||||
#include "Simulator/NoopFluidSimulator.h"
|
#include "Simulator/NoopFluidSimulator.h"
|
||||||
|
#include "Simulator/NoopRedstoneSimulator.h"
|
||||||
#include "Simulator/SandSimulator.h"
|
#include "Simulator/SandSimulator.h"
|
||||||
#include "Simulator/RedstoneSimulator.h"
|
#include "Simulator/RedstoneSimulator.h"
|
||||||
#include "Simulator/VaporizeFluidSimulator.h"
|
#include "Simulator/VaporizeFluidSimulator.h"
|
||||||
@ -596,12 +597,11 @@ void cWorld::Start(void)
|
|||||||
m_LavaSimulator = InitializeFluidSimulator(IniFile, "Lava", E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA);
|
m_LavaSimulator = InitializeFluidSimulator(IniFile, "Lava", E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA);
|
||||||
m_SandSimulator = new cSandSimulator(*this, IniFile);
|
m_SandSimulator = new cSandSimulator(*this, IniFile);
|
||||||
m_FireSimulator = new cFireSimulator(*this, IniFile);
|
m_FireSimulator = new cFireSimulator(*this, IniFile);
|
||||||
m_RedstoneSimulator = new cRedstoneSimulator(*this);
|
m_RedstoneSimulator = InitializeRedstoneSimulator(IniFile);
|
||||||
|
|
||||||
// Water and Lava simulators get registered in InitializeFluidSimulator()
|
// Water, Lava and Redstone simulators get registered in InitializeFluidSimulator()
|
||||||
m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1);
|
m_SimulatorManager->RegisterSimulator(m_SandSimulator, 1);
|
||||||
m_SimulatorManager->RegisterSimulator(m_FireSimulator, 1);
|
m_SimulatorManager->RegisterSimulator(m_FireSimulator, 1);
|
||||||
m_SimulatorManager->RegisterSimulator(m_RedstoneSimulator, 1);
|
|
||||||
|
|
||||||
m_Lighting.Start(this);
|
m_Lighting.Start(this);
|
||||||
m_Storage.Start(this, m_StorageSchema, m_StorageCompressionFactor );
|
m_Storage.Start(this, m_StorageSchema, m_StorageCompressionFactor );
|
||||||
@ -2871,6 +2871,40 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cRedstoneManager * cWorld::InitializeRedstoneSimulator(cIniFile & a_IniFile)
|
||||||
|
{
|
||||||
|
AString SimulatorName = a_IniFile.GetValueSet("Physics", "RedstoneSimulator", "");
|
||||||
|
|
||||||
|
if (SimulatorName.empty())
|
||||||
|
{
|
||||||
|
LOGWARNING("[Physics] RedstoneSimulator not present or empty in %s, using the default of \"Floody\".", GetIniFileName().c_str());
|
||||||
|
SimulatorName = "redstone";
|
||||||
|
}
|
||||||
|
|
||||||
|
cRedstoneManager * res = NULL;
|
||||||
|
|
||||||
|
if (
|
||||||
|
(NoCaseCompare(SimulatorName, "redstone") == 0)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
res = new cRedstoneSimulator(*this);
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
(NoCaseCompare(SimulatorName, "noop") == 0)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
res = new cRedstoneNoopSimulator(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_SimulatorManager->RegisterSimulator(res, 1);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock)
|
cFluidSimulator * cWorld::InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock)
|
||||||
{
|
{
|
||||||
AString SimulatorNameKey;
|
AString SimulatorNameKey;
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
class cFireSimulator;
|
class cFireSimulator;
|
||||||
class cFluidSimulator;
|
class cFluidSimulator;
|
||||||
class cSandSimulator;
|
class cSandSimulator;
|
||||||
class cRedstoneSimulator;
|
class cRedstoneManager;
|
||||||
class cItem;
|
class cItem;
|
||||||
class cPlayer;
|
class cPlayer;
|
||||||
class cClientHandle;
|
class cClientHandle;
|
||||||
@ -432,7 +432,7 @@ public:
|
|||||||
|
|
||||||
inline cFluidSimulator * GetWaterSimulator(void) { return m_WaterSimulator; }
|
inline cFluidSimulator * GetWaterSimulator(void) { return m_WaterSimulator; }
|
||||||
inline cFluidSimulator * GetLavaSimulator (void) { return m_LavaSimulator; }
|
inline cFluidSimulator * GetLavaSimulator (void) { return m_LavaSimulator; }
|
||||||
inline cRedstoneSimulator * GetRedstoneSimulator(void) { return m_RedstoneSimulator; }
|
inline cRedstoneManager * GetRedstoneSimulator(void) { return m_RedstoneSimulator; }
|
||||||
|
|
||||||
/** Calls the callback for each block entity in the specified chunk; returns true if all block entities processed, false if the callback aborted by returning true */
|
/** Calls the callback for each block entity in the specified chunk; returns true if all block entities processed, false if the callback aborted by returning true */
|
||||||
bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp
|
bool ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback); // Exported in ManualBindings.cpp
|
||||||
@ -759,7 +759,7 @@ private:
|
|||||||
cFluidSimulator * m_WaterSimulator;
|
cFluidSimulator * m_WaterSimulator;
|
||||||
cFluidSimulator * m_LavaSimulator;
|
cFluidSimulator * m_LavaSimulator;
|
||||||
cFireSimulator * m_FireSimulator;
|
cFireSimulator * m_FireSimulator;
|
||||||
cRedstoneSimulator * m_RedstoneSimulator;
|
cRedstoneManager * m_RedstoneSimulator;
|
||||||
|
|
||||||
cCriticalSection m_CSPlayers;
|
cCriticalSection m_CSPlayers;
|
||||||
cPlayerList m_Players;
|
cPlayerList m_Players;
|
||||||
@ -858,6 +858,9 @@ private:
|
|||||||
|
|
||||||
/** Creates a new fluid simulator, loads its settings from the inifile (a_FluidName section) */
|
/** Creates a new fluid simulator, loads its settings from the inifile (a_FluidName section) */
|
||||||
cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock);
|
cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock);
|
||||||
|
|
||||||
|
/** Creates a new redstone simulator.*/
|
||||||
|
cRedstoneManager * InitializeRedstoneSimulator(cIniFile & a_IniFile);
|
||||||
}; // tolua_export
|
}; // tolua_export
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user