Skip to content

Commit

Permalink
skip too long ticks and don't try to do 2 ticks at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
rom1504 committed Jan 14, 2016
1 parent 5940f91 commit 19b4c98
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/plugins/entities.js
Original file line number Diff line number Diff line change
@@ -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];
Expand All @@ -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));
});
};

Expand Down

0 comments on commit 19b4c98

Please sign in to comment.