@daneren2005/shared-memory-physics 1.7.0 → 1.7.1

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
@@ -348,10 +348,15 @@ world.addSystem(new InterpolationSystem<Components>(world));
348
348
  world.loadEntity({ x: 0, y: 0, width: 10, height: 10, velocityX: 100, interpolate: true });
349
349
  ```
350
350
 
351
- It takes no configuration and is not wired to the physics system. Physics publishes the transform, step
352
- duration, cumulative simulated time, and a tick stamp. Rendering caches each coherent target and its timing.
353
- If it catches physics mid-write, it continues consuming the cached segment until another complete snapshot
354
- is available.
351
+ It takes no configuration. Physics publishes the transform, step duration, cumulative simulated time, and a tick
352
+ stamp. Rendering caches each coherent target and its timing. If it catches physics mid-write, it continues
353
+ consuming the cached segment until another complete snapshot is available.
354
+
355
+ A worker publishes a run entity by entity while the main thread renders, so one frame can find some entities of a
356
+ run at its new step and the rest at the old one - two ships flying in formation would then drift apart on screen.
357
+ Each entity therefore keeps the publication it replaced, and `InterpolationSystem` snapshots every
358
+ `PhysicsSystem`'s committed tick once per frame: a publication newer than its run's commit is drawn from the
359
+ previous one until the whole run has landed. Both systems must share the same world object for this to apply.
355
360
  A game that retunes `deltaBetweenRuns` mid-flight is followed with nothing told to this system.
356
361
 
357
362
  Then draw from `interpolation` instead of `transform`, keeping the size and facing where they have always been:
@@ -489,15 +494,15 @@ spot, as above.
489
494
 
490
495
  The renderer retains the last coherent target while physics publishes a new step, so an overlapping read can keep advancing without freezing a frame.
491
496
 
492
- 44 bytes per interpolated entity, four publication writes per entity per physics step, and a per-frame pass of one
497
+ 68 bytes per interpolated entity, ten publication writes per entity per physics step, and a per-frame pass of one
493
498
  lerp per entity on the main thread - order 0.2ms at 10,000 entities. An entity without the component pays
494
499
  nothing at all. `forceMainThread: false` plus a `getWorker` moves the pass to a worker for worlds large enough
495
500
  that it shows up in a profile, at the price of the render position being one frame stale; because consumers only
496
501
  ever read `interpolation.x`, that is a constructor flag rather than a migration.
497
502
 
498
503
  Physics marks the tick dirty before changing timing and position, then publishes the completed tick with
499
- a release store. The reader accepts a new snapshot only when its tick reads match; otherwise it continues
500
- toward the cached target.
504
+ a release store. The reader accepts a new snapshot only when its tick reads match and its run has committed;
505
+ otherwise it reads the previous publication, and failing that continues toward the cached target.
501
506
 
502
507
  ## Collisions
503
508
 
@@ -14,6 +14,8 @@ export interface InterpolationComponent {
14
14
  targetX: number;
15
15
  targetY: number;
16
16
  syncedStepDuration: number;
17
+ previousX: number;
18
+ previousY: number;
17
19
  }
18
20
  export interface InterpolationConfig {
19
21
  interpolate?: boolean;
@@ -31,7 +33,13 @@ export declare const INTERPOLATION_REMAINING_DURATION_INDEX = 7;
31
33
  export declare const INTERPOLATION_TARGET_X_INDEX = 8;
32
34
  export declare const INTERPOLATION_TARGET_Y_INDEX = 9;
33
35
  export declare const INTERPOLATION_SYNCED_STEP_DURATION_INDEX = 10;
34
- export declare const INTERPOLATION_SIZE = 11;
36
+ export declare const INTERPOLATION_CHANNEL_INDEX = 11;
37
+ export declare const INTERPOLATION_PREVIOUS_X_INDEX = 12;
38
+ export declare const INTERPOLATION_PREVIOUS_Y_INDEX = 13;
39
+ export declare const INTERPOLATION_PREVIOUS_DURATION_INDEX = 14;
40
+ export declare const INTERPOLATION_PREVIOUS_TOTAL_DURATION_INDEX = 15;
41
+ export declare const INTERPOLATION_PREVIOUS_TICK_INDEX = 16;
42
+ export declare const INTERPOLATION_SIZE = 17;
35
43
  export declare const interpolationDefinition: ComponentDefinition<InterpolationComponent, Float32Array, InterpolationConfig>;
36
44
  export interface SnappableEntity {
37
45
  components: {
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export { default as bouncinessDefinition } from './components/bounciness-compone
17
17
  export { BOUNCINESS_INDEX, BOUNCINESS_SIZE, } from './components/bounciness-component';
18
18
  export type { BouncinessComponent, BouncinessConfig, } from './components/bounciness-component';
19
19
  export { default as interpolationDefinition, snapEntity, startSpawnInterpolation } from './components/interpolation-component';
20
- export { INTERPOLATION_X_INDEX, INTERPOLATION_Y_INDEX, INTERPOLATION_SYNCED_TICK_INDEX, INTERPOLATION_DURATION_INDEX, INTERPOLATION_TICK_INDEX, INTERPOLATION_TOTAL_DURATION_INDEX, INTERPOLATION_SYNCED_DURATION_INDEX, INTERPOLATION_REMAINING_DURATION_INDEX, INTERPOLATION_TARGET_X_INDEX, INTERPOLATION_TARGET_Y_INDEX, INTERPOLATION_SYNCED_STEP_DURATION_INDEX, INTERPOLATION_SIZE, } from './components/interpolation-component';
20
+ export { INTERPOLATION_X_INDEX, INTERPOLATION_Y_INDEX, INTERPOLATION_SYNCED_TICK_INDEX, INTERPOLATION_DURATION_INDEX, INTERPOLATION_TICK_INDEX, INTERPOLATION_TOTAL_DURATION_INDEX, INTERPOLATION_SYNCED_DURATION_INDEX, INTERPOLATION_REMAINING_DURATION_INDEX, INTERPOLATION_TARGET_X_INDEX, INTERPOLATION_TARGET_Y_INDEX, INTERPOLATION_SYNCED_STEP_DURATION_INDEX, INTERPOLATION_CHANNEL_INDEX, INTERPOLATION_PREVIOUS_X_INDEX, INTERPOLATION_PREVIOUS_Y_INDEX, INTERPOLATION_PREVIOUS_DURATION_INDEX, INTERPOLATION_PREVIOUS_TOTAL_DURATION_INDEX, INTERPOLATION_PREVIOUS_TICK_INDEX, INTERPOLATION_SIZE, } from './components/interpolation-component';
21
21
  export type { InterpolationComponent, InterpolationConfig, SnappableEntity, SpawnableEntity, SpawnInterpolationOptions, } from './components/interpolation-component';
22
22
  export { physicsRegistry } from './components/registry';
23
23
  export type { PhysicsComponents, PhysicsUpdateComponents, InterpolationComponents, InterpolationUpdateComponents, } from './components/registry';
@@ -37,5 +37,6 @@ export type { PhysicsSystemConfig, VelocityAssignment } from './systems/physics-
37
37
  export { default as integrateDynamics } from './systems/dynamics';
38
38
  export type { DynamicsCommand, DynamicsCommandBuffer, DynamicsCommandQueue, DynamicsCommands, DynamicsWorld } from './systems/dynamics';
39
39
  export { default as interpolationUpdate } from './systems/interpolation-update';
40
+ export type { InterpolationWorld } from './systems/interpolation-update';
40
41
  export { default as InterpolationSystem } from './systems/interpolation-system';
41
42
  export type { InterpolationSystemConfig } from './systems/interpolation-system';