diff options
-rw-r--r-- | messages.cpp | 24 | ||||
-rw-r--r-- | messages.h | 10 |
2 files changed, 16 insertions, 18 deletions
diff --git a/messages.cpp b/messages.cpp index 86067d7..2de0e6e 100644 --- a/messages.cpp +++ b/messages.cpp @@ -88,16 +88,12 @@ Pos::Pos(uint32_t id, Vector3 pos) { void Pos::do_send(boost::asio::ip::tcp::socket& socket) { write(socket, id); - write(socket, pos.x); - write(socket, pos.y); - write(socket, pos.z); + write(socket, pos); } void Pos::recv(boost::asio::ip::tcp::socket& socket) { read(socket, id); - read(socket, pos.x); - read(socket, pos.y); - read(socket, pos.z); + read(socket, pos); } uint32_t Pos::get_id() { @@ -195,17 +191,13 @@ Player::Player(uint32_t id, Vector3 pos, std::string name) { void Player::do_send(boost::asio::ip::tcp::socket& socket) { write(socket, id); - write(socket, pos.x); - write(socket, pos.y); - write(socket, pos.z); + write(socket, pos); write_string(socket, name); } void Player::recv(boost::asio::ip::tcp::socket& socket) { read(socket, id); - read(socket, pos.x); - read(socket, pos.y); - read(socket, pos.z); + read(socket, pos); name = read_string(socket); } @@ -236,16 +228,12 @@ Object::Object(uint32_t obj_type, Vector3 pos) { void Object::do_send(boost::asio::ip::tcp::socket& socket) { write(socket, obj_type); - write(socket, pos.x); - write(socket, pos.y); - write(socket, pos.z); + write(socket, pos); } void Object::recv(boost::asio::ip::tcp::socket& socket) { read(socket, obj_type); - read(socket, pos.x); - read(socket, pos.y); - read(socket, pos.z); + read(socket, pos); } uint32_t Object::get_type() { @@ -25,12 +25,22 @@ class MessageBase { static inline void read(boost::asio::ip::tcp::socket& socket, T& v) { boost::asio::read(socket, boost::asio::buffer(&v, sizeof(T))); } + static inline void read(boost::asio::ip::tcp::socket& socket, Vector3& pos) { + read(socket, pos.x); + read(socket, pos.y); + read(socket, pos.z); + } static std::string read_string(boost::asio::ip::tcp::socket& socket); template<typename T> static inline void write(boost::asio::ip::tcp::socket& socket, T& v) { boost::asio::write(socket, boost::asio::buffer(&v, sizeof(T))); } + static inline void write(boost::asio::ip::tcp::socket& socket, Vector3& pos) { + write(socket, pos.x); + write(socket, pos.y); + write(socket, pos.z); + } static void write_string(boost::asio::ip::tcp::socket& socket, std::string str); |