X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fobjdef.h;h=e40324a88cdad81f1185c54bf8c538bfbc91ffe0;hb=8c1871fa2c066a2086988684256da97bd0f4ab6f;hp=9ab3df9775e41a6e3a7022a99898ca2629942771;hpb=3face01a202040e4feff3b0936b4aa89c051c98d;p=minetest.git diff --git a/src/objdef.h b/src/objdef.h index 9ab3df977..e40324a88 100644 --- a/src/objdef.h +++ b/src/objdef.h @@ -45,21 +45,36 @@ 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 // added/set to. Note that ObjDefs managed by ObjDefManager are NOT refcounted, // so the same ObjDef instance must not be referenced multiple +// TODO: const correctness for getter methods class ObjDefManager { public: ObjDefManager(IGameDef *gamedef, ObjDefType type); 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 +103,10 @@ class ObjDefManager { ObjDefType *type, u32 *uid); protected: + ObjDefManager() {}; + // Helper for child classes to implement clone() + void cloneTo(ObjDefManager *mgr) const; + const NodeDefManager *m_ndef; std::vector m_objects; ObjDefType m_objtype;