🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@armniko/ticker

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@armniko/ticker - npm Package Compare versions

Comparing version
2.1.0
to
2.1.1
+43
dist/types.d.ts
export interface DrawQueueItem {
callback: (time: Time) => void;
}
export interface LogicQueueItem {
callback: (time: Time) => void;
}
export interface LowFpsQueueItem {
callback: (fps: number) => void;
}
export interface TickerOptions {
/**
* @deprecated Passing `maxFps` in ticker options is deprecated. Use `ticker.setFps({ max: 60 })` instead.
*/
maxFps?: number;
/**
* @deprecated Passing `expectedFps` in ticker options is deprecated. Use `ticker.setFps({ min: 10 })` instead.
*/
minFps?: number;
/**
* @deprecated Passing `expectedFps` in ticker options is deprecated. Use `ticker.setFps({ expected: 60 })` instead.
*/
expectedFps?: number;
/**
* @deprecated Passing `onLogicTick` in ticker options is deprecated. Use `ticker.addLogicTask(callback)` instead.
*/
onLogicTick?: () => void;
/**
* @deprecated Passing `onDrawTick` in ticker options is deprecated. Use `ticker.addDrawTask(callback)` instead.
*/
onDrawTick?: () => void;
/**
* @deprecated Passing `onLowFps` in ticker options is deprecated. Use `ticker.addLowFpsTask(callback)` instead.
*/
onLowFps?: () => void;
}
export interface TickerTaskId {
index: number;
type: 'draw' | 'logic' | 'low-fps';
}
export interface Time {
delta: number;
deltaMs: number;
}
+1
-1

@@ -1,2 +0,2 @@

