From 9b74d0cdd0075b7f1482ad462db2096f7bb38a87 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Mon, 29 Oct 2012 23:14:30 +0000 Subject: [PATCH] Added caching of textures for overworld. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11813 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/graphics/material_manager.cpp | 9 +++++++++ src/graphics/material_manager.hpp | 4 ++-- src/tracks/track.cpp | 20 ++++++++++++++++---- src/tracks/track.hpp | 6 +++++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/graphics/material_manager.cpp b/src/graphics/material_manager.cpp index 34c9c52e9..ea960940d 100644 --- a/src/graphics/material_manager.cpp +++ b/src/graphics/material_manager.cpp @@ -299,6 +299,15 @@ Material *MaterialManager::getMaterial(const std::string& fname, } // getMaterial +// ---------------------------------------------------------------------------- +/** Makes all materials permanent. Used for overworld. + */ +void MaterialManager::makeMaterialsPermanent() +{ + m_shared_material_index = m_materials.size(); +} // makeMaterialsPermanent + +// ---------------------------------------------------------------------------- bool MaterialManager::hasMaterial(const std::string& fname) { std::string basename=StringUtils::getBasename(fname); diff --git a/src/graphics/material_manager.hpp b/src/graphics/material_manager.hpp index 75ca9ed5f..ab51bd904 100644 --- a/src/graphics/material_manager.hpp +++ b/src/graphics/material_manager.hpp @@ -70,11 +70,11 @@ public: bool pushTempMaterial (const std::string& filename); bool pushTempMaterial (const XMLNode *root, const std::string& filename); void popTempMaterial (); - + void makeMaterialsPermanent(); bool hasMaterial(const std::string& fname); Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; } -}; +}; // MaterialManager extern MaterialManager *material_manager; diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 7aba03946..02dd57e0a 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -78,6 +78,7 @@ Track::Track(const std::string &filename) m_magic_number = 0x17AC3802; #endif + m_materials_loaded = false; m_filename = filename; m_root = StringUtils::getPath(StringUtils::removeExtension(m_filename)); m_ident = StringUtils::getBasename(m_root); @@ -215,8 +216,13 @@ void Track::cleanup() } m_sky_textures.clear(); - // remove temporary materials loaded by the material manager - material_manager->popTempMaterial(); + if(m_ident!="overworld") + { + // remove temporary materials loaded by the material manager + material_manager->popTempMaterial(); + } + else + material_manager->makeMaterialsPermanent(); if(UserConfigParams::logMemory()) { @@ -661,7 +667,6 @@ void Track::convertTrackToBullet(scene::ISceneNode *node) } // convertTrackToBullet // ---------------------------------------------------------------------------- - /** Loads the main track model (i.e. all other objects contained in the * scene might use raycast on this track model to determine the actual * height of the terrain. @@ -1221,7 +1226,14 @@ void Track::loadTrackModel(World* parent, bool reverse_track, try { std::string materials_file = m_root+"/materials.xml"; - material_manager->pushTempMaterial(materials_file); + if(m_ident=="overworld") + { + if(!m_materials_loaded) + material_manager->addSharedMaterial(materials_file); + m_materials_loaded = true; + } + else + material_manager->pushTempMaterial(materials_file); } catch (std::exception& e) { diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 104e39744..308975151 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -152,7 +152,7 @@ private: std::string m_screenshot; std::vector m_music; - /** Will only be sued on overworld */ + /** Will only be used on overworld */ std::vector m_challenges; std::vector m_force_fields; @@ -189,6 +189,10 @@ private: * be removed from the cache at cleanup time. */ std::vector m_all_cached_textures; + /** True if the materials.xml file is already loaded. This is used + * for the overworld to keep its textures loaded. */ + bool m_materials_loaded; + #ifdef DEBUG /** A list of textures that were cached before the track is loaded. * After cleanup of ta track it can be tested which new textures