From aac592f98598aae327d07b2a1bb155e33c6d51b1 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Fri, 3 Apr 2020 22:23:38 +0100 Subject: Manage block entity lifetime with unique_ptr (#4080) --- src/BlockEntities/BlockEntity.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/BlockEntities/BlockEntity.h') diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index cb377422e..2617edfb6 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -1,6 +1,7 @@ #pragma once +#include @@ -31,6 +32,10 @@ class cChunk; class cPlayer; class cWorld; +class cBlockEntity; + +using OwnedBlockEntity = std::unique_ptr; +using cBlockEntities = std::unordered_map; @@ -73,11 +78,11 @@ public: /** Creates a new block entity for the specified block type at the specified absolute pos. If a_World is valid, then the entity is created bound to that world Returns nullptr for unknown block types. */ - static cBlockEntity * CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World = nullptr); + static OwnedBlockEntity CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World = nullptr); /** Makes an exact copy of this block entity, except for its m_World (set to nullptr), and at a new position. Uses CopyFrom() to copy the properties. */ - cBlockEntity * Clone(Vector3i a_Pos); + OwnedBlockEntity Clone(Vector3i a_Pos); /** Copies all properties of a_Src into this entity, except for its m_World and location. Each non-abstract descendant should override to copy its specific properties, and call -- cgit v1.2.3