diff options
Diffstat (limited to 'game.cpp')
-rw-r--r-- | game.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -88,6 +88,9 @@ void Game::handle_type(const boost::system::error_code& error, std::size_t bytes case message::MSG_TYPE_PLAYER: handle_player(); break; + case message::MSG_TYPE_OBJECT: + handle_object(); + break; default: std::cout << "unknown type: " << (int)*type << std::endl; } @@ -154,6 +157,25 @@ void Game::handle_player() { scene->players.push_back(Player::p(new Player(id, pos, name))); } +void Game::handle_object() { + message::Object m; + + m.recv(socket); + + // type is ignored for now + uint32_t type = m.get_type(); + Vector3 pos(m.get_pos()); + + Terrain::Chunk *chunk = scene->terrain->find_chunk(pos.x, pos.z); + if(!chunk) { + std::cerr << "got object for non-existing chunk, discarding" << std::endl; + return; + } + + pos.y = chunk->find(pos.x, pos.z)->get_height(pos.x, pos.z); + chunk->objects.push_back(Terrain::Chunk::ObjectPair(scene->tree, pos)); +} + Game& Game::get_instance() { if(!game) game = new Game(); |