mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Handle particle spawners in env and delete expired ids
Rebased by Zeno (2016-04-2016)
This commit is contained in:
parent
26a9a85129
commit
6278da296b
4 changed files with 62 additions and 22 deletions
|
@ -50,6 +50,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#define LBM_NAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_:"
|
||||
|
||||
// A number that is much smaller than the timeout for particle spawners should/could ever be
|
||||
#define PARTICLE_SPAWNER_NO_EXPIRY -1024.f
|
||||
|
||||
Environment::Environment():
|
||||
m_time_of_day_speed(0),
|
||||
m_time_of_day(9000),
|
||||
|
@ -1544,6 +1547,49 @@ void ServerEnvironment::step(float dtime)
|
|||
*/
|
||||
removeRemovedObjects();
|
||||
}
|
||||
|
||||
/*
|
||||
Manage particle spawner expiration
|
||||
*/
|
||||
if (m_particle_management_interval.step(dtime, 1.0)) {
|
||||
for (std::map<u32, float>::iterator i = m_particle_spawners.begin();
|
||||
i != m_particle_spawners.end(); ) {
|
||||
//non expiring spawners
|
||||
if (i->second == PARTICLE_SPAWNER_NO_EXPIRY) {
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
|
||||
i->second -= 1.0f;
|
||||
if (i->second <= 0.f)
|
||||
m_particle_spawners.erase(i++);
|
||||
else
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 ServerEnvironment::addParticleSpawner(float exptime)
|
||||
{
|
||||
// Timers with lifetime 0 do not expire
|
||||
float time = exptime > 0.f ? exptime : PARTICLE_SPAWNER_NO_EXPIRY;
|
||||
|
||||
u32 id = 0;
|
||||
for (;;) { // look for unused particlespawner id
|
||||
id++;
|
||||
std::map<u32, float>::iterator f;
|
||||
f = m_particle_spawners.find(id);
|
||||
if (f == m_particle_spawners.end()) {
|
||||
m_particle_spawners[id] = time;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
void ServerEnvironment::deleteParticleSpawner(u32 id)
|
||||
{
|
||||
m_particle_spawners.erase(id);
|
||||
}
|
||||
|
||||
ServerActiveObject* ServerEnvironment::getActiveObject(u16 id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue