summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-07-01 17:40:37 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-07-01 17:40:37 +0200
commit6e746716d6a5c72fbd42539c6d5d92da8830cb9e (patch)
tree44dbe0cdb8f821a75d8ba0a832ceffd150ceb583
parentfbf91c0782c6b9cbf48209714c650cca45e8a836 (diff)
Overload read and write for Vector3.
-rw-r--r--messages.cpp24
-rw-r--r--messages.h10
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() {
diff --git a/messages.h b/messages.h
index f1625f8..f388805 100644
--- a/messages.h
+++ b/messages.h
@@ -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);