Preload icon materials to avoid hang when firstly insert item

This commit is contained in:
Benau 2022-09-04 11:37:09 +08:00
parent 9a7e2f6c39
commit 4335d95215
2 changed files with 19 additions and 0 deletions

View File

@ -21,6 +21,8 @@
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/sp/sp_base.hpp"
#include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp"
@ -117,10 +119,25 @@ void ItemManager::loadDefaultItemMeshes()
m_item_lowres_mesh[i]->grab();
}
m_icon[i] = "icon-" + item_names[(ItemState::ItemType)i] + ".png";
preloadIcon(m_icon[i]);
} // for i
delete root;
preloadIcon("item_spark.png");
} // loadDefaultItemMeshes
//-----------------------------------------------------------------------------
/** Preload icon materials to avoid hangs when firstly insert item
*/
void ItemManager::preloadIcon(const std::string& name)
{
// From IrrDriver::addBillboard
Material* m = material_manager->getMaterial(name, false/*full_path*/,
/*make_permanent*/true, /*complain_if_not_found*/true,
/*strip_path*/false, /*install*/false);
m->getTexture(true/*srgb*/, m->getShaderName() == "additive" ||
m->getShaderName() == "alphablend" ? true : false/*premul_alpha*/);
} // preloadIcon
//-----------------------------------------------------------------------------
/** Clean up all textures. This is necessary when switching resolution etc.
*/

View File

@ -56,6 +56,8 @@ private:
static std::mt19937 m_random_engine;
static uint32_t m_random_seed;
static void preloadIcon(const std::string& name);
public:
static void loadDefaultItemMeshes();
static void removeTextures();