3 Copyright (C) 2012 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 "util/serialize.h"
24 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
25 #define PP2(x) "("<<(x).X<<","<<(x).Y<<")"
27 ObjectProperties::ObjectProperties():
31 collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
36 initial_sprite_basepos(0,0),
38 makes_footstep_sound(false),
41 textures.push_back("unknown_object.png");
44 std::string ObjectProperties::dump()
46 std::ostringstream os(std::ios::binary);
47 os<<"hp_max="<<hp_max;
48 os<<", physical="<<physical;
49 os<<", weight="<<weight;
50 os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
51 os<<", visual="<<visual;
53 os<<", visual_size="<<PP2(visual_size);
55 for(u32 i=0; i<textures.size(); i++){
56 os<<"\""<<textures[i]<<"\" ";
59 os<<", spritediv="<<PP2(spritediv);
60 os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
61 os<<", is_visible="<<is_visible;
62 os<<", makes_footstep_sound="<<makes_footstep_sound;
63 os<<", automatic_rotate="<<automatic_rotate;
67 void ObjectProperties::serialize(std::ostream &os) const
69 writeU8(os, 1); // version
71 writeU8(os, physical);
72 writeF1000(os, weight);
73 writeV3F1000(os, collisionbox.MinEdge);
74 writeV3F1000(os, collisionbox.MaxEdge);
75 os<<serializeString(visual);
76 os<<serializeString(mesh);
77 writeV2F1000(os, visual_size);
78 writeU16(os, textures.size());
79 for(u32 i=0; i<textures.size(); i++){
80 os<<serializeString(textures[i]);
82 writeV2S16(os, spritediv);
83 writeV2S16(os, initial_sprite_basepos);
84 writeU8(os, is_visible);
85 writeU8(os, makes_footstep_sound);
86 writeF1000(os, automatic_rotate);
89 void ObjectProperties::deSerialize(std::istream &is)
91 int version = readU8(is);
92 if(version != 1) throw SerializationError(
93 "unsupported ObjectProperties version");
95 physical = readU8(is);
96 weight = readF1000(is);
97 collisionbox.MinEdge = readV3F1000(is);
98 collisionbox.MaxEdge = readV3F1000(is);
99 visual = deSerializeString(is);
100 mesh = deSerializeString(is);
101 visual_size = readV2F1000(is);
103 u32 texture_count = readU16(is);
104 for(u32 i=0; i<texture_count; i++){
105 textures.push_back(deSerializeString(is));
107 spritediv = readV2S16(is);
108 initial_sprite_basepos = readV2S16(is);
109 is_visible = readU8(is);
110 makes_footstep_sound = readU8(is);
112 automatic_rotate = readF1000(is);
113 }catch(SerializationError &e){}