@vworlds/vecs-physics 1.0.16
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/adapter/disposal.d.ts +8 -0
- package/adapter/disposal.js +14 -0
- package/adapter/disposal.js.map +1 -0
- package/adapter/runtime.d.ts +4 -0
- package/adapter/runtime.js +27 -0
- package/adapter/runtime.js.map +1 -0
- package/adapter/state.d.ts +79 -0
- package/adapter/state.js +89 -0
- package/adapter/state.js.map +1 -0
- package/components/body.d.ts +34 -0
- package/components/body.js +53 -0
- package/components/body.js.map +1 -0
- package/components/body_tuning.d.ts +21 -0
- package/components/body_tuning.js +33 -0
- package/components/body_tuning.js.map +1 -0
- package/components/events.d.ts +32 -0
- package/components/events.js +25 -0
- package/components/events.js.map +1 -0
- package/components/force.d.ts +22 -0
- package/components/force.js +35 -0
- package/components/force.js.map +1 -0
- package/components/geometry.d.ts +55 -0
- package/components/geometry.js +74 -0
- package/components/geometry.js.map +1 -0
- package/components/material.d.ts +18 -0
- package/components/material.js +32 -0
- package/components/material.js.map +1 -0
- package/components/shape_pose.d.ts +9 -0
- package/components/shape_pose.js +16 -0
- package/components/shape_pose.js.map +1 -0
- package/components/target.d.ts +13 -0
- package/components/target.js +21 -0
- package/components/target.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +23 -0
- package/index.js.map +1 -0
- package/install.d.ts +30 -0
- package/install.js +139 -0
- package/install.js.map +1 -0
- package/package.json +22 -0
- package/systems/debug.d.ts +5 -0
- package/systems/debug.js +266 -0
- package/systems/debug.js.map +1 -0
- package/systems/event_opt_in_sync.d.ts +3 -0
- package/systems/event_opt_in_sync.js +41 -0
- package/systems/event_opt_in_sync.js.map +1 -0
- package/systems/events.d.ts +3 -0
- package/systems/events.js +217 -0
- package/systems/events.js.map +1 -0
- package/systems/forces.d.ts +3 -0
- package/systems/forces.js +26 -0
- package/systems/forces.js.map +1 -0
- package/systems/impulse_accumulate.d.ts +4 -0
- package/systems/impulse_accumulate.js +70 -0
- package/systems/impulse_accumulate.js.map +1 -0
- package/systems/impulse_zero.d.ts +3 -0
- package/systems/impulse_zero.js +25 -0
- package/systems/impulse_zero.js.map +1 -0
- package/systems/index.d.ts +16 -0
- package/systems/index.js +81 -0
- package/systems/index.js.map +1 -0
- package/systems/kinematic.d.ts +3 -0
- package/systems/kinematic.js +88 -0
- package/systems/kinematic.js.map +1 -0
- package/systems/lifecycle.d.ts +3 -0
- package/systems/lifecycle.js +99 -0
- package/systems/lifecycle.js.map +1 -0
- package/systems/mass_recompute.d.ts +3 -0
- package/systems/mass_recompute.js +36 -0
- package/systems/mass_recompute.js.map +1 -0
- package/systems/material_filter_sync.d.ts +3 -0
- package/systems/material_filter_sync.js +64 -0
- package/systems/material_filter_sync.js.map +1 -0
- package/systems/pose_sync_in.d.ts +3 -0
- package/systems/pose_sync_in.js +52 -0
- package/systems/pose_sync_in.js.map +1 -0
- package/systems/pose_sync_out.d.ts +3 -0
- package/systems/pose_sync_out.js +50 -0
- package/systems/pose_sync_out.js.map +1 -0
- package/systems/shape_lifecycle.d.ts +4 -0
- package/systems/shape_lifecycle.js +281 -0
- package/systems/shape_lifecycle.js.map +1 -0
- package/systems/shape_pose_sync.d.ts +3 -0
- package/systems/shape_pose_sync.js +18 -0
- package/systems/shape_pose_sync.js.map +1 -0
- package/systems/step.d.ts +3 -0
- package/systems/step.js +13 -0
- package/systems/step.js.map +1 -0
- package/util/resolve_body.d.ts +6 -0
- package/util/resolve_body.js +16 -0
- package/util/resolve_body.js.map +1 -0
- package/util/warn.d.ts +21 -0
- package/util/warn.js +42 -0
- package/util/warn.js.map +1 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface EmscriptenAllocated {
|
|
2
|
+
delete(): void;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Every `new b2Xxx()` or factory allocation inside `src/adapter/` must use this
|
|
6
|
+
* helper, or an explicit try/finally `.delete()` in the same function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function withAllocated<TAllocated extends EmscriptenAllocated, TResult>(make: () => TAllocated, use: (allocated: TAllocated) => TResult): TResult;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every `new b2Xxx()` or factory allocation inside `src/adapter/` must use this
|
|
3
|
+
* helper, or an explicit try/finally `.delete()` in the same function.
|
|
4
|
+
*/
|
|
5
|
+
export function withAllocated(make, use) {
|
|
6
|
+
const allocated = make();
|
|
7
|
+
try {
|
|
8
|
+
return use(allocated);
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
allocated.delete();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=disposal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disposal.js","sourceRoot":"","sources":["../../../../src/adapter/disposal.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAsB,EACtB,GAAuC;IAEvC,MAAM,SAAS,GAAG,IAAI,EAAE,CAAC;IACzB,IAAI,CAAC;QACH,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC;YAAS,CAAC;QACT,SAAS,CAAC,MAAM,EAAE,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { cpus } from "node:os";
|
|
2
|
+
import Box2DFactory from "box2d3-wasm";
|
|
3
|
+
let modulePromise = null;
|
|
4
|
+
let module = null;
|
|
5
|
+
export async function preloadPhysics() {
|
|
6
|
+
var _a;
|
|
7
|
+
if (modulePromise) {
|
|
8
|
+
await modulePromise;
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
// box2d3-wasm reads navigator.hardwareConcurrency during Node initialization.
|
|
12
|
+
const global = globalThis;
|
|
13
|
+
global.navigator ?? (global.navigator = {});
|
|
14
|
+
(_a = global.navigator).hardwareConcurrency ?? (_a.hardwareConcurrency = cpus().length);
|
|
15
|
+
modulePromise = Box2DFactory().then((loadedModule) => {
|
|
16
|
+
module = loadedModule;
|
|
17
|
+
return loadedModule;
|
|
18
|
+
});
|
|
19
|
+
await modulePromise;
|
|
20
|
+
}
|
|
21
|
+
export function getBox2D() {
|
|
22
|
+
if (!module) {
|
|
23
|
+
throw new Error("Box2D module not loaded. Call `await preloadPhysics()` before `installPhysics()`.");
|
|
24
|
+
}
|
|
25
|
+
return module;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../../src/adapter/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,YAAY,MAAM,aAAa,CAAC;AAIvC,IAAI,aAAa,GAAgC,IAAI,CAAC;AACtD,IAAI,MAAM,GAAuB,IAAI,CAAC;AAEtC,MAAM,CAAC,KAAK,UAAU,cAAc;;IAClC,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,aAAa,CAAC;QACpB,OAAO;IACT,CAAC;IAED,8EAA8E;IAC9E,MAAM,MAAM,GAAG,UAA2D,CAAC;IAC3E,MAAM,CAAC,SAAS,KAAhB,MAAM,CAAC,SAAS,GAAK,EAAE,EAAC;IACxB,MAAC,MAAM,CAAC,SAA8C,EAAC,mBAAmB,QAAnB,mBAAmB,GAAK,IAAI,EAAE,CAAC,MAAM,EAAC;IAE7F,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;QACnD,MAAM,GAAG,YAAY,CAAC;QACtB,OAAO,YAAY,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,MAAM,aAAa,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ArrayMap, type Entity, type World } from "@vworlds/vecs";
|
|
2
|
+
import { type WarnSink, WarnDedupe } from "../util/warn.js";
|
|
3
|
+
import { type Box2DModule } from "./runtime.js";
|
|
4
|
+
export type EntityId = number;
|
|
5
|
+
export type b2WorldId = ReturnType<Box2DModule["b2CreateWorld"]>;
|
|
6
|
+
export type b2BodyId = ReturnType<Box2DModule["b2CreateBody"]>;
|
|
7
|
+
export type b2ShapeId = ReturnType<Box2DModule["b2CreateCircleShape"]>;
|
|
8
|
+
export type b2ChainId = ReturnType<Box2DModule["b2CreateChain"]>;
|
|
9
|
+
export type b2Vec2 = ReturnType<Box2DModule["b2Body_GetPosition"]>;
|
|
10
|
+
/** Fully-resolved engine configuration: every `PhysicsOptions` field with its
|
|
11
|
+
* default applied. Built by `installPhysics`; the source of truth for tunables
|
|
12
|
+
* the engine reads at runtime. */
|
|
13
|
+
export interface ResolvedPhysicsOptions {
|
|
14
|
+
gravityX: number;
|
|
15
|
+
gravityY: number;
|
|
16
|
+
fixedTimeStep: number;
|
|
17
|
+
subSteps: number;
|
|
18
|
+
debug: boolean;
|
|
19
|
+
restitutionThreshold: number;
|
|
20
|
+
hitEventThreshold: number;
|
|
21
|
+
contactHertz: number;
|
|
22
|
+
contactDampingRatio: number;
|
|
23
|
+
contactSpeed: number;
|
|
24
|
+
maximumLinearSpeed: number;
|
|
25
|
+
enableSleep: boolean;
|
|
26
|
+
enableContinuous: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Internal marker tagging every physics **system entity** (systems are entities
|
|
29
|
+
* in Vecs). `PhysicsPoseSyncIn.ignoreSource([PhysicsSystemTag])` uses it as a
|
|
30
|
+
* silence domain so the engine's own pose write-back is never mistaken for a
|
|
31
|
+
* user teleport. Never exported from the package public API and only ever lives
|
|
32
|
+
* on system entities, so it adds zero per-entity archetype churn. */
|
|
33
|
+
export declare class PhysicsSystemTag {
|
|
34
|
+
}
|
|
35
|
+
export declare function registerInternalComponents(world: World): void;
|
|
36
|
+
export declare function attachPhysics(world: World, state: PhysicsState): void;
|
|
37
|
+
export declare function getPhysics(world: World): PhysicsState;
|
|
38
|
+
export declare function hasPhysics(world: World): boolean;
|
|
39
|
+
export declare class PhysicsState {
|
|
40
|
+
worldId: b2WorldId;
|
|
41
|
+
readonly box2d: Box2DModule;
|
|
42
|
+
readonly options: ResolvedPhysicsOptions;
|
|
43
|
+
readonly gravityX: number;
|
|
44
|
+
readonly gravityY: number;
|
|
45
|
+
readonly fixedTimeStep: number;
|
|
46
|
+
readonly subSteps: number;
|
|
47
|
+
readonly debug: boolean;
|
|
48
|
+
readonly warn: WarnDedupe;
|
|
49
|
+
readonly restitutionThreshold: number;
|
|
50
|
+
readonly hitEventThreshold: number;
|
|
51
|
+
readonly contactHertz: number;
|
|
52
|
+
readonly contactDampingRatio: number;
|
|
53
|
+
readonly contactSpeed: number;
|
|
54
|
+
readonly maximumLinearSpeed: number;
|
|
55
|
+
readonly enableSleep: boolean;
|
|
56
|
+
readonly enableContinuous: boolean;
|
|
57
|
+
readonly bodyByEntityWasm: Map<number, import("node_modules/box2d3-wasm/build/dist/es/deluxe/Box2D.deluxe.js").b2BodyId>;
|
|
58
|
+
readonly entityByBodyIndex: ArrayMap<number>;
|
|
59
|
+
readonly shapeByEntityWasm: Map<number, import("node_modules/box2d3-wasm/build/dist/es/deluxe/Box2D.deluxe.js").b2ShapeId>;
|
|
60
|
+
readonly entityByShapeIndex: ArrayMap<number>;
|
|
61
|
+
readonly chainByEntity: Map<number, import("node_modules/box2d3-wasm/build/dist/es/deluxe/Box2D.deluxe.js").b2ChainId>;
|
|
62
|
+
readonly shapeEntityByEid: Map<number, Entity>;
|
|
63
|
+
readonly dirtyMassBodies: Set<number>;
|
|
64
|
+
readonly prevTouchedContact: Set<number>;
|
|
65
|
+
readonly prevTouchedSensor: Set<number>;
|
|
66
|
+
readonly prevTouchedHit: Set<number>;
|
|
67
|
+
readonly impulseEntitiesThisStep: Set<number>;
|
|
68
|
+
readonly pendingLinearImpulse: Map<import("node_modules/box2d3-wasm/build/dist/es/deluxe/Box2D.deluxe.js").b2BodyId, {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
wake: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
readonly pendingAngularImpulse: Map<import("node_modules/box2d3-wasm/build/dist/es/deluxe/Box2D.deluxe.js").b2BodyId, {
|
|
74
|
+
value: number;
|
|
75
|
+
wake: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
readonly scratchVec2: b2Vec2;
|
|
78
|
+
constructor(box2d: Box2DModule, options: ResolvedPhysicsOptions, warnSink?: WarnSink);
|
|
79
|
+
}
|
package/adapter/state.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ArrayMap, Singleton } from "@vworlds/vecs";
|
|
2
|
+
import { WarnDedupe } from "../util/warn.js";
|
|
3
|
+
/** Internal marker tagging every physics **system entity** (systems are entities
|
|
4
|
+
* in Vecs). `PhysicsPoseSyncIn.ignoreSource([PhysicsSystemTag])` uses it as a
|
|
5
|
+
* silence domain so the engine's own pose write-back is never mistaken for a
|
|
6
|
+
* user teleport. Never exported from the package public API and only ever lives
|
|
7
|
+
* on system entities, so it adds zero per-entity archetype churn. */
|
|
8
|
+
export class PhysicsSystemTag {
|
|
9
|
+
}
|
|
10
|
+
export function registerInternalComponents(world) {
|
|
11
|
+
world.component(PhysicsRoot);
|
|
12
|
+
world.component(PhysicsSystemTag);
|
|
13
|
+
}
|
|
14
|
+
export function attachPhysics(world, state) {
|
|
15
|
+
world.component(PhysicsRoot).add(Singleton);
|
|
16
|
+
world.set(PhysicsRoot, { state });
|
|
17
|
+
}
|
|
18
|
+
export function getPhysics(world) {
|
|
19
|
+
const root = world.get(PhysicsRoot);
|
|
20
|
+
if (!root) {
|
|
21
|
+
throw new Error("installPhysics(world, ...) must be called before world.start()");
|
|
22
|
+
}
|
|
23
|
+
return root.state;
|
|
24
|
+
}
|
|
25
|
+
export function hasPhysics(world) {
|
|
26
|
+
if (!world._classRegistry.has(PhysicsRoot)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const root = world.get(PhysicsRoot);
|
|
30
|
+
return root?.state !== undefined;
|
|
31
|
+
}
|
|
32
|
+
export class PhysicsState {
|
|
33
|
+
constructor(box2d, options, warnSink) {
|
|
34
|
+
// Entity → WASM body/shape IDs plus index-keyed reverse ArrayMaps.
|
|
35
|
+
// Emscripten returns fresh wrapper objects for b2*Id fields on events, so
|
|
36
|
+
// Map<b2*Id, EntityId> misses by object identity. Public index1 slot 0 is
|
|
37
|
+
// unused/null-aligned by Box2D, so ArrayMap slot 0 stays empty too. We do not
|
|
38
|
+
// check id generations in hot lookups: correctness comes from clearing each
|
|
39
|
+
// slot on Box2D destruction before Box2D can reuse that index1.
|
|
40
|
+
this.bodyByEntityWasm = new Map();
|
|
41
|
+
this.entityByBodyIndex = new ArrayMap();
|
|
42
|
+
this.shapeByEntityWasm = new Map();
|
|
43
|
+
this.entityByShapeIndex = new ArrayMap();
|
|
44
|
+
this.chainByEntity = new Map();
|
|
45
|
+
// Shape entity object map: shape eid → Entity object.
|
|
46
|
+
// Used by events.ts to resolve entities for teardown events even after
|
|
47
|
+
// the entity has been removed from the world lookup table.
|
|
48
|
+
this.shapeEntityByEid = new Map();
|
|
49
|
+
// Bodies whose mass needs recomputing this step (populated by shape lifecycle).
|
|
50
|
+
this.dirtyMassBodies = new Set();
|
|
51
|
+
// Per-step event tracking sets for PhysicsEvents (M7-8 should-fix: moved from
|
|
52
|
+
// closure-local to state so they survive future pause/resume cycles).
|
|
53
|
+
// Populated by PhysicsEvents at the end of each step; persist into the next
|
|
54
|
+
// step to detect which entities stopped receiving events.
|
|
55
|
+
this.prevTouchedContact = new Set();
|
|
56
|
+
this.prevTouchedSensor = new Set();
|
|
57
|
+
this.prevTouchedHit = new Set();
|
|
58
|
+
// EIDs of entities that had Impulse or AngularImpulse set this step.
|
|
59
|
+
// PhysicsImpulseZero walks this set in physics-post to silently zero them.
|
|
60
|
+
// Cleared by PhysicsImpulseZero at the end of each post phase.
|
|
61
|
+
this.impulseEntitiesThisStep = new Set();
|
|
62
|
+
// Pending impulses remain wrapper-keyed by invariant: hooks resolve bodyId
|
|
63
|
+
// from bodyByEntityWasm, then get/set with that same stored wrapper, and the
|
|
64
|
+
// pre-step drain iterates stored keys instead of looking up event wrappers.
|
|
65
|
+
this.pendingLinearImpulse = new Map();
|
|
66
|
+
this.pendingAngularImpulse = new Map();
|
|
67
|
+
this.box2d = box2d;
|
|
68
|
+
this.options = options;
|
|
69
|
+
this.gravityX = options.gravityX;
|
|
70
|
+
this.gravityY = options.gravityY;
|
|
71
|
+
this.fixedTimeStep = options.fixedTimeStep;
|
|
72
|
+
this.subSteps = options.subSteps;
|
|
73
|
+
this.debug = options.debug;
|
|
74
|
+
this.warn = new WarnDedupe(warnSink);
|
|
75
|
+
this.restitutionThreshold = options.restitutionThreshold;
|
|
76
|
+
this.hitEventThreshold = options.hitEventThreshold;
|
|
77
|
+
this.contactHertz = options.contactHertz;
|
|
78
|
+
this.contactDampingRatio = options.contactDampingRatio;
|
|
79
|
+
this.contactSpeed = options.contactSpeed;
|
|
80
|
+
this.maximumLinearSpeed = options.maximumLinearSpeed;
|
|
81
|
+
this.enableSleep = options.enableSleep;
|
|
82
|
+
this.enableContinuous = options.enableContinuous;
|
|
83
|
+
this.scratchVec2 = new box2d.b2Vec2();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Internal singleton state holder. Never exported from the package public API.
|
|
87
|
+
class PhysicsRoot {
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../../src/adapter/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAA2B,MAAM,eAAe,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AAC;QACzD,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;QACvD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;IACxC,CAAC;CACF;AAED,+EAA+E;AAC/E,MAAM,WAAW;CAEhB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Simulation behaviour of a {@link Body}. */
|
|
2
|
+
export declare enum BodyType {
|
|
3
|
+
/** Immovable level geometry. */
|
|
4
|
+
Static = "static",
|
|
5
|
+
/** Moved by user-authored velocity or kinematic targets; infinite mass. */
|
|
6
|
+
Kinematic = "kinematic",
|
|
7
|
+
/** Responds to forces, impulses, gravity, and contacts. */
|
|
8
|
+
Dynamic = "dynamic"
|
|
9
|
+
}
|
|
10
|
+
/** Marks an entity as a physics body. Missing `Body` means physics ignores it. */
|
|
11
|
+
export declare class Body {
|
|
12
|
+
type: BodyType;
|
|
13
|
+
bullet: boolean;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
allowFastRotation: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Canonical world-space body position. Teleports when written by user code. */
|
|
18
|
+
export declare class Position {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
}
|
|
22
|
+
/** World-space body rotation in radians. Missing `Rotation` means angle 0. */
|
|
23
|
+
export declare class Rotation {
|
|
24
|
+
angle: number;
|
|
25
|
+
}
|
|
26
|
+
/** Body linear velocity in metres per second. Authoritative both directions. */
|
|
27
|
+
export declare class LinearVelocity {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
}
|
|
31
|
+
/** Body angular velocity in radians per second. */
|
|
32
|
+
export declare class AngularVelocity {
|
|
33
|
+
value: number;
|
|
34
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Body-level components: the entity-marking `Body` plus the canonical pose and
|
|
2
|
+
// velocity state. Defaults match Box2D's `b2DefaultBodyDef()` (see
|
|
3
|
+
// `box2d/src/types.c`). Public API — see `docs/components.md`.
|
|
4
|
+
//
|
|
5
|
+
// These are plain data classes: every field is initialised on the class body so
|
|
6
|
+
// `new C()` yields a valid, default-shaped instance (the Vecs zero-arg
|
|
7
|
+
// contract). No imports from engine/ or systems/ — components are pure data.
|
|
8
|
+
/** Simulation behaviour of a {@link Body}. */
|
|
9
|
+
export var BodyType;
|
|
10
|
+
(function (BodyType) {
|
|
11
|
+
/** Immovable level geometry. */
|
|
12
|
+
BodyType["Static"] = "static";
|
|
13
|
+
/** Moved by user-authored velocity or kinematic targets; infinite mass. */
|
|
14
|
+
BodyType["Kinematic"] = "kinematic";
|
|
15
|
+
/** Responds to forces, impulses, gravity, and contacts. */
|
|
16
|
+
BodyType["Dynamic"] = "dynamic";
|
|
17
|
+
})(BodyType || (BodyType = {}));
|
|
18
|
+
/** Marks an entity as a physics body. Missing `Body` means physics ignores it. */
|
|
19
|
+
export class Body {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.type = BodyType.Static;
|
|
22
|
+
this.bullet = false;
|
|
23
|
+
this.enabled = true;
|
|
24
|
+
this.allowFastRotation = false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Canonical world-space body position. Teleports when written by user code. */
|
|
28
|
+
export class Position {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.x = 0;
|
|
31
|
+
this.y = 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** World-space body rotation in radians. Missing `Rotation` means angle 0. */
|
|
35
|
+
export class Rotation {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.angle = 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Body linear velocity in metres per second. Authoritative both directions. */
|
|
41
|
+
export class LinearVelocity {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.x = 0;
|
|
44
|
+
this.y = 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Body angular velocity in radians per second. */
|
|
48
|
+
export class AngularVelocity {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.value = 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../../../src/components/body.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,+DAA+D;AAC/D,EAAE;AACF,gFAAgF;AAChF,uEAAuE;AACvE,6EAA6E;AAE7E,8CAA8C;AAC9C,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,gCAAgC;IAChC,6BAAiB,CAAA;IACjB,2EAA2E;IAC3E,mCAAuB,CAAA;IACvB,2DAA2D;IAC3D,+BAAmB,CAAA;AACrB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED,kFAAkF;AAClF,MAAM,OAAO,IAAI;IAAjB;QACE,SAAI,GAAG,QAAQ,CAAC,MAAM,CAAC;QACvB,WAAM,GAAG,KAAK,CAAC;QACf,YAAO,GAAG,IAAI,CAAC;QACf,sBAAiB,GAAG,KAAK,CAAC;IAC5B,CAAC;CAAA;AAED,gFAAgF;AAChF,MAAM,OAAO,QAAQ;IAArB;QACE,MAAC,GAAG,CAAC,CAAC;QACN,MAAC,GAAG,CAAC,CAAC;IACR,CAAC;CAAA;AAED,8EAA8E;AAC9E,MAAM,OAAO,QAAQ;IAArB;QACE,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA;AAED,gFAAgF;AAChF,MAAM,OAAO,cAAc;IAA3B;QACE,MAAC,GAAG,CAAC,CAAC;QACN,MAAC,GAAG,CAAC,CAAC;IACR,CAAC;CAAA;AAED,mDAAmD;AACnD,MAAM,OAAO,eAAe;IAA5B;QACE,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Linear and angular velocity damping. */
|
|
2
|
+
export declare class Damping {
|
|
3
|
+
linear: number;
|
|
4
|
+
angular: number;
|
|
5
|
+
}
|
|
6
|
+
/** Per-body multiplier on world gravity. */
|
|
7
|
+
export declare class GravityScale {
|
|
8
|
+
value: number;
|
|
9
|
+
}
|
|
10
|
+
/** Restricts body translation (x/y) or rotation. */
|
|
11
|
+
export declare class MotionLocks {
|
|
12
|
+
x: boolean;
|
|
13
|
+
y: boolean;
|
|
14
|
+
rotation: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Per-body sleep behaviour. `threshold` is in metres/second (b2 sleepThreshold). */
|
|
17
|
+
export declare class Sleep {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
awake: boolean;
|
|
20
|
+
threshold: number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Optional body tunables. `Body` stays small; less common settings live here so
|
|
2
|
+
// they only cost an archetype slot when actually used. Defaults match
|
|
3
|
+
// `b2DefaultBodyDef()`. Public API — see `docs/components.md`.
|
|
4
|
+
/** Linear and angular velocity damping. */
|
|
5
|
+
export class Damping {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.linear = 0;
|
|
8
|
+
this.angular = 0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** Per-body multiplier on world gravity. */
|
|
12
|
+
export class GravityScale {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.value = 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Restricts body translation (x/y) or rotation. */
|
|
18
|
+
export class MotionLocks {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.x = false;
|
|
21
|
+
this.y = false;
|
|
22
|
+
this.rotation = false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Per-body sleep behaviour. `threshold` is in metres/second (b2 sleepThreshold). */
|
|
26
|
+
export class Sleep {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.enabled = true;
|
|
29
|
+
this.awake = true;
|
|
30
|
+
this.threshold = 0.05;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=body_tuning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body_tuning.js","sourceRoot":"","sources":["../../../../src/components/body_tuning.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,sEAAsE;AACtE,+DAA+D;AAE/D,2CAA2C;AAC3C,MAAM,OAAO,OAAO;IAApB;QACE,WAAM,GAAG,CAAC,CAAC;QACX,YAAO,GAAG,CAAC,CAAC;IACd,CAAC;CAAA;AAED,4CAA4C;AAC5C,MAAM,OAAO,YAAY;IAAzB;QACE,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA;AAED,oDAAoD;AACpD,MAAM,OAAO,WAAW;IAAxB;QACE,MAAC,GAAG,KAAK,CAAC;QACV,MAAC,GAAG,KAAK,CAAC;QACV,aAAQ,GAAG,KAAK,CAAC;IACnB,CAAC;CAAA;AAED,qFAAqF;AACrF,MAAM,OAAO,KAAK;IAAlB;QACE,YAAO,GAAG,IAAI,CAAC;QACf,UAAK,GAAG,IAAI,CAAC;QACb,cAAS,GAAG,IAAI,CAAC;IACnB,CAAC;CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Entity } from "@vworlds/vecs";
|
|
2
|
+
/** A single contact begin/end event. `other` is the colliding shape entity. */
|
|
3
|
+
export type ContactEvent = {
|
|
4
|
+
other: Entity;
|
|
5
|
+
};
|
|
6
|
+
/** A single sensor overlap begin/end event. */
|
|
7
|
+
export type SensorEvent = {
|
|
8
|
+
other: Entity;
|
|
9
|
+
};
|
|
10
|
+
/** A single hit event: contact point, normal, and approach speed. */
|
|
11
|
+
export type HitEvent = {
|
|
12
|
+
other: Entity;
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
normalX: number;
|
|
16
|
+
normalY: number;
|
|
17
|
+
speed: number;
|
|
18
|
+
};
|
|
19
|
+
/** Per-shape contact begin/end buffers. Add to opt a shape into contact events. */
|
|
20
|
+
export declare class ContactEvents {
|
|
21
|
+
begin: ContactEvent[];
|
|
22
|
+
end: ContactEvent[];
|
|
23
|
+
}
|
|
24
|
+
/** Per-shape sensor overlap begin/end buffers. */
|
|
25
|
+
export declare class SensorEvents {
|
|
26
|
+
begin: SensorEvent[];
|
|
27
|
+
end: SensorEvent[];
|
|
28
|
+
}
|
|
29
|
+
/** Per-shape hit-event buffer (fast/high-speed contacts). */
|
|
30
|
+
export declare class HitEvents {
|
|
31
|
+
hits: HitEvent[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Opt-in event buffers attached to shape entities. Arrays are cleared and reused
|
|
2
|
+
// each physics step; physics marks the component modified only when new events
|
|
3
|
+
// arrive (see PLAN → PhysicsEvents). The field initialisers give each instance
|
|
4
|
+
// its own arrays. Public API — see `docs/components.md`.
|
|
5
|
+
/** Per-shape contact begin/end buffers. Add to opt a shape into contact events. */
|
|
6
|
+
export class ContactEvents {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.begin = [];
|
|
9
|
+
this.end = [];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Per-shape sensor overlap begin/end buffers. */
|
|
13
|
+
export class SensorEvents {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.begin = [];
|
|
16
|
+
this.end = [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Per-shape hit-event buffer (fast/high-speed contacts). */
|
|
20
|
+
export class HitEvents {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.hits = [];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/components/events.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,+EAA+E;AAC/E,+EAA+E;AAC/E,yDAAyD;AAwBzD,mFAAmF;AACnF,MAAM,OAAO,aAAa;IAA1B;QACE,UAAK,GAAmB,EAAE,CAAC;QAC3B,QAAG,GAAmB,EAAE,CAAC;IAC3B,CAAC;CAAA;AAED,kDAAkD;AAClD,MAAM,OAAO,YAAY;IAAzB;QACE,UAAK,GAAkB,EAAE,CAAC;QAC1B,QAAG,GAAkB,EAAE,CAAC;IAC1B,CAAC;CAAA;AAED,6DAA6D;AAC7D,MAAM,OAAO,SAAS;IAAtB;QACE,SAAI,GAAe,EAAE,CAAC;IACxB,CAAC;CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Persistent force in newtons. */
|
|
2
|
+
export declare class Force {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
wake: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Persistent torque (angular force). */
|
|
8
|
+
export declare class Torque {
|
|
9
|
+
value: number;
|
|
10
|
+
wake: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** One-shot linear impulse in newton-seconds. Zeroed silently after applied. */
|
|
13
|
+
export declare class Impulse {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
wake: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** One-shot angular impulse. Zeroed silently after applied. */
|
|
19
|
+
export declare class AngularImpulse {
|
|
20
|
+
value: number;
|
|
21
|
+
wake: boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Force, torque, and one-shot impulse components. May live on a body entity or
|
|
2
|
+
// an immediate child of one. `wake` controls whether applying the load wakes a
|
|
3
|
+
// sleeping body. Impulses are zeroed silently after they are applied (see PLAN →
|
|
4
|
+
// PhysicsImpulseZero). Public API — see `docs/components.md`.
|
|
5
|
+
/** Persistent force in newtons. */
|
|
6
|
+
export class Force {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.x = 0;
|
|
9
|
+
this.y = 0;
|
|
10
|
+
this.wake = true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Persistent torque (angular force). */
|
|
14
|
+
export class Torque {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.value = 0;
|
|
17
|
+
this.wake = true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** One-shot linear impulse in newton-seconds. Zeroed silently after applied. */
|
|
21
|
+
export class Impulse {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.x = 0;
|
|
24
|
+
this.y = 0;
|
|
25
|
+
this.wake = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** One-shot angular impulse. Zeroed silently after applied. */
|
|
29
|
+
export class AngularImpulse {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.value = 0;
|
|
32
|
+
this.wake = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=force.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"force.js","sourceRoot":"","sources":["../../../../src/components/force.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+EAA+E;AAC/E,iFAAiF;AACjF,8DAA8D;AAE9D,mCAAmC;AACnC,MAAM,OAAO,KAAK;IAAlB;QACE,MAAC,GAAG,CAAC,CAAC;QACN,MAAC,GAAG,CAAC,CAAC;QACN,SAAI,GAAG,IAAI,CAAC;IACd,CAAC;CAAA;AAED,yCAAyC;AACzC,MAAM,OAAO,MAAM;IAAnB;QACE,UAAK,GAAG,CAAC,CAAC;QACV,SAAI,GAAG,IAAI,CAAC;IACd,CAAC;CAAA;AAED,gFAAgF;AAChF,MAAM,OAAO,OAAO;IAApB;QACE,MAAC,GAAG,CAAC,CAAC;QACN,MAAC,GAAG,CAAC,CAAC;QACN,SAAI,GAAG,IAAI,CAAC;IACd,CAAC;CAAA;AAED,+DAA+D;AAC/D,MAAM,OAAO,cAAc;IAA3B;QACE,UAAK,GAAG,CAAC,CAAC;QACV,SAAI,GAAG,IAAI,CAAC;IACd,CAAC;CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Plain 2D point used by {@link Polygon} and {@link Chain}. */
|
|
2
|
+
export type Vec2 = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Axis-aligned box in local shape space, stored as half extents (`hx`/`hy`) to
|
|
8
|
+
* match Box2D's internal representation. The `width`/`height` accessors are
|
|
9
|
+
* read/write ergonomics over the half extents.
|
|
10
|
+
*
|
|
11
|
+
* Vecs cannot observe accessor writes: after `box.width = 2` the caller must
|
|
12
|
+
* still go through `entity.set(Box, …)` or `entity.modified(Box)` for physics
|
|
13
|
+
* to notice. See PLAN → Box accessors.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Box {
|
|
16
|
+
hx: number;
|
|
17
|
+
hy: number;
|
|
18
|
+
get width(): number;
|
|
19
|
+
set width(value: number);
|
|
20
|
+
get height(): number;
|
|
21
|
+
set height(value: number);
|
|
22
|
+
}
|
|
23
|
+
/** Circle geometry. */
|
|
24
|
+
export declare class Circle {
|
|
25
|
+
radius: number;
|
|
26
|
+
}
|
|
27
|
+
/** Capsule geometry: two local endpoints joined by a radius. */
|
|
28
|
+
export declare class Capsule {
|
|
29
|
+
x1: number;
|
|
30
|
+
y1: number;
|
|
31
|
+
x2: number;
|
|
32
|
+
y2: number;
|
|
33
|
+
radius: number;
|
|
34
|
+
}
|
|
35
|
+
/** Line-segment geometry. */
|
|
36
|
+
export declare class Segment {
|
|
37
|
+
x1: number;
|
|
38
|
+
y1: number;
|
|
39
|
+
x2: number;
|
|
40
|
+
y2: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Convex polygon geometry (up to `B2_MAX_POLYGON_VERTICES` = 8 vertices).
|
|
44
|
+
* Convexity and vertex count are validated on shape creation, not on every
|
|
45
|
+
* update. See PLAN → Vec2 in Polygon / Chain.
|
|
46
|
+
*/
|
|
47
|
+
export declare class Polygon {
|
|
48
|
+
vertices: Vec2[];
|
|
49
|
+
radius: number;
|
|
50
|
+
}
|
|
51
|
+
/** Chain geometry for static terrain. Needs at least four points. */
|
|
52
|
+
export declare class Chain {
|
|
53
|
+
points: Vec2[];
|
|
54
|
+
loop: boolean;
|
|
55
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Geometry components. Exactly one per shape entity; `installPhysics` marks them
|
|
2
|
+
// mutually exclusive so adding one removes any previous geometry. Defaults match
|
|
3
|
+
// the documented shapes. Public API — see `docs/components.md`.
|
|
4
|
+
/**
|
|
5
|
+
* Axis-aligned box in local shape space, stored as half extents (`hx`/`hy`) to
|
|
6
|
+
* match Box2D's internal representation. The `width`/`height` accessors are
|
|
7
|
+
* read/write ergonomics over the half extents.
|
|
8
|
+
*
|
|
9
|
+
* Vecs cannot observe accessor writes: after `box.width = 2` the caller must
|
|
10
|
+
* still go through `entity.set(Box, …)` or `entity.modified(Box)` for physics
|
|
11
|
+
* to notice. See PLAN → Box accessors.
|
|
12
|
+
*/
|
|
13
|
+
export class Box {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.hx = 0.5;
|
|
16
|
+
this.hy = 0.5;
|
|
17
|
+
}
|
|
18
|
+
get width() {
|
|
19
|
+
return this.hx * 2;
|
|
20
|
+
}
|
|
21
|
+
set width(value) {
|
|
22
|
+
this.hx = value / 2;
|
|
23
|
+
}
|
|
24
|
+
get height() {
|
|
25
|
+
return this.hy * 2;
|
|
26
|
+
}
|
|
27
|
+
set height(value) {
|
|
28
|
+
this.hy = value / 2;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Circle geometry. */
|
|
32
|
+
export class Circle {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.radius = 0.5;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Capsule geometry: two local endpoints joined by a radius. */
|
|
38
|
+
export class Capsule {
|
|
39
|
+
constructor() {
|
|
40
|
+
this.x1 = -0.5;
|
|
41
|
+
this.y1 = 0;
|
|
42
|
+
this.x2 = 0.5;
|
|
43
|
+
this.y2 = 0;
|
|
44
|
+
this.radius = 0.25;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Line-segment geometry. */
|
|
48
|
+
export class Segment {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.x1 = -0.5;
|
|
51
|
+
this.y1 = 0;
|
|
52
|
+
this.x2 = 0.5;
|
|
53
|
+
this.y2 = 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Convex polygon geometry (up to `B2_MAX_POLYGON_VERTICES` = 8 vertices).
|
|
58
|
+
* Convexity and vertex count are validated on shape creation, not on every
|
|
59
|
+
* update. See PLAN → Vec2 in Polygon / Chain.
|
|
60
|
+
*/
|
|
61
|
+
export class Polygon {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.vertices = [];
|
|
64
|
+
this.radius = 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Chain geometry for static terrain. Needs at least four points. */
|
|
68
|
+
export class Chain {
|
|
69
|
+
constructor() {
|
|
70
|
+
this.points = [];
|
|
71
|
+
this.loop = false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../../../src/components/geometry.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,iFAAiF;AACjF,gEAAgE;AAKhE;;;;;;;;GAQG;AACH,MA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