diff options
author | sfan5 <sfan5@live.de> | 2020-04-09 23:40:12 +0200 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2020-05-05 19:26:59 +0200 |
commit | 2062c80e21b657fed8e68aa48523fa12ad5ef095 (patch) | |
tree | 4e760f58a01ddcf55593bed8abcbf41d11f1c96b /src/objdef.h | |
parent | d1c6cc72cce7e02dcaca7797b463d071d67d27db (diff) | |
download | minetest-2062c80e21b657fed8e68aa48523fa12ad5ef095.tar.gz minetest-2062c80e21b657fed8e68aa48523fa12ad5ef095.tar.bz2 minetest-2062c80e21b657fed8e68aa48523fa12ad5ef095.zip |
Allow ObjDefManager instances to be cloned
Diffstat (limited to 'src/objdef.h')
-rw-r--r-- | src/objdef.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/objdef.h b/src/objdef.h index 9ab3df977..20565029c 100644 --- a/src/objdef.h +++ b/src/objdef.h @@ -45,10 +45,22 @@ class ObjDef { public: virtual ~ObjDef() = default; + // Only implemented by child classes (leafs in class hierarchy) + // Should create new object of its own type, call cloneTo() of parent class + // and copy its own instance variables over + virtual ObjDef *clone() const = 0; + u32 index; u32 uid; ObjDefHandle handle; std::string name; + +protected: + // Only implemented by classes that have children themselves + // by copying the defintion and changing that argument type (!!!) + // Should defer to parent class cloneTo() if applicable and then copy + // over its own properties + void cloneTo(ObjDef *def) const; }; // WARNING: Ownership of ObjDefs is transferred to the ObjDefManager it is @@ -60,6 +72,8 @@ public: virtual ~ObjDefManager(); DISABLE_CLASS_COPY(ObjDefManager); + // T *clone() const; // implemented in child class with correct type + virtual const char *getObjectTitle() const { return "ObjDef"; } virtual void clear(); @@ -88,6 +102,10 @@ public: ObjDefType *type, u32 *uid); protected: + ObjDefManager() {}; + // Helper for child classes to implement clone() + void cloneTo(ObjDefManager *mgr) const; + const NodeDefManager *m_ndef; std::vector<ObjDef *> m_objects; ObjDefType m_objtype; |