Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2013 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 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.
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 Lesser General Public License for more details.
14 :
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.
18 : */
19 :
20 : #include "genericobject.h"
21 : #include <sstream>
22 : #include "util/serialize.h"
23 :
24 0 : std::string gob_cmd_set_properties(const ObjectProperties &prop)
25 : {
26 0 : std::ostringstream os(std::ios::binary);
27 0 : writeU8(os, GENERIC_CMD_SET_PROPERTIES);
28 0 : prop.serialize(os);
29 0 : return os.str();
30 : }
31 :
32 118 : ObjectProperties gob_read_set_properties(std::istream &is)
33 : {
34 118 : ObjectProperties prop;
35 118 : prop.deSerialize(is);
36 118 : return prop;
37 : }
38 :
39 0 : std::string gob_cmd_update_position(
40 : v3f position,
41 : v3f velocity,
42 : v3f acceleration,
43 : f32 yaw,
44 : bool do_interpolate,
45 : bool is_movement_end,
46 : f32 update_interval
47 : ){
48 0 : std::ostringstream os(std::ios::binary);
49 : // command
50 0 : writeU8(os, GENERIC_CMD_UPDATE_POSITION);
51 : // pos
52 0 : writeV3F1000(os, position);
53 : // velocity
54 0 : writeV3F1000(os, velocity);
55 : // acceleration
56 0 : writeV3F1000(os, acceleration);
57 : // yaw
58 0 : writeF1000(os, yaw);
59 : // do_interpolate
60 0 : writeU8(os, do_interpolate);
61 : // is_end_position (for interpolation)
62 0 : writeU8(os, is_movement_end);
63 : // update_interval (for interpolation)
64 0 : writeF1000(os, update_interval);
65 0 : return os.str();
66 : }
67 :
68 0 : std::string gob_cmd_set_texture_mod(const std::string &mod)
69 : {
70 0 : std::ostringstream os(std::ios::binary);
71 : // command
72 0 : writeU8(os, GENERIC_CMD_SET_TEXTURE_MOD);
73 : // parameters
74 0 : os<<serializeString(mod);
75 0 : return os.str();
76 : }
77 :
78 0 : std::string gob_cmd_set_sprite(
79 : v2s16 p,
80 : u16 num_frames,
81 : f32 framelength,
82 : bool select_horiz_by_yawpitch
83 : ){
84 0 : std::ostringstream os(std::ios::binary);
85 : // command
86 0 : writeU8(os, GENERIC_CMD_SET_SPRITE);
87 : // parameters
88 0 : writeV2S16(os, p);
89 0 : writeU16(os, num_frames);
90 0 : writeF1000(os, framelength);
91 0 : writeU8(os, select_horiz_by_yawpitch);
92 0 : return os.str();
93 : }
94 :
95 0 : std::string gob_cmd_punched(s16 damage, s16 result_hp)
96 : {
97 0 : std::ostringstream os(std::ios::binary);
98 : // command
99 0 : writeU8(os, GENERIC_CMD_PUNCHED);
100 : // damage
101 0 : writeS16(os, damage);
102 : // result_hp
103 0 : writeS16(os, result_hp);
104 0 : return os.str();
105 : }
106 :
107 0 : std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups)
108 : {
109 0 : std::ostringstream os(std::ios::binary);
110 0 : writeU8(os, GENERIC_CMD_UPDATE_ARMOR_GROUPS);
111 0 : writeU16(os, armor_groups.size());
112 0 : for(ItemGroupList::const_iterator i = armor_groups.begin();
113 0 : i != armor_groups.end(); i++){
114 0 : os<<serializeString(i->first);
115 0 : writeS16(os, i->second);
116 : }
117 0 : return os.str();
118 : }
119 :
120 0 : std::string gob_cmd_update_physics_override(float physics_override_speed, float physics_override_jump,
121 : float physics_override_gravity, bool sneak, bool sneak_glitch)
122 : {
123 0 : std::ostringstream os(std::ios::binary);
124 : // command
125 0 : writeU8(os, GENERIC_CMD_SET_PHYSICS_OVERRIDE);
126 : // parameters
127 0 : writeF1000(os, physics_override_speed);
128 0 : writeF1000(os, physics_override_jump);
129 0 : writeF1000(os, physics_override_gravity);
130 : // these are sent inverted so we get true when the server sends nothing
131 0 : writeU8(os, !sneak);
132 0 : writeU8(os, !sneak_glitch);
133 0 : return os.str();
134 : }
135 :
136 0 : std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend, bool frame_loop)
137 : {
138 0 : std::ostringstream os(std::ios::binary);
139 : // command
140 0 : writeU8(os, GENERIC_CMD_SET_ANIMATION);
141 : // parameters
142 0 : writeV2F1000(os, frames);
143 0 : writeF1000(os, frame_speed);
144 0 : writeF1000(os, frame_blend);
145 : // these are sent inverted so we get true when the server sends nothing
146 0 : writeU8(os, !frame_loop);
147 0 : return os.str();
148 : }
149 :
150 0 : std::string gob_cmd_update_bone_position(std::string bone, v3f position, v3f rotation)
151 : {
152 0 : std::ostringstream os(std::ios::binary);
153 : // command
154 0 : writeU8(os, GENERIC_CMD_SET_BONE_POSITION);
155 : // parameters
156 0 : os<<serializeString(bone);
157 0 : writeV3F1000(os, position);
158 0 : writeV3F1000(os, rotation);
159 0 : return os.str();
160 : }
161 :
162 0 : std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f position, v3f rotation)
163 : {
164 0 : std::ostringstream os(std::ios::binary);
165 : // command
166 0 : writeU8(os, GENERIC_CMD_ATTACH_TO);
167 : // parameters
168 0 : writeS16(os, parent_id);
169 0 : os<<serializeString(bone);
170 0 : writeV3F1000(os, position);
171 0 : writeV3F1000(os, rotation);
172 0 : return os.str();
173 : }
174 :
175 0 : std::string gob_cmd_update_nametag_attributes(video::SColor color)
176 : {
177 0 : std::ostringstream os(std::ios::binary);
178 : // command
179 0 : writeU8(os, GENERIC_CMD_UPDATE_NAMETAG_ATTRIBUTES);
180 : // parameters
181 0 : writeU8(os, 1); // version for forward compatibility
182 0 : writeARGB8(os, color);
183 0 : return os.str();
184 3 : }
|