Improved error handling (don't crash when invalid particles are defined)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7901 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -333,7 +333,7 @@ void Material::initParticlesEffect(const XMLNode *node)
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
fprintf(stderr, "[Material::initParticlesEffect] WARNING: Particles '%s' for material '%s' are declared but not used\n",
|
||||
fprintf(stderr, "[Material::initParticlesEffect] WARNING: Particles '%s' for material '%s' are declared but not used (no emission condition set)\n",
|
||||
base.c_str(), m_texname.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ void ParticleEmitter::setPosition(const Vec3 &pos)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
{
|
||||
{
|
||||
assert(m_magic_number == 0x58781325);
|
||||
if (m_particle_type == type) return; // already the right type
|
||||
|
||||
@@ -291,27 +291,38 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
const int lifeTimeMin = type->getMinLifetime();
|
||||
const int lifeTimeMax = type->getMaxLifetime();
|
||||
|
||||
assert(material->getTexture() != NULL);
|
||||
assert(maxSize >= minSize);
|
||||
assert(lifeTimeMax >= lifeTimeMin);
|
||||
|
||||
#ifdef DEBUG
|
||||
video::ITexture* tex = material->getTexture();
|
||||
assert(tex != NULL);
|
||||
const io::SNamedPath& name = tex->getName();
|
||||
const io::path& tpath = name.getPath();
|
||||
|
||||
std::string debug_name = std::string("particles(") + tpath.c_str() + ")";
|
||||
m_node->setName(debug_name.c_str());
|
||||
if (material != NULL)
|
||||
{
|
||||
video::ITexture* tex = material->getTexture();
|
||||
assert(tex != NULL);
|
||||
const io::SNamedPath& name = tex->getName();
|
||||
const io::path& tpath = name.getPath();
|
||||
|
||||
std::string debug_name = std::string("particles(") + tpath.c_str() + ")";
|
||||
m_node->setName(debug_name.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
video::SMaterial& mat0 = m_node->getMaterial(0);
|
||||
|
||||
m_node->setPosition(m_position.toIrrVector());
|
||||
material->setMaterialProperties(&mat0);
|
||||
m_node->setMaterialTexture(0, material->getTexture());
|
||||
|
||||
mat0.ZWriteEnable = !material->isTransparent(); // disable z-buffer writes if material is transparent
|
||||
if (material != NULL)
|
||||
{
|
||||
assert(material->getTexture() != NULL);
|
||||
material->setMaterialProperties(&mat0);
|
||||
m_node->setMaterialTexture(0, material->getTexture());
|
||||
|
||||
mat0.ZWriteEnable = !material->isTransparent(); // disable z-buffer writes if material is transparent
|
||||
}
|
||||
else
|
||||
{
|
||||
m_node->setMaterialTexture(0, irr_driver->getTexture((file_manager->getDataDir() + "/gui/main_help.png").c_str()));
|
||||
}
|
||||
|
||||
switch (type->getShape())
|
||||
{
|
||||
@@ -320,7 +331,7 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
m_emitter = m_node->createPointEmitter(core::vector3df(m_particle_type->getVelocityX(),
|
||||
m_particle_type->getVelocityY(),
|
||||
m_particle_type->getVelocityZ()), // velocity in m/ms
|
||||
type->getMinRate(), type->getMaxRate(),
|
||||
type->getMinRate(), type->getMaxRate(),
|
||||
type->getMinColor(), type->getMaxColor(),
|
||||
lifeTimeMin, lifeTimeMax,
|
||||
m_particle_type->getAngleSpread() /* angle */
|
||||
@@ -338,7 +349,7 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
core::vector3df(m_particle_type->getVelocityX(),
|
||||
m_particle_type->getVelocityY(),
|
||||
m_particle_type->getVelocityZ()), // velocity in m/ms
|
||||
type->getMinRate(), type->getMaxRate(),
|
||||
type->getMinRate(), type->getMaxRate(),
|
||||
type->getMinColor(), type->getMaxColor(),
|
||||
lifeTimeMin, lifeTimeMax,
|
||||
m_particle_type->getAngleSpread() /* angle */
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,255,255), m_max_start_color(255,255,255,255)
|
||||
ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,255,255),
|
||||
m_max_start_color(255,255,255,255), m_name(file)
|
||||
{
|
||||
// ---- Initial values to prevent readin uninitialized values
|
||||
m_max_size = 0.5f;
|
||||
@@ -135,7 +136,7 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "[ParticleKind] WARNING: particle image '%s' does not appear in the list of currently known materials, it will be opaque", materialFile.c_str());
|
||||
fprintf(stderr, "[ParticleKind] WARNING: particle image '%s' does not appear in the list of currently known materials\n", materialFile.c_str());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -83,6 +83,8 @@ private:
|
||||
/** Distance from camera at which particles start fading out, or negative if disabled */
|
||||
float m_fade_away_start, m_fade_away_end;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@@ -134,6 +136,8 @@ public:
|
||||
void setBoxSizeX (float newVal) { m_box_x = newVal; }
|
||||
void setBoxSizeY (float newVal) { m_box_y = newVal; }
|
||||
void setBoxSizeZ (float newVal) { m_box_z = newVal; }
|
||||
|
||||
std::string getName() const { return m_name; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user