]> git.lizzy.rs Git - minetest.git/blob - src/luaentity_common.cpp
Tool definition transfer to client
[minetest.git] / src / luaentity_common.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #include "luaentity_common.h"
21
22 #include "utility.h"
23
24 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
25
26 LuaEntityProperties::LuaEntityProperties():
27         physical(true),
28         weight(5),
29         collisionbox(-0.5,-0.5,-0.5, 0.5,0.5,0.5),
30         visual("single_sprite")
31 {
32         textures.push_back("unknown_object.png");
33 }
34
35 std::string LuaEntityProperties::dump()
36 {
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;
42         os<<", textures=[";
43         for(u32 i=0; i<textures.size(); i++){
44                 os<<"\""<<textures[i]<<"\" ";
45         }
46         os<<"]";
47         return os.str();
48 }
49
50 void LuaEntityProperties::serialize(std::ostream &os)
51 {
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]);
61         }
62 }
63
64 void LuaEntityProperties::deSerialize(std::istream &is)
65 {
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);
74         textures.clear();
75         u32 texture_count = readU16(is);
76         for(u32 i=0; i<texture_count; i++){
77                 textures.push_back(deSerializeString(is));
78         }
79 }
80
81