mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-18 22:11:07 +00:00
27 lines
611 B
JavaScript
27 lines
611 B
JavaScript
module.exports.server=function(serv) {
|
|
serv.tickCount = 0;
|
|
serv.lastTickTime = 0;
|
|
|
|
|
|
serv.setTickInterval = ticksPerSecond => {
|
|
serv.stopTickInterval();
|
|
|
|
serv.tickInterval = setInterval(() => {
|
|
serv.tickCount++;
|
|
var t=Date.now();
|
|
var time = (t - serv.lastTickTime) / 1000;
|
|
if (time > 100) time = 0;
|
|
serv.emit('tick', time, serv.tickCount);
|
|
serv.lastTickTime = t;
|
|
}, 1000/ticksPerSecond);
|
|
};
|
|
|
|
serv.stopTickInterval = () => {
|
|
if (serv.tickInterval) clearInterval(serv.tickInterval);
|
|
serv.tickInterval = null;
|
|
};
|
|
|
|
|
|
serv.setTickInterval(20);
|
|
};
|
|
|