Added limited lazy-load flag to avoid loading of all font textures

(most of which might not be needed). Fixes #1592.
This commit is contained in:
hiker 2014-10-05 21:35:14 +11:00
parent f63e7d93b8
commit df62c8921e
4 changed files with 71 additions and 50 deletions

View File

@ -1,22 +1,22 @@
<?xml version="1.0"?>
<materials>
<!-- Fonts -->
<material name="title_font.png" shader="unlit"/>
<material name="title_font_2.png" shader="unlit"/>
<material name="sigmar0.png" shader="unlit"/>
<material name="AR_PL_SungtiL_GB0.png" shader="unlit"/>
<material name="comix.png" shader="unlit"/>
<material name="LayneHansom0.png" shader="unlit"/>
<material name="LayneHansomBigDigits.png" shader="unlit"/>
<material name="Mplus2p_JP0.png" shader="unlit"/>
<material name="rasheeq0.png" shader="unlit"/>
<material name="rasheeq3.png" shader="unlit"/>
<material name="rasheeq4.png" shader="unlit"/>
<material name="wqyMicroHei0.png" shader="unlit"/>
<material name="wqyMicroHei1.png" shader="unlit"/>
<material name="wqyMicroHei2.png" shader="unlit"/>
<material name="wqyMicroHei3.png" shader="unlit"/>
<material name="wqyMicroHei4.png" shader="unlit"/>
<material name="wqyMicroHei5.png" shader="unlit"/>
<material name="title_font.png" shader="unlit" lazy-load="Y"/>
<material name="title_font_2.png" shader="unlit" lazy-load="Y"/>
<material name="sigmar0.png" shader="unlit" lazy-load="Y"/>
<material name="comix.png" shader="unlit" lazy-load="Y"/>
<material name="LayneHansom0.png" shader="unlit" lazy-load="Y"/>
<material name="Mplus2p_JP0.png" shader="unlit" lazy-load="Y"/>
<material name="rasheeq0.png" shader="unlit" lazy-load="Y"/>
<material name="rasheeq3.png" shader="unlit" lazy-load="Y"/>
<material name="rasheeq4.png" shader="unlit" lazy-load="Y"/>
<material name="wqyMicroHei0.png" shader="unlit" lazy-load="Y"/>
<material name="wqyMicroHei1.png" shader="unlit" lazy-load="Y"/>
<material name="wqyMicroHei2.png" shader="unlit" lazy-load="Y"/>
<material name="wqyMicroHei3.png" shader="unlit" lazy-load="Y"/>
<material name="wqyMicroHei4.png" shader="unlit" lazy-load="Y"/>
<material name="wqyMicroHei5.png" shader="unlit" lazy-load="Y"/>
<material name="AR_PL_SungtiL_GB0.png" shader="unlit" lazy-load="Y"/>
<material name="LayneHansomBigDigits.png" shader="unlit" lazy-load="Y"/>
</materials>

View File

