Create a "default material" object and use it for materials that don't appear in materials.xml, instead of an hardcoded special case

This commit is contained in:
Marianne Gagnon 2014-09-17 19:38:18 -04:00 committed by Vincent Lejeune
parent 3349b9907d
commit 933e27052d
4 changed files with 28 additions and 20 deletions

View File

@ -51,9 +51,8 @@ const unsigned int VCLAMP = 2;
//-----------------------------------------------------------------------------
/** Create a new material using the parameters specified in the xml file.
* \param node Node containing the parameters for this material.
* \param index Index in material_manager.
*/
Material::Material(const XMLNode *node, int index, bool deprecated)
Material::Material(const XMLNode *node, bool deprecated)
{
m_shader_type = SHADERTYPE_SOLID;
m_deprecated = deprecated;
@ -65,7 +64,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
throw std::runtime_error("[Material] No texture name specified "
"in file\n");
}
init(index);
init();
bool b = false;
@ -397,26 +396,25 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
//-----------------------------------------------------------------------------
/** Create a standard material using the default settings for materials.
* \param fname Name of the texture file.
* \param index Unique index in material_manager.
* \param is_full_path If the fname contains the full path.
*/
Material::Material(const std::string& fname, int index, bool is_full_path,
bool complain_if_not_found)
Material::Material(const std::string& fname, bool is_full_path,
bool complain_if_not_found, bool load_texture)
{
m_deprecated = false;
m_texname = fname;
init(index);
install(is_full_path, complain_if_not_found);
init();
if (load_texture)
install(is_full_path, complain_if_not_found);
} // Material
//-----------------------------------------------------------------------------
/** Inits all material data with the default settings.
* \param Index of this material in the material_manager index array.
*/
void Material::init(unsigned int index)
void Material::init()
{
m_index = index;
m_clamp_tex = 0;
m_shader_type = SHADERTYPE_SOLID;
//m_lightmap = false;

View File

@ -81,7 +81,7 @@ public:
private:
video::ITexture *m_texture;
unsigned int m_index;
//unsigned int m_index;
std::string m_texname;
/** Name of a special sfx to play when a kart is on this terrain, or
* "" if no special sfx exists. */
@ -228,16 +228,17 @@ private:
bool m_deprecated;
void init (unsigned int index);
void init ();
void install (bool is_full_path=false, bool complain_if_not_found=true);
void initCustomSFX(const XMLNode *sfx);
void initParticlesEffect(const XMLNode *node);
public:
Material(const XMLNode *node, int index, bool deprecated);
Material(const std::string& fname, int index,
Material(const XMLNode *node, bool deprecated);
Material(const std::string& fname,
bool is_full_path=false,
bool complain_if_not_found=true);
bool complain_if_not_found=true,
bool load_texture = true);
~Material ();
void setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) const;
@ -261,7 +262,7 @@ public:
bool highTireAdhesion () const { return m_high_tire_adhesion; }
const std::string&
getTexFname () const { return m_texname; }
int getIndex () const { return m_index; }
//int getIndex () const { return m_index; }
bool isTransparent () const
{

View File

@ -40,6 +40,7 @@ MaterialManager::MaterialManager()
{
/* Create list - and default material zero */
m_default_material = NULL;
m_materials.reserve(256);
// We can't call init/loadMaterial here, since the global variable
// material_manager has not yet been initialised, and
@ -95,6 +96,11 @@ void MaterialManager::setAllMaterialFlags(video::ITexture* t,
return;
}
if (m_default_material == NULL)
m_default_material = new Material("", false, false, false);
m_default_material->setMaterialProperties(&(mb->getMaterial()), mb);
/*
// This material does not appear in materials.xml. Set some common flags...
if (UserConfigParams::m_anisotropic > 0)
{
@ -132,7 +138,7 @@ void MaterialManager::setAllMaterialFlags(video::ITexture* t,
//if (UserConfigParams::m_fullscreen_antialiasing)
// mb->getMaterial().AntiAliasing = video::EAAM_LINE_SMOOTH;
*/
} // setAllMaterialFlags
//-----------------------------------------------------------------------------
@ -244,7 +250,7 @@ bool MaterialManager::pushTempMaterial(const XMLNode *root,
}
try
{
m_materials.push_back(new Material(node, m_materials.size(), deprecated));
m_materials.push_back(new Material(node, deprecated));
}
catch(std::exception& e)
{
@ -311,7 +317,7 @@ Material *MaterialManager::getMaterial(const std::string& fname,
}
// Add the new material
Material* m=new Material(fname, m_materials.size(), is_full_path, complain_if_not_found);
Material* m = new Material(fname, is_full_path, complain_if_not_found);
m_materials.push_back(m);
if(make_permanent)
{

View File

@ -47,6 +47,9 @@ private:
int m_shared_material_index;
std::vector<Material*> m_materials;
Material* m_default_material;
public:
MaterialManager();
~MaterialManager();