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 --- tests/Generating/Stubs.cpp | 56 ++++++++++++++------------------- tests/LuaThreadStress/Stubs.cpp | 54 ++++++++++++++----------------- tests/SchematicFileSerializer/Stubs.cpp | 54 ++++++++++++++----------------- 3 files changed, 72 insertions(+), 92 deletions(-) (limited to 'tests') diff --git a/tests/Generating/Stubs.cpp b/tests/Generating/Stubs.cpp index 2982457ab..f828b05ee 100644 --- a/tests/Generating/Stubs.cpp +++ b/tests/Generating/Stubs.cpp @@ -101,15 +101,7 @@ cBoundingBox::cBoundingBox(double, double, double, double, double, double) -cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType) -{ -} - - - - - -cBoundingBox cBlockHandler::GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) +cBoundingBox cBlockHandler::GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) const { return cBoundingBox(0, 0, 0, 0, 0, 0); } @@ -124,7 +116,7 @@ bool cBlockHandler::GetPlacementBlockTypeMeta( eBlockFace a_BlockFace, const Vector3i a_CursorPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta -) +) const { return true; } @@ -133,7 +125,7 @@ bool cBlockHandler::GetPlacementBlockTypeMeta( -void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos) +void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos) const { } @@ -141,7 +133,7 @@ void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface -void cBlockHandler::OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) +void cBlockHandler::OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const { } @@ -157,7 +149,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i -cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) +cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const { return cItems(); } @@ -166,7 +158,7 @@ cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_ -bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) +bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) const { return true; } @@ -175,7 +167,7 @@ bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a -bool cBlockHandler::IsUseable() +bool cBlockHandler::IsUseable() const { return false; } @@ -184,7 +176,7 @@ bool cBlockHandler::IsUseable() -bool cBlockHandler::IsClickedThrough(void) +bool cBlockHandler::IsClickedThrough(void) const { return false; } @@ -193,7 +185,7 @@ bool cBlockHandler::IsClickedThrough(void) -bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) +bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) const { return (m_BlockType == E_BLOCK_AIR); } @@ -202,7 +194,7 @@ bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, -bool cBlockHandler::DoesDropOnUnsuitable(void) +bool cBlockHandler::DoesDropOnUnsuitable(void) const { return true; } @@ -211,7 +203,7 @@ bool cBlockHandler::DoesDropOnUnsuitable(void) -void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, Vector3i a_RelPos, cChunk & a_Chunk) +void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, Vector3i a_RelPos, cChunk & a_Chunk) const { } @@ -219,7 +211,7 @@ void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterf -ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) +ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) const { return 0; } @@ -228,7 +220,7 @@ ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) -bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockMeta) +bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockMeta) const { return true; } @@ -237,6 +229,17 @@ bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockM +const cBlockHandler & cBlockHandler::For(BLOCKTYPE a_BlockType) +{ + // Dummy handler. + static cBlockHandler Handler(E_BLOCK_AIR); + return Handler; +} + + + + + OwnedBlockEntity cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World) { return nullptr; @@ -401,14 +404,3 @@ cItem::cItem( void cItem::Empty() { } - - - - - -cBlockHandler & cBlockHandler::GetBlockHandler(BLOCKTYPE a_BlockType) -{ - // Dummy handler. - static cBlockHandler Handler(E_BLOCK_AIR); - return Handler; -} diff --git a/tests/LuaThreadStress/Stubs.cpp b/tests/LuaThreadStress/Stubs.cpp index f921477b7..819c6b7ae 100644 --- a/tests/LuaThreadStress/Stubs.cpp +++ b/tests/LuaThreadStress/Stubs.cpp @@ -102,15 +102,6 @@ cBlockInfo::cBlockInfoArray::cBlockInfoArray() -cBlockHandler * cBlockInfo::GetHandler(BLOCKTYPE a_Type) -{ - return nullptr; -} - - - - - cBoundingBox::cBoundingBox(double, double, double, double, double, double) { } @@ -119,15 +110,7 @@ cBoundingBox::cBoundingBox(double, double, double, double, double, double) -cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType) -{ -} - - - - - -cBoundingBox cBlockHandler::GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) +cBoundingBox cBlockHandler::GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) const { return cBoundingBox(0, 0, 0, 0, 0, 0); } @@ -142,7 +125,7 @@ bool cBlockHandler::GetPlacementBlockTypeMeta( eBlockFace a_BlockFace, const Vector3i a_CursorPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta -) +) const { return true; } @@ -151,7 +134,7 @@ bool cBlockHandler::GetPlacementBlockTypeMeta( -void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos) +void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos) const { } @@ -159,7 +142,7 @@ void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface -void cBlockHandler::OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) +void cBlockHandler::OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const { } @@ -175,7 +158,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i -cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) +cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const { return cItems(); } @@ -184,7 +167,7 @@ cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_ -bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) +bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) const { return true; } @@ -193,7 +176,7 @@ bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a -bool cBlockHandler::IsUseable() +bool cBlockHandler::IsUseable() const { return false; } @@ -202,7 +185,7 @@ bool cBlockHandler::IsUseable() -bool cBlockHandler::IsClickedThrough(void) +bool cBlockHandler::IsClickedThrough(void) const { return false; } @@ -211,7 +194,7 @@ bool cBlockHandler::IsClickedThrough(void) -bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) +bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) const { return (m_BlockType == E_BLOCK_AIR); } @@ -220,7 +203,7 @@ bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, -bool cBlockHandler::DoesDropOnUnsuitable(void) +bool cBlockHandler::DoesDropOnUnsuitable(void) const { return true; } @@ -229,7 +212,7 @@ bool cBlockHandler::DoesDropOnUnsuitable(void) -void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, Vector3i a_RelPos, cChunk & a_Chunk) +void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, Vector3i a_RelPos, cChunk & a_Chunk) const { } @@ -237,7 +220,7 @@ void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterf -ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) +ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) const { return 0; } @@ -246,7 +229,7 @@ ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) -bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockMeta) +bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockMeta) const { return true; } @@ -255,6 +238,17 @@ bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockM +const cBlockHandler & cBlockHandler::For(BLOCKTYPE a_BlockType) +{ + // Dummy handler. + static cBlockHandler Handler(E_BLOCK_AIR); + return Handler; +} + + + + + OwnedBlockEntity cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World) { return nullptr; diff --git a/tests/SchematicFileSerializer/Stubs.cpp b/tests/SchematicFileSerializer/Stubs.cpp index 882175754..66d84ce06 100644 --- a/tests/SchematicFileSerializer/Stubs.cpp +++ b/tests/SchematicFileSerializer/Stubs.cpp @@ -29,15 +29,6 @@ cBlockInfo::cBlockInfoArray::cBlockInfoArray() -cBlockHandler * cBlockInfo::GetHandler(BLOCKTYPE a_Type) -{ - return nullptr; -} - - - - - cBoundingBox::cBoundingBox(double, double, double, double, double, double) { } @@ -46,15 +37,7 @@ cBoundingBox::cBoundingBox(double, double, double, double, double, double) -cBlockHandler::cBlockHandler(BLOCKTYPE a_BlockType) -{ -} - - - - - -cBoundingBox cBlockHandler::GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) +cBoundingBox cBlockHandler::GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) const { return cBoundingBox(0, 0, 0, 0, 0, 0); } @@ -69,7 +52,7 @@ bool cBlockHandler::GetPlacementBlockTypeMeta( eBlockFace a_BlockFace, const Vector3i a_CursorPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta -) +) const { return true; } @@ -78,7 +61,7 @@ bool cBlockHandler::GetPlacementBlockTypeMeta( -void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos) +void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, const Vector3i a_RelPos) const { } @@ -86,7 +69,7 @@ void cBlockHandler::OnUpdate(cChunkInterface & a_ChunkInterface, cWorldInterface -void cBlockHandler::OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) +void cBlockHandler::OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const { } @@ -102,7 +85,7 @@ void cBlockHandler::NeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i -cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) +cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) const { return cItems(); } @@ -111,7 +94,7 @@ cItems cBlockHandler::ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_ -bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) +bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a_RelPos, const cChunk & a_Chunk) const { return true; } @@ -120,7 +103,7 @@ bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, const Vector3i a -bool cBlockHandler::IsUseable() +bool cBlockHandler::IsUseable() const { return false; } @@ -129,7 +112,7 @@ bool cBlockHandler::IsUseable() -bool cBlockHandler::IsClickedThrough(void) +bool cBlockHandler::IsClickedThrough(void) const { return false; } @@ -138,7 +121,7 @@ bool cBlockHandler::IsClickedThrough(void) -bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) +bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) const { return (m_BlockType == E_BLOCK_AIR); } @@ -147,7 +130,7 @@ bool cBlockHandler::DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, -bool cBlockHandler::DoesDropOnUnsuitable(void) +bool cBlockHandler::DoesDropOnUnsuitable(void) const { return true; } @@ -156,7 +139,7 @@ bool cBlockHandler::DoesDropOnUnsuitable(void) -void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, Vector3i a_RelPos, cChunk & a_Chunk) +void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface, Vector3i a_RelPos, cChunk & a_Chunk) const { } @@ -164,7 +147,7 @@ void cBlockHandler::Check(cChunkInterface & a_ChunkInterface, cBlockPluginInterf -ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) +ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) const { return 0; } @@ -173,7 +156,7 @@ ColourID cBlockHandler::GetMapBaseColourID(NIBBLETYPE a_Meta) -bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockMeta) +bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockMeta) const { return true; } @@ -182,6 +165,17 @@ bool cBlockHandler::IsInsideBlock(Vector3d a_Position, const NIBBLETYPE a_BlockM +const cBlockHandler & cBlockHandler::For(BLOCKTYPE a_BlockType) +{ + // Dummy handler. + static cBlockHandler Handler(E_BLOCK_AIR); + return Handler; +} + + + + + bool cBlockEntity::IsBlockEntityBlockType(BLOCKTYPE a_BlockType) { return false; -- cgit v1.2.3