extra-game-loop 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"file":"game-loop.js","sourceRoot":"","sources":["../../src/game-loop.ts"],"names":[],"mappings":";;;AAAA,yCAAyE;AACzE,iDAA4C;AAwC5C,IAAK,KAGJ;AAHD,WAAK,KAAK;IACR,4BAAmB,CAAA;IACnB,4BAAmB,CAAA;AACrB,CAAC,EAHI,KAAK,KAAL,KAAK,QAGT;AAMD,MAAM,MAAM,GAA4C;IACtD,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE;IACzC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE;CACzC,CAAA;AAED,MAAa,QAAQ;IAanB,YAAY,OAAyC;QAZpC,QAAG,GAAG,IAAI,8BAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;QAS5D,yBAAoB,GAAG,CAAC,CAAA;QACxB,kBAAa,GAAG,CAAC,CAAA;QA2CjB,SAAI,GAAG,GAAS,EAAE;YAIxB,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAA;YACnC,MAAM,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,aAAc,CAAA;YACjD,IAAI,CAAC,aAAa,GAAG,SAAS,CAAA;YAC9B,IAAI,CAAC,aAAa,GAAG,SAAS,CAAA;YAE9B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;YAEzB,IAAI,CAAC,QAAQ,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClD,CAAC,CAAA;QApDC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAA;QA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AAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,cAAc,EAAE;YACvD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;YACrC,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,cAAc,CAAA;SACjD;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,cAAc,CAAA;QAC7D,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QACjC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC;CACF;AA5FD,4BA4FC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B"}
@@ -1,28 +0,0 @@
1
- interface IGameLoopOptions<FixedDeltaTime extends number = number> {
2
- fixedDeltaTime: FixedDeltaTime;
3
- maximumDeltaTime: number;
4
- update: (deltaTime: number) => void;
5
- fixedUpdate: (deltaTime: FixedDeltaTime) => void;
6
- lateUpdate: (deltaTime: number, alpha: number) => void;
7
- render: (alpha: number) => void;
8
- }
9
- export declare class GameLoop<FixedDeltaTime extends number> {
10
- private readonly fsm;
11
- private readonly fixedDeltaTime;
12
- private readonly maximumDeltaTime;
13
- private readonly update;
14
- private readonly fixedUpdate;
15
- private readonly lateUpdate;
16
- private readonly render;
17
- private requstId?;
18
- private lastTimestamp?;
19
- private deltaTimeAccumulator;
20
- private lastDeltaTime;
21
- constructor(options: IGameLoopOptions<FixedDeltaTime>);
22
- start(): void;
23
- stop(): void;
24
- getFramesOfSecond(): number;
25
- private loop;
26
- private nextFrame;
27
- }
28
- export {};
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GameLoop = void 0;
4
- const extra_fsm_1 = require("extra-fsm");
5
- const prelude_1 = require("@blackglory/prelude");
6
- var State;
7
- (function (State) {
8
- State["Stopped"] = "stopped";
9
- State["Running"] = "running";
10
- })(State || (State = {}));
11
- const schema = {
12
- [State.Stopped]: { start: State.Running },
13
- [State.Running]: { stop: State.Stopped }
14
- };
15
- class GameLoop {
16
- constructor(options) {
17
- this.fsm = new extra_fsm_1.FiniteStateMachine(schema, State.Stopped);
18
- this.deltaTimeAccumulator = 0;
19
- this.lastDeltaTime = 0;
20
- this.loop = () => {
21
- const timestamp = performance.now();
22
- const deltaTime = timestamp - this.lastTimestamp;
23
- this.lastDeltaTime = deltaTime;
24
- this.lastTimestamp = timestamp;
25
- this.nextFrame(deltaTime);
26
- this.requstId = requestAnimationFrame(this.loop);
27
- };
28
- this.fixedDeltaTime = options.fixedDeltaTime;
29
- this.maximumDeltaTime = options.maximumDeltaTime;
30
- (0, prelude_1.assert)(this.maximumDeltaTime >= this.fixedDeltaTime, 'maximumDeltaTime must be greater than or equal to fixedDeltaTime');
31
- this.update = options.update;
32
- this.fixedUpdate = options.fixedUpdate;
33
- this.lateUpdate = options.lateUpdate;
34
- this.render = options.render;
35
- }
36
- start() {
37
- this.fsm.send('start');
38
- this.lastTimestamp = performance.now();
39
- this.loop();
40
- }
41
- stop() {
42
- this.fsm.send('stop');
43
- cancelAnimationFrame(this.requstId);
44
- delete this.requstId;
45
- delete this.lastTimestamp;
46
- this.lastDeltaTime = 0;
47
- }
48
- getFramesOfSecond() {
49
- if (this.fsm.matches(State.Running)) {
50
- return this.lastDeltaTime !== 0
51
- ? 1000 / this.lastDeltaTime
52
- : 0;
53
- }
54
- else {
55
- return 0;
56
- }
57
- }
58
- nextFrame(deltaTime) {
59
- this.deltaTimeAccumulator = Math.min(this.deltaTimeAccumulator + deltaTime, this.maximumDeltaTime);
60
- this.update(deltaTime);
61
- while (this.deltaTimeAccumulator >= this.fixedDeltaTime) {
62
- this.fixedUpdate(this.fixedDeltaTime);
63
- this.deltaTimeAccumulator -= this.fixedDeltaTime;
64
- }
65
- const alpha = this.deltaTimeAccumulator / this.fixedDeltaTime;
66
- this.lateUpdate(deltaTime, alpha);
67
- this.render(alpha);
68
- }
69
- }
70
- exports.GameLoop = GameLoop;
71
- //# sourceMappingURL=game-loop.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"game-loop.js","sourceRoot":"","sources":["../../src/game-loop.ts"],"names":[],"mappings":";;;AAAA,yCAAyE;AACzE,iDAA4C;AAwC5C,IAAK,KAGJ;AAHD,WAAK,KAAK;IACR,4BAAmB,CAAA;IACnB,4BAAmB,CAAA;AACrB,CAAC,EAHI,KAAK,KAAL,KAAK,QAGT;AAMD,MAAM,MAAM,GAA4C;IACtD,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE;IACzC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE;CACzC,CAAA;AAED,MAAa,QAAQ;IAanB,YAAY,OAAyC;QAZpC,QAAG,GAAG,IAAI,8BAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;QAS5D,yBAAoB,GAAG,CAAC,CAAA;QACxB,kBAAa,GAAG,CAAC,CAAA;QA2CjB,SAAI,GAAG,GAAS,EAAE;YAIxB,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAA;YACnC,MAAM,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,aAAc,CAAA;YACjD,IAAI,CAAC,aAAa,GAAG,SAAS,CAAA;YAC9B,IAAI,CAAC,aAAa,GAAG,SAAS,CAAA;YAE9B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;YAEzB,IAAI,CAAC,QAAQ,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClD,CAAC,CAAA;QApDC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAA;QAChD,I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CAAC,oBAAoB,IAAI,IAAI,CAAC,cAAc,EAAE;YACvD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;YACrC,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,cAAc,CAAA;SACjD;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,cAAc,CAAA;QAC7D,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QACjC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC;CACF;AA5FD,4BA4FC"}
@@ -1 +0,0 @@
1
- export * from './game-loop';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./game-loop"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B"}
File without changes
File without changes
File without changes