@ -58,7 +58,6 @@ Material::Material(const XMLNode *node, bool deprecated)
m_deprecated = deprecated;
node->get("name", &m_texname);
if (m_texname=="")
{
throw std::runtime_error("[Material] No texture name specified "
@ -66,6 +65,7 @@ Material::Material(const XMLNode *node, bool deprecated)
}
init();
node->get("lazy-load", &m_lazy_load);
bool b = false;
node->get("clampu", &b); if (b) m_clamp_tex |= UCLAMP; //blender 2.4 style
@ -412,10 +412,10 @@ Material::Material(const std::string& fname, bool is_full_path,
*/
void Material::init()
{
m_lazy_load = false;
m_texture = NULL;
m_clamp_tex = 0;
m_shader_type = SHADERTYPE_SOLID;
//m_lightmap = false;
//m_adjust_image = ADJ_NONE;
m_backface_culling = true;
m_high_tire_adhesion = false;
m_below_surface = false;
@ -455,6 +455,9 @@ void Material::init()
//-----------------------------------------------------------------------------
void Material::install(bool is_full_path, bool complain_if_not_found)
{
// Don't load a texture that is lazily loaded.
if(m_lazy_load) return;
const std::string &full_path = is_full_path
? m_texname
: file_manager->searchTexture(m_texname);

View File

@ -22,13 +22,11 @@
#include "utils/no_copy.hpp"
#include <assert.h>
#include <map>
#include <string>
#include <vector>
#include <IShaderConstantSetCallBack.h>
namespace irr
{
namespace video { class ITexture; class SMaterial; }
@ -81,9 +79,18 @@ public:
private:
/** Pointer to the texture. */
video::ITexture *m_texture;
//unsigned int m_index;
/** Name of the texture. */
std::string m_texname;
/** If true, the texture will not automatically be loaded and bound
* at load time, it must be loaded elsewhere. This is used to store
* material settings for font textures, without loading fonts for
* languages that might not be needed at all. */
bool m_lazy_load;
/** Name of a special sfx to play when a kart is on this terrain, or
* "" if no special sfx exists. */
std::string m_sfx_name;
@ -114,7 +121,7 @@ private:
/** If a kart is rescued when driving on this surface. */
bool m_drive_reset;
/** True if this is a texture that will start the jump animatoin when
/** True if this is a texture that will start the jump animation when
* leaving it and being in the air. */
bool m_is_jump_texture;
@ -244,27 +251,45 @@ public:
void setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) const;
void setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb);
void adjustForFog(scene::ISceneNode* parent, video::SMaterial *m, bool use_fog) const;
void adjustForFog(scene::ISceneNode* parent, video::SMaterial *m,
bool use_fog) const;
void onMadeVisible(scene::IMeshBuffer* who);
void onHidden(scene::IMeshBuffer* who);
void isInitiallyHidden(scene::IMeshBuffer* who);
/** Returns the ITexture associated with this material. */
video::ITexture *getTexture() const { return m_texture; }
video::ITexture *getTexture() const
{
// Note that atm lazy load means that the textures are not loaded
// via the material. So getTexture should only get called for non
// lazily loaded textures (used atm for font textures.
assert(!m_lazy_load);
return m_texture;
} // getTexture
// ------------------------------------------------------------------------
bool isIgnore () const { return m_ignore; }
// ------------------------------------------------------------------------
/** Returns true if this material is a zipper. */
bool isZipper () const { return m_zipper; }
// ------------------------------------------------------------------------
/** Returns if this material should trigger a rescue if a kart
* is driving on it. */
bool isDriveReset () const { return m_drive_reset; }
// ------------------------------------------------------------------------
/** Returns if this material should trigger a rescue if a kart
* crashes against it. */
CollisionReaction getCollisionReaction() const { return m_collision_reaction; }
// ------------------------------------------------------------------------
std::string getCrashResetParticles() const { return m_collision_particles; }
// ------------------------------------------------------------------------
bool highTireAdhesion () const { return m_high_tire_adhesion; }
// ------------------------------------------------------------------------
const std::string&
getTexFname () const { return m_texname; }
//int getIndex () const { return m_index; }
// ------------------------------------------------------------------------
bool isTransparent () const
{
return m_shader_type == SHADERTYPE_ADDITIVE ||
@ -272,12 +297,6 @@ public:
m_shader_type == SHADERTYPE_ALPHA_TEST;
}
// ------------------------------------------------------------------------
/** Returns true if this materials need pre-multiply of alpha. */
//bool isPreMul() const {return m_adjust_image==ADJ_PREMUL; }
// ------------------------------------------------------------------------
/** Returns true if this materials need pre-division of alpha. */
//bool isPreDiv() const {return m_adjust_image==ADJ_DIV; }
// ------------------------------------------------------------------------
/** Returns the fraction of maximum speed on this material. */
float getMaxSpeedFraction() const { return m_max_speed_fraction; }
@ -300,17 +319,20 @@ public:
// ------------------------------------------------------------------------
/** Returns the name of a special sfx to play while a kart is on this
* terrain. The string will be "" if no special sfx exists. */
const std::string &
getSFXName () const { return m_sfx_name; }
const std::string &getSFXName() const { return m_sfx_name; }
// ------------------------------------------------------------------------
/** Returns if fog is enabled. */
bool isFogEnabled() const { return m_fog; }
/**
* \brief Get the kind of particles that are to be used on this material, in the given conditions
* \return The particles to use, or NULL if none
*/
const ParticleKind* getParticlesWhen(ParticleConditions cond) const { return m_particles_effects[cond]; }
// ------------------------------------------------------------------------
/** \brief Get the kind of particles that are to be used on this material,
* in the given conditions.
* \return The particles to use, or NULL if none. */
const ParticleKind* getParticlesWhen(ParticleConditions cond) const
{
return m_particles_effects[cond];
} // getParticlesWhen
// ------------------------------------------------------------------------
/** Returns true if a kart falling over this kind of material triggers
* the special falling camera. */
@ -346,9 +368,6 @@ public:
// ------------------------------------------------------------------------
ShaderType getShaderType() const { return m_shader_type; }
// ------------------------------------------------------------------------
void onMadeVisible(scene::IMeshBuffer* who);
void onHidden(scene::IMeshBuffer* who);
void isInitiallyHidden(scene::IMeshBuffer* who);
} ;

View File

@ -1208,12 +1208,11 @@ int main(int argc, char *argv[] )
main_loop = new MainLoop();
material_manager->loadMaterial();
// Load the font textures
file_manager->pushTextureSearchPath(
file_manager->getAsset(FileManager::FONT,""));
// Load the font textures - they are all lazily loaded
// so no need to push a texture search path. They will actually
// be loaded from ScalableFont.
material_manager->addSharedMaterial(
file_manager->getAsset(FileManager::FONT,"materials.xml"));
file_manager->popTextureSearchPath();
GUIEngine::addLoadingIcon( irr_driver->getTexture(FileManager::GUI,
"options_video.png"));