From a99ab0f30082559a8798acd8320ded486eb6accd Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 28 Aug 2011 01:36:54 +0000 Subject: [PATCH] Lazily get particle materials, mostly fixing the issue of per-track particles git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9635 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/gfx/acid_splash.xml | 30 ------------------------- src/graphics/particle_kind.cpp | 41 +++++++++++++++++++--------------- src/graphics/particle_kind.hpp | 8 +++---- 3 files changed, 27 insertions(+), 52 deletions(-) delete mode 100644 data/gfx/acid_splash.xml diff --git a/data/gfx/acid_splash.xml b/data/gfx/acid_splash.xml deleted file mode 100644 index 484acd0ae..000000000 --- a/data/gfx/acid_splash.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/graphics/particle_kind.cpp b/src/graphics/particle_kind.cpp index de155b167..98a6405c2 100644 --- a/src/graphics/particle_kind.cpp +++ b/src/graphics/particle_kind.cpp @@ -35,7 +35,6 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2 m_max_size = 0.5f; m_min_size = 0.5f; m_shape = EMITTER_POINT; - m_material = NULL; m_min_rate = 10; m_max_rate = 10; m_lifetime_min = 400; @@ -117,29 +116,14 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2 throw std::runtime_error("[ParticleKind] No node in " + file); } - std::string materialFile; - material->get("file", &materialFile); + material->get("file", &m_material_file); - if (materialFile.size() == 0) + if (m_material_file.size() == 0) { delete xml; throw std::runtime_error("[ParticleKind] tag has invalid 'file' attribute"); } - if (material_manager->hasMaterial(materialFile)) - { - m_material = material_manager->getMaterial(materialFile); - if (m_material->getTexture() == NULL) - { - throw std::runtime_error("[ParticleKind] Cannot locate file " + materialFile); - } - } - else - { - fprintf(stderr, "[ParticleKind] WARNING: particle image '%s' does not appear in the list of " - "currently known materials\n", materialFile.c_str()); - } - // ------------------------------------------------------------------------ const XMLNode* rate = xml->getNode("rate"); @@ -218,3 +202,24 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2 delete xml; } + +// ---------------------------------------------------------------------------- + +Material* ParticleKind::getMaterial() const +{ + if (material_manager->hasMaterial(m_material_file)) + { + Material* material = material_manager->getMaterial(m_material_file); + if (material->getTexture() == NULL) + { + throw std::runtime_error("[ParticleKind] Cannot locate file " + m_material_file); + } + return material; + } + else + { + fprintf(stderr, "[ParticleKind] WARNING: particle image '%s' does not appear in the list of " + "currently known materials\n", m_material_file.c_str()); + return NULL; + } +} diff --git a/src/graphics/particle_kind.hpp b/src/graphics/particle_kind.hpp index 497912d4c..9940b79bc 100644 --- a/src/graphics/particle_kind.hpp +++ b/src/graphics/particle_kind.hpp @@ -54,9 +54,7 @@ private: float m_velocity_z; EmitterShape m_shape; - - Material* m_material; - + /** Minimal emission rate in particles per second */ int m_min_rate; @@ -85,6 +83,8 @@ private: std::string m_name; + std::string m_material_file; + public: /** @@ -104,7 +104,7 @@ public: EmitterShape getShape () const { return m_shape; } - Material* getMaterial () const { return m_material; } + Material* getMaterial () const; int getMaxLifetime () const { return m_lifetime_max; } int getMinLifetime () const { return m_lifetime_min; }