mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-11 04:31:35 -10:00
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.
66 lines
1.4 KiB
C++
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);
|
|
}
|
|
}
|
|
}
|
|
}
|