Skip to content

Commit 125549f

Browse files
committed
add global variable F to count frames
1 parent a0e6be9 commit 125549f

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ export default function litecanvas(settings = {}) {
105105
/** @type {number} */
106106
T: 0,
107107

108+
/** @type {number} */
109+
F: 0,
110+
108111
/** @type {number} */
109112
MX: -1,
110113

@@ -1622,6 +1625,7 @@ export default function litecanvas(settings = {}) {
16221625

16231626
if (updated) {
16241627
instance.emit('draw', _ctx)
1628+
instance.def('F', instance.F + 1)
16251629
if (updated > 1) {
16261630
_accumulated = 0
16271631
DEV: console.warn(

tests/globals.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import test from 'ava'
2+
import litecanvas from '../src/index.js'
3+
import * as sinon from 'sinon'
4+
5+
test.before(() => {
6+
sinon.stub(console) // silent console
7+
})
8+
9+
test('variable F should count frames', async (t) => {
10+
t.plan(1)
11+
12+
const local = litecanvas({
13+
global: false,
14+
})
15+
const expected = 3
16+
17+
await new Promise((resolve) => {
18+
let i = expected
19+
local.listen('draw', () => {
20+
i--
21+
if (i === 0) {
22+
resolve()
23+
local.quit()
24+
}
25+
})
26+
})
27+
28+
t.is(local.F, expected)
29+
})

types/global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ declare global {
1111
var H: number
1212
/** the amount of time (in seconds) since the game started */
1313
var T: number
14+
/** the amount of rendered frames */
15+
var F: number
1416
/** The current mouse's horizontal (X) position or -1 (if the mouse was not used or detected) */
1517
var MX: number
1618
/** The current mouse's vertical (Y) position or -1 (if the mouse was not used or detected) */

types/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ type LitecanvasInstance = {
55
H: number
66
/** the amount of time (in seconds) since the game started */
77
T: number
8+
/** the amount of rendered frames */
9+
F: number
810
/** The current mouse's horizontal (X) position or -1 (if the mouse was not used or detected) */
911
MX: number
1012
/** The current mouse's vertical (Y) position or -1 (if the mouse was not used or detected) */

0 commit comments

Comments
 (0)