2012-10-06 16:04:58 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Simulator.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-10-06 16:04:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cRedstoneSimulator :
|
|
|
|
public cSimulator
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
typedef cSimulator super;
|
|
|
|
public:
|
2013-02-28 08:39:20 -05:00
|
|
|
cRedstoneSimulator(cWorld & a_World);
|
2012-06-14 09:06:06 -04:00
|
|
|
~cRedstoneSimulator();
|
|
|
|
|
2012-09-30 12:37:44 -04:00
|
|
|
virtual void Simulate( float a_Dt ) override;
|
2012-10-03 04:52:11 -04:00
|
|
|
virtual bool IsAllowedBlock( BLOCKTYPE a_BlockType ) override { return true; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-02-28 02:42:45 -05:00
|
|
|
virtual void WakeUp(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
enum eRedstoneDirection
|
|
|
|
{
|
|
|
|
REDSTONE_NONE = 0,
|
|
|
|
REDSTONE_X_POS = 0x1,
|
|
|
|
REDSTONE_X_NEG = 0x2,
|
|
|
|
REDSTONE_Z_POS = 0x4,
|
|
|
|
REDSTONE_Z_NEG = 0x8,
|
|
|
|
};
|
2012-12-16 02:07:30 -05:00
|
|
|
eRedstoneDirection GetWireDirection(int a_BlockX, int a_BlockY, int a_BlockZ);
|
|
|
|
eRedstoneDirection GetWireDirection(const Vector3i & a_Pos) { return GetWireDirection(a_Pos.x, a_Pos.y, a_Pos.z); }
|
2012-10-06 16:04:58 -04:00
|
|
|
|
|
|
|
static bool IsRepeaterPointingTo (const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos);
|
|
|
|
static bool IsRepeaterPointingAway(const Vector3i & a_RepeaterPos, char a_MetaData, const Vector3i & a_BlockPos);
|
2013-03-09 09:35:43 -05:00
|
|
|
static NIBBLETYPE RepeaterRotationToMetaData(double a_Rotation);
|
2012-10-06 16:04:58 -04:00
|
|
|
static Vector3i GetRepeaterDirection(NIBBLETYPE a_MetaData);
|
2012-12-16 02:07:30 -05:00
|
|
|
static NIBBLETYPE LeverDirectionToMetaData(char a_Dir);
|
|
|
|
static bool IsLeverOn(cWorld * a_World, const Vector3i & a_BlockPos);
|
|
|
|
static bool IsLeverOn(NIBBLETYPE a_BlockMeta);
|
2012-10-06 16:04:58 -04:00
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
|
|
|
struct sRepeaterChange
|
|
|
|
{
|
|
|
|
Vector3i Position;
|
|
|
|
int Ticks;
|
|
|
|
bool bPowerOn;
|
|
|
|
bool bPowerOffNextTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::deque <Vector3i> BlockList;
|
|
|
|
|
|
|
|
typedef std::deque< sRepeaterChange > RepeaterList;
|
|
|
|
RepeaterList m_SetRepeaters;
|
2012-10-06 16:04:58 -04:00
|
|
|
|
|
|
|
void SetRepeater(const Vector3i & a_Position, int a_Ticks, bool a_bPowerOn);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-02-28 02:42:45 -05:00
|
|
|
virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override {}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
void HandleChange( const Vector3i & a_BlockPos );
|
|
|
|
BlockList RemoveCurrent( const Vector3i & a_BlockPos );
|
|
|
|
|
|
|
|
bool PowerBlock( const Vector3i & a_BlockPos, const Vector3i & a_FromBlock, char a_Power );
|
|
|
|
int UnPowerBlock( const Vector3i & a_BlockPos, const Vector3i & a_FromBlock );
|
|
|
|
|
|
|
|
bool IsPowered( const Vector3i & a_BlockPos, bool a_bOnlyByWire = false );
|
|
|
|
bool IsPowering( const Vector3i & a_PowerPos, const Vector3i & a_BlockPos, eRedstoneDirection a_WireDirection, bool a_bOnlyByWire );
|
|
|
|
|
|
|
|
BlockList m_Blocks;
|
|
|
|
BlockList m_BlocksBuffer;
|
|
|
|
|
|
|
|
BlockList m_RefreshPistons;
|
2012-12-26 12:16:33 -05:00
|
|
|
BlockList m_RefreshDispensers;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
BlockList m_RefreshTorchesAround;
|
|
|
|
|
|
|
|
void RefreshTorchesAround( const Vector3i & a_BlockPos );
|
|
|
|
|
2013-02-28 02:42:45 -05:00
|
|
|
// TODO: The entire simulator is synchronized, no need to lock data structures; remove this
|
2012-06-14 09:06:06 -04:00
|
|
|
cCriticalSection m_CS;
|
2012-10-06 16:04:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|