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.emplace_back("unknown_object.png");
30 colors.emplace_back(255,255,255,255);
33 std::string ObjectProperties::dump()
35 std::ostringstream os(std::ios::binary);
36 os << "hp_max=" << hp_max;
37 os << ", breath_max=" << breath_max;
38 os << ", physical=" << physical;
39 os << ", collideWithObjects=" << collideWithObjects;
40 os << ", collisionbox=" << PP(collisionbox.MinEdge) << "," << PP(collisionbox.MaxEdge);
41 os << ", visual=" << visual;
42 os << ", mesh=" << mesh;
43 os << ", visual_size=" << PP(visual_size);
45 for (const std::string &texture : textures) {
46 os << "\"" << texture << "\" ";
50 for (const video::SColor &color : colors) {
51 os << "\"" << color.getAlpha() << "," << color.getRed() << ","
52 << color.getGreen() << "," << color.getBlue() << "\" ";
55 os << ", spritediv=" << PP2(spritediv);
56 os << ", initial_sprite_basepos=" << PP2(initial_sprite_basepos);
57 os << ", is_visible=" << is_visible;
58 os << ", makes_footstep_sound=" << makes_footstep_sound;
59 os << ", automatic_rotate="<< automatic_rotate;
60 os << ", backface_culling="<< backface_culling;
61 os << ", glow=" << glow;
62 os << ", nametag=" << nametag;
63 os << ", nametag_color=" << "\"" << nametag_color.getAlpha() << "," << nametag_color.getRed()
64 << "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" ";
65 os << ", selectionbox=" << PP(selectionbox.MinEdge) << "," << PP(selectionbox.MaxEdge);
66 os << ", pointable=" << pointable;
67 os << ", static_save=" << static_save;
68 os << ", eye_height=" << eye_height;
69 os << ", zoom_fov=" << zoom_fov;
70 os << ", use_texture_alpha=" << use_texture_alpha;
71 os << ", damage_texture_modifier=" << damage_texture_modifier;
72 os << ", shaded=" << shaded;
73 os << ", show_on_minimap=" << show_on_minimap;
77 void ObjectProperties::serialize(std::ostream &os) const
79 writeU8(os, 4); // PROTOCOL_VERSION >= 37
81 writeU8(os, physical);
82 writeF32(os, 0.f); // Removed property (weight)
83 writeV3F32(os, collisionbox.MinEdge);
84 writeV3F32(os, collisionbox.MaxEdge);
85 writeV3F32(os, selectionbox.MinEdge);
86 writeV3F32(os, selectionbox.MaxEdge);
87 writeU8(os, pointable);
88 os << serializeString16(visual);
89 writeV3F32(os, visual_size);
90 writeU16(os, textures.size());
91 for (const std::string &texture : textures) {
92 os << serializeString16(texture);
94 writeV2S16(os, spritediv);
95 writeV2S16(os, initial_sprite_basepos);
96 writeU8(os, is_visible);
97 writeU8(os, makes_footstep_sound);
98 writeF32(os, automatic_rotate);
99 // Added in protocol version 14
100 os << serializeString16(mesh);
101 writeU16(os, colors.size());
102 for (video::SColor color : colors) {
103 writeARGB8(os, color);
105 writeU8(os, collideWithObjects);
106 writeF32(os, stepheight);
107 writeU8(os, automatic_face_movement_dir);
108 writeF32(os, automatic_face_movement_dir_offset);
109 writeU8(os, backface_culling);
110 os << serializeString16(nametag);
111 writeARGB8(os, nametag_color);
112 writeF32(os, automatic_face_movement_max_rotation_per_sec);
113 os << serializeString16(infotext);
114 os << serializeString16(wield_item);
116 writeU16(os, breath_max);
117 writeF32(os, eye_height);
118 writeF32(os, zoom_fov);
119 writeU8(os, use_texture_alpha);
120 os << serializeString16(damage_texture_modifier);
122 writeU8(os, show_on_minimap);
124 // Add stuff only at the bottom.
125 // Never remove anything, because we don't want new versions of this
128 void ObjectProperties::deSerialize(std::istream &is)
130 int version = readU8(is);
132 throw SerializationError("unsupported ObjectProperties version");
134 hp_max = readU16(is);
135 physical = readU8(is);
136 readU32(is); // removed property (weight)
137 collisionbox.MinEdge = readV3F32(is);
138 collisionbox.MaxEdge = readV3F32(is);
139 selectionbox.MinEdge = readV3F32(is);
140 selectionbox.MaxEdge = readV3F32(is);
141 pointable = readU8(is);
142 visual = deSerializeString16(is);
143 visual_size = readV3F32(is);
145 u32 texture_count = readU16(is);
146 for (u32 i = 0; i < texture_count; i++){
147 textures.push_back(deSerializeString16(is));
149 spritediv = readV2S16(is);
150 initial_sprite_basepos = readV2S16(is);
151 is_visible = readU8(is);
152 makes_footstep_sound = readU8(is);
153 automatic_rotate = readF32(is);
154 mesh = deSerializeString16(is);
156 u32 color_count = readU16(is);
157 for (u32 i = 0; i < color_count; i++){
158 colors.push_back(readARGB8(is));
160 collideWithObjects = readU8(is);
161 stepheight = readF32(is);
162 automatic_face_movement_dir = readU8(is);
163 automatic_face_movement_dir_offset = readF32(is);
164 backface_culling = readU8(is);
165 nametag = deSerializeString16(is);
166 nametag_color = readARGB8(is);
167 automatic_face_movement_max_rotation_per_sec = readF32(is);
168 infotext = deSerializeString16(is);
169 wield_item = deSerializeString16(is);
171 breath_max = readU16(is);
172 eye_height = readF32(is);
173 zoom_fov = readF32(is);
174 use_texture_alpha = readU8(is);
176 damage_texture_modifier = deSerializeString16(is);
184 show_on_minimap = tmp;
185 } catch (SerializationError &e) {}