From 5b62c4c3145c08b093521e42c565922fa85de4ad Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 26 Jun 2015 17:24:51 -0500 Subject: Reorganised the redstone simulator -> Many thanks to @worktycho for the idea, and @Haxi52 for the implementation plan! * Uses classes and inheritance now * Speed should be improved --- src/BlockEntities/CMakeLists.txt | 1 - src/BlockEntities/CommandBlockEntity.cpp | 14 -------------- src/BlockEntities/CommandBlockEntity.h | 8 +------- src/BlockEntities/DropSpenserEntity.cpp | 16 +--------------- src/BlockEntities/DropSpenserEntity.h | 8 -------- src/BlockEntities/NoteEntity.cpp | 4 ++-- src/BlockEntities/NoteEntity.h | 12 ------------ src/BlockEntities/RedstonePoweredEntity.h | 30 ------------------------------ 8 files changed, 4 insertions(+), 89 deletions(-) delete mode 100644 src/BlockEntities/RedstonePoweredEntity.h (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index 931484be0..fbf85d2af 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -42,7 +42,6 @@ SET (HDRS MobHeadEntity.h MobSpawnerEntity.h NoteEntity.h - RedstonePoweredEntity.h SignEntity.h ) diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index 2709201f4..c4a742bc0 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -20,7 +20,6 @@ cCommandBlockEntity::cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_World) : super(E_BLOCK_COMMAND_BLOCK, a_X, a_Y, a_Z, a_World), m_ShouldExecute(false), - m_IsPowered(false), m_Result(0) {} @@ -113,19 +112,6 @@ void cCommandBlockEntity::Activate(void) -void cCommandBlockEntity::SetRedstonePower(bool a_IsPowered) -{ - if (a_IsPowered && !m_IsPowered) - { - Activate(); - } - m_IsPowered = a_IsPowered; -} - - - - - bool cCommandBlockEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { UNUSED(a_Dt); diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h index 0f93ff916..184211ce0 100644 --- a/src/BlockEntities/CommandBlockEntity.h +++ b/src/BlockEntities/CommandBlockEntity.h @@ -10,7 +10,6 @@ #pragma once #include "BlockEntity.h" -#include "RedstonePoweredEntity.h" @@ -19,8 +18,7 @@ // tolua_begin class cCommandBlockEntity : - public cBlockEntity, - public cRedstonePoweredEntity + public cBlockEntity { typedef cBlockEntity super; @@ -43,9 +41,6 @@ public: // tolua_begin - /** Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate */ - virtual void SetRedstonePower(bool a_IsPowered) override; - /** Sets the command block to execute a command in the next tick */ void Activate(void); @@ -69,7 +64,6 @@ private: void Execute(); bool m_ShouldExecute; - bool m_IsPowered; AString m_Command; diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index 6a8b5311e..7270c9586 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -17,8 +17,7 @@ cDropSpenserEntity::cDropSpenserEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(a_BlockType, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World), - m_ShouldDropSpense(false), - m_IsPowered(false) + m_ShouldDropSpense(false) { } @@ -114,19 +113,6 @@ void cDropSpenserEntity::Activate(void) -void cDropSpenserEntity::SetRedstonePower(bool a_IsPowered) -{ - if (a_IsPowered && !m_IsPowered) - { - Activate(); - } - m_IsPowered = a_IsPowered; -} - - - - - bool cDropSpenserEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { UNUSED(a_Dt); diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h index 9e73269fb..fa1f37454 100644 --- a/src/BlockEntities/DropSpenserEntity.h +++ b/src/BlockEntities/DropSpenserEntity.h @@ -11,7 +11,6 @@ #pragma once #include "BlockEntityWithItems.h" -#include "RedstonePoweredEntity.h" @@ -26,9 +25,6 @@ class cClientHandle; // tolua_begin class cDropSpenserEntity : public cBlockEntityWithItems - // tolua_end - , public cRedstonePoweredEntity - // tolua_begin { typedef cBlockEntityWithItems super; @@ -60,13 +56,9 @@ public: void Activate(void); // tolua_end - - /** Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate */ - virtual void SetRedstonePower(bool a_IsPowered) override; protected: bool m_ShouldDropSpense; ///< If true, the dropspenser will dropspense an item in the next tick - bool m_IsPowered; ///< Set to true when the dropspenser receives redstone power. /** Does the actual work on dropspensing an item. Chooses the slot, calls DropSpenseFromSlot() and handles smoke / sound effects */ void DropSpense(cChunk & a_Chunk); diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp index 0b110b14e..0eef633dc 100644 --- a/src/BlockEntities/NoteEntity.cpp +++ b/src/BlockEntities/NoteEntity.cpp @@ -44,7 +44,7 @@ void cNoteEntity::MakeSound(void) { // TODO: add other wood-based blocks if needed instrument = E_INST_DOUBLE_BASS; - sampleName = "note.db"; + sampleName = "note.bassattack"; break; } @@ -76,7 +76,7 @@ void cNoteEntity::MakeSound(void) { // TODO: add other stone-based blocks if needed instrument = E_INST_BASS_DRUM; - sampleName = "note.bassattack"; + sampleName = "note.bd"; break; } diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index 3a70ffec5..2cd703c52 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -2,7 +2,6 @@ #pragma once #include "BlockEntity.h" -#include "RedstonePoweredEntity.h" @@ -25,9 +24,6 @@ enum ENUM_NOTE_INSTRUMENTS class cNoteEntity : public cBlockEntity - // tolua_end - , public cRedstonePoweredEntity - // tolua_begin { typedef cBlockEntity super; public: @@ -51,14 +47,6 @@ public: virtual bool UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle &) override {} - - virtual void SetRedstonePower(bool a_Value) override - { - if (a_Value) - { - MakeSound(); - } - } private: char m_Pitch; diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h deleted file mode 100644 index 06856f3ea..000000000 --- a/src/BlockEntities/RedstonePoweredEntity.h +++ /dev/null @@ -1,30 +0,0 @@ - -// RedstonePoweredEntity.h - -// Declares the cRedstonePoweredEntity class representing a mix-in for block entities that respond to redstone - - - - - -#pragma once - - - - - -/** Interface class representing a mix-in for block entities that respond to redstone */ -class cRedstonePoweredEntity -{ -public: - - virtual ~cRedstonePoweredEntity() {} - - /** Sets the internal redstone power flag to "on" or "off", depending on the parameter. - Calls Activate() if appropriate */ - virtual void SetRedstonePower(bool a_IsPowered) = 0; -}; - - - - -- cgit v1.2.3