diff options
m--------- | common | 0 | ||||
-rw-r--r-- | game.cpp | 24 | ||||
-rw-r--r-- | game.h | 1 |
3 files changed, 24 insertions, 1 deletions
diff --git a/common b/common -Subproject e483f468085379a986cbc48bb13a7983315475c +Subproject ff7f9de199213ea6d4832c0b91f2a96f5edc6bb @@ -45,8 +45,9 @@ void Game::run(const std::string host, const std::string port) { async_read(); unsigned int last = SDL_GetTicks(); + Vector3 last_pos = scene->pos; while(scene->running) { - if(SDL_GetTicks() - last >= 1000) { + if(SDL_GetTicks() - last >= 100 && scene->pos != last_pos) { message::Pos pos(scene->pos); pos.send(socket); last = SDL_GetTicks(); @@ -75,6 +76,9 @@ void Game::handle_type(const boost::system::error_code& error, std::size_t bytes } switch(*type) { + case message::MSG_TYPE_POS: + handle_pos(); + break; case message::MSG_TYPE_CHUNK: handle_chunk(); break; @@ -92,6 +96,24 @@ void Game::handle_type(const boost::system::error_code& error, std::size_t bytes async_read(); } +void Game::handle_pos() { + message::Pos m; + + m.recv(socket); + uint32_t id = m.get_id(); + Vector3 pos = m.get_pos(); + if(id == 0) { // my pos + scene->pos = pos; + } else { // other player's pos + for(PlayerList::iterator it = scene->players.begin(); it != scene->players.end(); it++) { + if((*it)->get_id() == id) { + (*it)->set_pos(pos); + break; + } + } + } +} + void Game::handle_chunk() { message::Chunk m; @@ -26,6 +26,7 @@ class Game { void async_read(); void handle_type(const boost::system::error_code& error, std::size_t bytes_transferred, uint8_t *type); + void handle_pos(); void handle_chunk(); void handle_message(); void handle_player(); |