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<<")"
26 LuaEntityProperties::LuaEntityProperties():
29 collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
30 visual("single_sprite")
32 textures.push_back("unknown_object.png");
35 std::string LuaEntityProperties::dump()
37 std::ostringstream os(std::ios::binary);
38 os<<"physical="<<physical;
39 os<<", weight="<<weight;
40 os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
41 os<<", visual="<<visual;
43 for(u32 i=0; i<textures.size(); i++){
44 os<<"\""<<textures[i]<<"\" ";
50 void LuaEntityProperties::serialize(std::ostream &os)
52 writeU8(os, 0); // version
53 writeU8(os, physical);
54 writeF1000(os, weight);
55 writeV3F1000(os, collisionbox.MinEdge);
56 writeV3F1000(os, collisionbox.MaxEdge);
57 os<<serializeString(visual);
58 writeU16(os, textures.size());
59 for(u32 i=0; i<textures.size(); i++){
60 os<<serializeString(textures[i]);
64 void LuaEntityProperties::deSerialize(std::istream &is)
66 int version = readU8(is);
67 if(version != 0) throw SerializationError(
68 "unsupported LuaEntityProperties version");
69 physical = readU8(is);
70 weight = readF1000(is);
71 collisionbox.MinEdge = readV3F1000(is);
72 collisionbox.MaxEdge = readV3F1000(is);
73 visual = deSerializeString(is);
75 u32 texture_count = readU16(is);
76 for(u32 i=0; i<texture_count; i++){
77 textures.push_back(deSerializeString(is));