aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-11-14 23:39:32 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-11-29 19:13:42 +0200
commit8d2d28f1dc575a6ed5e3aeb63a6c1b917813aeb4 (patch)
treee416e4cef3bbbc5c637a04c0400577f8085a3044
parente9620d9c8ca194a8cdac9e9b0ae32d67f3cf5cc2 (diff)
downloadminetest-8d2d28f1dc575a6ed5e3aeb63a6c1b917813aeb4.tar.gz
minetest-8d2d28f1dc575a6ed5e3aeb63a6c1b917813aeb4.tar.bz2
minetest-8d2d28f1dc575a6ed5e3aeb63a6c1b917813aeb4.zip
ToolDefinition serialization
-rw-r--r--src/tooldef.cpp60
-rw-r--r--src/tooldef.h21
2 files changed, 67 insertions, 14 deletions
diff --git a/src/tooldef.cpp b/src/tooldef.cpp
index f35cf2b82..93bedf92a 100644
--- a/src/tooldef.cpp
+++ b/src/tooldef.cpp
@@ -20,7 +20,65 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "tooldef.h"
#include "irrlichttypes.h"
#include "log.h"
-#include <ostream>
+#include <sstream>
+#include "utility.h"
+
+ToolDiggingProperties::ToolDiggingProperties(
+ float a, float b, float c, float d, float e,
+ float f, float g, float h, float i, float j):
+ basetime(a),
+ dt_weight(b),
+ dt_crackiness(c),
+ dt_crumbliness(d),
+ dt_cuttability(e),
+ basedurability(f),
+ dd_weight(g),
+ dd_crackiness(h),
+ dd_crumbliness(i),
+ dd_cuttability(j)
+{}
+
+std::string ToolDefinition::dump()
+{
+ std::ostringstream os(std::ios::binary);
+ os<<"[ToolDefinition::dump() not implemented due to lazyness]"
+ <<std::endl;
+ return os.str();
+}
+
+void ToolDefinition::serialize(std::ostream &os)
+{
+ writeU8(os, 0); // version
+ os<<serializeString(imagename);
+ writeF1000(os, properties.basetime);
+ writeF1000(os, properties.dt_weight);
+ writeF1000(os, properties.dt_crackiness);
+ writeF1000(os, properties.dt_crumbliness);
+ writeF1000(os, properties.dt_cuttability);
+ writeF1000(os, properties.basedurability);
+ writeF1000(os, properties.dd_weight);
+ writeF1000(os, properties.dd_crackiness);
+ writeF1000(os, properties.dd_crumbliness);
+ writeF1000(os, properties.dd_cuttability);
+}
+
+void ToolDefinition::deSerialize(std::istream &is)
+{
+ int version = readU8(is);
+ if(version != 0) throw SerializationError(
+ "unsupported ToolDiggingProperties version");
+ imagename = deSerializeString(is);
+ properties.basetime = readF1000(is);
+ properties.dt_weight = readF1000(is);
+ properties.dt_crackiness = readF1000(is);
+ properties.dt_crumbliness = readF1000(is);
+ properties.dt_cuttability = readF1000(is);
+ properties.basedurability = readF1000(is);
+ properties.dd_weight = readF1000(is);
+ properties.dd_crackiness = readF1000(is);
+ properties.dd_crumbliness = readF1000(is);
+ properties.dd_cuttability = readF1000(is);
+}
class CToolDefManager: public IWritableToolDefManager
{
diff --git a/src/tooldef.h b/src/tooldef.h
index 8aa6abea4..fdb02b012 100644
--- a/src/tooldef.h
+++ b/src/tooldef.h
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define TOOLDEF_HEADER
#include <string>
+#include <iostream>
/*
TODO: Rename to tooldef.h
@@ -40,19 +41,9 @@ struct ToolDiggingProperties
float dd_crumbliness;
float dd_cuttability;
- ToolDiggingProperties(float a=0.75, float b=0, float c=0, float d=0, float e=0,
- float f=50, float g=0, float h=0, float i=0, float j=0):
- basetime(a),
- dt_weight(b),
- dt_crackiness(c),
- dt_crumbliness(d),
- dt_cuttability(e),
- basedurability(f),
- dd_weight(g),
- dd_crackiness(h),
- dd_crumbliness(i),
- dd_cuttability(j)
- {}
+ ToolDiggingProperties(
+ float a=0.75, float b=0, float c=0, float d=0, float e=0,
+ float f=50, float g=0, float h=0, float i=0, float j=0);
};
struct ToolDefinition
@@ -66,6 +57,10 @@ struct ToolDefinition
imagename(imagename_),
properties(properties_)
{}
+
+ std::string dump();
+ void serialize(std::ostream &os);
+ void deSerialize(std::istream &is);
};
class IToolDefManager