summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-06-13 13:20:38 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-06-13 13:20:38 +0200
commitbe84d27784f0d9c3c814c023e2e8d1b8e64a53ab (patch)
treecaf9933cea6ff80738f4cc66c8538d5799eda461
parent48b4b813a51c374fce43a553608c67c6ca08ea37 (diff)
Handle player position updates.
m---------common0
-rw-r--r--game.cpp24
-rw-r--r--game.h1
3 files changed, 24 insertions, 1 deletions
diff --git a/common b/common
-Subproject e483f468085379a986cbc48bb13a7983315475c
+Subproject ff7f9de199213ea6d4832c0b91f2a96f5edc6bb
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;
diff --git a/game.h b/game.h
index 44222c2..6c58565 100644
--- a/game.h
+++ b/game.h
@@ -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();