@remvst/game-navigation-core 2.0.0 → 3.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @remvst/game-navigation-core
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 045c062: Add an opt-in per-frame phase timer. Set `Game.onFrameTiming` to receive a
8
+ `FrameTiming` each frame — whole frame vs cycle phase vs render/draw phase,
9
+ plus the `otherMs` remainder. The loop owns the phases, so it produces the
10
+ split natively instead of a game reconstructing it from plugin hooks. Null by
11
+ default, in which case the per-frame timing is simply discarded.
12
+
13
+ The finer model-vs-render-update split within `cycle()` still has to be timed
14
+ by the game at its own screen-level seam.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [3bfd18b]
19
+ - @remvst/optimization@1.10.0
20
+
21
+ ## 2.0.1
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [68f058a]
26
+ - Updated dependencies [0688920]
27
+ - Updated dependencies [239134e]
28
+ - @remvst/optimization@1.9.0
29
+
3
30
  ## 2.0.0
4
31
 
5
32
  ### Major Changes
@@ -0,0 +1,16 @@
1
+ export interface FrameTiming {
2
+ /** Whole-frame main-thread time, in ms. */
3
+ frameMs: number;
4
+ /**
5
+ * Time in the cycle phase, in ms. This covers the whole simulation plus any
6
+ * view-controller updates that run inside a screen's `cycle()`. The finer
7
+ * model-vs-render-update split within a frame has to be timed by the game
8
+ * at its own screen-level seam.
9
+ */
10
+ cycleMs: number;
11
+ /** Time in the render/draw phase, in ms. */
12
+ drawMs: number;
13
+ /** `frameMs − cycleMs − drawMs` — plugin hooks, input, GC, browser. */
14
+ otherMs: number;
15
+ }
16
+ export type FrameTimingObserver = (timing: FrameTiming) => void;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=frame-timing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame-timing.js","sourceRoot":"","sources":["../../src/game/frame-timing.ts"],"names":[],"mappings":""}
@@ -1,5 +1,6 @@
1
1
  import { GameInputs } from "../interaction/inputs";
2
2
  import { ScreenStack } from "../navigation/screen-stack";
3
+ import { FrameTimingObserver } from "./frame-timing";
3
4
  import { GameParams } from "./game-params";
4
5
  import { GamePlugin } from "./game-plugin";
