From 4335d95215cc126cd52ffc5dd3cf511ba758a880 Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 4 Sep 2022 11:37:09 +0800 Subject: [PATCH] Preload icon materials to avoid hang when firstly insert item --- src/items/item_manager.cpp | 17 +++++++++++++++++ src/items/item_manager.hpp | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/items/item_manager.cpp b/src/items/item_manager.cpp index d5317966f..1b4698f11 100644 --- a/src/items/item_manager.cpp +++ b/src/items/item_manager.cpp @@ -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. */ diff --git a/src/items/item_manager.hpp b/src/items/item_manager.hpp index 22db4a0c3..23a38f668 100644 --- a/src/items/item_manager.hpp +++ b/src/items/item_manager.hpp @@ -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();