3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "object_properties.h"
21 #include "irrlichttypes_bloated.h"
22 #include "exceptions.h"
23 #include "util/serialize.h"
24 #include "util/basic_macros.h"
27 ObjectProperties::ObjectProperties()
29 textures.push_back("unknown_object.png");
30 colors.push_back(video::SColor(255,255,255,255));
33 std::string ObjectProperties::dump()
35 std::ostringstream os(std::ios::binary);
36 os<<"hp_max="<<hp_max;
37 os<<", physical="<<physical;
38 os<<", collideWithObjects="<<collideWithObjects;
39 os<<", weight="<<weight;
40 os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
41 os<<", visual="<<visual;
43 os<<", visual_size="<<PP2(visual_size);
45 for(u32 i=0; i<textures.size(); i++){
46 os<<"\""<<textures[i]<<"\" ";
50 for(u32 i=0; i<colors.size(); i++){
51 os<<"\""<<colors[i].getAlpha()<<","<<colors[i].getRed()<<","<<colors[i].getGreen()<<","<<colors[i].getBlue()<<"\" ";
54 os<<", spritediv="<<PP2(spritediv);
55 os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
56 os<<", is_visible="<<is_visible;
57 os<<", makes_footstep_sound="<<makes_footstep_sound;
58 os<<", automatic_rotate="<<automatic_rotate;
59 os<<", backface_culling="<<backface_culling;
60 os << ", nametag=" << nametag;
61 os << ", nametag_color=" << "\"" << nametag_color.getAlpha() << "," << nametag_color.getRed()
62 << "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" ";
66 void ObjectProperties::serialize(std::ostream &os) const
68 writeU8(os, 1); // version
70 writeU8(os, physical);
71 writeF1000(os, weight);
72 writeV3F1000(os, collisionbox.MinEdge);
73 writeV3F1000(os, collisionbox.MaxEdge);
74 os<<serializeString(visual);
75 writeV2F1000(os, visual_size);
76 writeU16(os, textures.size());
77 for(u32 i=0; i<textures.size(); i++){
78 os<<serializeString(textures[i]);
80 writeV2S16(os, spritediv);
81 writeV2S16(os, initial_sprite_basepos);
82 writeU8(os, is_visible);
83 writeU8(os, makes_footstep_sound);
84 writeF1000(os, automatic_rotate);
85 // Added in protocol version 14
86 os<<serializeString(mesh);
87 writeU16(os, colors.size());
88 for(u32 i=0; i<colors.size(); i++){
89 writeARGB8(os, colors[i]);
91 writeU8(os, collideWithObjects);
92 writeF1000(os,stepheight);
93 writeU8(os, automatic_face_movement_dir);
94 writeF1000(os, automatic_face_movement_dir_offset);
95 writeU8(os, backface_culling);
96 os << serializeString(nametag);
97 writeARGB8(os, nametag_color);
98 writeF1000(os, automatic_face_movement_max_rotation_per_sec);
99 os << serializeString(infotext);
100 os << serializeString(wield_item);
102 // Add stuff only at the bottom.
103 // Never remove anything, because we don't want new versions of this
106 void ObjectProperties::deSerialize(std::istream &is)
108 int version = readU8(is);
112 hp_max = readS16(is);
113 physical = readU8(is);
114 weight = readF1000(is);
115 collisionbox.MinEdge = readV3F1000(is);
116 collisionbox.MaxEdge = readV3F1000(is);
117 visual = deSerializeString(is);
118 visual_size = readV2F1000(is);
120 u32 texture_count = readU16(is);
121 for(u32 i=0; i<texture_count; i++){
122 textures.push_back(deSerializeString(is));
124 spritediv = readV2S16(is);
125 initial_sprite_basepos = readV2S16(is);
126 is_visible = readU8(is);
127 makes_footstep_sound = readU8(is);
128 automatic_rotate = readF1000(is);
129 mesh = deSerializeString(is);
130 u32 color_count = readU16(is);
131 for(u32 i=0; i<color_count; i++){
132 colors.push_back(readARGB8(is));
134 collideWithObjects = readU8(is);
135 stepheight = readF1000(is);
136 automatic_face_movement_dir = readU8(is);
137 automatic_face_movement_dir_offset = readF1000(is);
138 backface_culling = readU8(is);
139 nametag = deSerializeString(is);
140 nametag_color = readARGB8(is);
141 automatic_face_movement_max_rotation_per_sec = readF1000(is);
142 infotext = deSerializeString(is);
143 wield_item = deSerializeString(is);
144 }catch(SerializationError &e){}
148 throw SerializationError("unsupported ObjectProperties version");