From fbf91c0782c6b9cbf48209714c650cca45e8a836 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 1 Jul 2011 17:15:47 +0200 Subject: Added MSG_TYPE_OBJECT with a draft class. --- messages.cpp | 35 +++++++++++++++++++++++++++++++++++ messages.h | 21 ++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/messages.cpp b/messages.cpp index ff4a6db..86067d7 100644 --- a/messages.cpp +++ b/messages.cpp @@ -220,3 +220,38 @@ Vector3 Player::get_pos() { std::string Player::get_name() { return name; } + +/* Object */ + +Object::Object() { + type = MSG_TYPE_OBJECT; +} + +Object::Object(uint32_t obj_type, Vector3 pos) { + type = MSG_TYPE_OBJECT; + + this->obj_type = obj_type; + this->pos = 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); +} + +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); +} + +uint32_t Object::get_type() { + return obj_type; +} + +Vector3 Object::get_pos() { + return pos; +} diff --git a/messages.h b/messages.h index 743914e..f1625f8 100644 --- a/messages.h +++ b/messages.h @@ -13,7 +13,8 @@ enum MessageType { MSG_TYPE_POS, MSG_TYPE_CHUNK, MSG_TYPE_MSG, - MSG_TYPE_PLAYER + MSG_TYPE_PLAYER, + MSG_TYPE_OBJECT }; class MessageBase { @@ -133,6 +134,24 @@ class Player : public MessageBase { std::string get_name(); }; +// NOTE: This message type is subject to change! +class Object : public MessageBase { + protected: + uint32_t obj_type; + Vector3 pos; + + virtual void do_send(boost::asio::ip::tcp::socket& socket); + + public: + Object(); + Object(uint32_t obj_type, Vector3 pos); + + virtual void recv(boost::asio::ip::tcp::socket& socket); + + uint32_t get_type(); + Vector3 get_pos(); +}; + } #endif -- cgit v1.2.3