1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Create framework for getting rid of global definitions of node/tool/item/whatever types

This commit is contained in:
Perttu Ahola 2011-11-14 00:19:48 +02:00
parent 5fc791ac9a
commit abceeee92f
60 changed files with 1017 additions and 743 deletions

View file

@ -34,21 +34,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
class Inventory;
class IGameDef;
class NodeMetadata
{
public:
typedef NodeMetadata* (*Factory)(std::istream&);
typedef NodeMetadata* (*Factory)(std::istream&, IGameDef *gamedef);
NodeMetadata();
NodeMetadata(IGameDef *gamedef);
virtual ~NodeMetadata();
static NodeMetadata* deSerialize(std::istream &is);
static NodeMetadata* deSerialize(std::istream &is, IGameDef *gamedef);
void serialize(std::ostream &os);
// This usually is the CONTENT_ value
virtual u16 typeId() const = 0;
virtual NodeMetadata* clone() = 0;
virtual NodeMetadata* clone(IGameDef *gamedef) = 0;
virtual void serializeBody(std::ostream &os) = 0;
virtual std::string infoText() {return "";}
virtual Inventory* getInventory() {return NULL;}
@ -69,6 +70,7 @@ public:
virtual void setText(const std::string &t){}
protected:
static void registerType(u16 id, Factory f);
IGameDef *m_gamedef;
private:
static core::map<u16, Factory> m_types;
};
@ -83,7 +85,7 @@ public:
~NodeMetadataList();
void serialize(std::ostream &os);
void deSerialize(std::istream &is);
void deSerialize(std::istream &is, IGameDef *gamedef);
// Get pointer to data
NodeMetadata* get(v3s16 p);