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 << ", weight=" << weight;
41 os << ", collisionbox=" << PP(collisionbox.MinEdge) << "," << PP(collisionbox.MaxEdge);
42 os << ", visual=" << visual;
43 os << ", mesh=" << mesh;
44 os << ", visual_size=" << PP(visual_size);
46 for (const std::string &texture : textures) {
47 os << "\"" << texture << "\" ";
51 for (const video::SColor &color : colors) {
52 os << "\"" << color.getAlpha() << "," << color.getRed() << ","
53 << color.getGreen() << "," << color.getBlue() << "\" ";
56 os << ", spritediv=" << PP2(spritediv);
57 os << ", initial_sprite_basepos=" << PP2(initial_sprite_basepos);
58 os << ", is_visible=" << is_visible;
59 os << ", makes_footstep_sound=" << makes_footstep_sound;
60 os << ", automatic_rotate="<< automatic_rotate;
61 os << ", backface_culling="<< backface_culling;
62 os << ", glow=" << glow;
63 os << ", nametag=" << nametag;
64 os << ", nametag_color=" << "\"" << nametag_color.getAlpha() << "," << nametag_color.getRed()
65 << "," << nametag_color.getGreen() << "," << nametag_color.getBlue() << "\" ";
66 os << ", selectionbox=" << PP(selectionbox.MinEdge) << "," << PP(selectionbox.MaxEdge);
67 os << ", pointable=" << pointable;
68 os << ", static_save=" << static_save;
69 os << ", eye_height=" << eye_height;
70 os << ", zoom_fov=" << zoom_fov;
71 os << ", use_texture_alpha=" << use_texture_alpha;
75 void ObjectProperties::serialize(std::ostream &os) const
77 writeU8(os, 4); // PROTOCOL_VERSION >= 37
79 writeU8(os, physical);
81 writeV3F32(os, collisionbox.MinEdge);
82 writeV3F32(os, collisionbox.MaxEdge);
83 writeV3F32(os, selectionbox.MinEdge);
84 writeV3F32(os, selectionbox.MaxEdge);
85 writeU8(os, pointable);
86 os << serializeString(visual);
87 writeV3F32(os, visual_size);
88 writeU16(os, textures.size());
89 for (const std::string &texture : textures) {
90 os << serializeString(texture);
92 writeV2S16(os, spritediv);
93 writeV2S16(os, initial_sprite_basepos);
94 writeU8(os, is_visible);
95 writeU8(os, makes_footstep_sound);
96 writeF32(os, automatic_rotate);
97 // Added in protocol version 14
98 os << serializeString(mesh);
99 writeU16(os, colors.size());
100 for (video::SColor color : colors) {
101 writeARGB8(os, color);
103 writeU8(os, collideWithObjects);
104 writeF32(os, stepheight);
105 writeU8(os, automatic_face_movement_dir);
106 writeF32(os, automatic_face_movement_dir_offset);
107 writeU8(os, backface_culling);
108 os << serializeString(nametag);
109 writeARGB8(os, nametag_color);
110 writeF32(os, automatic_face_movement_max_rotation_per_sec);
111 os << serializeString(infotext);
112 os << serializeString(wield_item);
114 writeU16(os, breath_max);
115 writeF32(os, eye_height);
116 writeF32(os, zoom_fov);
117 writeU8(os, use_texture_alpha);
119 // Add stuff only at the bottom.
120 // Never remove anything, because we don't want new versions of this
123 void ObjectProperties::deSerialize(std::istream &is)
125 int version = readU8(is);
127 throw SerializationError("unsupported ObjectProperties version");
129 hp_max = readU16(is);
130 physical = readU8(is);
131 weight = readF32(is);
132 collisionbox.MinEdge = readV3F32(is);
133 collisionbox.MaxEdge = readV3F32(is);
134 selectionbox.MinEdge = readV3F32(is);
135 selectionbox.MaxEdge = readV3F32(is);
136 pointable = readU8(is);
137 visual = deSerializeString(is);
138 visual_size = readV3F32(is);
140 u32 texture_count = readU16(is);
141 for (u32 i = 0; i < texture_count; i++){
142 textures.push_back(deSerializeString(is));
144 spritediv = readV2S16(is);
145 initial_sprite_basepos = readV2S16(is);
146 is_visible = readU8(is);
147 makes_footstep_sound = readU8(is);
148 automatic_rotate = readF32(is);
149 mesh = deSerializeString(is);
151 u32 color_count = readU16(is);
152 for (u32 i = 0; i < color_count; i++){
153 colors.push_back(readARGB8(is));
155 collideWithObjects = readU8(is);
156 stepheight = readF32(is);
157 automatic_face_movement_dir = readU8(is);
158 automatic_face_movement_dir_offset = readF32(is);
159 backface_culling = readU8(is);
160 nametag = deSerializeString(is);
161 nametag_color = readARGB8(is);
162 automatic_face_movement_max_rotation_per_sec = readF32(is);
163 infotext = deSerializeString(is);
164 wield_item = deSerializeString(is);
166 breath_max = readU16(is);
167 eye_height = readF32(is);
168 zoom_fov = readF32(is);
169 use_texture_alpha = readU8(is);