mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 06:59:18 +02:00
particles: do not use reserve/capacity, use separate var
This commit is contained in:
@@ -109,14 +109,14 @@ smoke_source::deserialize_mapping( cParser &Input ) {
|
|||||||
void
|
void
|
||||||
smoke_source::initialize() {
|
smoke_source::initialize() {
|
||||||
|
|
||||||
m_particles.reserve(
|
m_max_particles =
|
||||||
// put a cap on number of particles in a single source. TBD, TODO: make it part of he source configuration?
|
// put a cap on number of particles in a single source. TBD, TODO: make it part of he source configuration?
|
||||||
std::min(
|
std::min(
|
||||||
500,
|
500,
|
||||||
// NOTE: given nature of the smoke we're presuming opacity decreases over time and the particle is killed when it reaches 0
|
// NOTE: given nature of the smoke we're presuming opacity decreases over time and the particle is killed when it reaches 0
|
||||||
// this gives us estimate of longest potential lifespan of single particle, and how many particles total can there be at any given time
|
// this gives us estimate of longest potential lifespan of single particle, and how many particles total can there be at any given time
|
||||||
// TBD, TODO: explicit lifespan variable as part of the source configuration?
|
// TBD, TODO: explicit lifespan variable as part of the source configuration?
|
||||||
static_cast<int>( m_spawnrate / std::abs( m_opacitymodifier.value_change() ) ) ) );
|
static_cast<int>( m_spawnrate / std::abs( m_opacitymodifier.value_change() ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -154,7 +154,7 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) {
|
|||||||
0.f :
|
0.f :
|
||||||
std::min<float>(
|
std::min<float>(
|
||||||
m_spawncount + ( m_spawnrate * Timedelta ),
|
m_spawncount + ( m_spawnrate * Timedelta ),
|
||||||
m_particles.capacity() ) );
|
m_max_particles ) );
|
||||||
// update spawned particles
|
// update spawned particles
|
||||||
for( auto particleiterator { std::begin( m_particles ) }; particleiterator != std::end( m_particles ); ++particleiterator ) {
|
for( auto particleiterator { std::begin( m_particles ) }; particleiterator != std::end( m_particles ); ++particleiterator ) {
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) {
|
|||||||
}
|
}
|
||||||
// spawn pending particles in remaining container slots
|
// spawn pending particles in remaining container slots
|
||||||
while( ( m_spawncount >= 1.f )
|
while( ( m_spawncount >= 1.f )
|
||||||
&& ( m_particles.size() < m_particles.capacity() ) ) {
|
&& ( m_particles.size() < m_max_particles ) ) {
|
||||||
|
|
||||||
m_spawncount -= 1.f;
|
m_spawncount -= 1.f;
|
||||||
// work with a temporary copy in case initial update renders the particle dead
|
// work with a temporary copy in case initial update renders the particle dead
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ private:
|
|||||||
// current state
|
// current state
|
||||||
float m_spawncount { 0.f }; // number of particles to spawn during next update
|
float m_spawncount { 0.f }; // number of particles to spawn during next update
|
||||||
particle_sequence m_particles; // collection of spawned particles
|
particle_sequence m_particles; // collection of spawned particles
|
||||||
|
size_t m_max_particles; // maximum number of particles existing
|
||||||
/*
|
/*
|
||||||
smoke_sequence::iterator // helpers, iterators marking currently used part of the particle container
|
smoke_sequence::iterator // helpers, iterators marking currently used part of the particle container
|
||||||
m_particlehead,
|
m_particlehead,
|
||||||
|
|||||||
Reference in New Issue
Block a user