From 68cced73afe546328cf94ed07c57deee47bfadec Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 20 Sep 2020 14:50:52 +0100 Subject: BlockHandler initialisation is a constant expression (#4891) * BlockHandler initialisation is a constant expression If we can't make it all namespaces, this is the next best I guess. + Tag handlers constexpr, const as needed + Inherit constructors * Privatise handler functions * More constexpr Co-authored-by: Alexander Harkness --- src/Blocks/BlockPiston.h | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src/Blocks/BlockPiston.h') diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 8799ba3ca..f8d155196 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -22,13 +22,7 @@ class cBlockPistonHandler: public: - cBlockPistonHandler(BLOCKTYPE a_BlockType); - - virtual void OnBroken( - cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, - Vector3i a_BlockPos, - BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta - ) override; + using Super::Super; static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData) { @@ -54,12 +48,6 @@ public: static void ExtendPiston(Vector3i a_BlockPos, cWorld & a_World); static void RetractPiston(Vector3i a_BlockPos, cWorld & a_World); - virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override - { - UNUSED(a_Meta); - return 11; - } - /** Returns true if the piston (with the specified meta) is extended */ static inline bool IsExtended(NIBBLETYPE a_PistonMeta) { return ((a_PistonMeta & 0x8) != 0x0); } @@ -131,6 +119,18 @@ private: Vector3iSet & a_BlocksPushed, const Vector3i & a_PushDir ); + virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override + { + UNUSED(a_Meta); + return 11; + } + + virtual void OnBroken( + cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, + Vector3i a_BlockPos, + BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta + ) const override; + /** Moves a list of blocks in a specific direction */ static void PushBlocks(const Vector3iSet & a_BlocksToPush, cWorld & a_World, const Vector3i & a_PushDir @@ -147,13 +147,17 @@ class cBlockPistonHeadHandler: using Super = cBlockHandler; public: - cBlockPistonHeadHandler(void); + + constexpr cBlockPistonHeadHandler(void) : + Super(E_BLOCK_PISTON_EXTENSION) + { + } virtual void OnBroken( cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta - ) override; + ) const override; - virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override; + virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const override; } ; -- cgit v1.2.3