First attempt at #2316. WIP, issues remains

This commit is contained in:
auria.mg
2016-12-25 20:21:00 -05:00
parent 3c9174d278
commit 4aa31dc56e
4 changed files with 46 additions and 12 deletions

View File

@@ -398,8 +398,30 @@ Material::Material(const XMLNode *node, bool deprecated)
if(m_has_gravity)
m_high_tire_adhesion = true;
install(/*is_full_path*/false);
//Log::info("Material", "setting for lazy load: '%s' '%s'", m_full_path.c_str(), m_texname.c_str());
//install(/*is_full_path*/false);
// now set the name to the basename, so that all tests work as expected
//m_full_path = file_manager->searchTexture(m_texname);
//m_texname = StringUtils::getBasename(m_full_path);
} // Material
//-----------------------------------------------------------------------------
video::ITexture* Material::getTexture()
{
// Note that dont load means that the textures are not loaded
// via the material. So getTexture should only get called for
// automatically loaded textures (used atm for font textures).
assert(!m_dont_load_texture);
if (!m_installed)
{
//m_texname = m_full_path;
Log::info("Material", "LazyLoading (getTexture) '%s'", m_texname.c_str());
install(/*is_full_path*/true, true);
}
return m_texture;
} // getTexture
//-----------------------------------------------------------------------------
/** Create a standard material using the default settings for materials.
@@ -476,6 +498,8 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
// Don't load a texture that are not supposed to be loaded automatically
if(m_dont_load_texture) return;
m_installed = true;
const std::string &full_path = is_full_path
? m_texname
: file_manager->searchTexture(m_texname);
@@ -708,6 +732,13 @@ void Material::setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) con
*/
void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb)
{
if (!m_installed)
{
//Log::info("Material", "LazyLoading (setMaterialProperties) '%s' : '%s'", m_texname.c_str(), m_full_path.c_str());
install(/*is_full_path*/true, true);
}
//Log::info("Material", "setMaterialProperties '%s'", m_texname.c_str());
if (m_deprecated ||
(m->getTexture(0) != NULL &&
((core::stringc)m->getTexture(0)->getName()).find("deprecated") != -1))

View File

@@ -268,6 +268,8 @@ private:
bool m_deprecated;
bool m_installed = false;
void init ();
void install (bool is_full_path=false, bool complain_if_not_found=true);
void initCustomSFX(const XMLNode *sfx);
@@ -290,14 +292,7 @@ public:
void isInitiallyHidden(scene::IMeshBuffer* who);
/** Returns the ITexture associated with this material. */
video::ITexture *getTexture() const
{
// Note that dont load means that the textures are not loaded
// via the material. So getTexture should only get called for
// automatically loaded textures (used atm for font textures).
assert(!m_dont_load_texture);
return m_texture;
} // getTexture
video::ITexture *getTexture();
// ------------------------------------------------------------------------
bool isIgnore () const { return m_ignore; }
// ------------------------------------------------------------------------

View File

@@ -86,13 +86,20 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t,
return getDefaultMaterial(material_type);
core::stringc img_path = core::stringc(t->getName());
img_path.make_lower();
const std::string image = StringUtils::getBasename(img_path.c_str());
if (!img_path.empty() && (img_path.findFirst('/') != -1 || img_path.findFirst('\\') != -1))
{
// Search backward so that temporary (track) textures are found first
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
{
if (m_materials[i]->getTexFullPath() == img_path.c_str())
//Log::info("DEBUG_TEX", "<%s> <%s>", m_materials[i]->getTexFullPath().c_str(), img_path.c_str());
core::stringc fullpath = core::stringc(m_materials[i]->getTexFullPath().c_str());
fullpath.make_lower();
//if (fullpath.find("bumpy") > 0)
// Log::info("DEBUG_TEX", "<%s> <%s>", fullpath.c_str(), img_path.c_str());
if (fullpath == img_path.c_str())
{
return m_materials[i];
}
@@ -102,6 +109,7 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t,
{
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
{
//Log::info("DEBUG_TEX2", "<%s> <%s>", m_materials[i]->getTexFname().c_str(), image.c_str());
if (m_materials[i]->getTexFname() == image)
{
return m_materials[i];
@@ -139,7 +147,7 @@ Material* MaterialManager::getDefaultMaterial(video::E_MATERIAL_TYPE shader_type
auto it = m_default_materials.find(shader_type);
if (it == m_default_materials.end())
{
Material* default_material = new Material("", false, false, false);
Material* default_material = new Material("Default", false, false, false);
// TODO: workaround, should not hardcode these material types here?
// Try to find a cleaner way

View File

@@ -49,7 +49,7 @@ public:
// ------------------------------------------------------------------------
/** Returns the icon to display in the race gui if a kart
* has an attachment. */
const Material* getIcon (int type) const {return m_all_icons [type]; }
Material* getIcon (int type) const { return m_all_icons [type]; }
// ------------------------------------------------------------------------
};