summaryrefslogtreecommitdiff
path: root/game.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-07-01 17:20:53 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-07-02 18:10:14 +0200
commit75a90df8bf7f38e746e021c23248e1607931132c (patch)
treedf2b4f48d5157f775c719192484188a2b0b8a04a /game.cpp
parent90d570822f85f70c31f80789ad6791cebd904468 (diff)
Import and render tree models.
Trees are loaded from the new trees.blend using assimp. Tree objects are then received from the server and rendered on the given terrain locations. Each chunk now holds a list of objects and coordinates, which can be used to easily add other models as well. Also moded the GLSL fog code to its own shader which can be linked in different programs.
Diffstat (limited to 'game.cpp')
-rw-r--r--game.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/game.cpp b/game.cpp
index e24bacf..1288b0c 100644
--- a/game.cpp
+++ b/game.cpp
@@ -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();