5
6
  export declare abstract class Game<ParamsType extends GameParams = GameParams> {
@@ -11,6 +12,7 @@ export declare abstract class Game<ParamsType extends GameParams = GameParams> {
11
12
  private lastFrame;
12
13
  private animationFrameId;
13
14
  private runningLoop;
15
+ onFrameTiming: FrameTimingObserver | null;
14
16
  constructor(params: ParamsType);
15
17
  abstract get plugins(): GamePlugin[];
16
18
  abstract get container(): HTMLElement;
package/lib/game/game.js CHANGED
@@ -7,6 +7,7 @@ export class Game {
7
7
  // Time
8
8
  this.age = 0;
9
9
  this.runningLoop = false;
10
+ this.onFrameTiming = null;
10
11
  this.parseURL();
11
12
  }
12
13
  plugin(keyProvider) {
@@ -54,6 +55,8 @@ export class Game {
54
55
  this.animationFrameId = null;
55
56
  }
56
57
  frame() {
58
+ var _a;
59
+ const frameStart = window.performance.now();
57
60
  for (const plugin of this.plugins)
58
61
  plugin.onFrameStart();
59
62
  const now = window.performance.now();
@@ -62,17 +65,30 @@ export class Game {
62
65
  this.lastFrame = now;
63
66
  for (const plugin of this.plugins)
64
67
  plugin.onCycleStart();
68
+ const cycleStart = window.performance.now();
65
69
  this.cycle(elapsed);
70
+ const cycleEnd = window.performance.now();
66
71
  for (const plugin of this.plugins)
67
72
  plugin.onCycleEnd();
68
73
  for (const plugin of this.plugins)
69
74
  plugin.onRenderStart();
75
+ const drawStart = window.performance.now();
70
76
  for (const plugin of this.plugins)
71
77
  plugin.render();
78
+ const drawEnd = window.performance.now();
72
79
  for (const plugin of this.plugins)
73
80
  plugin.onRenderEnd();
74
81
  for (const plugin of this.plugins)
75
82
  plugin.onFrameEnd();
83
+ const frameMs = window.performance.now() - frameStart;
84
+ const cycleMs = cycleEnd - cycleStart;
85
+ const drawMs = drawEnd - drawStart;
86
+ (_a = this.onFrameTiming) === null || _a === void 0 ? void 0 : _a.call(this, {
87
+ frameMs,
88
+ cycleMs,
89
+ drawMs,
90
+ otherMs: frameMs - cycleMs - drawMs,
91
+ });
76
92
  if (this.runningLoop) {
77
93
  this.scheduleFrame();
78
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"game.js","sourceRoot":"","sources":["../../src/game/game.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAIzD,MAAM,OAAgB,IAAI;IAiBtB,YAAqB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAhBtB,cAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;QAQ3D,OAAO;QACP,QAAG,GAAG,CAAC,CAAC;QAKA,gBAAW,GAAG,KAAK,CAAC;QAGxB,IAAI,CAAC,QAAQ,EAAE,CAAC;IACpB,CAAC;IAMD,MAAM,CACF,WAA0D;QAE1D,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAM,CAAC;IACpD,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;QAEzC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC3C,CAAC;QAED,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,C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AAO,EAAE,EAAE,CAAC;YACpD,IAAI,KAAK,GAAG,aAAoB,CAAC;YACjC,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;gBACxC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;iBAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC9B,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;YACvC,CAAC;YAEA,IAAI,CAAC,MAAc,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;QACxC,CAAC;IACL,CAAC;IAED,sBAAsB;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;QAC1C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAC;QAEjD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAChC,MAAM,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;IACL,CAAC;CACJ"}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./game/frame-timing";
1
2
  export * from "./game/game";
2
3
  export * from "./game/game-params";
3
4
  export * from "./game/game-plugin";
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./game/frame-timing";
1
2
  export * from "./game/game";
2
3
  export * from "./game/game-params";
3
4
  export * from "./game/game-plugin";
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mCAAmC,CAAC;AAElD,cAA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AAC5C,cAAc,4BAA4B,CAAC;AAE3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qCAAqC,CAAC;AAEpD,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remvst/game-navigation-core",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Core functionality and plugins",
5
5
  "main": "lib/index.js",
6
6
  "author": "Rémi Vansteelandt",
@@ -8,7 +8,7 @@
8
8
  "dependencies": {
9
9
  "@remvst/animate.js": "3.3.0",
10
10
  "@remvst/client-inputs": "1.1.3",
11
- "@remvst/optimization": "1.8.0"
11
+ "@remvst/optimization": "1.10.0"
12
12
  },
13
13
  "devDependencies": {
14
14
  "typescript": "^7.0.2"
@@ -0,0 +1,17 @@
1
+ export interface FrameTiming {
2
+ /** Whole-frame main-thread time, in ms. */
3
+ frameMs: number;
4
+ /**
5
+ * Time in the cycle phase, in ms. This covers the whole simulation plus any
6
+ * view-controller updates that run inside a screen's `cycle()`. The finer
7
+ * model-vs-render-update split within a frame has to be timed by the game
8
+ * at its own screen-level seam.
9
+ */
10
+ cycleMs: number;
11
+ /** Time in the render/draw phase, in ms. */
12
+ drawMs: number;
13
+ /** `frameMs − cycleMs − drawMs` — plugin hooks, input, GC, browser. */
14
+ otherMs: number;
15
+ }
16
+
17
+ export type FrameTimingObserver = (timing: FrameTiming) => void;
package/src/game/game.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { GameInputs } from "../interaction/inputs";
2
2
  import { ScreenStack } from "../navigation/screen-stack";
3
+ import { FrameTimingObserver } from "./frame-timing";
3
4
  import { GameParams } from "./game-params";
4
5
  import { GamePlugin } from "./game-plugin";
5
6
 
@@ -20,6 +21,8 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
20
21
  private animationFrameId: number;
21
22
  private runningLoop = false;
22
23
 
24
+ onFrameTiming: FrameTimingObserver | null = null;
25
+
23
26
  constructor(readonly params: ParamsType) {
24
27
  this.parseURL();
25
28
  }
@@ -87,6 +90,8 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
87
90
  }
88
91
 
89
92
  frame() {
93
+ const frameStart = window.performance.now();
94
+
90
95
  for (const plugin of this.plugins) plugin.onFrameStart();
91
96
 
92
97
  const now = window.performance.now();
@@ -99,15 +104,29 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
99
104
  this.lastFrame = now;
100
105
 
101
106
  for (const plugin of this.plugins) plugin.onCycleStart();
107
+ const cycleStart = window.performance.now();
102
108
  this.cycle(elapsed);
109
+ const cycleEnd = window.performance.now();
103
110
  for (const plugin of this.plugins) plugin.onCycleEnd();
104
111
 
105
112
  for (const plugin of this.plugins) plugin.onRenderStart();
113
+ const drawStart = window.performance.now();
106
114
  for (const plugin of this.plugins) plugin.render();
115
+ const drawEnd = window.performance.now();
107
116
  for (const plugin of this.plugins) plugin.onRenderEnd();
108
117
 
109
118
  for (const plugin of this.plugins) plugin.onFrameEnd();
110
119
 
120
+ const frameMs = window.performance.now() - frameStart;
121
+ const cycleMs = cycleEnd - cycleStart;
122
+ const drawMs = drawEnd - drawStart;
123
+ this.onFrameTiming?.({
124
+ frameMs,
125
+ cycleMs,
126
+ drawMs,
127
+ otherMs: frameMs - cycleMs - drawMs,
128
+ });
129
+
111
130
  if (this.runningLoop) {
112
131
  this.scheduleFrame();
113
132
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./game/frame-timing";
1
2
  export * from "./game/game";
2
3
  export * from "./game/game-params";
3
4
  export * from "./game/game-plugin";