Fixed issue where particles needed to be manually added at the evry top of materials.xml

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10314 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-12-03 22:06:23 +00:00
parent 662a95d0e8
commit 828705bca6
3 changed files with 36 additions and 15 deletions

View File

@ -221,14 +221,23 @@ bool MaterialManager::pushTempMaterial(const std::string& filename)
if(root) delete root;
return true;
}
const bool success = pushTempMaterial(root, filename);
delete root;
return success;
} // pushTempMaterial
//-----------------------------------------------------------------------------
bool MaterialManager::pushTempMaterial(const XMLNode *root,
const std::string& filename)
{
for(unsigned int i=0; i<root->getNumNodes(); i++)
{
const XMLNode *node = root->getNode(i);
if(!node)
{
// We don't have access to the filename at this stage anymore :(
fprintf(stderr, "Unknown node in material.dat file\n");
exit(-1);
fprintf(stderr, "Unknown node in material.xml file\n");
continue;
}
try
{
@ -240,10 +249,10 @@ bool MaterialManager::pushTempMaterial(const std::string& filename)
fprintf(stderr, e.what(), filename.c_str());
}
} // for i<xml->getNumNodes)(
delete root;
return true;
} // pushTempMaterial
//-----------------------------------------------------------------------------
void MaterialManager::popTempMaterial()
{

View File

@ -34,6 +34,7 @@ using namespace irr;
class Material;
class XMLReader;
class XMLNode;
/**
* \ingroup graphics
@ -64,9 +65,12 @@ public:
bool make_permanent=false);
void addSharedMaterial(const std::string& filename);
bool pushTempMaterial (const std::string& filename);
bool pushTempMaterial (const XMLNode *root, const std::string& filename);
void popTempMaterial ();
bool hasMaterial(const std::string& fname);
Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; }
};
extern MaterialManager *material_manager;

View File

@ -109,20 +109,17 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
velocity->get("z", &m_velocity_z);
// ------------------------------------------------------------------------
// old deperecated way
const XMLNode* material = xml->getNode("material");
if (material == NULL)
if (material != NULL)
{
delete xml;
throw std::runtime_error("[ParticleKind] No <material> node in " + file);
}
material->get("file", &m_material_file);
if (m_material_file.size() == 0)
{
delete xml;
throw std::runtime_error("[ParticleKind] <material> tag has invalid 'file' attribute");
material->get("file", &m_material_file);
if (m_material_file.size() == 0)
{
delete xml;
throw std::runtime_error("[ParticleKind] <material> tag has invalid 'file' attribute");
}
}
// ------------------------------------------------------------------------
@ -200,6 +197,17 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
fadeaway->get("end", &m_fade_away_end);
}
// ------------------------------------------------------------------------
const XMLNode* materials = xml->getNode("materials");
if (materials != NULL)
{
material_manager->pushTempMaterial(materials, file);
m_material_file = material_manager->getLatestMaterial()->getTexFname();
}
// ------------------------------------------------------------------------
delete xml;