@daneren2005/shared-memory-physics 0.0.1 → 1.1.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 +297 -27
- package/dist/components/interpolation-component.d.ts +32 -0
- package/dist/components/registry.d.ts +12 -0
- package/dist/index.d.ts +13 -5
- package/dist/index.js +230 -117
- package/dist/index.js.map +1 -1
- package/dist/math/shapes.d.ts +0 -1
- package/dist/systems/interpolation-system.d.ts +10 -0
- package/dist/systems/interpolation-update.d.ts +4 -0
- package/dist/systems/physics-system.d.ts +9 -4
- package/dist/systems/physics-update.d.ts +9 -4
- package/dist/systems/spatial-index.d.ts +23 -0
- package/package.json +6 -2
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { ComponentMap, ComponentSystemWorld, EntityUpdateComponents, EntityUpdateFunction } from '@daneren2005/shared-memory-ecs';
|
|
2
2
|
import type { PhysicsComponents, PhysicsUpdateComponents } from '../components/registry';
|
|
3
3
|
import { type CollisionFunction } from './collision';
|
|
4
|
-
export interface
|
|
4
|
+
export interface PhysicsWorld extends ComponentSystemWorld {
|
|
5
|
+
tick: number;
|
|
6
|
+
reportMoves?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const POSITION_UPDATED_EVENT = "position-updated";
|
|
9
|
+
export interface PhysicsUpdateOptions<C extends ComponentMap, T extends PhysicsUpdateComponents & EntityUpdateComponents<C>, W extends PhysicsWorld = PhysicsWorld> {
|
|
5
10
|
onCollision?: CollisionFunction<C, T, W>;
|
|
6
11
|
optional?: Array<keyof C & string>;
|
|
7
12
|
}
|
|
@@ -9,9 +14,9 @@ export interface PhysicsUpdateMetadata<C extends ComponentMap> {
|
|
|
9
14
|
collision: boolean;
|
|
10
15
|
optional: Array<keyof C & string>;
|
|
11
16
|
}
|
|
12
|
-
export type PhysicsUpdateFunction<C extends ComponentMap, T extends PhysicsUpdateComponents & EntityUpdateComponents<C>, W extends
|
|
17
|
+
export type PhysicsUpdateFunction<C extends ComponentMap, T extends PhysicsUpdateComponents & EntityUpdateComponents<C>, W extends PhysicsWorld = PhysicsWorld> = EntityUpdateFunction<C, T, W> & {
|
|
13
18
|
physics: PhysicsUpdateMetadata<C>;
|
|
14
19
|
};
|
|
15
|
-
export declare function createPhysicsUpdate<C extends ComponentMap & PhysicsComponents = PhysicsComponents, T extends PhysicsUpdateComponents & EntityUpdateComponents<C> = PhysicsUpdateComponents & EntityUpdateComponents<C>, W extends
|
|
16
|
-
export declare const physicsUpdate: EntityUpdateFunction<PhysicsComponents, PhysicsUpdateComponents>;
|
|
20
|
+
export declare function createPhysicsUpdate<C extends ComponentMap & PhysicsComponents = PhysicsComponents, T extends PhysicsUpdateComponents & EntityUpdateComponents<C> = PhysicsUpdateComponents & EntityUpdateComponents<C>, W extends PhysicsWorld = PhysicsWorld>(options?: PhysicsUpdateOptions<C, T, W>): PhysicsUpdateFunction<C, T, W>;
|
|
21
|
+
export declare const physicsUpdate: EntityUpdateFunction<PhysicsComponents, PhysicsUpdateComponents, PhysicsWorld>;
|
|
17
22
|
export default physicsUpdate;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { EntityUpdateComponents } from '@daneren2005/shared-memory-ecs';
|
|
2
|
+
export type SpatialComponents = {
|
|
3
|
+
transform: Float32Array;
|
|
4
|
+
body?: Uint32Array;
|
|
5
|
+
};
|
|
6
|
+
export interface SpatialEntity<T extends SpatialComponents = SpatialComponents> {
|
|
7
|
+
entityId: number;
|
|
8
|
+
components: T;
|
|
9
|
+
}
|
|
10
|
+
export type SpatialFilter<T extends SpatialComponents = SpatialComponents> = (entity: SpatialEntity<T>) => boolean;
|
|
11
|
+
export default class SpatialIndex<T extends SpatialComponents = SpatialComponents> {
|
|
12
|
+
private entries;
|
|
13
|
+
private index;
|
|
14
|
+
constructor(entities: Iterable<{
|
|
15
|
+
entityId: number;
|
|
16
|
+
components: EntityUpdateComponents;
|
|
17
|
+
}>);
|
|
18
|
+
get size(): number;
|
|
19
|
+
search(minX: number, minY: number, maxX: number, maxY: number, filter?: SpatialFilter<T>): Array<SpatialEntity<T>>;
|
|
20
|
+
searchAround(x: number, y: number, reachX: number, reachY: number, filter?: SpatialFilter<T>): Array<SpatialEntity<T>>;
|
|
21
|
+
findNearest(x: number, y: number, maxDistance?: number, filter?: SpatialFilter<T>): SpatialEntity<T> | undefined;
|
|
22
|
+
findNearby(x: number, y: number, maxResults: number, maxDistance?: number, filter?: SpatialFilter<T>): Array<SpatialEntity<T>>;
|
|
23
|
+
}
|
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": "
|
|
5
|
+
"version": "1.1.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -26,7 +26,10 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
|
+
"start": "vite --config examples/vite.config.ts",
|
|
29
30
|
"build": "vite build && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
31
|
+
"build:examples": "vite build --config examples/vite.config.ts",
|
|
32
|
+
"preview:examples": "vite preview --config examples/vite.config.ts",
|
|
30
33
|
"type-check": "tsc --noEmit",
|
|
31
34
|
"lint": "cross-env NODE_ENV=production oxlint .",
|
|
32
35
|
"lint:fix": "cross-env NODE_ENV=production oxlint --fix .",
|
|
@@ -35,7 +38,7 @@
|
|
|
35
38
|
"prepare": "husky"
|
|
36
39
|
},
|
|
37
40
|
"devDependencies": {
|
|
38
|
-
"@daneren2005/shared-memory-ecs": "^1.
|
|
41
|
+
"@daneren2005/shared-memory-ecs": "^1.2.1",
|
|
39
42
|
"@daneren2005/shared-memory-objects": "^1.0.0",
|
|
40
43
|
"@semantic-release/git": "^10.0.1",
|
|
41
44
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
@@ -46,6 +49,7 @@
|
|
|
46
49
|
"lint-staged": "^17.0.8",
|
|
47
50
|
"oxlint": "^1.76.0",
|
|
48
51
|
"oxlint-tsgolint": "^7.0.2001",
|
|
52
|
+
"phaser": "^4.2.1",
|
|
49
53
|
"semantic-release": "^25.0.6",
|
|
50
54
|
"typescript": "^7.0.2",
|
|
51
55
|
"vite": "^8.1.4",
|