- Avoid usage of setTimeout in hot functions
This commit is contained in:
Felix 2016-09-13 18:12:58 +02:00
parent 00588b2d72
commit 1522fa1709
2 changed files with 6 additions and 2 deletions

View File

@ -22,6 +22,7 @@ export default class WildPokemon extends Pokemon {
this.encounterId = this.getEncounterId();
this.despawnIn = -1;
this.isDespawned = false;
this.minExpire = obj.minExpire;

View File

@ -60,9 +60,12 @@ export default class SpawnPoint extends MapObject {
this.activeSpawns.map((pkmn) => {
if (pkmn.isExpired() && !pkmn.isDespawned) {
pkmn.isDespawned = true;
setTimeout(() => {
pkmn.despawnIn = +new Date() + ((MAP_REFRESH_RATE * 1e3) + pkmn.expiration);
}
else if (pkmn.isDespawned) {
if (+new Date() >= pkmn.despawnIn) {
this.despawnPkmn(pkmn);
}, (MAP_REFRESH_RATE * 1e3) * 2);
}
}
});
}