dacha 0.18.0-alpha.0 → 0.18.0-alpha.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/build/contrib/components/collider/index.d.ts +11 -2
- package/build/contrib/components/collider/index.js +23 -0
- package/build/contrib/components/shape/index.d.ts +17 -2
- package/build/contrib/components/shape/index.js +16 -0
- package/build/contrib/systems/camera-system/{service.d.ts → api.d.ts} +4 -4
- package/build/contrib/systems/camera-system/{service.js → api.js} +2 -2
- package/build/contrib/systems/camera-system/index.d.ts +1 -1
- package/build/contrib/systems/camera-system/index.js +1 -1
- package/build/contrib/systems/camera-system/system.d.ts +1 -1
- package/build/contrib/systems/camera-system/system.js +5 -4
- package/build/contrib/systems/index.d.ts +3 -3
- package/build/contrib/systems/index.js +3 -3
- package/build/contrib/systems/mouse-input-system/subsystems/coordinates-projector/index.d.ts +0 -1
- package/build/contrib/systems/mouse-input-system/subsystems/coordinates-projector/index.js +4 -5
- package/build/contrib/systems/physics-system/api.d.ts +58 -0
- package/build/contrib/systems/physics-system/api.js +67 -0
- package/build/contrib/systems/physics-system/index.d.ts +2 -20
- package/build/contrib/systems/physics-system/index.js +2 -35
- package/build/contrib/systems/physics-system/physics-system.d.ts +24 -0
- package/build/contrib/systems/physics-system/physics-system.js +47 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-circle-aabb.js +1 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-point-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-point-aabb.js +7 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-ray-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-ray-aabb.js +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-segment-aabb.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-segment-aabb.js +14 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/index.js +6 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-geometry.d.ts +3 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-geometry.js +52 -16
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-geometry.d.ts +3 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-geometry.js +32 -7
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-point-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-point-geometry.js +5 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-ray-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-ray-geometry.js +7 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-segment-geometry.d.ts +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-segment-geometry.js +33 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.d.ts +12 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.js +6 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/index.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/index.js +76 -5
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.js +1 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/utils.d.ts +0 -6
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/utils.js +3 -20
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.js +1 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.js +28 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/utils.d.ts +19 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/utils.js +76 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.js +2 -4
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.js +33 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.js +24 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.js +36 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.js +33 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.js +26 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-box/check-ray-and-box-intersection.d.ts +11 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-box/check-ray-and-box-intersection.js +69 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-circle/check-ray-and-circle-intersection.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-circle/check-ray-and-circle-intersection.js +45 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/check-ray-and-segment-intersection.d.ts +16 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/check-ray-and-segment-intersection.js +51 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/utils.d.ts +2 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/utils.js +4 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.d.ts +5 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.js +41 -38
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/utils.d.ts +5 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/utils.js +14 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.js +63 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/reorientation-checkers/check-collider.js +13 -7
- package/build/contrib/systems/physics-system/subsystems/collision-detection/types.d.ts +31 -10
- package/build/contrib/systems/physics-system/types.d.ts +28 -0
- package/build/contrib/systems/renderer/actor-render-tree.js +1 -2
- package/build/contrib/systems/renderer/{service → api}/index.d.ts +6 -6
- package/build/contrib/systems/renderer/{service → api}/index.js +14 -16
- package/build/contrib/systems/renderer/api/utils.d.ts +4 -0
- package/build/contrib/systems/renderer/{service → api}/utils.js +5 -0
- package/build/contrib/systems/renderer/builders/shape-builder/index.js +9 -1
- package/build/contrib/systems/renderer/builders/shape-builder/utils.js +16 -0
- package/build/contrib/systems/renderer/index.d.ts +1 -1
- package/build/contrib/systems/renderer/index.js +1 -1
- package/build/contrib/systems/renderer/renderer.d.ts +2 -1
- package/build/contrib/systems/renderer/renderer.js +9 -7
- package/build/engine/actor/actor-creator.js +6 -4
- package/build/engine/math-lib/math/ops.d.ts +1 -2
- package/build/engine/math-lib/math/ops.js +3 -3
- package/build/engine/math-lib/vector/ops.d.ts +15 -0
- package/build/engine/math-lib/vector/ops.js +20 -0
- package/build/engine/template/template-collection.js +1 -1
- package/build/engine/world/index.d.ts +4 -24
- package/build/engine/world/index.js +5 -33
- package/build/engine/world/system-api-registry.d.ts +17 -0
- package/build/engine/world/system-api-registry.js +34 -0
- package/build/types/global.d.ts +4 -0
- package/package.json +4 -1
- package/build/contrib/systems/renderer/service/utils.d.ts +0 -3
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { Component } from '../../../engine/component';
|
|
2
|
+
import type { Point } from '../../../engine/math-lib';
|
|
2
3
|
export interface ColliderConfig {
|
|
3
|
-
type: 'box' | 'circle';
|
|
4
|
+
type: 'box' | 'circle' | 'segment';
|
|
4
5
|
centerX: number;
|
|
5
6
|
centerY: number;
|
|
6
7
|
sizeX?: number;
|
|
7
8
|
sizeY?: number;
|
|
9
|
+
point1X?: number;
|
|
10
|
+
point1Y?: number;
|
|
11
|
+
point2X?: number;
|
|
12
|
+
point2Y?: number;
|
|
8
13
|
radius?: number;
|
|
9
14
|
layer: string;
|
|
15
|
+
debugColor?: string;
|
|
10
16
|
}
|
|
11
17
|
/**
|
|
12
18
|
* Collider component for defining collision boundaries.
|
|
@@ -42,13 +48,16 @@ export interface ColliderConfig {
|
|
|
42
48
|
* @category Components
|
|
43
49
|
*/
|
|
44
50
|
export declare class Collider extends Component {
|
|
45
|
-
type: 'box' | 'circle';
|
|
51
|
+
type: 'box' | 'circle' | 'segment';
|
|
46
52
|
centerX: number;
|
|
47
53
|
centerY: number;
|
|
48
54
|
sizeX?: number;
|
|
49
55
|
sizeY?: number;
|
|
50
56
|
radius?: number;
|
|
57
|
+
point1?: Point;
|
|
58
|
+
point2?: Point;
|
|
51
59
|
layer: string;
|
|
60
|
+
debugColor?: string;
|
|
52
61
|
constructor(config: ColliderConfig);
|
|
53
62
|
clone(): Collider;
|
|
54
63
|
}
|
|
@@ -39,7 +39,10 @@ export class Collider extends Component {
|
|
|
39
39
|
sizeX;
|
|
40
40
|
sizeY;
|
|
41
41
|
radius;
|
|
42
|
+
point1;
|
|
43
|
+
point2;
|
|
42
44
|
layer;
|
|
45
|
+
debugColor;
|
|
43
46
|
constructor(config) {
|
|
44
47
|
super();
|
|
45
48
|
this.type = config.type;
|
|
@@ -48,7 +51,22 @@ export class Collider extends Component {
|
|
|
48
51
|
this.sizeX = config.sizeX;
|
|
49
52
|
this.sizeY = config.sizeY;
|
|
50
53
|
this.radius = config.radius;
|
|
54
|
+
this.point1 =
|
|
55
|
+
config.point1X !== undefined || config.point1Y !== undefined
|
|
56
|
+
? {
|
|
57
|
+
x: config.point1X ?? 0,
|
|
58
|
+
y: config.point1Y ?? 0,
|
|
59
|
+
}
|
|
60
|
+
: undefined;
|
|
61
|
+
this.point2 =
|
|
62
|
+
config.point2X !== undefined || config.point2Y !== undefined
|
|
63
|
+
? {
|
|
64
|
+
x: config.point2X ?? 0,
|
|
65
|
+
y: config.point2Y ?? 0,
|
|
66
|
+
}
|
|
67
|
+
: undefined;
|
|
51
68
|
this.layer = config.layer;
|
|
69
|
+
this.debugColor = config.debugColor;
|
|
52
70
|
}
|
|
53
71
|
clone() {
|
|
54
72
|
return new Collider({
|
|
@@ -58,7 +76,12 @@ export class Collider extends Component {
|
|
|
58
76
|
sizeX: this.sizeX,
|
|
59
77
|
sizeY: this.sizeY,
|
|
60
78
|
radius: this.radius,
|
|
79
|
+
point1X: this.point1?.x,
|
|
80
|
+
point1Y: this.point1?.y,
|
|
81
|
+
point2X: this.point2?.x,
|
|
82
|
+
point2Y: this.point2?.y,
|
|
61
83
|
layer: this.layer,
|
|
84
|
+
debugColor: this.debugColor,
|
|
62
85
|
});
|
|
63
86
|
}
|
|
64
87
|
}
|
|
@@ -5,7 +5,7 @@ interface RenderData {
|
|
|
5
5
|
view: Graphics;
|
|
6
6
|
graphicsContextKey?: string;
|
|
7
7
|
}
|
|
8
|
-
export type ShapeType = 'rectangle' | 'roundRectangle' | 'circle' | 'ellipse';
|
|
8
|
+
export type ShapeType = 'rectangle' | 'roundRectangle' | 'circle' | 'ellipse' | 'line';
|
|
9
9
|
export interface BaseShape {
|
|
10
10
|
type: ShapeType;
|
|
11
11
|
strokeColor?: string;
|
|
@@ -39,7 +39,14 @@ export interface Ellipse extends BaseShape {
|
|
|
39
39
|
radiusX: number;
|
|
40
40
|
radiusY: number;
|
|
41
41
|
}
|
|
42
|
-
export
|
|
42
|
+
export interface Line extends BaseShape {
|
|
43
|
+
type: 'line';
|
|
44
|
+
point1X: number;
|
|
45
|
+
point1Y: number;
|
|
46
|
+
point2X: number;
|
|
47
|
+
point2Y: number;
|
|
48
|
+
}
|
|
49
|
+
export type ShapeConfig = BaseShape & Partial<Rectangle | RoundRectangle | Circle | Ellipse | Line>;
|
|
43
50
|
/**
|
|
44
51
|
* Shape component for rendering 2D geometry.
|
|
45
52
|
*
|
|
@@ -112,6 +119,14 @@ export declare class Shape extends Component {
|
|
|
112
119
|
radiusX?: number;
|
|
113
120
|
/** Radius Y of the shape */
|
|
114
121
|
radiusY?: number;
|
|
122
|
+
/** Start point X coordinate for line shape */
|
|
123
|
+
point1X?: number;
|
|
124
|
+
/** Start point Y coordinate for line shape */
|
|
125
|
+
point1Y?: number;
|
|
126
|
+
/** End point X coordinate for line shape */
|
|
127
|
+
point2X?: number;
|
|
128
|
+
/** End point Y coordinate for line shape */
|
|
129
|
+
point2Y?: number;
|
|
115
130
|
/** Internal rendering data */
|
|
116
131
|
renderData?: RenderData;
|
|
117
132
|
/**
|
|
@@ -71,6 +71,14 @@ export class Shape extends Component {
|
|
|
71
71
|
radiusX;
|
|
72
72
|
/** Radius Y of the shape */
|
|
73
73
|
radiusY;
|
|
74
|
+
/** Start point X coordinate for line shape */
|
|
75
|
+
point1X;
|
|
76
|
+
/** Start point Y coordinate for line shape */
|
|
77
|
+
point1Y;
|
|
78
|
+
/** End point X coordinate for line shape */
|
|
79
|
+
point2X;
|
|
80
|
+
/** End point Y coordinate for line shape */
|
|
81
|
+
point2Y;
|
|
74
82
|
/** Internal rendering data */
|
|
75
83
|
renderData;
|
|
76
84
|
/**
|
|
@@ -96,6 +104,10 @@ export class Shape extends Component {
|
|
|
96
104
|
this.radius = config.radius;
|
|
97
105
|
this.radiusX = config.radiusX;
|
|
98
106
|
this.radiusY = config.radiusY;
|
|
107
|
+
this.point1X = config.point1X;
|
|
108
|
+
this.point1Y = config.point1Y;
|
|
109
|
+
this.point2X = config.point2X;
|
|
110
|
+
this.point2Y = config.point2Y;
|
|
99
111
|
}
|
|
100
112
|
clone() {
|
|
101
113
|
return new Shape({
|
|
@@ -114,6 +126,10 @@ export class Shape extends Component {
|
|
|
114
126
|
radius: this.radius,
|
|
115
127
|
radiusX: this.radiusX,
|
|
116
128
|
radiusY: this.radiusY,
|
|
129
|
+
point1X: this.point1X,
|
|
130
|
+
point1Y: this.point1Y,
|
|
131
|
+
point2X: this.point2X,
|
|
132
|
+
point2Y: this.point2Y,
|
|
117
133
|
fill: this.fill,
|
|
118
134
|
});
|
|
119
135
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { Actor } from '../../../engine/actor';
|
|
2
|
-
interface
|
|
2
|
+
interface CameraAPIOptions {
|
|
3
3
|
onCameraUpdate: (actor: Actor) => void;
|
|
4
4
|
findCurrentCamera: () => Actor | undefined;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* API that manages camera control and current camera tracking
|
|
8
8
|
*
|
|
9
9
|
* Provides methods to set and get the current camera actor
|
|
10
10
|
*
|
|
11
11
|
* @category Systems
|
|
12
12
|
*/
|
|
13
|
-
export declare class
|
|
13
|
+
export declare class CameraAPI {
|
|
14
14
|
private onCameraUpdate;
|
|
15
15
|
private findCurrentCamera;
|
|
16
|
-
constructor({ onCameraUpdate, findCurrentCamera }:
|
|
16
|
+
constructor({ onCameraUpdate, findCurrentCamera }: CameraAPIOptions);
|
|
17
17
|
setCurrentCamera(actor: Actor): void;
|
|
18
18
|
getCurrentCamera(): Actor | undefined;
|
|
19
19
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Camera } from '../../components';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* API that manages camera control and current camera tracking
|
|
4
4
|
*
|
|
5
5
|
* Provides methods to set and get the current camera actor
|
|
6
6
|
*
|
|
7
7
|
* @category Systems
|
|
8
8
|
*/
|
|
9
|
-
export class
|
|
9
|
+
export class CameraAPI {
|
|
10
10
|
onCameraUpdate;
|
|
11
11
|
findCurrentCamera;
|
|
12
12
|
constructor({ onCameraUpdate, findCurrentCamera }) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { CameraSystem } from './system';
|
|
2
|
-
export {
|
|
2
|
+
export { CameraAPI } from './api';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { CameraSystem } from './system';
|
|
2
|
-
export {
|
|
2
|
+
export { CameraAPI } from './api';
|
|
@@ -11,7 +11,7 @@ import type { WorldSystemOptions } from '../../../engine/system';
|
|
|
11
11
|
export declare class CameraSystem extends WorldSystem {
|
|
12
12
|
private actorQuery?;
|
|
13
13
|
private window;
|
|
14
|
-
private
|
|
14
|
+
private cameraApi;
|
|
15
15
|
constructor(options: WorldSystemOptions);
|
|
16
16
|
onSceneEnter(scene: Scene): void;
|
|
17
17
|
onSceneExit(): void;
|
|
@@ -2,7 +2,7 @@ import { WorldSystem } from '../../../engine/system';
|
|
|
2
2
|
import { ActorQuery } from '../../../engine/actor';
|
|
3
3
|
import { Camera } from '../../components/camera';
|
|
4
4
|
import { getWindowNode } from '../../utils/get-window-node';
|
|
5
|
-
import {
|
|
5
|
+
import { CameraAPI } from './api';
|
|
6
6
|
/**
|
|
7
7
|
* Camera system that manages camera control and current camera tracking
|
|
8
8
|
*
|
|
@@ -13,17 +13,17 @@ import { CameraService } from './service';
|
|
|
13
13
|
export class CameraSystem extends WorldSystem {
|
|
14
14
|
actorQuery;
|
|
15
15
|
window;
|
|
16
|
-
|
|
16
|
+
cameraApi;
|
|
17
17
|
constructor(options) {
|
|
18
18
|
super();
|
|
19
19
|
const { windowNodeId, world } = options;
|
|
20
20
|
const windowNode = getWindowNode(windowNodeId);
|
|
21
21
|
this.window = windowNode;
|
|
22
|
-
this.
|
|
22
|
+
this.cameraApi = new CameraAPI({
|
|
23
23
|
onCameraUpdate: this.handleCameraUpdate,
|
|
24
24
|
findCurrentCamera: this.findCurrentCamera,
|
|
25
25
|
});
|
|
26
|
-
world.
|
|
26
|
+
world.systemApi.register(this.cameraApi);
|
|
27
27
|
window.addEventListener('resize', this.handleWindowResize);
|
|
28
28
|
}
|
|
29
29
|
onSceneEnter(scene) {
|
|
@@ -34,6 +34,7 @@ export class CameraSystem extends WorldSystem {
|
|
|
34
34
|
this.handleWindowResize();
|
|
35
35
|
}
|
|
36
36
|
onSceneExit() {
|
|
37
|
+
this.actorQuery?.destroy();
|
|
37
38
|
this.actorQuery = undefined;
|
|
38
39
|
}
|
|
39
40
|
onWorldDestroy() {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { Animator } from './animator';
|
|
2
|
-
export { CameraSystem,
|
|
2
|
+
export { CameraSystem, CameraAPI } from './camera-system';
|
|
3
3
|
export { GameStatsMeter } from './game-stats-meter';
|
|
4
4
|
export { KeyboardInputSystem } from './keyboard-input-system';
|
|
5
5
|
export { KeyboardControlSystem } from './keyboard-control-system';
|
|
6
6
|
export { MouseControlSystem } from './mouse-control-system';
|
|
7
7
|
export { MouseInputSystem } from './mouse-input-system';
|
|
8
|
-
export { PhysicsSystem } from './physics-system';
|
|
8
|
+
export { PhysicsSystem, PhysicsAPI } from './physics-system';
|
|
9
9
|
export { BehaviorSystem, Behavior } from './behavior-system';
|
|
10
10
|
export type { BehaviorOptions } from './behavior-system';
|
|
11
11
|
export { UIBridge } from './ui-bridge';
|
|
12
12
|
export type { UIOptions, UIInitFn, UIDestroyFn, LoadUIFn } from './ui-bridge';
|
|
13
13
|
export { AudioSystem } from './audio-system';
|
|
14
|
-
export { Renderer,
|
|
14
|
+
export { Renderer, RendererAPI, FilterEffect, Shader } from './renderer';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { Animator } from './animator';
|
|
2
|
-
export { CameraSystem,
|
|
2
|
+
export { CameraSystem, CameraAPI } from './camera-system';
|
|
3
3
|
export { GameStatsMeter } from './game-stats-meter';
|
|
4
4
|
export { KeyboardInputSystem } from './keyboard-input-system';
|
|
5
5
|
export { KeyboardControlSystem } from './keyboard-control-system';
|
|
6
6
|
export { MouseControlSystem } from './mouse-control-system';
|
|
7
7
|
export { MouseInputSystem } from './mouse-input-system';
|
|
8
|
-
export { PhysicsSystem } from './physics-system';
|
|
8
|
+
export { PhysicsSystem, PhysicsAPI } from './physics-system';
|
|
9
9
|
export { BehaviorSystem, Behavior } from './behavior-system';
|
|
10
10
|
export { UIBridge } from './ui-bridge';
|
|
11
11
|
export { AudioSystem } from './audio-system';
|
|
12
|
-
export { Renderer,
|
|
12
|
+
export { Renderer, RendererAPI, FilterEffect, Shader } from './renderer';
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { MouseInput } from '../../../../events';
|
|
2
|
-
import {
|
|
3
|
-
import { getProjectedX, getProjectedY } from '../../../../utils/coordinates-projection';
|
|
2
|
+
import { CameraAPI } from '../../../camera-system';
|
|
3
|
+
import { getProjectedX, getProjectedY, } from '../../../../utils/coordinates-projection';
|
|
4
4
|
export class CoordinatesProjector {
|
|
5
5
|
world;
|
|
6
|
-
cameraService;
|
|
7
6
|
constructor(options) {
|
|
8
7
|
const { world } = options;
|
|
9
8
|
this.world = world;
|
|
10
|
-
this.cameraService = world.getService(CameraService);
|
|
11
9
|
this.world.addEventListener(MouseInput, this.handleMouseInput);
|
|
12
10
|
}
|
|
13
11
|
destroy() {
|
|
14
12
|
this.world.removeEventListener(MouseInput, this.handleMouseInput);
|
|
15
13
|
}
|
|
16
14
|
handleMouseInput = (event) => {
|
|
17
|
-
const
|
|
15
|
+
const cameraApi = this.world.systemApi.get(CameraAPI);
|
|
16
|
+
const currentCamera = cameraApi.getCurrentCamera();
|
|
18
17
|
event.x = currentCamera ? getProjectedX(event.x, currentCamera) : event.x;
|
|
19
18
|
event.y = currentCamera ? getProjectedY(event.y, currentCamera) : event.y;
|
|
20
19
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Actor } from '../../../engine/actor';
|
|
2
|
+
import type { CollisionDetectionSubsystem } from './subsystems';
|
|
3
|
+
import type { RaycastHit, RaycastParams, OverlapBoxParams, OverlapCircleParams, OverlapPointParams } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* API that provides methods for performing physics queries such as raycasting and overlap tests.
|
|
6
|
+
*
|
|
7
|
+
* Query results are based on the latest prepared physics state.
|
|
8
|
+
* That state is updated during the physics system fixed update step,
|
|
9
|
+
* so direct transform or collider changes made outside physics update
|
|
10
|
+
* are not guaranteed to be reflected immediately in query results.
|
|
11
|
+
*
|
|
12
|
+
* @category Systems
|
|
13
|
+
*/
|
|
14
|
+
export declare class PhysicsAPI {
|
|
15
|
+
private collisionDetectionSubsystem;
|
|
16
|
+
constructor(collisionDetectionSubsystem: CollisionDetectionSubsystem);
|
|
17
|
+
/**
|
|
18
|
+
* Casts a ray and returns the nearest hit, if any.
|
|
19
|
+
*
|
|
20
|
+
* The ray starts at `params.origin`, travels in `params.direction`,
|
|
21
|
+
* and is limited by `params.maxDistance`.
|
|
22
|
+
*
|
|
23
|
+
* @param params - Raycast parameters
|
|
24
|
+
* @returns The nearest hit or `null` when nothing is hit
|
|
25
|
+
*/
|
|
26
|
+
raycast(params: RaycastParams): RaycastHit | null;
|
|
27
|
+
/**
|
|
28
|
+
* Casts a ray and returns all hits sorted by distance.
|
|
29
|
+
*
|
|
30
|
+
* The ray starts at `params.origin`, travels in `params.direction`,
|
|
31
|
+
* and is limited by `params.maxDistance`.
|
|
32
|
+
*
|
|
33
|
+
* @param params - Raycast parameters
|
|
34
|
+
* @returns All hits sorted from nearest to farthest
|
|
35
|
+
*/
|
|
36
|
+
raycastAll(params: RaycastParams): RaycastHit[];
|
|
37
|
+
/**
|
|
38
|
+
* Returns all actors whose colliders contain the given point.
|
|
39
|
+
*
|
|
40
|
+
* @param params - Point overlap parameters
|
|
41
|
+
* @returns Actors whose colliders overlap the point
|
|
42
|
+
*/
|
|
43
|
+
overlapPoint(params: OverlapPointParams): Actor[];
|
|
44
|
+
/**
|
|
45
|
+
* Returns all actors whose colliders overlap the given circle.
|
|
46
|
+
*
|
|
47
|
+
* @param params - Circle overlap parameters
|
|
48
|
+
* @returns Actors whose colliders overlap the circle
|
|
49
|
+
*/
|
|
50
|
+
overlapCircle(params: OverlapCircleParams): Actor[];
|
|
51
|
+
/**
|
|
52
|
+
* Returns all actors whose colliders overlap the given box.
|
|
53
|
+
*
|
|
54
|
+
* @param params - Box overlap parameters
|
|
55
|
+
* @returns Actors whose colliders overlap the box
|
|
56
|
+
*/
|
|
57
|
+
overlapBox(params: OverlapBoxParams): Actor[];
|
|
58
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API that provides methods for performing physics queries such as raycasting and overlap tests.
|
|
3
|
+
*
|
|
4
|
+
* Query results are based on the latest prepared physics state.
|
|
5
|
+
* That state is updated during the physics system fixed update step,
|
|
6
|
+
* so direct transform or collider changes made outside physics update
|
|
7
|
+
* are not guaranteed to be reflected immediately in query results.
|
|
8
|
+
*
|
|
9
|
+
* @category Systems
|
|
10
|
+
*/
|
|
11
|
+
export class PhysicsAPI {
|
|
12
|
+
collisionDetectionSubsystem;
|
|
13
|
+
constructor(collisionDetectionSubsystem) {
|
|
14
|
+
this.collisionDetectionSubsystem = collisionDetectionSubsystem;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Casts a ray and returns the nearest hit, if any.
|
|
18
|
+
*
|
|
19
|
+
* The ray starts at `params.origin`, travels in `params.direction`,
|
|
20
|
+
* and is limited by `params.maxDistance`.
|
|
21
|
+
*
|
|
22
|
+
* @param params - Raycast parameters
|
|
23
|
+
* @returns The nearest hit or `null` when nothing is hit
|
|
24
|
+
*/
|
|
25
|
+
raycast(params) {
|
|
26
|
+
return this.collisionDetectionSubsystem.raycast(params);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Casts a ray and returns all hits sorted by distance.
|
|
30
|
+
*
|
|
31
|
+
* The ray starts at `params.origin`, travels in `params.direction`,
|
|
32
|
+
* and is limited by `params.maxDistance`.
|
|
33
|
+
*
|
|
34
|
+
* @param params - Raycast parameters
|
|
35
|
+
* @returns All hits sorted from nearest to farthest
|
|
36
|
+
*/
|
|
37
|
+
raycastAll(params) {
|
|
38
|
+
return this.collisionDetectionSubsystem.raycastAll(params);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns all actors whose colliders contain the given point.
|
|
42
|
+
*
|
|
43
|
+
* @param params - Point overlap parameters
|
|
44
|
+
* @returns Actors whose colliders overlap the point
|
|
45
|
+
*/
|
|
46
|
+
overlapPoint(params) {
|
|
47
|
+
return this.collisionDetectionSubsystem.overlapPoint(params);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns all actors whose colliders overlap the given circle.
|
|
51
|
+
*
|
|
52
|
+
* @param params - Circle overlap parameters
|
|
53
|
+
* @returns Actors whose colliders overlap the circle
|
|
54
|
+
*/
|
|
55
|
+
overlapCircle(params) {
|
|
56
|
+
return this.collisionDetectionSubsystem.overlapCircle(params);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns all actors whose colliders overlap the given box.
|
|
60
|
+
*
|
|
61
|
+
* @param params - Box overlap parameters
|
|
62
|
+
* @returns Actors whose colliders overlap the box
|
|
63
|
+
*/
|
|
64
|
+
overlapBox(params) {
|
|
65
|
+
return this.collisionDetectionSubsystem.overlapBox(params);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Physics system that handles 2D physics simulation and collision detection
|
|
5
|
-
*
|
|
6
|
-
* Manages rigid body physics and collision detection and resolution.
|
|
7
|
-
*
|
|
8
|
-
* @extends SceneSystem
|
|
9
|
-
*
|
|
10
|
-
* @category Systems
|
|
11
|
-
*/
|
|
12
|
-
export declare class PhysicsSystem extends SceneSystem {
|
|
13
|
-
private physicsSubsystem;
|
|
14
|
-
private collisionDetectionSubsystem;
|
|
15
|
-
private collisionBroadcastSubsystem;
|
|
16
|
-
private constraintSolver;
|
|
17
|
-
constructor(options: SceneSystemOptions);
|
|
18
|
-
onSceneDestroy(): void;
|
|
19
|
-
fixedUpdate(options: UpdateOptions): void;
|
|
20
|
-
}
|
|
1
|
+
export { PhysicsSystem } from './physics-system';
|
|
2
|
+
export { PhysicsAPI } from './api';
|
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Physics system that handles 2D physics simulation and collision detection
|
|
5
|
-
*
|
|
6
|
-
* Manages rigid body physics and collision detection and resolution.
|
|
7
|
-
*
|
|
8
|
-
* @extends SceneSystem
|
|
9
|
-
*
|
|
10
|
-
* @category Systems
|
|
11
|
-
*/
|
|
12
|
-
export class PhysicsSystem extends SceneSystem {
|
|
13
|
-
physicsSubsystem;
|
|
14
|
-
collisionDetectionSubsystem;
|
|
15
|
-
collisionBroadcastSubsystem;
|
|
16
|
-
constraintSolver;
|
|
17
|
-
constructor(options) {
|
|
18
|
-
super();
|
|
19
|
-
this.physicsSubsystem = new PhysicsSubsystem(options);
|
|
20
|
-
this.collisionDetectionSubsystem = new CollisionDetectionSubsystem(options);
|
|
21
|
-
this.collisionBroadcastSubsystem = new CollisionBroadcastSubsystem();
|
|
22
|
-
this.constraintSolver = new ConstraintSolver();
|
|
23
|
-
}
|
|
24
|
-
onSceneDestroy() {
|
|
25
|
-
this.physicsSubsystem.destroy();
|
|
26
|
-
this.collisionDetectionSubsystem.destroy();
|
|
27
|
-
}
|
|
28
|
-
fixedUpdate(options) {
|
|
29
|
-
this.physicsSubsystem.update(options);
|
|
30
|
-
const contacts = this.collisionDetectionSubsystem.update();
|
|
31
|
-
this.constraintSolver.update(contacts);
|
|
32
|
-
this.collisionBroadcastSubsystem.update(contacts);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
PhysicsSystem.systemName = 'PhysicsSystem';
|
|
1
|
+
export { PhysicsSystem } from './physics-system';
|
|
2
|
+
export { PhysicsAPI } from './api';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SceneSystem } from '../../../engine/system';
|
|
2
|
+
import type { SceneSystemOptions, UpdateOptions } from '../../../engine/system';
|
|
3
|
+
/**
|
|
4
|
+
* Physics system that handles 2D physics simulation and collision detection
|
|
5
|
+
*
|
|
6
|
+
* Manages rigid body physics and collision detection and resolution.
|
|
7
|
+
*
|
|
8
|
+
* @extends SceneSystem
|
|
9
|
+
*
|
|
10
|
+
* @category Systems
|
|
11
|
+
*/
|
|
12
|
+
export declare class PhysicsSystem extends SceneSystem {
|
|
13
|
+
private world;
|
|
14
|
+
private physicsSubsystem;
|
|
15
|
+
private collisionDetectionSubsystem;
|
|
16
|
+
private collisionBroadcastSubsystem;
|
|
17
|
+
private constraintSolver;
|
|
18
|
+
private physicsApi;
|
|
19
|
+
constructor(options: SceneSystemOptions);
|
|
20
|
+
onSceneEnter(): void;
|
|
21
|
+
onSceneExit(): void;
|
|
22
|
+
onSceneDestroy(): void;
|
|
23
|
+
fixedUpdate(options: UpdateOptions): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SceneSystem } from '../../../engine/system';
|
|
2
|
+
import { PhysicsSubsystem, CollisionDetectionSubsystem, CollisionBroadcastSubsystem, ConstraintSolver, } from './subsystems';
|
|
3
|
+
import { PhysicsAPI } from './api';
|
|
4
|
+
/**
|
|
5
|
+
* Physics system that handles 2D physics simulation and collision detection
|
|
6
|
+
*
|
|
7
|
+
* Manages rigid body physics and collision detection and resolution.
|
|
8
|
+
*
|
|
9
|
+
* @extends SceneSystem
|
|
10
|
+
*
|
|
11
|
+
* @category Systems
|
|
12
|
+
*/
|
|
13
|
+
export class PhysicsSystem extends SceneSystem {
|
|
14
|
+
world;
|
|
15
|
+
physicsSubsystem;
|
|
16
|
+
collisionDetectionSubsystem;
|
|
17
|
+
collisionBroadcastSubsystem;
|
|
18
|
+
constraintSolver;
|
|
19
|
+
physicsApi;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super();
|
|
22
|
+
this.world = options.world;
|
|
23
|
+
this.physicsSubsystem = new PhysicsSubsystem(options);
|
|
24
|
+
this.collisionDetectionSubsystem = new CollisionDetectionSubsystem(options);
|
|
25
|
+
this.collisionBroadcastSubsystem = new CollisionBroadcastSubsystem();
|
|
26
|
+
this.constraintSolver = new ConstraintSolver();
|
|
27
|
+
this.physicsApi = new PhysicsAPI(this.collisionDetectionSubsystem);
|
|
28
|
+
}
|
|
29
|
+
onSceneEnter() {
|
|
30
|
+
this.world.systemApi.register(this.physicsApi);
|
|
31
|
+
}
|
|
32
|
+
onSceneExit() {
|
|
33
|
+
this.world.systemApi.unregister(PhysicsAPI);
|
|
34
|
+
}
|
|
35
|
+
onSceneDestroy() {
|
|
36
|
+
this.world.systemApi.unregister(PhysicsAPI);
|
|
37
|
+
this.physicsSubsystem.destroy();
|
|
38
|
+
this.collisionDetectionSubsystem.destroy();
|
|
39
|
+
}
|
|
40
|
+
fixedUpdate(options) {
|
|
41
|
+
this.physicsSubsystem.update(options);
|
|
42
|
+
const contacts = this.collisionDetectionSubsystem.update();
|
|
43
|
+
this.constraintSolver.update(contacts);
|
|
44
|
+
this.collisionBroadcastSubsystem.update(contacts);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
PhysicsSystem.systemName = 'PhysicsSystem';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export const buildCircleAABB = (geometry) => {
|
|
2
|
-
const { radius } = geometry;
|
|
3
|
-
const { x: centerX, y: centerY } = geometry.center;
|
|
2
|
+
const { radius, center: { x: centerX, y: centerY }, } = geometry;
|
|
4
3
|
return {
|
|
5
4
|
min: { x: centerX - radius, y: centerY - radius },
|
|
6
5
|
max: { x: centerX + radius, y: centerY + radius },
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const buildRayAABB = (geometry) => {
|
|
2
|
+
const { origin, direction, maxDistance } = geometry;
|
|
3
|
+
const endX = origin.x + direction.x * maxDistance;
|
|
4
|
+
const endY = origin.y + direction.y * maxDistance;
|
|
5
|
+
return {
|
|
6
|
+
min: { x: Math.min(origin.x, endX), y: Math.min(origin.y, endY) },
|
|
7
|
+
max: { x: Math.max(origin.x, endX), y: Math.max(origin.y, endY) },
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { INTERSECTION_EPSILON } from '../intersection-checkers/utils';
|
|
2
|
+
export const buildSegmentAABB = (geometry) => {
|
|
3
|
+
const { point1, point2 } = geometry;
|
|
4
|
+
return {
|
|
5
|
+
min: {
|
|
6
|
+
x: Math.min(point1.x, point2.x) - INTERSECTION_EPSILON,
|
|
7
|
+
y: Math.min(point1.y, point2.y) - INTERSECTION_EPSILON,
|
|
8
|
+
},
|
|
9
|
+
max: {
|
|
10
|
+
x: Math.max(point1.x, point2.x) + INTERSECTION_EPSILON,
|
|
11
|
+
y: Math.max(point1.y, point2.y) + INTERSECTION_EPSILON,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|