aboutsummaryrefslogtreecommitdiff
path: root/src/shared/net/proto.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/net/proto.cc')
-rw-r--r--src/shared/net/proto.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/shared/net/proto.cc b/src/shared/net/proto.cc
new file mode 100644
index 0000000..1c954b1
--- /dev/null
+++ b/src/shared/net/proto.cc
@@ -0,0 +1,55 @@
+#include "shared/net/proto.hh"
+
+namespace shared {
+namespace net {
+
+shared::player get_player(const proto::player& packet) noexcept {
+ return shared::player{
+ .index = packet.index(),
+ .commands = packet.commands(),
+ .chunk_pos = {packet.chunk_pos().x(), packet.chunk_pos().z()},
+ .local_pos = {packet.local_pos().x(), packet.local_pos().y(),
+ packet.local_pos().z()},
+ .viewangles = {packet.viewangles().pitch(), packet.viewangles().yaw()},
+ .velocity = {packet.velocity().x(), packet.velocity().y(),
+ packet.velocity().z()},
+ };
+}
+
+void set_angles(proto::angles& proto_angles,
+ const shared::math::angles& angles) noexcept {
+ proto_angles.set_pitch(angles.pitch);
+ proto_angles.set_yaw(angles.yaw);
+}
+
+void set_coords(proto::coords& proto_coords,
+ const shared::math::coords& coords) noexcept {
+ proto_coords.set_x(coords.x);
+ proto_coords.set_z(coords.z);
+}
+
+void set_vec3(proto::vec3& proto_vec3, const glm::vec3& vec3) noexcept {
+ proto_vec3.set_x(vec3.x);
+ proto_vec3.set_y(vec3.y);
+ proto_vec3.set_z(vec3.z);
+}
+
+void set_ivec3(proto::ivec3& proto_ivec3, const glm::ivec3& ivec3) noexcept {
+ proto_ivec3.set_x(ivec3.x);
+ proto_ivec3.set_y(ivec3.y);
+ proto_ivec3.set_z(ivec3.z);
+}
+
+void set_player(proto::player& proto_player,
+ const shared::player& player) noexcept {
+ proto_player.set_index(player.index);
+ proto_player.set_commands(player.commands);
+ set_coords(*proto_player.mutable_chunk_pos(), player.chunk_pos);
+ set_vec3(*proto_player.mutable_local_pos(), player.local_pos);
+ set_angles(*proto_player.mutable_viewangles(), player.viewangles);
+ set_vec3(*proto_player.mutable_velocity(), player.velocity);
+}
+
+} // namespace net
+
+} // namespace shared