3 Copyright (C) 2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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 "luaentity_common.h"
24 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
25 #define PP2(x) "("<<(x).X<<","<<(x).Y<<")"
27 LuaEntityProperties::LuaEntityProperties():
30 collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
34 initial_sprite_basepos(0,0)
36 textures.push_back("unknown_object.png");
39 std::string LuaEntityProperties::dump()
41 std::ostringstream os(std::ios::binary);
42 os<<"physical="<<physical;
43 os<<", weight="<<weight;
44 os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
45 os<<", visual="<<visual;
46 os<<", visual_size="<<PP2(visual_size);
48 for(u32 i=0; i<textures.size(); i++){
49 os<<"\""<<textures[i]<<"\" ";
52 os<<", spritediv="<<PP2(spritediv);
53 os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
57 void LuaEntityProperties::serialize(std::ostream &os)
59 writeU8(os, 0); // version
60 writeU8(os, physical);
61 writeF1000(os, weight);
62 writeV3F1000(os, collisionbox.MinEdge);
63 writeV3F1000(os, collisionbox.MaxEdge);
64 os<<serializeString(visual);
65 writeV2F1000(os, visual_size);
66 writeU16(os, textures.size());
67 for(u32 i=0; i<textures.size(); i++){
68 os<<serializeString(textures[i]);
70 writeV2S16(os, spritediv);
71 writeV2S16(os, initial_sprite_basepos);
74 void LuaEntityProperties::deSerialize(std::istream &is)
76 int version = readU8(is);
77 if(version != 0) throw SerializationError(
78 "unsupported LuaEntityProperties version");
79 physical = readU8(is);
80 weight = readF1000(is);
81 collisionbox.MinEdge = readV3F1000(is);
82 collisionbox.MaxEdge = readV3F1000(is);
83 visual = deSerializeString(is);
84 visual_size = readV2F1000(is);
86 u32 texture_count = readU16(is);
87 for(u32 i=0; i<texture_count; i++){
88 textures.push_back(deSerializeString(is));
90 spritediv = readV2S16(is);
91 initial_sprite_basepos = readV2S16(is);