@thi.ng/timestep 0.4.0 → 0.4.2

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,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-06-19T09:41:50Z
3
+ - **Last updated**: 2023-08-04T10:58:19Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [0.4.2](https://github.com/thi-ng/umbrella/tree/@thi.ng/timestep@0.4.2) (2023-08-04)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - update INotify impl & event types ([02d83e8](https://github.com/thi-ng/umbrella/commit/02d83e8))
17
+ - rename EVENT_INTEGRATE => EVENT_SUBFRAME
18
+ - update INotify impls ([cbdc527](https://github.com/thi-ng/umbrella/commit/cbdc527))
19
+
12
20
  ## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/timestep@0.4.0) (2023-06-19)
13
21
 
14
22
  #### 🚀 Features
package/README.md CHANGED
@@ -151,7 +151,7 @@ For Node.js REPL:
151
151
  const timestep = await import("@thi.ng/timestep");
152
152
  ```
153
153
 
154
- Package sizes (brotli'd, pre-treeshake): ESM: 817 bytes
154
+ Package sizes (brotli'd, pre-treeshake): ESM: 816 bytes
155
155
 
156
156
  ## Dependencies
157
157
 
package/api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { EVENT_ALL } from "@thi.ng/api";
1
2
  /**
2
3
  * Interface for participating in the {@link TimeStep.update} logic.
3
4
  */
@@ -92,14 +93,15 @@ export interface TimeStepOpts {
92
93
  }
93
94
  export type StateUpdate<T> = (curr: T, dt: number, ctx: ReadonlyTimeStep) => T;
94
95
  export type StateInterpolation<T> = (prev: T, curr: T, alpha: number, ctx: ReadonlyTimeStep) => T;
95
- /**
96
- * Event ID for {@link TimeStep.addListener} to be notified of individual
97
- * {@link ITimeStep.integrate} iterations.
98
- */
99
- export declare const EVENT_INTEGRATE = "integrate";
100
96
  /**
101
97
  * Event ID for {@link TimeStep.addListener} to be notified of calls to
102
98
  * {@link TimeStep.update} (triggered at the very end of a frame update).
103
99
  */
104
100
  export declare const EVENT_FRAME = "frame";
101
+ /**
102
+ * Event ID for {@link TimeStep.addListener} to be notified of individual
103
+ * {@link ITimeStep.integrate} iterations.
104
+ */
105
+ export declare const EVENT_SUBFRAME = "subframe";
106
+ export type TimeStepEventType = typeof EVENT_FRAME | typeof EVENT_SUBFRAME | typeof EVENT_ALL;
105
107
  //# sourceMappingURL=api.d.ts.map
package/api.js CHANGED
@@ -1,10 +1,10 @@
1
- /**
2
- * Event ID for {@link TimeStep.addListener} to be notified of individual
3
- * {@link ITimeStep.integrate} iterations.
4
- */
5
- export const EVENT_INTEGRATE = "integrate";
6
1
  /**
7
2
  * Event ID for {@link TimeStep.addListener} to be notified of calls to
8
3
  * {@link TimeStep.update} (triggered at the very end of a frame update).
9
4
  */
10
5
  export const EVENT_FRAME = "frame";
6
+ /**
7
+ * Event ID for {@link TimeStep.addListener} to be notified of individual
8
+ * {@link ITimeStep.integrate} iterations.
9
+ */
10
+ export const EVENT_SUBFRAME = "subframe";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/timestep",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Deterministic fixed timestep simulation updates with state interpolation",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,17 +34,17 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.8.2",
38
- "@thi.ng/math": "^5.4.11",
39
- "@thi.ng/vectors": "^7.7.0"
37
+ "@thi.ng/api": "^8.9.0",
38
+ "@thi.ng/math": "^5.5.1",
39
+ "@thi.ng/vectors": "^7.7.2"
40
40
  },
41
41
  "devDependencies": {
42
- "@microsoft/api-extractor": "^7.35.3",
43
- "@thi.ng/testament": "^0.3.17",
42
+ "@microsoft/api-extractor": "^7.36.3",
43
+ "@thi.ng/testament": "^0.3.18",
44
44
  "rimraf": "^5.0.1",
45
45
  "tools": "^0.0.1",
46
46
  "typedoc": "^0.24.8",
47
- "typescript": "^5.1.3"
47
+ "typescript": "^5.1.6"
48
48
  },
49
49
  "keywords": [
50
50
  "deterministic",
@@ -88,5 +88,5 @@
88
88
  "status": "alpha",
89
89
  "year": 2023
90
90
  },
91
- "gitHead": "db8b3ed2ab79e513d378a465a6d8cacf3243b052\n"
91
+ "gitHead": "9fa3f7f8169efa30e3c71b43c82f77393581c3b5\n"
92
92
  }
package/state.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare class NumericState implements IDeref<number>, ITimeStep {
16
16
  */
17
17
  reset(value: number): void;
18
18
  integrate(dt: number, ctx: ReadonlyTimeStep): void;
19
- interpolate(alpha: number): void;
19
+ interpolate(alpha: number, _: ReadonlyTimeStep): void;
20
20
  }
21
21
  export declare class VectorState implements IDeref<ReadonlyVec>, ITimeStep {
22
22
  value: Vec;
package/state.js CHANGED
@@ -23,7 +23,7 @@ export class NumericState {
23
23
  this.prev = this.curr;
24
24
  this.curr = this.update(this.curr, dt, ctx);
25
25
  }
26
- interpolate(alpha) {
26
+ interpolate(alpha, _) {
27
27
  this.value = mix(this.prev, this.curr, alpha);
28
28
  }
29
29
  }
package/timestep.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type Event, type INotify, type Listener } from "@thi.ng/api";
2
- import { type ITimeStep, type ReadonlyTimeStep, type TimeStepOpts } from "./api.js";
3
- export declare class TimeStep implements INotify {
2
+ import { type ITimeStep, type ReadonlyTimeStep, type TimeStepEventType, type TimeStepOpts } from "./api.js";
3
+ export declare class TimeStep implements INotify<TimeStepEventType> {
4
4
  start: number;
5
5
  dt: number;
6
6
  maxFrameTime: number;
@@ -10,12 +10,12 @@ export declare class TimeStep implements INotify {
10
10
  accumulator: number;
11
11
  frame: number;
12
12
  updates: number;
13
- protected __eventIntegrate: Event;
14
- protected __eventFrame: Event;
13
+ protected __eventFrame: Event<TimeStepEventType>;
14
+ protected __eventSubFrame: Event<TimeStepEventType>;
15
15
  constructor(opts?: Partial<TimeStepOpts>);
16
- addListener(id: string, fn: Listener, scope?: any): boolean;
17
- removeListener(id: string, fn: Listener, scope?: any): boolean;
18
- notify(event: Event): boolean;
16
+ addListener(id: TimeStepEventType, fn: Listener<TimeStepEventType>, scope?: any): boolean;
17
+ removeListener(id: TimeStepEventType, fn: Listener<TimeStepEventType>, scope?: any): boolean;
18
+ notify(event: Event<TimeStepEventType>): boolean;
19
19
  /**
20
20
  * Updates internal time to given new time `now` (given value will be scaled
21
21
  * via {@link TimeStepOpts.scale}) and performs the required number of fixed
package/timestep.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { INotifyMixin, } from "@thi.ng/api";
3
- import { EVENT_FRAME, EVENT_INTEGRATE, } from "./api.js";
3
+ import { EVENT_FRAME, EVENT_SUBFRAME, } from "./api.js";
4
4
  export let TimeStep = class TimeStep {
5
5
  constructor(opts) {
6
6
  this.t = 0;
@@ -19,15 +19,17 @@ export let TimeStep = class TimeStep {
19
19
  this.maxFrameTime = $opts.maxFrameTime;
20
20
  this.scale = $opts.scale;
21
21
  this.start = $opts.startTime * this.scale;
22
- this.__eventIntegrate = Object.freeze({
23
- id: EVENT_INTEGRATE,
22
+ this.__eventFrame = Object.freeze({ id: EVENT_FRAME, target: this });
23
+ this.__eventSubFrame = Object.freeze({
24
+ id: EVENT_SUBFRAME,
24
25
  target: this,
25
26
  });
26
- this.__eventFrame = Object.freeze({ id: EVENT_FRAME, target: this });
27
27
  }
28
28
  // @ts-ignore mixin
29
+ // prettier-ignore
29
30
  addListener(id, fn, scope) { }
30
31
  // @ts-ignore mixin
32
+ // prettier-ignore
31
33
  removeListener(id, fn, scope) { }
32
34
  // @ts-ignore mixin
33
35
  notify(event) { }
@@ -61,7 +63,7 @@ export let TimeStep = class TimeStep {
61
63
  this.t += dt;
62
64
  this.accumulator -= dt;
63
65
  this.updates++;
64
- this.notify(this.__eventIntegrate);
66
+ this.notify(this.__eventSubFrame);
65
67
  }
66
68
  if (interpolate) {
67
69
  const alpha = this.accumulator / dt;