From 19b4c98608a0d9df2c35bb9e7f94915bb2d9e7ad Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Thu, 14 Jan 2016 14:39:38 +0100 Subject: [PATCH] skip too long ticks and don't try to do 2 ticks at the same time --- src/lib/plugins/entities.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/plugins/entities.js b/src/lib/plugins/entities.js index 3c1ae3e..95358cb 100644 --- a/src/lib/plugins/entities.js +++ b/src/lib/plugins/entities.js @@ -1,5 +1,9 @@ module.exports.server=function(serv) { + let ticking=false; serv.on('tick', function(delta) { + if(ticking || delta>1) + return; + ticking=true; Promise.all( Object.keys(serv.entities).map(async (id) => { const entity = serv.entities[id]; @@ -20,7 +24,9 @@ module.exports.server=function(serv) { const posAndOnGround = await entity.calculatePhysics(delta); if (entity.type == 'mob') entity.sendPosition(posAndOnGround.position, posAndOnGround.onGround); }) - ).catch((err)=> setTimeout(() => {throw err;},0)); + ) + .then(() => ticking=false) + .catch((err)=> setTimeout(() => {throw err;},0)); }); };