@daneren2005/shared-memory-physics 1.4.0 → 1.5.0
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 +73 -8
- package/dist/components/body-component.d.ts +3 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +355 -213
- package/dist/index.js.map +1 -1
- package/dist/systems/collision.d.ts +18 -0
- package/dist/systems/physics-system.d.ts +3 -1
- package/dist/systems/physics-update.d.ts +13 -1
- package/dist/systems/spatial-bounds.d.ts +13 -0
- package/dist/world.d.ts +30 -0
- package/package.json +4 -4
|
@@ -24,6 +24,19 @@ export interface MoveResult<T extends PhysicsUpdateComponents> {
|
|
|
24
24
|
moveY: number;
|
|
25
25
|
blocking: Array<CollisionEntity<T>>;
|
|
26
26
|
}
|
|
27
|
+
interface ContactSource {
|
|
28
|
+
entityId: number;
|
|
29
|
+
components: {
|
|
30
|
+
transform: Float32Array;
|
|
31
|
+
body?: Uint32Array;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface ContactTarget {
|
|
35
|
+
components: {
|
|
36
|
+
transform: Float32Array;
|
|
37
|
+
body: Uint32Array;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
27
40
|
export default class CollisionBroadphase<T extends PhysicsUpdateComponents> {
|
|
28
41
|
private buckets;
|
|
29
42
|
readonly hasBounciness: boolean;
|
|
@@ -34,6 +47,10 @@ export default class CollisionBroadphase<T extends PhysicsUpdateComponents> {
|
|
|
34
47
|
}>, seconds: number);
|
|
35
48
|
claimContact(a: number, b: number): boolean;
|
|
36
49
|
forEachOverlapping(self: MovingEntity<T>, handle: (other: CollisionEntity<T>) => void, moveX?: number, moveY?: number): void;
|
|
50
|
+
contactPoint(self: ContactSource, other: ContactTarget, moveX: number, moveY: number): {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
};
|
|
37
54
|
sweep(self: MovingEntity<T>, moveX: number, moveY: number): SweepResult<T>;
|
|
38
55
|
resolveMove(self: MovingEntity<T>, moveX: number, moveY: number, slide: boolean): MoveResult<T>;
|
|
39
56
|
private gatherCandidates;
|
|
@@ -45,3 +62,4 @@ export default class CollisionBroadphase<T extends PhysicsUpdateComponents> {
|
|
|
45
62
|
private blockedAt;
|
|
46
63
|
private forEachCandidate;
|
|
47
64
|
}
|
|
65
|
+
export {};
|
|
@@ -3,6 +3,7 @@ import type { BaseEntity, BaseWorld, ComponentDefinitionMap, ComponentMap, Compo
|
|
|
3
3
|
import { type SpawnableEntity } from '../components/interpolation-component';
|
|
4
4
|
import type { PhysicsComponents, PhysicsUpdateComponents } from '../components/registry';
|
|
5
5
|
import { type PhysicsUpdateMetadata, type PhysicsWorld } from './physics-update';
|
|
6
|
+
import { type PhysicalWorldSource } from '../world';
|
|
6
7
|
export declare const DEFAULT_PHYSICS_STEP_MS = 50;
|
|
7
8
|
export interface PhysicsSystemConfig<C extends ComponentMap & PhysicsComponents, T extends PhysicsUpdateComponents & EntityUpdateComponents<C>, W extends PhysicsWorld = PhysicsWorld> extends Partial<SystemConfig> {
|
|
8
9
|
getWorker?: () => Worker;
|
|
@@ -21,10 +22,11 @@ export interface PhysicsSystemConfig<C extends ComponentMap & PhysicsComponents,
|
|
|
21
22
|
skipGroup?: number;
|
|
22
23
|
}
|
|
23
24
|
export default class PhysicsSystem<C extends ComponentMap & PhysicsComponents, T extends PhysicsUpdateComponents & EntityUpdateComponents<C> = PhysicsUpdateComponents & EntityUpdateComponents<C>, W extends PhysicsWorld = PhysicsWorld> extends ComponentSystem<C, T, W> {
|
|
25
|
+
private spatialWorld;
|
|
24
26
|
tick: number;
|
|
25
27
|
reportMoves: boolean | undefined;
|
|
26
28
|
skipGroup: number | undefined;
|
|
27
|
-
constructor(world: BaseWorld<ComponentDefinitionMap, C
|
|
29
|
+
constructor(world: BaseWorld<ComponentDefinitionMap, C> & PhysicalWorldSource, options?: PhysicsSystemConfig<C, T, W>);
|
|
28
30
|
startInterpolation(entity: SpawnableEntity): void;
|
|
29
31
|
addDataToWorld(world: W): void;
|
|
30
32
|
}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import type { ComponentMap, ComponentSystemCallbacks, ComponentSystemWorld, EntityQueryComponents, EntityUpdateComponents, EntityUpdateFunction } from '@daneren2005/shared-memory-ecs';
|
|
2
2
|
import type { PhysicsComponents, PhysicsUpdateComponents } from '../components/registry';
|
|
3
3
|
import { type CollisionFunction } from './collision';
|
|
4
|
-
|
|
4
|
+
import { type SpatialBlockComponents } from './spatial-bounds';
|
|
5
|
+
import { type PhysicalSystemWorld } from '../world';
|
|
6
|
+
export interface PhysicsWorld extends ComponentSystemWorld, PhysicalSystemWorld {
|
|
5
7
|
tick: number;
|
|
6
8
|
reportMoves?: boolean;
|
|
7
9
|
skipGroup?: number;
|
|
10
|
+
dieAtImpact?(dying: DeathInterpolationEntity, other: DeathInterpolationEntity): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function updateSpatialMap(world: PhysicalSystemWorld, entityId: number, components: SpatialBlockComponents): void;
|
|
13
|
+
export interface DeathInterpolationEntity {
|
|
14
|
+
entityId: number;
|
|
15
|
+
components: {
|
|
16
|
+
transform?: Float32Array;
|
|
17
|
+
velocity?: Float32Array;
|
|
18
|
+
body?: Uint32Array;
|
|
19
|
+
};
|
|
8
20
|
}
|
|
9
21
|
export declare const POSITION_UPDATED_EVENT = "position-updated";
|
|
10
22
|
export interface PhysicsUpdateOptions<C extends ComponentMap, T extends PhysicsUpdateComponents & EntityUpdateComponents<C>, W extends PhysicsWorld = PhysicsWorld> {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface SpatialBounds {
|
|
2
|
+
minX: number;
|
|
3
|
+
minY: number;
|
|
4
|
+
maxX: number;
|
|
5
|
+
maxY: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SpatialBlockComponents {
|
|
8
|
+
transform: Float32Array;
|
|
9
|
+
body?: Uint32Array;
|
|
10
|
+
}
|
|
11
|
+
export declare function spatialBounds(components: SpatialBlockComponents): SpatialBounds;
|
|
12
|
+
export declare function boundsOverlap(a: SpatialBounds, minX: number, minY: number, maxX: number, maxY: number): boolean;
|
|
13
|
+
export declare function querySize(min: number, max: number): number;
|
package/dist/world.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import SharedSpatialMap from '@daneren2005/shared-memory-objects/spatial/shared-spatial-map';
|
|
2
|
+
import type { SharedSpatialMapConfig, SharedSpatialMapMemory } from '@daneren2005/shared-memory-objects/spatial/shared-spatial-map';
|
|
3
|
+
import { BaseWorld } from '@daneren2005/shared-memory-ecs';
|
|
4
|
+
import type { BaseEntity, ComponentDefinitionMap, ComponentsOf, ComponentSystemWorld, EntityConfigOf, WorldOptions } from '@daneren2005/shared-memory-ecs';
|
|
5
|
+
export interface PhysicalWorldData {
|
|
6
|
+
spatialMapMemory?: SharedSpatialMapMemory;
|
|
7
|
+
}
|
|
8
|
+
export interface PhysicalSystemWorld extends ComponentSystemWorld, PhysicalWorldData {
|
|
9
|
+
spatialMap?: SharedSpatialMap;
|
|
10
|
+
}
|
|
11
|
+
export interface PhysicalWorldSource {
|
|
12
|
+
spatialMap: SharedSpatialMap;
|
|
13
|
+
}
|
|
14
|
+
export type PhysicalWorldOptions<R extends ComponentDefinitionMap> = WorldOptions<ComponentsOf<R>, EntityConfigOf<R>> & {
|
|
15
|
+
spatial?: SharedSpatialMapConfig;
|
|
16
|
+
};
|
|
17
|
+
export type PhysicalWorldEntity<R extends ComponentDefinitionMap> = BaseEntity<ComponentsOf<R>, EntityConfigOf<R>>;
|
|
18
|
+
export type PhysicalWorldFilter<R extends ComponentDefinitionMap> = (entity: PhysicalWorldEntity<R>) => boolean;
|
|
19
|
+
export declare function addPhysicalWorldData(source: PhysicalWorldSource, target: PhysicalWorldData): void;
|
|
20
|
+
export declare function getSpatialMap(world: PhysicalSystemWorld): SharedSpatialMap;
|
|
21
|
+
export default class PhysicalWorld<R extends ComponentDefinitionMap> extends BaseWorld<R> implements PhysicalWorldSource {
|
|
22
|
+
readonly spatialMap: SharedSpatialMap;
|
|
23
|
+
private spatialIds;
|
|
24
|
+
constructor(registry: R, options?: PhysicalWorldOptions<R>);
|
|
25
|
+
updateSpatialEntity(entityOrId: PhysicalWorldEntity<R> | number): void;
|
|
26
|
+
searchSpatial(minX: number, minY: number, maxX: number, maxY: number, filter?: PhysicalWorldFilter<R>): Array<PhysicalWorldEntity<R>>;
|
|
27
|
+
searchSpatialAround(x: number, y: number, reachX: number, reachY: number, filter?: PhysicalWorldFilter<R>): Array<PhysicalWorldEntity<R>>;
|
|
28
|
+
findNearestSpatial(x: number, y: number, maxDistance?: number, filter?: PhysicalWorldFilter<R>): PhysicalWorldEntity<R> | undefined;
|
|
29
|
+
findNearbySpatial(x: number, y: number, maxResults: number, maxDistance?: number, filter?: PhysicalWorldFilter<R>): Array<PhysicalWorldEntity<R>>;
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@daneren2005/shared-memory-physics",
|
|
3
3
|
"description": "2D physics components and systems built on the shared-memory ECS.",
|
|
4
4
|
"author": "Scott Jackson",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.5.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"repository": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"prepare": "husky"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@daneren2005/shared-memory-ecs": "^1.5.
|
|
44
|
-
"@daneren2005/shared-memory-objects": "^1.
|
|
43
|
+
"@daneren2005/shared-memory-ecs": "^1.5.1",
|
|
44
|
+
"@daneren2005/shared-memory-objects": "^1.5.0",
|
|
45
45
|
"@semantic-release/git": "^10.0.1",
|
|
46
46
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
47
47
|
"@types/node": "^26.1.1",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"vitest": "^4.1.10"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@daneren2005/shared-memory-ecs": "^1.
|
|
61
|
+
"@daneren2005/shared-memory-ecs": "^1.5.1",
|
|
62
62
|
"@daneren2005/shared-memory-objects": "^1.1.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|