@vworlds/vecs-physics 1.0.26 → 1.0.28
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/{state.d.ts → engine.d.ts} +12 -5
- package/adapter/{state.js → engine.js} +19 -21
- package/adapter/engine.js.map +1 -0
- package/adapter/queries.d.ts +68 -0
- package/adapter/queries.js +145 -0
- package/adapter/queries.js.map +1 -0
- package/adapter/runtime.d.ts +4 -0
- package/adapter/runtime.js +20 -0
- package/adapter/runtime.js.map +1 -1
- package/components/body.js +1 -1
- package/components/body.js.map +1 -1
- package/components/geometry.d.ts +15 -8
- package/components/geometry.js +26 -14
- package/components/geometry.js.map +1 -1
- package/components/material.d.ts +5 -0
- package/components/material.js +5 -0
- package/components/material.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +4 -2
- package/index.js.map +1 -1
- package/module.js +25 -22
- package/module.js.map +1 -1
- package/package.json +2 -2
- package/systems/chain_lifecycle.d.ts +6 -0
- package/systems/chain_lifecycle.js +102 -0
- package/systems/chain_lifecycle.js.map +1 -0
- package/systems/debug.d.ts +2 -2
- package/systems/debug.js +17 -17
- package/systems/debug.js.map +1 -1
- package/systems/event_opt_in_sync.d.ts +2 -2
- package/systems/event_opt_in_sync.js +64 -28
- package/systems/event_opt_in_sync.js.map +1 -1
- package/systems/events.d.ts +2 -2
- package/systems/events.js +34 -34
- package/systems/events.js.map +1 -1
- package/systems/forces.d.ts +2 -2
- package/systems/forces.js +9 -9
- package/systems/forces.js.map +1 -1
- package/systems/impulse_accumulate.d.ts +3 -3
- package/systems/impulse_accumulate.js +28 -26
- package/systems/impulse_accumulate.js.map +1 -1
- package/systems/impulse_zero.d.ts +2 -2
- package/systems/impulse_zero.js +4 -4
- package/systems/impulse_zero.js.map +1 -1
- package/systems/index.d.ts +3 -3
- package/systems/index.js +31 -28
- package/systems/index.js.map +1 -1
- package/systems/kinematic.d.ts +2 -2
- package/systems/kinematic.js +26 -25
- package/systems/kinematic.js.map +1 -1
- package/systems/lifecycle.d.ts +2 -2
- package/systems/lifecycle.js +21 -21
- package/systems/lifecycle.js.map +1 -1
- package/systems/mass_recompute.d.ts +2 -2
- package/systems/mass_recompute.js +12 -12
- package/systems/mass_recompute.js.map +1 -1
- package/systems/material_filter_sync.d.ts +2 -2
- package/systems/material_filter_sync.js +48 -34
- package/systems/material_filter_sync.js.map +1 -1
- package/systems/pose_sync_in.d.ts +2 -2
- package/systems/pose_sync_in.js +14 -11
- package/systems/pose_sync_in.js.map +1 -1
- package/systems/pose_sync_out.d.ts +2 -2
- package/systems/pose_sync_out.js +6 -6
- package/systems/pose_sync_out.js.map +1 -1
- package/systems/shape_lifecycle.d.ts +29 -4
- package/systems/shape_lifecycle.js +46 -86
- package/systems/shape_lifecycle.js.map +1 -1
- package/systems/shape_pose_sync.d.ts +2 -2
- package/systems/shape_pose_sync.js +28 -13
- package/systems/shape_pose_sync.js.map +1 -1
- package/systems/shape_predicates.d.ts +8 -3
- package/systems/shape_predicates.js +3 -2
- package/systems/shape_predicates.js.map +1 -1
- package/systems/step.d.ts +2 -2
- package/systems/step.js +5 -5
- package/systems/step.js.map +1 -1
- package/util/resolve_body.d.ts +1 -1
- package/util/resolve_body.js +1 -3
- package/util/resolve_body.js.map +1 -1
- package/adapter/state.js.map +0 -1
package/systems/events.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ContactEvents, HitEvents, SensorEvents } from "../components/events.js";
|
|
2
|
-
import { PhysicsSystemTag } from "../adapter/
|
|
3
|
-
export function installEvents(world,
|
|
2
|
+
import { PhysicsSystemTag } from "../adapter/engine.js";
|
|
3
|
+
export function installEvents(world, engine, phase) {
|
|
4
4
|
const system = world
|
|
5
5
|
.system("PhysicsEvents")
|
|
6
6
|
.phase(phase)
|
|
@@ -8,41 +8,41 @@ export function installEvents(world, state, phase) {
|
|
|
8
8
|
const touchedContact = new Set();
|
|
9
9
|
const touchedSensor = new Set();
|
|
10
10
|
const touchedHit = new Set();
|
|
11
|
-
publishContactAndHitEvents(world,
|
|
12
|
-
publishSensorEvents(world,
|
|
11
|
+
publishContactAndHitEvents(world, engine, touchedContact, touchedHit);
|
|
12
|
+
publishSensorEvents(world, engine, touchedSensor);
|
|
13
13
|
markModified(world, touchedContact, ContactEvents);
|
|
14
14
|
markModified(world, touchedSensor, SensorEvents);
|
|
15
15
|
markModified(world, touchedHit, HitEvents);
|
|
16
|
-
clearUntouchedContactEvents(world,
|
|
17
|
-
clearUntouchedSensorEvents(world,
|
|
18
|
-
clearUntouchedHitEvents(world,
|
|
19
|
-
// Store touched sets on
|
|
20
|
-
|
|
16
|
+
clearUntouchedContactEvents(world, engine.prevTouchedContact, touchedContact);
|
|
17
|
+
clearUntouchedSensorEvents(world, engine.prevTouchedSensor, touchedSensor);
|
|
18
|
+
clearUntouchedHitEvents(world, engine.prevTouchedHit, touchedHit);
|
|
19
|
+
// Store touched sets on engine for the next step's clear pass.
|
|
20
|
+
engine.prevTouchedContact.clear();
|
|
21
21
|
for (const eid of touchedContact) {
|
|
22
|
-
|
|
22
|
+
engine.prevTouchedContact.add(eid);
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
engine.prevTouchedSensor.clear();
|
|
25
25
|
for (const eid of touchedSensor) {
|
|
26
|
-
|
|
26
|
+
engine.prevTouchedSensor.add(eid);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
engine.prevTouchedHit.clear();
|
|
29
29
|
for (const eid of touchedHit) {
|
|
30
|
-
|
|
30
|
+
engine.prevTouchedHit.add(eid);
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
system.entity.add(PhysicsSystemTag);
|
|
34
34
|
}
|
|
35
35
|
// Contact begin/end and hit events all come from a single
|
|
36
36
|
// `b2World_GetContactEvents` poll, so fetch the event block once per step and
|
|
37
|
-
// fan begin/end into `touchedContact` and hits into `touchedHit` (
|
|
37
|
+
// fan begin/end into `touchedContact` and hits into `touchedHit` (ARCHITECTURE.md ->
|
|
38
38
|
// PhysicsEvents: "poll once per step").
|
|
39
|
-
function publishContactAndHitEvents(world,
|
|
40
|
-
const events =
|
|
39
|
+
function publishContactAndHitEvents(world, engine, touchedContact, touchedHit) {
|
|
40
|
+
const events = engine.box2d.b2World_GetContactEvents(engine.worldId);
|
|
41
41
|
try {
|
|
42
42
|
for (let i = 0; i < events.beginCount; i++) {
|
|
43
43
|
const event = events.GetBeginEvent(i);
|
|
44
44
|
try {
|
|
45
|
-
emitContactEvent(world,
|
|
45
|
+
emitContactEvent(world, engine, touchedContact, event, "begin");
|
|
46
46
|
}
|
|
47
47
|
finally {
|
|
48
48
|
deleteIfPresent(event);
|
|
@@ -50,12 +50,12 @@ function publishContactAndHitEvents(world, state, touchedContact, touchedHit) {
|
|
|
50
50
|
}
|
|
51
51
|
for (let i = 0; i < events.endCount; i++) {
|
|
52
52
|
const event = events.GetEndEvent(i);
|
|
53
|
-
emitContactEvent(world,
|
|
53
|
+
emitContactEvent(world, engine, touchedContact, event, "end");
|
|
54
54
|
}
|
|
55
55
|
for (let i = 0; i < events.hitCount; i++) {
|
|
56
56
|
const event = events.GetHitEvent(i);
|
|
57
57
|
try {
|
|
58
|
-
emitHitEvent(world,
|
|
58
|
+
emitHitEvent(world, engine, touchedHit, event);
|
|
59
59
|
}
|
|
60
60
|
finally {
|
|
61
61
|
event.delete();
|
|
@@ -66,32 +66,32 @@ function publishContactAndHitEvents(world, state, touchedContact, touchedHit) {
|
|
|
66
66
|
events.delete();
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
function publishSensorEvents(world,
|
|
70
|
-
const events =
|
|
69
|
+
function publishSensorEvents(world, engine, touched) {
|
|
70
|
+
const events = engine.box2d.b2World_GetSensorEvents(engine.worldId);
|
|
71
71
|
try {
|
|
72
72
|
for (let i = 0; i < events.beginCount; i++) {
|
|
73
|
-
emitSensorEvent(world,
|
|
73
|
+
emitSensorEvent(world, engine, touched, events.GetBeginEvent(i), "begin");
|
|
74
74
|
}
|
|
75
75
|
for (let i = 0; i < events.endCount; i++) {
|
|
76
|
-
emitSensorEvent(world,
|
|
76
|
+
emitSensorEvent(world, engine, touched, events.GetEndEvent(i), "end");
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
finally {
|
|
80
80
|
events.delete();
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
function emitContactEvent(world,
|
|
84
|
-
const entityA = getLiveEntity(world,
|
|
85
|
-
const entityB = getLiveEntity(world,
|
|
83
|
+
function emitContactEvent(world, engine, touched, event, kind) {
|
|
84
|
+
const entityA = getLiveEntity(world, engine.entityByShapeIndex.get(event.shapeIdA.index1));
|
|
85
|
+
const entityB = getLiveEntity(world, engine.entityByShapeIndex.get(event.shapeIdB.index1));
|
|
86
86
|
if (entityA === undefined || entityB === undefined) {
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
emitContactToEntity(touched, entityA, entityB, kind);
|
|
90
90
|
emitContactToEntity(touched, entityB, entityA, kind);
|
|
91
91
|
}
|
|
92
|
-
function emitSensorEvent(world,
|
|
93
|
-
const sensor = getLiveEntity(world,
|
|
94
|
-
const visitor = getLiveEntity(world,
|
|
92
|
+
function emitSensorEvent(world, engine, touched, event, kind) {
|
|
93
|
+
const sensor = getLiveEntity(world, engine.entityByShapeIndex.get(event.sensorShapeId.index1));
|
|
94
|
+
const visitor = getLiveEntity(world, engine.entityByShapeIndex.get(event.visitorShapeId.index1));
|
|
95
95
|
if (sensor === undefined || visitor === undefined) {
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
@@ -111,9 +111,9 @@ function emitSensorEvent(world, state, touched, event, kind) {
|
|
|
111
111
|
events.end.push({ other: visitor });
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
function emitHitEvent(world,
|
|
115
|
-
const entityA = getLiveEntity(world,
|
|
116
|
-
const entityB = getLiveEntity(world,
|
|
114
|
+
function emitHitEvent(world, engine, touched, event) {
|
|
115
|
+
const entityA = getLiveEntity(world, engine.entityByShapeIndex.get(event.shapeIdA.index1));
|
|
116
|
+
const entityB = getLiveEntity(world, engine.entityByShapeIndex.get(event.shapeIdB.index1));
|
|
117
117
|
if (entityA === undefined || entityB === undefined) {
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
@@ -209,6 +209,6 @@ function deleteIfPresent(value) {
|
|
|
209
209
|
value.delete?.();
|
|
210
210
|
}
|
|
211
211
|
function isDestroyed(entity) {
|
|
212
|
-
return entity.
|
|
212
|
+
return entity.destroyed;
|
|
213
213
|
}
|
|
214
214
|
//# sourceMappingURL=events.js.map
|
package/systems/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/systems/events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../../src/systems/events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAsB,MAAM,sBAAsB,CAAC;AAc5E,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,MAAqB,EAAE,KAAa;IAC9E,MAAM,MAAM,GAAG,KAAK;SACjB,MAAM,CAAC,eAAe,CAAC;SACvB,KAAK,CAAC,KAAK,CAAC;SACZ,GAAG,CAAC,GAAG,EAAE;QACR,MAAM,cAAc,GAAG,IAAI,GAAG,EAAO,CAAC;QACtC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAO,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAO,CAAC;QAElC,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;QACtE,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,C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AAC,CAAC;QACzB,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,KAA8B;IACrD,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;AACnB,CAAC;AAED,SAAS,WAAW,CAAC,MAAc;IACjC,OAAO,MAAM,CAAC,SAAS,CAAC;AAC1B,CAAC"}
|
package/systems/forces.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type Entity, type World } from "@vworlds/vecs";
|
|
2
|
-
import { type
|
|
3
|
-
export declare function installForceGather(world: World,
|
|
2
|
+
import { type PhysicsEngine } from "../adapter/engine.js";
|
|
3
|
+
export declare function installForceGather(world: World, engine: PhysicsEngine, phase: Entity): void;
|
package/systems/forces.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import { ChildOf } from "@vworlds/vecs";
|
|
2
2
|
import { Body } from "../components/body.js";
|
|
3
3
|
import { Force, Torque } from "../components/force.js";
|
|
4
|
-
import {
|
|
4
|
+
import { scr_b2Vec2 } from "../adapter/runtime.js";
|
|
5
|
+
import { PhysicsSystemTag } from "../adapter/engine.js";
|
|
5
6
|
const forceTargetPredicate = { any: [Body, { parent: Body }] };
|
|
6
|
-
export function installForceGather(world,
|
|
7
|
+
export function installForceGather(world, engine, phase) {
|
|
7
8
|
const forceSystem = world
|
|
8
9
|
.system("PhysicsForceGather:Force")
|
|
9
10
|
.with(Force, forceTargetPredicate)
|
|
10
11
|
.phase(phase);
|
|
11
12
|
forceSystem.entity.add(PhysicsSystemTag);
|
|
12
|
-
forceSystem.each([Force, Body, { target: [ChildOf, [Body]] }], (_entity,
|
|
13
|
-
const [force, body, parentBody] = tuple;
|
|
13
|
+
forceSystem.each([Force, Body, { target: [ChildOf, [Body]] }], (_entity, [force, body, parentBody]) => {
|
|
14
14
|
const bodyId = body?._bodyId ?? parentBody?._bodyId;
|
|
15
15
|
if (bodyId === undefined) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const vec = scr_b2Vec2[0];
|
|
19
|
+
vec.Set(force.x, force.y);
|
|
20
|
+
engine.box2d.b2Body_ApplyForceToCenter(bodyId, vec, force.wake);
|
|
20
21
|
});
|
|
21
22
|
const torqueSystem = world
|
|
22
23
|
.system("PhysicsForceGather:Torque")
|
|
23
24
|
.with(Torque, forceTargetPredicate)
|
|
24
25
|
.phase(phase)
|
|
25
|
-
.each([Torque, Body, { target: [ChildOf, [Body]] }], (_entity,
|
|
26
|
-
const [torque, body, parentBody] = tuple;
|
|
26
|
+
.each([Torque, Body, { target: [ChildOf, [Body]] }], (_entity, [torque, body, parentBody]) => {
|
|
27
27
|
const bodyId = body?._bodyId ?? parentBody?._bodyId;
|
|
28
28
|
if (bodyId === undefined) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
engine.box2d.b2Body_ApplyTorque(bodyId, torque.value, torque.wake);
|
|
32
32
|
});
|
|
33
33
|
torqueSystem.entity.add(PhysicsSystemTag);
|
|
34
34
|
}
|
package/systems/forces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forces.js","sourceRoot":"","sources":["../../../../src/systems/forces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA2B,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"forces.js","sourceRoot":"","sources":["../../../../src/systems/forces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA2B,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAA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AM,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE;QAC3F,MAAM,MAAM,GAAG,IAAI,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,CAAC;QACpD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;IACL,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Entity, type World } from "@vworlds/vecs";
|
|
2
|
-
import { type
|
|
3
|
-
export declare function installImpulseAccumulate(world: World,
|
|
4
|
-
export declare function registerImpulseHooks(world: World,
|
|
2
|
+
import { type PhysicsEngine } from "../adapter/engine.js";
|
|
3
|
+
export declare function installImpulseAccumulate(world: World, engine: PhysicsEngine, phase: Entity): void;
|
|
4
|
+
export declare function registerImpulseHooks(world: World, engine: PhysicsEngine): void;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { AngularImpulse, Impulse } from "../components/force.js";
|
|
2
|
-
import {
|
|
2
|
+
import { scr_b2Vec2 } from "../adapter/runtime.js";
|
|
3
|
+
import { PhysicsSystemTag } from "../adapter/engine.js";
|
|
3
4
|
import { resolveBodyId } from "../util/resolve_body.js";
|
|
4
|
-
export function installImpulseAccumulate(world,
|
|
5
|
+
export function installImpulseAccumulate(world, engine, phase) {
|
|
5
6
|
const system = world
|
|
6
7
|
.system("PhysicsImpulseAccumulate")
|
|
7
8
|
.phase(phase)
|
|
8
9
|
.run(() => {
|
|
9
|
-
drainLinearImpulses(
|
|
10
|
-
drainAngularImpulses(
|
|
10
|
+
drainLinearImpulses(engine);
|
|
11
|
+
drainAngularImpulses(engine);
|
|
11
12
|
});
|
|
12
13
|
system.entity.add(PhysicsSystemTag);
|
|
13
14
|
}
|
|
14
|
-
export function registerImpulseHooks(world,
|
|
15
|
+
export function registerImpulseHooks(world, engine) {
|
|
15
16
|
world.component(Impulse).onSet((entity, impulse) => {
|
|
16
17
|
const bodyId = resolveBodyId(entity);
|
|
17
18
|
if (bodyId === undefined) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
const accumulator = getLinearAccumulator(
|
|
21
|
+
engine.impulseEntitiesThisStep.add(entity.eid);
|
|
22
|
+
const accumulator = getLinearAccumulator(engine, bodyId);
|
|
22
23
|
accumulator.x += impulse.x;
|
|
23
24
|
accumulator.y += impulse.y;
|
|
24
25
|
accumulator.wake || (accumulator.wake = impulse.wake);
|
|
@@ -28,44 +29,45 @@ export function registerImpulseHooks(world, state) {
|
|
|
28
29
|
if (bodyId === undefined) {
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
const accumulator = getAngularAccumulator(
|
|
32
|
+
engine.impulseEntitiesThisStep.add(entity.eid);
|
|
33
|
+
const accumulator = getAngularAccumulator(engine, bodyId);
|
|
33
34
|
accumulator.value += impulse.value;
|
|
34
35
|
accumulator.wake || (accumulator.wake = impulse.wake);
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
|
-
function drainLinearImpulses(
|
|
38
|
-
for (const [bodyId, impulse] of
|
|
39
|
-
if (!
|
|
38
|
+
function drainLinearImpulses(engine) {
|
|
39
|
+
for (const [bodyId, impulse] of engine.pendingLinearImpulse) {
|
|
40
|
+
if (!engine.entityByBodyIndex.has(bodyId.index1)) {
|
|
40
41
|
continue;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
const vec = scr_b2Vec2[0];
|
|
44
|
+
vec.Set(impulse.x, impulse.y);
|
|
45
|
+
engine.box2d.b2Body_ApplyLinearImpulseToCenter(bodyId, vec, impulse.wake);
|
|
44
46
|
}
|
|
45
|
-
|
|
47
|
+
engine.pendingLinearImpulse.clear();
|
|
46
48
|
}
|
|
47
|
-
function drainAngularImpulses(
|
|
48
|
-
for (const [bodyId, impulse] of
|
|
49
|
-
if (!
|
|
49
|
+
function drainAngularImpulses(engine) {
|
|
50
|
+
for (const [bodyId, impulse] of engine.pendingAngularImpulse) {
|
|
51
|
+
if (!engine.entityByBodyIndex.has(bodyId.index1)) {
|
|
50
52
|
continue;
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
engine.box2d.b2Body_ApplyAngularImpulse(bodyId, impulse.value, impulse.wake);
|
|
53
55
|
}
|
|
54
|
-
|
|
56
|
+
engine.pendingAngularImpulse.clear();
|
|
55
57
|
}
|
|
56
|
-
function getLinearAccumulator(
|
|
57
|
-
let accumulator =
|
|
58
|
+
function getLinearAccumulator(engine, bodyId) {
|
|
59
|
+
let accumulator = engine.pendingLinearImpulse.get(bodyId);
|
|
58
60
|
if (accumulator === undefined) {
|
|
59
61
|
accumulator = { x: 0, y: 0, wake: false };
|
|
60
|
-
|
|
62
|
+
engine.pendingLinearImpulse.set(bodyId, accumulator);
|
|
61
63
|
}
|
|
62
64
|
return accumulator;
|
|
63
65
|
}
|
|
64
|
-
function getAngularAccumulator(
|
|
65
|
-
let accumulator =
|
|
66
|
+
function getAngularAccumulator(engine, bodyId) {
|
|
67
|
+
let accumulator = engine.pendingAngularImpulse.get(bodyId);
|
|
66
68
|
if (accumulator === undefined) {
|
|
67
69
|
accumulator = { value: 0, wake: false };
|
|
68
|
-
|
|
70
|
+
engine.pendingAngularImpulse.set(bodyId, accumulator);
|
|
69
71
|
}
|
|
70
72
|
return accumulator;
|
|
71
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impulse_accumulate.js","sourceRoot":"","sources":["../../../../src/systems/impulse_accumulate.ts"],"names":[],"mappings":"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Entity, type World } from "@vworlds/vecs";
|
|
2
|
-
import { type
|
|
3
|
-
export declare function installImpulseZero(world: World,
|
|
2
|
+
import { type PhysicsEngine } from "../adapter/engine.js";
|
|
3
|
+
export declare function installImpulseZero(world: World, engine: PhysicsEngine, phase: Entity): void;
|
package/systems/impulse_zero.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AngularImpulse, Impulse } from "../components/force.js";
|
|
2
|
-
import { PhysicsSystemTag } from "../adapter/
|
|
3
|
-
export function installImpulseZero(world,
|
|
2
|
+
import { PhysicsSystemTag } from "../adapter/engine.js";
|
|
3
|
+
export function installImpulseZero(world, engine, phase) {
|
|
4
4
|
const system = world
|
|
5
5
|
.system("PhysicsImpulseZero")
|
|
6
6
|
.phase(phase)
|
|
7
7
|
.run(() => {
|
|
8
|
-
for (const eid of
|
|
8
|
+
for (const eid of engine.impulseEntitiesThisStep) {
|
|
9
9
|
const entity = world.getEntity(eid);
|
|
10
10
|
if (entity === undefined) {
|
|
11
11
|
continue;
|
|
@@ -20,7 +20,7 @@ export function installImpulseZero(world, state, phase) {
|
|
|
20
20
|
ai.value = 0;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
engine.impulseEntitiesThisStep.clear();
|
|
24
24
|
});
|
|
25
25
|
system.entity.add(PhysicsSystemTag);
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impulse_zero.js","sourceRoot":"","sources":["../../../../src/systems/impulse_zero.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"impulse_zero.js","sourceRoot":"","sources":["../../../../src/systems/impulse_zero.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAsB,MAAM,sBAAsB,CAAC;AAE5E,MAAM,UAAU,kBAAkB,CAAC,KAAY,EAAE,MAAqB,EAAE,KAAa;IACnF,MAAM,MAAM,GAAG,KAAK;SACjB,MAAM,CAAC,oBAAoB,CAAC;SAC5B,KAAK,CAAC,KAAK,CAAC;SACZ,GAAG,CAAC,GAAG,EAAE;QACR,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,uBAAuB,EAAE,CAAC;YACjD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,SAAS;YACX,CAAC;YAED,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAwB,CAAC;YACvD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACtB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;gBACV,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YACZ,CAAC;YAED,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAA+B,CAAC;YACpE,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;gBACrB,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC;YACf,CAAC;QACH,CAAC;QAED,MAAM,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;IACL,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AACtC,CAAC"}
|
package/systems/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Entity, type World } from "@vworlds/vecs";
|
|
2
|
-
import { type
|
|
2
|
+
import { type PhysicsEngine } from "../adapter/engine.js";
|
|
3
3
|
/** The three phases the physics systems split across. */
|
|
4
4
|
export interface PhysicsPhases {
|
|
5
5
|
preStep: Entity;
|
|
@@ -11,5 +11,5 @@ export interface PhysicsSystemsOptions {
|
|
|
11
11
|
/** Install `PhysicsDebugValidation` when `true`. Default `false`. */
|
|
12
12
|
debug?: boolean;
|
|
13
13
|
}
|
|
14
|
-
/** Register every physics system into `world`, bound to `
|
|
15
|
-
export declare function registerPhysicsSystems(world: World,
|
|
14
|
+
/** Register every physics system into `world`, bound to `engine`. */
|
|
15
|
+
export declare function registerPhysicsSystems(world: World, engine: PhysicsEngine, phases: PhysicsPhases, opts?: PhysicsSystemsOptions): void;
|
package/systems/index.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
// Physics system installation. Creates all physics systems in their canonical
|
|
2
2
|
// run order and tags each one with `PhysicsSystemTag` so the pose-sync feedback
|
|
3
3
|
// suppression (`PhysicsPoseSyncIn.ignoreSource([PhysicsSystemTag])`) can filter
|
|
4
|
-
// the engine's own write-back. This is registration step 12 (
|
|
4
|
+
// the engine's own write-back. This is registration step 12 (ARCHITECTURE.md →
|
|
5
5
|
// _Component registration order_).
|
|
6
6
|
//
|
|
7
7
|
// Physics-pre phase order (creation order = run order within a phase):
|
|
8
8
|
// 1. PhysicsBodyLifecycle — body must exist before any shape is inserted
|
|
9
|
-
// 2. PhysicsShapeLifecycle — creates/destroys
|
|
10
|
-
// 3.
|
|
11
|
-
// 4.
|
|
12
|
-
// 5.
|
|
13
|
-
// 6.
|
|
14
|
-
// 7.
|
|
15
|
-
// 8.
|
|
16
|
-
// 9.
|
|
17
|
-
// 10.
|
|
18
|
-
// 11.
|
|
9
|
+
// 2. PhysicsShapeLifecycle — creates/destroys b2Shape records + broad-phase proxies
|
|
10
|
+
// 3. PhysicsChainLifecycle — creates/destroys b2Chain records + segment proxies
|
|
11
|
+
// 4. PhysicsMaterialFilterSync — propagates Material/Filter/Sensor updates
|
|
12
|
+
// 5. PhysicsEventOptInSync — runtime ContactEvents/HitEvents/SensorEvents add/remove (hooks)
|
|
13
|
+
// 6. PhysicsShapePoseSync — propagates ShapePosition/ShapeRotation updates
|
|
14
|
+
// 7. PhysicsPoseSyncIn — syncs Position/Rotation/Velocity into body sims
|
|
15
|
+
// 8. PhysicsKinematicTargets — sets target-convergence velocity on kinematic bodies (VP-20)
|
|
16
|
+
// 9. PhysicsForceGather:* — applies Force and Torque to body sims each step (VP-19)
|
|
17
|
+
// 10. PhysicsImpulseAccumulate — drains Impulse/AngularImpulse into pendingImpulses (VP-19)
|
|
18
|
+
// 11. PhysicsMassRecompute — recomputes mass for dirty bodies (last pre-step)
|
|
19
|
+
// 12. PhysicsDebugValidation — structural validation (ONLY when debug: true, VP-25)
|
|
19
20
|
//
|
|
20
21
|
// Physics-post phase order:
|
|
21
22
|
// 1. PhysicsPoseSyncOut — write simulated pose back to ECS
|
|
22
23
|
// 2. PhysicsEvents — fan raw event arrays out to ContactEvents/SensorEvents/HitEvents (VP-21b)
|
|
23
24
|
// 3. PhysicsImpulseZero — silently zero consumed Impulse/AngularImpulse (VP-19)
|
|
25
|
+
import { installChainLifecycle } from "./chain_lifecycle.js";
|
|
24
26
|
import { installDebugValidation } from "./debug.js";
|
|
25
27
|
import { installEventOptInSync } from "./event_opt_in_sync.js";
|
|
26
28
|
import { installEvents } from "./events.js";
|
|
@@ -36,37 +38,38 @@ import { installPoseSyncOut } from "./pose_sync_out.js";
|
|
|
36
38
|
import { installShapeLifecycle } from "./shape_lifecycle.js";
|
|
37
39
|
import { installShapePoseSync } from "./shape_pose_sync.js";
|
|
38
40
|
import { installStep } from "./step.js";
|
|
39
|
-
/** Register every physics system into `world`, bound to `
|
|
40
|
-
export function registerPhysicsSystems(world,
|
|
41
|
+
/** Register every physics system into `world`, bound to `engine`. */
|
|
42
|
+
export function registerPhysicsSystems(world, engine, phases, opts = {}) {
|
|
41
43
|
// physics-pre: lifecycle + sync systems in dependency order.
|
|
42
|
-
installBodyLifecycle(world,
|
|
43
|
-
installShapeLifecycle(world,
|
|
44
|
-
|
|
44
|
+
installBodyLifecycle(world, engine, phases.preStep);
|
|
45
|
+
installShapeLifecycle(world, engine, phases.preStep);
|
|
46
|
+
installChainLifecycle(world, engine, phases.preStep);
|
|
47
|
+
installMaterialFilterSync(world, engine, phases.preStep);
|
|
45
48
|
// physics-pre: keep event opt-in flags in sync when ContactEvents/HitEvents/
|
|
46
49
|
// SensorEvents are added/removed on a shape after creation (hook-based).
|
|
47
|
-
installEventOptInSync(world,
|
|
48
|
-
installShapePoseSync(world,
|
|
49
|
-
installPoseSyncIn(world,
|
|
50
|
+
installEventOptInSync(world, engine, phases.preStep);
|
|
51
|
+
installShapePoseSync(world, engine, phases.preStep);
|
|
52
|
+
installPoseSyncIn(world, engine, phases.preStep);
|
|
50
53
|
// physics-pre: kinematic target drive after PoseSyncIn, before ForceGather (VP-20).
|
|
51
|
-
installKinematicTargets(world,
|
|
54
|
+
installKinematicTargets(world, engine, phases.preStep);
|
|
52
55
|
// physics-pre: force/impulse systems after KinematicTargets, before MassRecompute (VP-19).
|
|
53
|
-
installForceGather(world,
|
|
54
|
-
installImpulseAccumulate(world,
|
|
56
|
+
installForceGather(world, engine, phases.preStep);
|
|
57
|
+
installImpulseAccumulate(world, engine, phases.preStep);
|
|
55
58
|
// physics-pre: mass recompute — last pre-step, after all lifecycle/sync/force.
|
|
56
|
-
installMassRecompute(world,
|
|
59
|
+
installMassRecompute(world, engine, phases.preStep);
|
|
57
60
|
// physics-step: integrator.
|
|
58
|
-
installStep(world,
|
|
61
|
+
installStep(world, engine, phases.step);
|
|
59
62
|
// physics-post: write simulated pose back to ECS.
|
|
60
|
-
installPoseSyncOut(world,
|
|
63
|
+
installPoseSyncOut(world, engine, phases.postStep);
|
|
61
64
|
// physics-post: fan raw event arrays out to ECS event components (VP-21b).
|
|
62
65
|
// Must run AFTER PoseSyncOut (so positions are up to date) and BEFORE ImpulseZero.
|
|
63
|
-
installEvents(world,
|
|
66
|
+
installEvents(world, engine, phases.postStep);
|
|
64
67
|
// physics-post: silently zero consumed Impulse/AngularImpulse (last in post).
|
|
65
|
-
installImpulseZero(world,
|
|
68
|
+
installImpulseZero(world, engine, phases.postStep);
|
|
66
69
|
// physics-pre: debug validation — LAST in physics-pre, ONLY when debug: true.
|
|
67
70
|
// Runs after all lifecycle/sync/mass so the world is fully wired for the step.
|
|
68
71
|
if (opts.debug === true) {
|
|
69
|
-
installDebugValidation(world,
|
|
72
|
+
installDebugValidation(world, engine, phases.preStep);
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
//# sourceMappingURL=index.js.map
|
package/systems/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/systems/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,gFAAgF;AAChF
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/systems/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,mCAAmC;AACnC,EAAE;AACF,uEAAuE;AACvE,gFAAgF;AAChF,0FAA0F;AAC1F,sFAAsF;AACtF,6EAA6E;AAC7E,mGAAmG;AACnG,kFAAkF;AAClF,mFAAmF;AACnF,gGAAgG;AAChG,2FAA2F;AAC3F,8FAA8F;AAC9F,oFAAoF;AACpF,wFAAwF;AACxF,EAAE;AACF,4BAA4B;AAC5B,8DAA8D;AAC9D,uGAAuG;AACvG,mFAAmF;AAKnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC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M,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAClD,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxD,+EAA+E;IAC/E,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACpD,4BAA4B;IAC5B,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACxC,kDAAkD;IAClD,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnD,2EAA2E;IAC3E,mFAAmF;IACnF,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC9C,8EAA8E;IAC9E,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEnD,8EAA8E;IAC9E,+EAA+E;IAC/E,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QACxB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;AACH,CAAC"}
|
package/systems/kinematic.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type Entity, type World } from "@vworlds/vecs";
|
|
2
|
-
import { type
|
|
3
|
-
export declare function installKinematicTargets(world: World,
|
|
2
|
+
import { type PhysicsEngine } from "../adapter/engine.js";
|
|
3
|
+
export declare function installKinematicTargets(world: World, engine: PhysicsEngine, phase: Entity): void;
|