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_block.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(core::list<std::string>::Iterator i = textures.begin();
44 i != textures.end(); i++){
45 os<<"\""<<(*i)<<"\" ";
51 void LuaEntityProperties::serialize(std::ostream &os)
53 writeU8(os, 0); // version
54 writeU8(os, physical);
55 writeF1000(os, weight);
56 writeV3F1000(os, collisionbox.MinEdge);
57 writeV3F1000(os, collisionbox.MaxEdge);
58 os<<serializeString(visual);
59 writeU16(os, textures.size());
60 for(core::list<std::string>::Iterator i = textures.begin();
61 i != textures.end(); i++){
62 os<<serializeString(*i);
66 void LuaEntityProperties::deSerialize(std::istream &is)
68 int version = readU8(is);
69 if(version != 0) throw SerializationError(
70 "unsupported LuaEntityProperties version");
71 physical = readU8(is);
72 weight = readF1000(is);
73 collisionbox.MinEdge = readV3F1000(is);
74 collisionbox.MaxEdge = readV3F1000(is);
75 visual = deSerializeString(is);
77 int texture_count = readU16(is);
78 for(int i=0; i<texture_count; i++){
79 textures.push_back(deSerializeString(is));