summaryrefslogtreecommitdiff
path: root/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game.cpp')
-rw-r--r--game.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/game.cpp b/game.cpp
index 42e8b53..e24bacf 100644
--- a/game.cpp
+++ b/game.cpp
@@ -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;