import { Time } from '../interfaces/time.interface';
import { Time } from '../types';
export declare class Fps {

@@ -3,0 +3,0 @@ private _minFps?;

@@ -1,4 +0,3 @@

export * from './ticker/ticker';
export * from './ticker/ticker-mock';
export * from './interfaces/time.interface';
export * from './interfaces/ticker-task-id.interface';
export { Ticker } from './ticker/ticker';
export { TickerMock } from './ticker/ticker-mock';
export type { Time, TickerTaskId } from './types';

@@ -1,155 +0,1 @@

class a {
_minFps;
_currentFps = 60;
_lastChecks = [];
_calculateFpsEachMs = 2e3;
_msSinceLastCalculation = 0;
_lowFpsInRow = 0;
_lowFpsCallback;
currentFps() {
return this._currentFps;
}
calculate(s) {
this.collectFps(s), this._msSinceLastCalculation += s.deltaMs, this._msSinceLastCalculation >= this._calculateFpsEachMs && (this._msSinceLastCalculation = 0, this.calculateAverageFps(), this.checkAndNotifyLowFps());
}
onLowFps(s) {
this._lowFpsCallback = s;
}
setMinFps(s) {
return this._minFps = s, this;
}
collectFps(s) {
this._lastChecks.push(Math.round(1e3 / s.deltaMs));
}
calculateAverageFps() {
const s = this._lastChecks.reduce((e, t) => e + t, 0);
this._currentFps = Math.round(s / this._lastChecks.length), this._lastChecks = [];
}
checkAndNotifyLowFps() {
this._minFps && this._currentFps < this._minFps && (this._lowFpsInRow++, this._lowFpsInRow === 5 && (this._lowFpsInRow = 0, this._lowFpsCallback && this._lowFpsCallback()));
}
}
class c {
_fps = new a();
_drawQueue = [];
_logicQueue = [];
_lowFpsQueue = [];
_maxFps;
_expectedFps;
_time = { delta: 0, deltaMs: 0 };
_lastTimestamp = 0;
_logicTicksAccumulatedMs = 0;
_requestFrameId;
constructor(s) {
this.setFps({ min: s?.minFps || 0, max: s?.maxFps || 60, expected: s?.expectedFps || 60 }), s?.onDrawTick && this.addDrawTask(s.onDrawTick), s?.onLogicTick && this.addLogicTask(s.onLogicTick), s?.onLowFps && this.addLowFpsTask(s.onLowFps), this._fps.onLowFps(() => {
this._lowFpsQueue.forEach((e) => e.callback(this.fps()));
});
}
start() {
this._lastTimestamp = performance.now(), this.loop(this._lastTimestamp);
}
stop() {
this._requestFrameId && (window.cancelAnimationFrame(this._requestFrameId), this._requestFrameId = void 0);
}
isStarted() {
return !!this._requestFrameId;
}
setFps(s) {
return s.min && s.min > 0 && this._fps.setMinFps(s.min), s.max && s.max > 0 && (this._maxFps = this.compensatedMaxFps(s.max)), s.expected && s.expected > 0 && (this._expectedFps = s.expected), this;
}
addDrawTask(s) {
return { index: this._drawQueue.push({ callback: s }) - 1, type: "draw" };
}
addLogicTask(s) {
return { index: this._logicQueue.push({ callback: s }) - 1, type: "logic" };
}
addLowFpsTask(s) {
return { index: this._lowFpsQueue.push({ callback: s }) - 1, type: "low-fps" };
}
remove(s) {
switch (s.type) {
case "draw":
this._drawQueue.splice(s.index, 1);
break;
case "logic":
this._logicQueue.splice(s.index, 1);
break;
case "low-fps":
this._lowFpsQueue.splice(s.index, 1);
break;
}
}
fps() {
return this._fps.currentFps();
}
/**
* @deprecated Use `time.deltaMs` provided in draw/logic task callbacks instead.
*/
msBetweenTicks() {
return this._time.deltaMs;
}
/**
* @deprecated Use `time.deltaMs` provided in draw/logic task callbacks instead.
*/
ticksMissed() {
return this._time.deltaMs / (1e3 / this._expectedFps);
}
loop(s) {
const e = 1e3 / this._maxFps, t = s - this._lastTimestamp;
t >= e && (this._time = { delta: t / 1e3, deltaMs: t }, this._lastTimestamp = s, this._fps.calculate(this._time), this.runQueue()), this._requestFrameId = window.requestAnimationFrame(this.loop.bind(this));
}
runQueue() {
this._logicQueue.length > 0 && this.runLogicQueue(), this._drawQueue.length > 0 && this.runDrawQueue();
}
runLogicQueue() {
const s = 1e3 / this._expectedFps;
this._logicTicksAccumulatedMs += this._time.deltaMs;
const e = { delta: s / 1e3, deltaMs: s };
for (; this._logicTicksAccumulatedMs >= s; )
this._logicQueue.forEach((t) => t.callback(e)), this._logicTicksAccumulatedMs -= s;
}
runDrawQueue() {
this._drawQueue.forEach((s) => s.callback(this._time));
}
compensatedMaxFps(s) {
return Math.floor(s * 1.1) + Math.floor(s / 100) * 10;
}
}
class l extends c {
_isStarted = !1;
start() {
this._isStarted = !0;
}
stop() {
this._isStarted = !1;
}
isStarted() {
return this._isStarted;
}
fps() {
return 60;
}
msBetweenTicks() {
return 1e3 / 60;
}
ticksMissed() {
return 1;
}
simulateLogicTick(s = void 0) {
this._logicQueue.forEach(
(e) => e.callback(s || { delta: 1 / this.fps(), deltaMs: 1e3 / this.fps() })
);
}
simulateDrawTick(s = void 0) {
this._drawQueue.forEach(
(e) => e.callback(s || { delta: 1 / this.fps(), deltaMs: 1e3 / this.fps() })
);
}
simulateLowFps() {
this._lowFpsQueue.forEach((s) => s.callback(this.fps()));
}
}
export {
c as Ticker,
l as TickerMock
};
var s=class{_minFps;_currentFps=60;_lastChecks=[];_calculateFpsEachMs=2e3;_msSinceLastCalculation=0;_lowFpsInRow=0;_lowFpsCallback;currentFps(){return this._currentFps}calculate(s){this.collectFps(s),this._msSinceLastCalculation+=s.deltaMs,this._msSinceLastCalculation>=this._calculateFpsEachMs&&(this._msSinceLastCalculation=0,this.calculateAverageFps(),this.checkAndNotifyLowFps())}onLowFps(s){this._lowFpsCallback=s}setMinFps(s){return this._minFps=s,this}collectFps(s){this._lastChecks.push(Math.round(1e3/s.deltaMs))}calculateAverageFps(){const s=this._lastChecks.reduce((s,e)=>s+e,0);this._currentFps=Math.round(s/this._lastChecks.length),this._lastChecks=[]}checkAndNotifyLowFps(){this._minFps&&this._currentFps<this._minFps&&(this._lowFpsInRow++,5===this._lowFpsInRow&&(this._lowFpsInRow=0,this._lowFpsCallback&&this._lowFpsCallback()))}},e=class{_fps=new s;_drawQueue=[];_logicQueue=[];_lowFpsQueue=[];_maxFps;_expectedFps;_time={delta:0,deltaMs:0};_lastTimestamp=0;_logicTicksAccumulatedMs=0;_requestFrameId;constructor(s){this.setFps({min:s?.minFps||0,max:s?.maxFps||60,expected:s?.expectedFps||60}),s?.onDrawTick&&this.addDrawTask(s.onDrawTick),s?.onLogicTick&&this.addLogicTask(s.onLogicTick),s?.onLowFps&&this.addLowFpsTask(s.onLowFps),this._fps.onLowFps(()=>{this._lowFpsQueue.forEach(s=>s.callback(this.fps()))})}start(){this._lastTimestamp=performance.now(),this.loop(this._lastTimestamp)}stop(){this._requestFrameId&&(window.cancelAnimationFrame(this._requestFrameId),this._requestFrameId=void 0)}isStarted(){return!!this._requestFrameId}setFps(s){return s.min&&s.min>0&&this._fps.setMinFps(s.min),s.max&&s.max>0&&(this._maxFps=this.compensatedMaxFps(s.max)),s.expected&&s.expected>0&&(this._expectedFps=s.expected),this}addDrawTask(s){return{index:this._drawQueue.push({callback:s})-1,type:"draw"}}addLogicTask(s){return{index:this._logicQueue.push({callback:s})-1,type:"logic"}}addLowFpsTask(s){return{index:this._lowFpsQueue.push({callback:s})-1,type:"low-fps"}}remove(s){switch(s.type){case"draw":this._drawQueue.splice(s.index,1);break;case"logic":this._logicQueue.splice(s.index,1);break;case"low-fps":this._lowFpsQueue.splice(s.index,1)}}fps(){return this._fps.currentFps()}msBetweenTicks(){return this._time.deltaMs}ticksMissed(){return this._time.deltaMs/(1e3/this._expectedFps)}loop(s){const e=1e3/this._maxFps,t=s-this._lastTimestamp;t>=e&&(this._time={delta:t/1e3,deltaMs:t},this._lastTimestamp=s,this._fps.calculate(this._time),this.runQueue()),this._requestFrameId=window.requestAnimationFrame(this.loop.bind(this))}runQueue(){this._logicQueue.length>0&&this.runLogicQueue(),this._drawQueue.length>0&&this.runDrawQueue()}runLogicQueue(){const s=1e3/this._expectedFps;this._logicTicksAccumulatedMs+=this._time.deltaMs;const e={delta:s/1e3,deltaMs:s};for(;this._logicTicksAccumulatedMs>=s;)this._logicQueue.forEach(s=>s.callback(e)),this._logicTicksAccumulatedMs-=s}runDrawQueue(){this._drawQueue.forEach(s=>s.callback(this._time))}compensatedMaxFps(s){return Math.floor(1.1*s)+10*Math.floor(s/100)}},t=class extends e{_isStarted=!1;start(){this._isStarted=!0}stop(){this._isStarted=!1}isStarted(){return this._isStarted}fps(){return 60}msBetweenTicks(){return 1e3/60}ticksMissed(){return 1}simulateLogicTick(s=void 0){this._logicQueue.forEach(e=>e.callback(s||{delta:1/this.fps(),deltaMs:1e3/this.fps()}))}simulateDrawTick(s=void 0){this._drawQueue.forEach(e=>e.callback(s||{delta:1/this.fps(),deltaMs:1e3/this.fps()}))}simulateLowFps(){this._lowFpsQueue.forEach(s=>s.callback(this.fps()))}};export{e as Ticker,t as TickerMock};

@@ -1,1 +0,1 @@

(function(t,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(t=typeof globalThis<"u"?globalThis:t||self,a(t.Ticker={}))})(this,(function(t){"use strict";class a{_minFps;_currentFps=60;_lastChecks=[];_calculateFpsEachMs=2e3;_msSinceLastCalculation=0;_lowFpsInRow=0;_lowFpsCallback;currentFps(){return this._currentFps}calculate(e){this.collectFps(e),this._msSinceLastCalculation+=e.deltaMs,this._msSinceLastCalculation>=this._calculateFpsEachMs&&(this._msSinceLastCalculation=0,this.calculateAverageFps(),this.checkAndNotifyLowFps())}onLowFps(e){this._lowFpsCallback=e}setMinFps(e){return this._minFps=e,this}collectFps(e){this._lastChecks.push(Math.round(1e3/e.deltaMs))}calculateAverageFps(){const e=this._lastChecks.reduce((s,i)=>s+i,0);this._currentFps=Math.round(e/this._lastChecks.length),this._lastChecks=[]}checkAndNotifyLowFps(){this._minFps&&this._currentFps<this._minFps&&(this._lowFpsInRow++,this._lowFpsInRow===5&&(this._lowFpsInRow=0,this._lowFpsCallback&&this._lowFpsCallback()))}}class c{_fps=new a;_drawQueue=[];_logicQueue=[];_lowFpsQueue=[];_maxFps;_expectedFps;_time={delta:0,deltaMs:0};_lastTimestamp=0;_logicTicksAccumulatedMs=0;_requestFrameId;constructor(e){this.setFps({min:e?.minFps||0,max:e?.maxFps||60,expected:e?.expectedFps||60}),e?.onDrawTick&&this.addDrawTask(e.onDrawTick),e?.onLogicTick&&this.addLogicTask(e.onLogicTick),e?.onLowFps&&this.addLowFpsTask(e.onLowFps),this._fps.onLowFps(()=>{this._lowFpsQueue.forEach(s=>s.callback(this.fps()))})}start(){this._lastTimestamp=performance.now(),this.loop(this._lastTimestamp)}stop(){this._requestFrameId&&(window.cancelAnimationFrame(this._requestFrameId),this._requestFrameId=void 0)}isStarted(){return!!this._requestFrameId}setFps(e){return e.min&&e.min>0&&this._fps.setMinFps(e.min),e.max&&e.max>0&&(this._maxFps=this.compensatedMaxFps(e.max)),e.expected&&e.expected>0&&(this._expectedFps=e.expected),this}addDrawTask(e){return{index:this._drawQueue.push({callback:e})-1,type:"draw"}}addLogicTask(e){return{index:this._logicQueue.push({callback:e})-1,type:"logic"}}addLowFpsTask(e){return{index:this._lowFpsQueue.push({callback:e})-1,type:"low-fps"}}remove(e){switch(e.type){case"draw":this._drawQueue.splice(e.index,1);break;case"logic":this._logicQueue.splice(e.index,1);break;case"low-fps":this._lowFpsQueue.splice(e.index,1);break}}fps(){return this._fps.currentFps()}msBetweenTicks(){return this._time.deltaMs}ticksMissed(){return this._time.deltaMs/(1e3/this._expectedFps)}loop(e){const s=1e3/this._maxFps,i=e-this._lastTimestamp;i>=s&&(this._time={delta:i/1e3,deltaMs:i},this._lastTimestamp=e,this._fps.calculate(this._time),this.runQueue()),this._requestFrameId=window.requestAnimationFrame(this.loop.bind(this))}runQueue(){this._logicQueue.length>0&&this.runLogicQueue(),this._drawQueue.length>0&&this.runDrawQueue()}runLogicQueue(){const e=1e3/this._expectedFps;this._logicTicksAccumulatedMs+=this._time.deltaMs;const s={delta:e/1e3,deltaMs:e};for(;this._logicTicksAccumulatedMs>=e;)this._logicQueue.forEach(i=>i.callback(s)),this._logicTicksAccumulatedMs-=e}runDrawQueue(){this._drawQueue.forEach(e=>e.callback(this._time))}compensatedMaxFps(e){return Math.floor(e*1.1)+Math.floor(e/100)*10}}class u extends c{_isStarted=!1;start(){this._isStarted=!0}stop(){this._isStarted=!1}isStarted(){return this._isStarted}fps(){return 60}msBetweenTicks(){return 1e3/60}ticksMissed(){return 1}simulateLogicTick(e=void 0){this._logicQueue.forEach(s=>s.callback(e||{delta:1/this.fps(),deltaMs:1e3/this.fps()}))}simulateDrawTick(e=void 0){this._drawQueue.forEach(s=>s.callback(e||{delta:1/this.fps(),deltaMs:1e3/this.fps()}))}simulateLowFps(){this._lowFpsQueue.forEach(e=>e.callback(this.fps()))}}t.Ticker=c,t.TickerMock=u,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
!function(s,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((s="undefined"!=typeof globalThis?globalThis:s||self).Ticker={})}(this,function(s){Object.defineProperty(s,Symbol.toStringTag,{value:"Module"});var e=class{_minFps;_currentFps=60;_lastChecks=[];_calculateFpsEachMs=2e3;_msSinceLastCalculation=0;_lowFpsInRow=0;_lowFpsCallback;currentFps(){return this._currentFps}calculate(s){this.collectFps(s),this._msSinceLastCalculation+=s.deltaMs,this._msSinceLastCalculation>=this._calculateFpsEachMs&&(this._msSinceLastCalculation=0,this.calculateAverageFps(),this.checkAndNotifyLowFps())}onLowFps(s){this._lowFpsCallback=s}setMinFps(s){return this._minFps=s,this}collectFps(s){this._lastChecks.push(Math.round(1e3/s.deltaMs))}calculateAverageFps(){const s=this._lastChecks.reduce((s,e)=>s+e,0);this._currentFps=Math.round(s/this._lastChecks.length),this._lastChecks=[]}checkAndNotifyLowFps(){this._minFps&&this._currentFps<this._minFps&&(this._lowFpsInRow++,5===this._lowFpsInRow&&(this._lowFpsInRow=0,this._lowFpsCallback&&this._lowFpsCallback()))}},t=class{_fps=new e;_drawQueue=[];_logicQueue=[];_lowFpsQueue=[];_maxFps;_expectedFps;_time={delta:0,deltaMs:0};_lastTimestamp=0;_logicTicksAccumulatedMs=0;_requestFrameId;constructor(s){this.setFps({min:s?.minFps||0,max:s?.maxFps||60,expected:s?.expectedFps||60}),s?.onDrawTick&&this.addDrawTask(s.onDrawTick),s?.onLogicTick&&this.addLogicTask(s.onLogicTick),s?.onLowFps&&this.addLowFpsTask(s.onLowFps),this._fps.onLowFps(()=>{this._lowFpsQueue.forEach(s=>s.callback(this.fps()))})}start(){this._lastTimestamp=performance.now(),this.loop(this._lastTimestamp)}stop(){this._requestFrameId&&(window.cancelAnimationFrame(this._requestFrameId),this._requestFrameId=void 0)}isStarted(){return!!this._requestFrameId}setFps(s){return s.min&&s.min>0&&this._fps.setMinFps(s.min),s.max&&s.max>0&&(this._maxFps=this.compensatedMaxFps(s.max)),s.expected&&s.expected>0&&(this._expectedFps=s.expected),this}addDrawTask(s){return{index:this._drawQueue.push({callback:s})-1,type:"draw"}}addLogicTask(s){return{index:this._logicQueue.push({callback:s})-1,type:"logic"}}addLowFpsTask(s){return{index:this._lowFpsQueue.push({callback:s})-1,type:"low-fps"}}remove(s){switch(s.type){case"draw":this._drawQueue.splice(s.index,1);break;case"logic":this._logicQueue.splice(s.index,1);break;case"low-fps":this._lowFpsQueue.splice(s.index,1)}}fps(){return this._fps.currentFps()}msBetweenTicks(){return this._time.deltaMs}ticksMissed(){return this._time.deltaMs/(1e3/this._expectedFps)}loop(s){const e=1e3/this._maxFps,t=s-this._lastTimestamp;t>=e&&(this._time={delta:t/1e3,deltaMs:t},this._lastTimestamp=s,this._fps.calculate(this._time),this.runQueue()),this._requestFrameId=window.requestAnimationFrame(this.loop.bind(this))}runQueue(){this._logicQueue.length>0&&this.runLogicQueue(),this._drawQueue.length>0&&this.runDrawQueue()}runLogicQueue(){const s=1e3/this._expectedFps;this._logicTicksAccumulatedMs+=this._time.deltaMs;const e={delta:s/1e3,deltaMs:s};for(;this._logicTicksAccumulatedMs>=s;)this._logicQueue.forEach(s=>s.callback(e)),this._logicTicksAccumulatedMs-=s}runDrawQueue(){this._drawQueue.forEach(s=>s.callback(this._time))}compensatedMaxFps(s){return Math.floor(1.1*s)+10*Math.floor(s/100)}};s.Ticker=t,s.TickerMock=class extends t{_isStarted=!1;start(){this._isStarted=!0}stop(){this._isStarted=!1}isStarted(){return this._isStarted}fps(){return 60}msBetweenTicks(){return 1e3/60}ticksMissed(){return 1}simulateLogicTick(s=void 0){this._logicQueue.forEach(e=>e.callback(s||{delta:1/this.fps(),deltaMs:1e3/this.fps()}))}simulateDrawTick(s=void 0){this._drawQueue.forEach(e=>e.callback(s||{delta:1/this.fps(),deltaMs:1e3/this.fps()}))}simulateLowFps(){this._lowFpsQueue.forEach(s=>s.callback(this.fps()))}}});

@@ -0,3 +1,3 @@

import { Time } from '../types';
import { Ticker } from './ticker';
import { Time } from '../interfaces/time.interface';
export declare class TickerMock extends Ticker {

@@ -4,0 +4,0 @@ private _isStarted;

@@ -1,6 +0,2 @@

import { TickerOptions } from '../interfaces/ticker-options.interface';
import { TickerTaskId } from '../interfaces/ticker-task-id.interface';
import { DrawQueueItem } from '../interfaces/draw-queue-item.interface';
import { LogicQueueItem } from '../interfaces/logic-queue-item.interface';
import { LowFpsQueueItem } from '../interfaces/low-fps-queue-item.interface';
import { LowFpsQueueItem, LogicQueueItem, DrawQueueItem, TickerTaskId, TickerOptions } from '../types';
export declare class Ticker {

@@ -7,0 +3,0 @@ private readonly _fps;

{
"name": "@armniko/ticker",
"version": "2.1.0",
"version": "2.1.1",
"description": "Javascript/typescript library for running app loop with separate logical/drawing ticks and FPS limitation.",

@@ -13,3 +13,4 @@ "author": "Armīns Nikolajevs <armins.nikolajevs@gmail.com>",

"loop",
"fps"
"fps",
"game-loop"
],

@@ -26,4 +27,4 @@ "main": "./dist/index.umd.js",

"dev": "vite build --watch",
"lint": "tsc --noEmit && eslint ./src --max-warnings=0 && npm run lint --prefix=demo",
"lint:fix": "npm run lint -- --fix && npm run lint:fix --prefix=demo",
"lint": "tsc --noEmit && eslint ./src --max-warnings=0",
"lint:fix": "npm run lint -- --fix",
"test": "vitest",

@@ -33,16 +34,16 @@ "test:coverage": "vitest run --coverage"

"devDependencies": {
"@eslint/js": "^9.39.2",
"@types/node": "^25.0.3",
"@vitest/coverage-v8": "^4.0.16",
"eslint": "^9.39.2",
"@eslint/js": "^10.0.1",
"@vitest/coverage-v8": "^4.1.4",
"eslint": "^10.2.1",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"happy-dom": "^20.0.11",
"prettier": "^3.7.4",
"typescript": "^5.9.3",
"typescript-eslint": "^8.50.1",
"vite": "^7.3.0",
"eslint-plugin-prettier": "^5.5.5",
"happy-dom": "^20.9.0",
"prettier": "^3.8.3",
"terser": "^5.46.1",
"typescript": "^6.0.3",
"typescript-eslint": "^8.58.2",
"vite": "^8.0.8",
"vite-plugin-dts": "^4.5.4",
"vitest": "^4.0.16"
"vitest": "^4.1.4"
}
}
+26
-21

@@ -1,13 +0,12 @@

<h1 align="center">Ticker</h1>
<p align="center">
<a href="https://gitlab.com/Armniko/game-core/ticker/-/releases"><img alt="Latest Release" src="https://gitlab.com/Armniko/game-core/ticker/-/badges/release.svg" /></a>
<a href="https://gitlab.com/Armniko/game-core/ticker/-/commits/prod"><img alt="pipeline status" src="https://gitlab.com/Armniko/game-core/ticker/badges/prod/pipeline.svg" /></a>
<a href="https://gitlab.com/Armniko/game-core/ticker/-/commits/prod"><img alt="coverage report" src="https://gitlab.com/Armniko/game-core/ticker/badges/prod/coverage.svg" /></a>
</p>
<p align="center">
Javascript/typescript library for running app loop with separate logical/drawing ticks and FPS limitation.
</p>
# Ticker
[![npm](https://img.shields.io/npm/v/@armniko/ticker)](https://www.npmjs.com/package/@armniko/canvas)
![last published](https://img.shields.io/npm/last-update/@armniko/ticker)
![zero dependencies](https://img.shields.io/badge/zero-dependencies-brightgreen)
[![types](https://img.shields.io/npm/types/@armniko/ticker)](https://www.npmjs.com/package/@armniko/ticker)
Javascript/typescript library for running app loop with separate logical/drawing ticks and FPS limitation.
<hr>
## Installation
### Installation

@@ -18,3 +17,3 @@ ```

## Usage
### Usage

@@ -52,7 +51,7 @@ ```typescript

- remove(taskId: TickerTaskId) - removes provided task.
- fps() - current FPS at witch app operate.
- fps() - current FPS at which app operate.
## Migration
### Migration
### v1 -> v2
#### v1 -> v2

@@ -102,10 +101,16 @@ Before (v1):

## Changelog
### Changelog
<table>
<tr>
<td>v2.1.1</td>
<td>
Update packages.
</td>
</tr>
<tr>
<td>v2.1.0</td>
<td>
Added option to provide Time for TickerMock<br>
Migrated from webpack to vite
Added option to provide Time for TickerMock.<br>
Migrated from webpack to vite.
</td>

@@ -116,4 +121,4 @@ </tr>

<td>
Multiple tick callbacks support<br>
Added TickerMock for testing<br>
Multiple tick callbacks support.<br>
Added TickerMock for testing.<br>
Deprecated: constructor options, msBetweenTicks(), ticksMissed(). (See migration v1 -> v2)

@@ -125,3 +130,3 @@ </td>

<td>
Precompile UMD and ESM
Precompile UMD and ESM.
</td>

@@ -132,5 +137,5 @@ </tr>

<td>
Initial version
Initial version.
</td>
</tr>
</table>
import { Time } from './time.interface';
export interface DrawQueueItem {
callback: (time: Time) => void;
}
import { Time } from './time.interface';
export interface LogicQueueItem {
callback: (time: Time) => void;
}
export interface LowFpsQueueItem {
callback: (fps: number) => void;
}
export interface TickerOptions {
/**
* @deprecated Passing `maxFps` in ticker options is deprecated. Use `ticker.setFps({ max: 60 })` instead.
*/
maxFps?: number;
/**
* @deprecated Passing `expectedFps` in ticker options is deprecated. Use `ticker.setFps({ min: 10 })` instead.
*/
minFps?: number;
/**
* @deprecated Passing `expectedFps` in ticker options is deprecated. Use `ticker.setFps({ expected: 60 })` instead.
*/
expectedFps?: number;
/**
* @deprecated Passing `onLogicTick` in ticker options is deprecated. Use `ticker.addLogicTask(callback)` instead.
*/
onLogicTick?: () => void;
/**
* @deprecated Passing `onDrawTick` in ticker options is deprecated. Use `ticker.addDrawTask(callback)` instead.
*/
onDrawTick?: () => void;
/**
* @deprecated Passing `onLowFps` in ticker options is deprecated. Use `ticker.addLowFpsTask(callback)` instead.
*/
onLowFps?: () => void;
}
export interface TickerTaskId {
index: number;
type: 'draw' | 'logic' | 'low-fps';
}
export interface Time {
delta: number;
deltaMs: number;
}