From 5205d99629a9b15865e7a1950b49d8da40a91309 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 3 Jul 2011 15:33:54 +0200 Subject: Load and save terrain objects, added ModelManager for object models. --- game.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'game.cpp') diff --git a/game.cpp b/game.cpp index 1288b0c..819b35c 100644 --- a/game.cpp +++ b/game.cpp @@ -171,9 +171,20 @@ void Game::handle_object() { 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)); + + int64_t x = pos.x; + x -= x % Terrain::chunk_size; + + int64_t z = pos.z; + z -= z % Terrain::chunk_size; + + TerrainCacheObject::p ob = scene->terrain->tc->get_chunk(x, z, Terrain::chunk_size_total, Terrain::chunk_size_total); + ob->objects.push_back(pos); + + models::ModelManager& model_mgr = models::ModelManager::get_instance(); + + chunk->objects.push_back(Terrain::Chunk::ObjectPair(model_mgr.get_model("tree"), pos)); } Game& Game::get_instance() { @@ -181,3 +192,10 @@ Game& Game::get_instance() { game = new Game(); return *game; } + +void Game::free() { + if(game) { + delete game; + game = NULL; + } +} -- cgit v1.2.3