From 828705bca68e0811ab90aa02fffc294e6abf1f8c Mon Sep 17 00:00:00 2001 From: auria Date: Sat, 3 Dec 2011 22:06:23 +0000 Subject: [PATCH] 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 --- src/graphics/material_manager.cpp | 15 ++++++++++++--- src/graphics/material_manager.hpp | 4 ++++ src/graphics/particle_kind.cpp | 32 +++++++++++++++++++------------ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/graphics/material_manager.cpp b/src/graphics/material_manager.cpp index 1315e35d0..577240a7f 100644 --- a/src/graphics/material_manager.cpp +++ b/src/graphics/material_manager.cpp @@ -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; igetNumNodes(); 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 igetNumNodes)( - delete root; return true; } // pushTempMaterial + //----------------------------------------------------------------------------- void MaterialManager::popTempMaterial() { diff --git a/src/graphics/material_manager.hpp b/src/graphics/material_manager.hpp index fce20bf76..9a4cd0def 100644 --- a/src/graphics/material_manager.hpp +++ b/src/graphics/material_manager.hpp @@ -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; diff --git a/src/graphics/particle_kind.cpp b/src/graphics/particle_kind.cpp index 3f71313b1..82f44113b 100644 --- a/src/graphics/particle_kind.cpp +++ b/src/graphics/particle_kind.cpp @@ -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 node in " + file); - } - - material->get("file", &m_material_file); - - if (m_material_file.size() == 0) - { - delete xml; - throw std::runtime_error("[ParticleKind] tag has invalid 'file' attribute"); + material->get("file", &m_material_file); + + if (m_material_file.size() == 0) + { + delete xml; + throw std::runtime_error("[ParticleKind] 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;