@daneren2005/shared-memory-physics 1.2.1 → 1.2.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/README.md CHANGED
@@ -85,10 +85,17 @@ exactly still counts as **not** overlapping, whichever pair it is, and a shape w
85
85
  anything. Which of the two sizes decides that depends on the shape: a circle with no height is a perfectly
86
86
  good circle, while a rectangle with no height is nothing at all.
87
87
 
88
+ `contactNormal` answers the other half of a contact: the unit direction one shape is pushed off the other,
89
+ written into a `{ x, y }` you pass in, and `false` when the two are exactly on top of each other and there is no
90
+ such direction. It splits the same three ways off the same geometry, so the direction is the face that was
91
+ actually hit at the angle the pair is turned to - not the nearest world axis. This is what the native bounce
92
+ reflects around; a game reaching for its own response can use it the same way.
93
+
88
94
  `shapesOverlap` is exported, along with `shapeHalfWidth` / `shapeHalfHeight` (the axis-aligned box a shape is
89
95
  indexed under), `shapeRadius`, `shapeIsEmpty`, `capsuleHalfLength`, and the distance primitives underneath -
90
- `segmentSegmentDistanceSquared`, `segmentBoxDistanceSquared` and `pointSegmentDistanceSquared`.
91
- `orientedBoxesOverlap`, `boundsHalfWidth` and `boundsHalfHeight` are still there and still rectangle-only.
96
+ `segmentSegmentDistanceSquared`, `segmentBoxDistanceSquared` and `pointSegmentDistanceSquared`, each of which
97
+ takes an optional `out` vector and fills it with the gap it measured. `orientedBoxesOverlap`, `boundsHalfWidth`
98
+ and `boundsHalfHeight` are still there and still rectangle-only.
92
99
 
93
100
  ## Registering
94
101
 
@@ -401,11 +408,13 @@ world.addSystem(new PhysicsSystem<Components, GameUpdateComponents>(world, {
401
408
  `createPhysicsUpdate` stamps what it needs onto the function it returns, so `optional` and the collidable
402
409
  query come across with `updateFunction` and never have to be repeated on the system.
403
410
 
404
- **Per entity, not per pair.** The callback fires for the entity that *moved*, once for each thing it ended up
405
- on top of. `self` is that entity, with every block the system asked for; `other` is what it hit, where only
406
- `transform` is guaranteed. Two moving entities that run into each other therefore get one call each with the
407
- roles swapped - which is what lets a callback act on itself and leave the other side to its own call. An
408
- entity with no velocity is never `self`, because the system never moves it, but it is still found as `other`.
411
+ **Once per pair, per run.** Both sides of a contact find it - one by sweeping into it, the other by overlapping
412
+ it on its own turn - and the callback fires once, for whichever got there first. `self` is that entity, with
413
+ every block the system asked for; `other` is the one it hit, where only `transform` is guaranteed. **The other
414
+ side gets no call of its own**, so a callback that only touches `self` leaves it untouched: apply damage, tag a
415
+ kill, or raise an event for *both* entities in the one call. Which of the two is `self` follows update order
416
+ and is not something to depend on. An entity with no velocity is never `self`, because the system never moves
417
+ it, but it is still found as `other`.
409
418
 
410
419
  Writes go straight into shared memory, so a callback can bounce an entity by flipping its velocity, or push a
411
420
  value another thread also touches with the atomics from `@daneren2005/shared-memory-objects`. To reach past
@@ -600,8 +609,8 @@ npm start # http://127.0.0.1:8080
600
609
  ```
601
610
 
602
611
  - **Bouncing circles** - circles with a random position and heading, reflected off each other and off the
603
- walls by an `onCollision` that mirrors the velocity about the contact normal.
604
- - **Bouncing rectangles** - the same, on boxes of random width and height, where the normal is the axis the
612
+ walls by the native bounce, which mirrors the velocity about the contact normal.
613
+ - **Bouncing rectangles** - the same, on boxes of random width and height, where the normal is the face the
605
614
  two are least through each other on rather than the line between their centres.
606
615
  - **Walking into a wall** - one unit between two boxes, turned around on a timer so it presses into each of
607
616
  them in turn. It starts on a deliberately long 100ms physics step, so turning **interpolate rendering** off is
@@ -27,6 +27,7 @@ export type PhysicsUpdateComponents = {
27
27
  body?: Uint32Array;
28
28
  bounciness?: Float32Array;
29
29
  interpolation?: Float32Array;
30
+ entity?: Uint32Array;
30
31
  };
31
32
  export type InterpolationUpdateComponents = {
32
33
  transform: Float32Array;
package/dist/index.d.ts CHANGED
@@ -15,7 +15,8 @@ export { INTERPOLATION_X_INDEX, INTERPOLATION_Y_INDEX, INTERPOLATION_PREV_X_INDE
15
15
  export type { InterpolationComponent, InterpolationConfig, SnappableEntity, } from './components/interpolation-component';
16
16
  export { physicsRegistry } from './components/registry';
17
17
  export type { PhysicsComponents, PhysicsUpdateComponents, InterpolationComponents, InterpolationUpdateComponents, } from './components/registry';
18
- export { shapesOverlap, shapeHalfWidth, shapeHalfHeight, shapeIsEmpty, shapeRadius, capsuleHalfLength, boundsHalfWidth, boundsHalfHeight, orientedBoxesOverlap, segmentSegmentDistanceSquared, segmentBoxDistanceSquared, pointSegmentDistanceSquared, } from './math/shapes';
18
+ export { shapesOverlap, contactNormal, shapeHalfWidth, shapeHalfHeight, shapeIsEmpty, shapeRadius, capsuleHalfLength, boundsHalfWidth, boundsHalfHeight, orientedBoxesOverlap, segmentSegmentDistanceSquared, segmentBoxDistanceSquared, pointSegmentDistanceSquared, } from './math/shapes';
19
+ export type { Vector } from './math/shapes';
19
20
  export { default as CollisionBroadphase, COLLIDABLE_QUERY } from './systems/collision';
20
21
  export type { CollisionComponents, CollisionEntity, CollisionFunction, MoveResult, MovingEntity, SweepResult } from './systems/collision';
21
22
  export { default as SpatialIndex } from './systems/spatial-index';