From: Perttu Ahola Date: Mon, 14 Nov 2011 22:05:26 +0000 (+0200) Subject: ToolDefManager serialization X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=0754f2a7af831922e26c12e707dfb6724897322f;p=zefram%2Fminetest%2Fminetest_engine.git ToolDefManager serialization --- diff --git a/src/tooldef.cpp b/src/tooldef.cpp index 93bedf92..1c85dbd8 100644 --- a/src/tooldef.cpp +++ b/src/tooldef.cpp @@ -66,7 +66,7 @@ void ToolDefinition::deSerialize(std::istream &is) { int version = readU8(is); if(version != 0) throw SerializationError( - "unsupported ToolDiggingProperties version"); + "unsupported ToolDefinition version"); imagename = deSerializeString(is); properties.basetime = readF1000(is); properties.dt_weight = readF1000(is); @@ -133,6 +133,41 @@ public: m_tool_definitions[toolname] = new ToolDefinition(def); return true; } + virtual void serialize(std::ostream &os) + { + writeU8(os, 0); // version + u16 count = m_tool_definitions.size(); + writeU16(os, count); + for(core::map::Iterator + i = m_tool_definitions.getIterator(); + i.atEnd() == false; i++){ + std::string name = i.getNode()->getKey(); + ToolDefinition *def = i.getNode()->getValue(); + // Serialize name + os<serialize(tmp_os); + os< m_tool_definitions; diff --git a/src/tooldef.h b/src/tooldef.h index fdb02b01..2c758d90 100644 --- a/src/tooldef.h +++ b/src/tooldef.h @@ -85,6 +85,9 @@ public: const std::string &toolname) const =0; virtual bool registerTool(std::string toolname, const ToolDefinition &def)=0; + + virtual void serialize(std::ostream &os)=0; + virtual void deSerialize(std::istream &is)=0; }; IWritableToolDefManager* createToolDefManager();