Modernize client code (#6250)
[oweals/minetest.git] / src / object_properties.cpp
index ec988a37d2a511422ed67a90c9a89828c6bdbb5e..af442806b11749267b972e1aed61911236c040b8 100644 (file)
@@ -1,6 +1,6 @@
 /*
-Minetest-c55
-Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -19,26 +19,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "object_properties.h"
 #include "irrlichttypes_bloated.h"
+#include "exceptions.h"
 #include "util/serialize.h"
+#include "util/basic_macros.h"
 #include <sstream>
-#include <map>
 
-#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
-#define PP2(x) "("<<(x).X<<","<<(x).Y<<")"
-
-ObjectProperties::ObjectProperties():
-       hp_max(1),
-       physical(false),
-       weight(5),
-       collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
-       visual("sprite"),
-       mesh(""),
-       visual_size(1,1),
-       spritediv(1,1),
-       initial_sprite_basepos(0,0),
-       is_visible(true),
-       makes_footstep_sound(false),
-       automatic_rotate(0)
+ObjectProperties::ObjectProperties()
 {
        textures.push_back("unknown_object.png");
        colors.push_back(video::SColor(255,255,255,255));
@@ -49,6 +35,7 @@ std::string ObjectProperties::dump()
        std::ostringstream os(std::ios::binary);
        os<<"hp_max="<<hp_max;
        os<<", physical="<<physical;
+       os<<", collideWithObjects="<<collideWithObjects;
        os<<", weight="<<weight;
        os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
        os<<", visual="<<visual;
@@ -69,6 +56,10 @@ std::string ObjectProperties::dump()
        os<<", is_visible="<<is_visible;
        os<<", makes_footstep_sound="<<makes_footstep_sound;
        os<<", automatic_rotate="<<automatic_rotate;
+       os<<", backface_culling="<<backface_culling;
+       os << ", nametag=" << nametag;
+       os << ", nametag_color=" << "\"" << nametag_color.getAlpha() << "," << nametag_color.getRed()
+                       << "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" ";
        return os.str();
 }
 
@@ -97,6 +88,17 @@ void ObjectProperties::serialize(std::ostream &os) const
        for(u32 i=0; i<colors.size(); i++){
                writeARGB8(os, colors[i]);
        }
+       writeU8(os, collideWithObjects);
+       writeF1000(os,stepheight);
+       writeU8(os, automatic_face_movement_dir);
+       writeF1000(os, automatic_face_movement_dir_offset);
+       writeU8(os, backface_culling);
+       os << serializeString(nametag);
+       writeARGB8(os, nametag_color);
+       writeF1000(os, automatic_face_movement_max_rotation_per_sec);
+       os << serializeString(infotext);
+       os << serializeString(wield_item);
+
        // Add stuff only at the bottom.
        // Never remove anything, because we don't want new versions of this
 }
@@ -129,6 +131,16 @@ void ObjectProperties::deSerialize(std::istream &is)
                        for(u32 i=0; i<color_count; i++){
                                colors.push_back(readARGB8(is));
                        }
+                       collideWithObjects = readU8(is);
+                       stepheight = readF1000(is);
+                       automatic_face_movement_dir = readU8(is);
+                       automatic_face_movement_dir_offset = readF1000(is);
+                       backface_culling = readU8(is);
+                       nametag = deSerializeString(is);
+                       nametag_color = readARGB8(is);
+                       automatic_face_movement_max_rotation_per_sec = readF1000(is);
+                       infotext = deSerializeString(is);
+                       wield_item = deSerializeString(is);
                }catch(SerializationError &e){}
        }
        else
@@ -136,4 +148,3 @@ void ObjectProperties::deSerialize(std::istream &is)
                throw SerializationError("unsupported ObjectProperties version");
        }
 }
-