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
This commit is contained in:
auria 2011-08-28 01:36:54 +00:00
parent 94ddc4a59b
commit a99ab0f300
3 changed files with 27 additions and 52 deletions

View File

@ -1,30 +0,0 @@
<?xml version="1.0"?>
<particles emitter="box" box_x="0.75" box_y="0.75" box_z="0.75">
<spreading angle="25" />
<velocity x="0.000"
y="0.002"
z="0.000" />
<material file="smoke_acid.png" />
<!-- Amount of particles emitted per second -->
<rate min="300"
max="400" />
<!-- Minimal and maximal lifetime of a particle, in milliseconds. -->
<lifetime min="1000"
max="1000" />
<!-- Size of the particles -->
<size min="0.2"
max="0.66" />
<color min="255 255 255"
max="0 0 0" />
<!-- How much time in milliseconds before the particle is fully faded out -->
<fadeout time="500" />
</particles>

View File

@ -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 <material> 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] <material> 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;
}
}

View File

@ -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; }