1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include "particle/util/ParticleProperties.h"
#include "particle/ParticleManager.h"
#include "bmpman/bmpman.h"
#include "math/curve.h"
namespace particle {
namespace util {
ParticleProperties::ParticleProperties() : m_radius(0.0f, 1.0f), m_lifetime(0.0f, 1.0f), m_length (0.0f), m_size_lifetime_curve (-1), m_vel_lifetime_curve (-1){
}
void ParticleProperties::parse(bool nocreate) {
if (internal::required_string_if_new("+Filename:", nocreate)) {
m_bitmap_list = internal::parseAnimationList(true);
m_bitmap_range = ::util::UniformRange<size_t>(0, m_bitmap_list.size() - 1);
}
if (optional_string("+Size:")) {
m_radius = ::util::parseUniformRange<float>();
} else if (optional_string("+Parent Size Factor:")) {
m_radius = ::util::parseUniformRange<float>();
m_parentScale = true;
} else if (!nocreate) {
Error(LOCATION, "Missing +Size or +Parent Size Factor");
}
if (optional_string("+Length:")) {
m_length = ::util::parseUniformRange<float>();
}
if (optional_string("+Lifetime:")) {
if (optional_string("<none>")) {
// Use lifetime of effect
m_hasLifetime = false;
} else {
m_hasLifetime = true;
m_lifetime = ::util::parseUniformRange<float>();
}
} else if (optional_string("+Parent Lifetime Factor:")) {
m_hasLifetime = true;
m_parentLifetime = true;
m_lifetime = ::util::parseUniformRange<float>();
}
if (optional_string("+Size over lifetime curve:")) {
SCP_string buf;
stuff_string(buf, F_NAME);
m_size_lifetime_curve = curve_get_by_name(buf);
if (m_size_lifetime_curve < 0) {
Warning(LOCATION, "Could not find curve '%s'", buf.c_str());
}
}
if (optional_string("+Velocity scalar over lifetime curve:")) {
SCP_string buf;
stuff_string(buf, F_NAME);
m_vel_lifetime_curve = curve_get_by_name(buf);
if (m_vel_lifetime_curve < 0) {
Warning(LOCATION, "Could not find curve '%s'", buf.c_str());
}
}
}
int ParticleProperties::chooseBitmap()
{
// failsafe check, though we should not have been able to get to this point
Assertion(!m_bitmap_list.empty(), "No bitmaps found!");
return m_bitmap_list[m_bitmap_range.next()];
}
void ParticleProperties::createParticle(particle_info& info) {
info.optional_data = ParticleProperties::chooseBitmap();
info.type = PARTICLE_BITMAP;
if (m_parentScale)
// if we were spawned by a particle, info.rad is the parent's radius and m_radius is a factor of that
info.rad *= m_radius.next();
else
info.rad = m_radius.next();
info.length = m_length.next();
if (m_hasLifetime) {
if (m_parentLifetime)
// if we were spawned by a particle, info.lifetime is the parent's remaining liftime and m_lifetime is a factor of that
info.lifetime *= m_lifetime.next();
else
info.lifetime = m_lifetime.next();
info.lifetime_from_animation = false;
}
info.size_lifetime_curve = m_size_lifetime_curve;
info.vel_lifetime_curve = m_vel_lifetime_curve;
create(&info);
}
WeakParticlePtr ParticleProperties::createPersistentParticle(particle_info& info) {
info.optional_data = ParticleProperties::chooseBitmap();
info.type = PARTICLE_BITMAP;
info.rad = m_radius.next();
info.length = m_length.next();
info.size_lifetime_curve = m_size_lifetime_curve;
info.vel_lifetime_curve = m_vel_lifetime_curve;
auto p = createPersistent(&info);
if (m_hasLifetime && !p.expired()) {
p.lock()->max_life = m_lifetime.next();
}
return p;
}
void ParticleProperties::pageIn() {
for (int bitmap : m_bitmap_list) {
bm_page_in_texture(bitmap);
}
}
}
}
|