diff options
author | Tycho Bickerstaff <work.tycho@gmail.com> | 2013-12-21 14:32:40 +0100 |
---|---|---|
committer | Tycho Bickerstaff <work.tycho@gmail.com> | 2013-12-21 14:32:40 +0100 |
commit | 779aca60511055832e776ab4a6299a2b7e049a16 (patch) | |
tree | dfb031e9bd01b25ab0199286cf6e660f26489817 /src/Simulator | |
parent | Merge branch 'master' into cmake (diff) | |
parent | Merge branch 'master', remote-tracking branch 'upstream/master' (diff) | |
download | cuberite-779aca60511055832e776ab4a6299a2b7e049a16.tar cuberite-779aca60511055832e776ab4a6299a2b7e049a16.tar.gz cuberite-779aca60511055832e776ab4a6299a2b7e049a16.tar.bz2 cuberite-779aca60511055832e776ab4a6299a2b7e049a16.tar.lz cuberite-779aca60511055832e776ab4a6299a2b7e049a16.tar.xz cuberite-779aca60511055832e776ab4a6299a2b7e049a16.tar.zst cuberite-779aca60511055832e776ab4a6299a2b7e049a16.zip |
Diffstat (limited to 'src/Simulator')
-rw-r--r-- | src/Simulator/RedstoneSimulator.cpp | 41 | ||||
-rw-r--r-- | src/Simulator/RedstoneSimulator.h | 9 |
2 files changed, 38 insertions, 12 deletions
diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 92aeda29a..e53c7c172 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -228,12 +228,13 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c int a_Z = BaseZ + dataitr->z; switch (BlockType) { - case E_BLOCK_BLOCK_OF_REDSTONE: HandleRedstoneBlock(a_X, dataitr->y, a_Z); break; - case E_BLOCK_LEVER: HandleRedstoneLever(a_X, dataitr->y, a_Z); break; - case E_BLOCK_TNT: HandleTNT(a_X, dataitr->y, a_Z); break; + case E_BLOCK_BLOCK_OF_REDSTONE: HandleRedstoneBlock(a_X, dataitr->y, a_Z); break; + case E_BLOCK_LEVER: HandleRedstoneLever(a_X, dataitr->y, a_Z); break; + case E_BLOCK_TNT: HandleTNT(a_X, dataitr->y, a_Z); break; case E_BLOCK_TRAPDOOR: HandleTrapdoor(a_X, dataitr->y, a_Z); break; - case E_BLOCK_REDSTONE_WIRE: HandleRedstoneWire(a_X, dataitr->y, a_Z); break; + case E_BLOCK_REDSTONE_WIRE: HandleRedstoneWire(a_X, dataitr->y, a_Z); break; case E_BLOCK_NOTE_BLOCK: HandleNoteBlock(a_X, dataitr->y, a_Z); break; + case E_BLOCK_DAYLIGHT_SENSOR: HandleDaylightSensor(a_X, dataitr->y, a_Z); break; case E_BLOCK_REDSTONE_TORCH_OFF: case E_BLOCK_REDSTONE_TORCH_ON: @@ -611,7 +612,10 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int { if (itr->ShouldPowerOn) { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); + if (!IsOn) + { + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); // For performance + } switch (a_Meta & 0x3) // We only want the direction (bottom) bits { @@ -647,7 +651,10 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int } else { - m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + if (IsOn) + { + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + } m_RepeatersDelayList.erase(itr); // We can remove off repeaters which don't need further updating return; } @@ -814,6 +821,7 @@ void cRedstoneSimulator::HandleRail(int a_BlockX, int a_BlockY, int a_BlockZ, BL } break; } + default: LOGD("Unhandled type of rail in %s", __FUNCTION__); } } @@ -887,6 +895,18 @@ void cRedstoneSimulator::HandleNoteBlock(int a_BlockX, int a_BlockY, int a_Block +void cRedstoneSimulator::HandleDaylightSensor(int a_BlockX, int a_BlockY, int a_BlockZ) +{ + if (m_World.GetBlockSkyLight(a_BlockX, a_BlockY + 1, a_BlockZ) > 10) + { + SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_DAYLIGHT_SENSOR); + } +} + + + + + bool cRedstoneSimulator::AreCoordsDirectlyPowered(int a_BlockX, int a_BlockY, int a_BlockZ) { for (PoweredBlocksList::const_iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) // Check powered list @@ -1298,7 +1318,7 @@ void cRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, in } // Already in here (normal to allow repeater to continue on powering and updating blocks in front) - just update info and quit - itr->a_DelayTicks = ((a_Meta & 0xC) >> 0x2) + 1; + itr->a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + 1) * 2; // See below for description itr->a_ElapsedTicks = 0; itr->ShouldPowerOn = ShouldPowerOn; return; @@ -1308,7 +1328,12 @@ void cRedstoneSimulator::QueueRepeaterPowerChange(int a_BlockX, int a_BlockY, in // Self not in list, add self to list sRepeatersDelayList RC; RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); - RC.a_DelayTicks = ((a_Meta & 0xC) >> 0x2) + 1; // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) + + // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) + // * 2 because apparently, MCS ticks are way faster than vanilla ticks, so repeater aren't noticeably delayed + RC.a_DelayTicks = (((a_Meta & 0xC) >> 0x2) + 1) * 2; + + RC.a_ElapsedTicks = 0; RC.ShouldPowerOn = ShouldPowerOn; m_RepeatersDelayList.push_back(RC); diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index d40d88342..309135497 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -115,6 +115,8 @@ private: void HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ); /// <summary>Handles noteblocks</summary> void HandleNoteBlock(int a_BlockX, int a_BlockY, int a_BlockZ); + /// <summary>Handles noteblocks</summary> + void HandleDaylightSensor(int a_BlockX, int a_BlockY, int a_BlockZ); /* ===================== */ /* ====== Helper functions ====== */ @@ -164,13 +166,11 @@ private: case E_BLOCK_STICKY_PISTON: case E_BLOCK_REDSTONE_REPEATER_ON: case E_BLOCK_REDSTONE_REPEATER_OFF: + case E_BLOCK_DAYLIGHT_SENSOR: { return false; } - default: - { - return true; - } + default: return true; } } @@ -208,6 +208,7 @@ private: { switch (Block) { + case E_BLOCK_DAYLIGHT_SENSOR: case E_BLOCK_WOODEN_BUTTON: case E_BLOCK_STONE_BUTTON: case E_BLOCK_REDSTONE_WIRE: |