Files
fs2open.github.com/code/particle/util/ParticleProperties.cpp
T
asarium d1a6b48beb Improve handling of non-persistent particles
The current particle system uses dynamic allocation of particle
instances for keeping track of particle instances. This adds unnecessary
overhead in case the code does not need a handle to this particle which
is the case in pretty much all instances.

The new non-persistent particles are stored in a standard vector without
dynamic allocation which should make the processing steps using this
vector much faster and allow better scalability in case more particles
are used by a mission.
2018-04-22 16:22:28 +02:00

66 lines
1.4 KiB
C++

#include "particle/util/ParticleProperties.h"
#include "particle/ParticleManager.h"
#include "bmpman/bmpman.h"
namespace particle {
namespace util {
ParticleProperties::ParticleProperties() : m_radius(0.0f, 1.0f), m_lifetime(0.0f, 1.0f) {
}
void ParticleProperties::parse(bool nocreate) {
if (internal::required_string_if_new("+Filename:", nocreate)) {
m_bitmap = internal::parseAnimation(true);
}
if (internal::required_string_if_new("+Size:", nocreate)) {
m_radius = ::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>();
}
}
}
void ParticleProperties::createParticle(particle_info& info) {
info.optional_data = m_bitmap;
info.type = PARTICLE_BITMAP;
info.rad = m_radius.next();
if (m_hasLifetime) {
info.lifetime = m_lifetime.next();
info.lifetime_from_animation = false;
}
create(&info);
}
WeakParticlePtr ParticleProperties::createPersistentParticle(particle_info& info) {
info.optional_data = m_bitmap;
info.type = PARTICLE_BITMAP;
info.rad = m_radius.next();
auto p = createPersistent(&info);
if (m_hasLifetime && !p.expired()) {
p.lock()->max_life = m_lifetime.next();
}
return p;
}
void ParticleProperties::pageIn() {
if (m_bitmap >= 0) {
bm_page_in_aabitmap(m_bitmap, -1);
}
}
}
}