#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),
*/
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)
// env_meta.txt doesn't exist (e.g. new world)
void loadDefaultMeta();
+ u32 addParticleSpawner(float exptime);
+ void deleteParticleSpawner(u32 id);
+
/*
External ActiveObject interface
-------------------------------------------
// Estimate for general maximum lag as determined by server.
// Can raise to high values like 15s with eg. map generation mods.
float m_max_lag_estimate;
+
+ // Particles
+ IntervalLimiter m_particle_management_interval;
+ std::map<u32, float> m_particle_spawners;
};
#ifndef SERVER
peer_id = player->peer_id;
}
- u32 id = 0;
- for(;;) // look for unused particlespawner id
- {
- id++;
- if (std::find(m_particlespawner_ids.begin(),
- m_particlespawner_ids.end(), id)
- == m_particlespawner_ids.end())
- {
- m_particlespawner_ids.push_back(id);
- break;
- }
- }
-
+ u32 id = m_env->addParticleSpawner(spawntime);
SendAddParticleSpawner(peer_id, amount, spawntime,
minpos, maxpos, minvel, maxvel, minacc, maxacc,
minexptime, maxexptime, minsize, maxsize,
peer_id = player->peer_id;
}
- m_particlespawner_ids.erase(
- std::remove(m_particlespawner_ids.begin(),
- m_particlespawner_ids.end(), id),
- m_particlespawner_ids.end());
+ m_env->deleteParticleSpawner(id);
SendDeleteParticleSpawner(peer_id, id);
}
+void Server::deleteParticleSpawnerAll(u32 id)
+{
+ m_env->deleteParticleSpawner(id);
+ SendDeleteParticleSpawner(PEER_ID_INEXISTENT, id);
+}
+
Inventory* Server::createDetachedInventory(const std::string &name)
{
if(m_detached_inventories.count(name) > 0){
const std::string &playername);
void deleteParticleSpawner(const std::string &playername, u32 id);
+ void deleteParticleSpawnerAll(u32 id);
// Creates or resets inventory
Inventory* createDetachedInventory(const std::string &name);
// key = name
std::map<std::string, Inventory*> m_detached_inventories;
- /*
- Particles
- */
- std::vector<u32> m_particlespawner_ids;
-
DISABLE_CLASS_COPY(Server);
};