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/BlockPlant.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/Blocks/BlockPlant.h') diff --git a/src/Blocks/BlockPlant.h b/src/Blocks/BlockPlant.h index a0d6ffe52..e99a0b130 100644 --- a/src/Blocks/BlockPlant.h +++ b/src/Blocks/BlockPlant.h @@ -14,17 +14,11 @@ class cBlockPlant: { using Super = cBlockHandler; - public: - cBlockPlant(BLOCKTYPE a_BlockType): - Super(a_BlockType) - { - } - - - + using Super::Super; +private: virtual void OnUpdate( cChunkInterface & a_ChunkInterface, @@ -32,7 +26,7 @@ public: cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos - ) override + ) const override { auto Action = CanGrow(a_Chunk, a_RelPos); switch (Action) @@ -74,7 +68,7 @@ protected: If the plant requires light to grow and there is enough light, it returns paGrowth. If the plant requires light to grow and there isn't enough light, it returns paStay. If the plant requires light to grow and there is too little light, it returns paDeath. */ - PlantAction HasEnoughLight(cChunk & a_Chunk, Vector3i a_RelPos) + static PlantAction HasEnoughLight(cChunk & a_Chunk, Vector3i a_RelPos) { // If the plant requires light to grow, check to see if there is enough light // Otherwise, return true @@ -117,7 +111,7 @@ protected: paDeath is returned when there isn't enough light for the plant to survive. Plants that don't require light will never have a paDeath returned */ - virtual PlantAction CanGrow(cChunk & a_Chunk, Vector3i a_RelPos) + virtual PlantAction CanGrow(cChunk & a_Chunk, Vector3i a_RelPos) const { // Plant can grow if it has the required amount of light, and it passes a random chance based on surrounding blocks auto action = HasEnoughLight(a_Chunk, a_RelPos); @@ -134,7 +128,7 @@ protected: /** Generates an int value between 4 and 25 based on surrounding blocks that affect how quickly the plant grows. The higher the value, the less likely the plant is to grow */ - virtual int GetGrowthChance(cChunk & a_Chunk, Vector3i a_RelPos) + virtual int GetGrowthChance(cChunk & a_Chunk, Vector3i a_RelPos) const { float Chance = 1.0f; a_RelPos.y -= 1; @@ -149,10 +143,8 @@ protected: // If the chunk we are trying to get the block information from is loaded if (a_Chunk.UnboundedRelGetBlock(a_RelPos + Vector3i(x, 0, z), Block, Meta)) { - cBlockHandler * Handler = BlockHandler(Block); - // If the block affects growth, add to the adjustment - if (Handler->CanSustainPlant(m_BlockType)) + if (cBlockHandler::For(Block).CanSustainPlant(m_BlockType)) { Adjustment = 1.0f; -- cgit v1.2.3