@remvst/game-navigation-core 1.7.1 → 1.8.1
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.
- package/lib/game/game-plugin.d.ts +6 -0
- package/lib/game/game-plugin.js +6 -0
- package/lib/game/game.d.ts +0 -2
- package/lib/game/game.js +13 -13
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/navigation/resolver.d.ts +1 -0
- package/lib/navigation/resolver.js +3 -0
- package/lib/plugins/metrics-game-plugin.d.ts +0 -2
- package/lib/plugins/metrics-game-plugin.js +0 -6
- package/package.json +1 -2
- package/src/game/game-plugin.ts +9 -0
- package/src/game/game.ts +7 -15
- package/src/index.ts +0 -1
- package/src/navigation/resolver.ts +5 -1
- package/src/plugins/metrics-game-plugin.ts +0 -12
- package/lib/tracking/framerate-counts.d.ts +0 -10
- package/lib/tracking/framerate-counts.js +0 -47
- package/src/tracking/framerate-counts.ts +0 -50
|
@@ -8,5 +8,11 @@ export declare abstract class GamePlugin {
|
|
|
8
8
|
setup(): void;
|
|
9
9
|
setupScreen(screen: Screen): void;
|
|
10
10
|
cycle(elapsed: number): void;
|
|
11
|
+
onCycleStart(): void;
|
|
12
|
+
onCycleEnd(): void;
|
|
13
|
+
onRenderStart(): void;
|
|
14
|
+
onRenderEnd(): void;
|
|
11
15
|
render(): void;
|
|
16
|
+
onFrameStart(): void;
|
|
17
|
+
onFrameEnd(): void;
|
|
12
18
|
}
|
package/lib/game/game-plugin.js
CHANGED
|
@@ -11,6 +11,12 @@ class GamePlugin {
|
|
|
11
11
|
setup() { }
|
|
12
12
|
setupScreen(screen) { }
|
|
13
13
|
cycle(elapsed) { }
|
|
14
|
+
onCycleStart() { }
|
|
15
|
+
onCycleEnd() { }
|
|
16
|
+
onRenderStart() { }
|
|
17
|
+
onRenderEnd() { }
|
|
14
18
|
render() { }
|
|
19
|
+
onFrameStart() { }
|
|
20
|
+
onFrameEnd() { }
|
|
15
21
|
}
|
|
16
22
|
exports.GamePlugin = GamePlugin;
|
package/lib/game/game.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PerformanceRecorder } from "@remvst/client-performance";
|
|
2
1
|
import { GameInputs } from "../interaction/inputs";
|
|
3
2
|
import { ScreenStack } from "../navigation/screen-stack";
|
|
4
3
|
import { GameParams } from "./game-params";
|
|
@@ -12,7 +11,6 @@ export declare abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
12
11
|
private lastFrame;
|
|
13
12
|
private animationFrameId;
|
|
14
13
|
private runningLoop;
|
|
15
|
-
readonly performanceRecorder: PerformanceRecorder;
|
|
16
14
|
constructor(params: ParamsType);
|
|
17
15
|
abstract get plugins(): GamePlugin[];
|
|
18
16
|
abstract get container(): HTMLElement;
|
package/lib/game/game.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Game = void 0;
|
|
4
|
-
const client_performance_1 = require("@remvst/client-performance");
|
|
5
4
|
const inputs_1 = require("../interaction/inputs");
|
|
6
5
|
const screen_stack_1 = require("../navigation/screen-stack");
|
|
7
6
|
class Game {
|
|
@@ -11,10 +10,6 @@ class Game {
|
|
|
11
10
|
// Time
|
|
12
11
|
this.age = 0;
|
|
13
12
|
this.runningLoop = false;
|
|
14
|
-
// Performance
|
|
15
|
-
this.performanceRecorder = new client_performance_1.PerformanceRecorder({
|
|
16
|
-
recordCount: Math.floor(window.innerWidth / 3),
|
|
17
|
-
});
|
|
18
13
|
this.parseURL();
|
|
19
14
|
}
|
|
20
15
|
plugin(keyProvider) {
|
|
@@ -56,19 +51,25 @@ class Game {
|
|
|
56
51
|
this.animationFrameId = null;
|
|
57
52
|
}
|
|
58
53
|
frame() {
|
|
59
|
-
this.
|
|
60
|
-
|
|
54
|
+
for (const plugin of this.plugins)
|
|
55
|
+
plugin.onFrameStart();
|
|
61
56
|
const now = window.performance.now();
|
|
62
57
|
const elapsedMs = now - this.lastFrame;
|
|
63
58
|
const elapsed = Math.min(this.params.maxFrameInterval || 1, elapsedMs / 1000);
|
|
64
59
|
this.lastFrame = now;
|
|
60
|
+
for (const plugin of this.plugins)
|
|
61
|
+
plugin.onCycleStart();
|
|
65
62
|
this.cycle(elapsed);
|
|
66
|
-
this.
|
|
67
|
-
|
|
63
|
+
for (const plugin of this.plugins)
|
|
64
|
+
plugin.onCycleEnd();
|
|
65
|
+
for (const plugin of this.plugins)
|
|
66
|
+
plugin.onRenderStart();
|
|
67
|
+
for (const plugin of this.plugins)
|
|
68
68
|
plugin.render();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.
|
|
69
|
+
for (const plugin of this.plugins)
|
|
70
|
+
plugin.onRenderEnd();
|
|
71
|
+
for (const plugin of this.plugins)
|
|
72
|
+
plugin.onFrameEnd();
|
|
72
73
|
if (this.runningLoop) {
|
|
73
74
|
this.scheduleFrame();
|
|
74
75
|
}
|
|
@@ -114,7 +115,6 @@ class Game {
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
onCurrentScreenChanged() {
|
|
117
|
-
window.S = this.screenStack.current();
|
|
118
118
|
this.container.style.cursor = this.screenStack.current()?.cursorType;
|
|
119
119
|
}
|
|
120
120
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export * from "./plugins/version-label-game-plugin";
|
|
|
17
17
|
export * from "./storage/get-client-storage";
|
|
18
18
|
export * from "./storage/in-memory-storage";
|
|
19
19
|
export * from "./storage/local-json-store";
|
|
20
|
-
export * from "./tracking/framerate-counts";
|
|
21
20
|
export * from "./tracking/properties-provider";
|
|
22
21
|
export * from "./tracking/tracker";
|
|
23
22
|
export * from "./tracking/tracking-screen-delegate";
|
package/lib/index.js
CHANGED
|
@@ -33,7 +33,6 @@ __exportStar(require("./plugins/version-label-game-plugin"), exports);
|
|
|
33
33
|
__exportStar(require("./storage/get-client-storage"), exports);
|
|
34
34
|
__exportStar(require("./storage/in-memory-storage"), exports);
|
|
35
35
|
__exportStar(require("./storage/local-json-store"), exports);
|
|
36
|
-
__exportStar(require("./tracking/framerate-counts"), exports);
|
|
37
36
|
__exportStar(require("./tracking/properties-provider"), exports);
|
|
38
37
|
__exportStar(require("./tracking/tracker"), exports);
|
|
39
38
|
__exportStar(require("./tracking/tracking-screen-delegate"), exports);
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Resolver = exports.UserCancelledError = void 0;
|
|
4
4
|
class UserCancelledError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message || 'User backed out and cancelled navigation flow');
|
|
7
|
+
}
|
|
5
8
|
}
|
|
6
9
|
exports.UserCancelledError = UserCancelledError;
|
|
7
10
|
class Resolver {
|
|
@@ -5,9 +5,7 @@ export declare class MetricsGamePlugin extends GamePlugin {
|
|
|
5
5
|
readonly tracker: Tracker;
|
|
6
6
|
static readonly key = "metrics";
|
|
7
7
|
readonly key = "metrics";
|
|
8
|
-
private framerateCounts;
|
|
9
8
|
constructor(tracker: Tracker);
|
|
10
9
|
setup(): void;
|
|
11
|
-
cycle(elapsed: number): void;
|
|
12
10
|
setupScreen(screen: Screen): void;
|
|
13
11
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MetricsGamePlugin = void 0;
|
|
4
4
|
const game_plugin_1 = require("../game/game-plugin");
|
|
5
5
|
const resolver_1 = require("../navigation/resolver");
|
|
6
|
-
const framerate_counts_1 = require("../tracking/framerate-counts");
|
|
7
6
|
const tracking_screen_delegate_1 = require("../tracking/tracking-screen-delegate");
|
|
8
7
|
class MetricsGamePlugin extends game_plugin_1.GamePlugin {
|
|
9
8
|
constructor(tracker) {
|
|
@@ -13,7 +12,6 @@ class MetricsGamePlugin extends game_plugin_1.GamePlugin {
|
|
|
13
12
|
}
|
|
14
13
|
setup() {
|
|
15
14
|
super.setup();
|
|
16
|
-
this.framerateCounts = new framerate_counts_1.FrameRateCounts(this.game.performanceRecorder);
|
|
17
15
|
window.addEventListener("error", (event) => {
|
|
18
16
|
this.tracker.track("errorOccurred", {
|
|
19
17
|
errorType: "error",
|
|
@@ -34,10 +32,6 @@ class MetricsGamePlugin extends game_plugin_1.GamePlugin {
|
|
|
34
32
|
}, false);
|
|
35
33
|
this.tracker.track("gameSetup", {});
|
|
36
34
|
}
|
|
37
|
-
cycle(elapsed) {
|
|
38
|
-
super.cycle(elapsed);
|
|
39
|
-
this.framerateCounts.cycle(elapsed);
|
|
40
|
-
}
|
|
41
35
|
setupScreen(screen) {
|
|
42
36
|
super.setupScreen(screen);
|
|
43
37
|
screen.delegate = new tracking_screen_delegate_1.TrackingScreenDelegate(screen, this.tracker);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remvst/game-navigation-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@remvst/animate.js": "^3.0.0",
|
|
14
14
|
"@remvst/client-inputs": "^1.0.4",
|
|
15
|
-
"@remvst/client-performance": "^1.0.0",
|
|
16
15
|
"@remvst/optimization": "^1.0.1"
|
|
17
16
|
},
|
|
18
17
|
"devDependencies": {
|
package/src/game/game-plugin.ts
CHANGED
package/src/game/game.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PerformanceRecorder } from "@remvst/client-performance";
|
|
2
1
|
import { GameInputs } from "../interaction/inputs";
|
|
3
2
|
import { ScreenStack } from "../navigation/screen-stack";
|
|
4
3
|
import { GameParams } from "./game-params";
|
|
@@ -21,11 +20,6 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
21
20
|
private animationFrameId: number;
|
|
22
21
|
private runningLoop = false;
|
|
23
22
|
|
|
24
|
-
// Performance
|
|
25
|
-
readonly performanceRecorder = new PerformanceRecorder({
|
|
26
|
-
recordCount: Math.floor(window.innerWidth / 3),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
23
|
constructor(readonly params: ParamsType) {
|
|
30
24
|
this.parseURL();
|
|
31
25
|
}
|
|
@@ -85,8 +79,7 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
85
79
|
}
|
|
86
80
|
|
|
87
81
|
frame() {
|
|
88
|
-
this.
|
|
89
|
-
this.performanceRecorder.onStart("FRAME");
|
|
82
|
+
for (const plugin of this.plugins) plugin.onFrameStart();
|
|
90
83
|
|
|
91
84
|
const now = window.performance.now();
|
|
92
85
|
const elapsedMs = now - this.lastFrame;
|
|
@@ -97,15 +90,15 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
97
90
|
|
|
98
91
|
this.lastFrame = now;
|
|
99
92
|
|
|
93
|
+
for (const plugin of this.plugins) plugin.onCycleStart();
|
|
100
94
|
this.cycle(elapsed);
|
|
95
|
+
for (const plugin of this.plugins) plugin.onCycleEnd();
|
|
101
96
|
|
|
102
|
-
this.
|
|
103
|
-
for (const plugin of this.plugins)
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
this.performanceRecorder.onEnd("RENDER");
|
|
97
|
+
for (const plugin of this.plugins) plugin.onRenderStart();
|
|
98
|
+
for (const plugin of this.plugins) plugin.render();
|
|
99
|
+
for (const plugin of this.plugins) plugin.onRenderEnd();
|
|
107
100
|
|
|
108
|
-
this.
|
|
101
|
+
for (const plugin of this.plugins) plugin.onFrameEnd();
|
|
109
102
|
|
|
110
103
|
if (this.runningLoop) {
|
|
111
104
|
this.scheduleFrame();
|
|
@@ -164,7 +157,6 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
|
|
|
164
157
|
}
|
|
165
158
|
|
|
166
159
|
onCurrentScreenChanged() {
|
|
167
|
-
(window as any).S = this.screenStack.current();
|
|
168
160
|
this.container.style.cursor = this.screenStack.current()?.cursorType;
|
|
169
161
|
}
|
|
170
162
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,6 @@ export * from "./storage/get-client-storage";
|
|
|
23
23
|
export * from "./storage/in-memory-storage";
|
|
24
24
|
export * from "./storage/local-json-store";
|
|
25
25
|
|
|
26
|
-
export * from "./tracking/framerate-counts";
|
|
27
26
|
export * from "./tracking/properties-provider";
|
|
28
27
|
export * from "./tracking/tracker";
|
|
29
28
|
export * from "./tracking/tracking-screen-delegate";
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Screen } from "../ui/screen";
|
|
2
2
|
|
|
3
|
-
export class UserCancelledError extends Error {
|
|
3
|
+
export class UserCancelledError extends Error {
|
|
4
|
+
constructor(message: string) {
|
|
5
|
+
super(message || 'User backed out and cancelled navigation flow');
|
|
6
|
+
}
|
|
7
|
+
}
|
|
4
8
|
|
|
5
9
|
export class Resolver<T> {
|
|
6
10
|
private readonly screen: Screen;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GamePlugin } from "../game/game-plugin";
|
|
2
2
|
import { UserCancelledError } from "../navigation/resolver";
|
|
3
|
-
import { FrameRateCounts } from "../tracking/framerate-counts";
|
|
4
3
|
import { Tracker } from "../tracking/tracker";
|
|
5
4
|
import { TrackingScreenDelegate } from "../tracking/tracking-screen-delegate";
|
|
6
5
|
import { Screen } from "../ui/screen";
|
|
@@ -9,8 +8,6 @@ export class MetricsGamePlugin extends GamePlugin {
|
|
|
9
8
|
static readonly key = "metrics";
|
|
10
9
|
readonly key = MetricsGamePlugin.key;
|
|
11
10
|
|
|
12
|
-
private framerateCounts: FrameRateCounts;
|
|
13
|
-
|
|
14
11
|
constructor(readonly tracker: Tracker) {
|
|
15
12
|
super();
|
|
16
13
|
}
|
|
@@ -18,10 +15,6 @@ export class MetricsGamePlugin extends GamePlugin {
|
|
|
18
15
|
setup(): void {
|
|
19
16
|
super.setup();
|
|
20
17
|
|
|
21
|
-
this.framerateCounts = new FrameRateCounts(
|
|
22
|
-
this.game.performanceRecorder,
|
|
23
|
-
);
|
|
24
|
-
|
|
25
18
|
window.addEventListener(
|
|
26
19
|
"error",
|
|
27
20
|
(event) => {
|
|
@@ -53,11 +46,6 @@ export class MetricsGamePlugin extends GamePlugin {
|
|
|
53
46
|
this.tracker.track("gameSetup", {});
|
|
54
47
|
}
|
|
55
48
|
|
|
56
|
-
cycle(elapsed: number): void {
|
|
57
|
-
super.cycle(elapsed);
|
|
58
|
-
this.framerateCounts.cycle(elapsed);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
49
|
setupScreen(screen: Screen): void {
|
|
62
50
|
super.setupScreen(screen);
|
|
63
51
|
screen.delegate = new TrackingScreenDelegate(screen, this.tracker);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PerformanceRecorder } from "@remvst/client-performance";
|
|
2
|
-
import { Properties } from "./tracker";
|
|
3
|
-
export declare class FrameRateCounts {
|
|
4
|
-
private readonly performanceRecorder;
|
|
5
|
-
private readonly counts;
|
|
6
|
-
private age;
|
|
7
|
-
constructor(performanceRecorder: PerformanceRecorder);
|
|
8
|
-
cycle(elapsed: number): void;
|
|
9
|
-
toJson(): Properties;
|
|
10
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FrameRateCounts = void 0;
|
|
4
|
-
class FrameRateCounts {
|
|
5
|
-
constructor(performanceRecorder) {
|
|
6
|
-
this.performanceRecorder = performanceRecorder;
|
|
7
|
-
this.counts = {
|
|
8
|
-
above60: 0,
|
|
9
|
-
above45: 0,
|
|
10
|
-
above30: 0,
|
|
11
|
-
above15: 0,
|
|
12
|
-
above0: 0,
|
|
13
|
-
};
|
|
14
|
-
this.age = 0;
|
|
15
|
-
}
|
|
16
|
-
cycle(elapsed) {
|
|
17
|
-
this.age += elapsed;
|
|
18
|
-
if (this.age > 0.5) {
|
|
19
|
-
const previousFrame = this.performanceRecorder.frame(this.performanceRecorder.frameCount - 1);
|
|
20
|
-
const currentFrame = this.performanceRecorder.frame(this.performanceRecorder.frameCount);
|
|
21
|
-
const framerate = 1000 /
|
|
22
|
-
(currentFrame.onStartTimes.get("FRAME") -
|
|
23
|
-
previousFrame.onStartTimes.get("FRAME"));
|
|
24
|
-
let key;
|
|
25
|
-
if (framerate > 60) {
|
|
26
|
-
key = "above60";
|
|
27
|
-
}
|
|
28
|
-
else if (framerate > 45) {
|
|
29
|
-
key = "above45";
|
|
30
|
-
}
|
|
31
|
-
else if (framerate > 30) {
|
|
32
|
-
key = "above30";
|
|
33
|
-
}
|
|
34
|
-
else if (framerate > 15) {
|
|
35
|
-
key = "above15";
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
key = "above0";
|
|
39
|
-
}
|
|
40
|
-
this.counts[key]++;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
toJson() {
|
|
44
|
-
return this.counts;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.FrameRateCounts = FrameRateCounts;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { PerformanceRecorder } from "@remvst/client-performance";
|
|
2
|
-
import { Properties } from "./tracker";
|
|
3
|
-
|
|
4
|
-
export class FrameRateCounts {
|
|
5
|
-
private readonly counts = {
|
|
6
|
-
above60: 0,
|
|
7
|
-
above45: 0,
|
|
8
|
-
above30: 0,
|
|
9
|
-
above15: 0,
|
|
10
|
-
above0: 0,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
private age = 0;
|
|
14
|
-
|
|
15
|
-
constructor(private readonly performanceRecorder: PerformanceRecorder) {}
|
|
16
|
-
|
|
17
|
-
cycle(elapsed: number) {
|
|
18
|
-
this.age += elapsed;
|
|
19
|
-
|
|
20
|
-
if (this.age > 0.5) {
|
|
21
|
-
const previousFrame = this.performanceRecorder.frame(
|
|
22
|
-
this.performanceRecorder.frameCount - 1,
|
|
23
|
-
);
|
|
24
|
-
const currentFrame = this.performanceRecorder.frame(
|
|
25
|
-
this.performanceRecorder.frameCount,
|
|
26
|
-
);
|
|
27
|
-
const framerate =
|
|
28
|
-
1000 /
|
|
29
|
-
(currentFrame.onStartTimes.get("FRAME") -
|
|
30
|
-
previousFrame.onStartTimes.get("FRAME"));
|
|
31
|
-
let key: keyof typeof this.counts;
|
|
32
|
-
if (framerate > 60) {
|
|
33
|
-
key = "above60";
|
|
34
|
-
} else if (framerate > 45) {
|
|
35
|
-
key = "above45";
|
|
36
|
-
} else if (framerate > 30) {
|
|
37
|
-
key = "above30";
|
|
38
|
-
} else if (framerate > 15) {
|
|
39
|
-
key = "above15";
|
|
40
|
-
} else {
|
|
41
|
-
key = "above0";
|
|
42
|
-
}
|
|
43
|
-
this.counts[key]++;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
toJson(): Properties {
|
|
48
|
-
return this.counts;
|
|
49
|
-
}
|
|
50
|
-
}
|