dacha 0.17.2 → 0.18.0-alpha.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/build/contrib/components/collider/index.d.ts +6 -2
- package/build/contrib/components/collider/index.js +7 -2
- package/build/contrib/components/rigid-body/index.d.ts +29 -17
- package/build/contrib/components/rigid-body/index.js +64 -21
- package/build/contrib/events/index.d.ts +10 -75
- package/build/contrib/events/index.js +0 -36
- package/build/contrib/systems/physics-system/index.d.ts +0 -1
- package/build/contrib/systems/physics-system/index.js +6 -11
- package/build/contrib/systems/physics-system/subsystems/collision-broadcast/collision.d.ts +5 -3
- package/build/contrib/systems/physics-system/subsystems/collision-broadcast/collision.js +7 -5
- package/build/contrib/systems/physics-system/subsystems/collision-broadcast/index.d.ts +4 -6
- package/build/contrib/systems/physics-system/subsystems/collision-broadcast/index.js +20 -17
- package/build/contrib/systems/physics-system/subsystems/collision-detection/index.d.ts +12 -9
- package/build/contrib/systems/physics-system/subsystems/collision-detection/index.js +107 -93
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.d.ts +10 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.js +36 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/utils.d.ts +23 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/utils.js +143 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.d.ts +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.js +47 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.d.ts +12 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.js +49 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.d.ts +2 -2
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.js +3 -3
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.d.ts +17 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.js +66 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/utils.d.ts +4 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/utils.js +9 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/reorientation-checkers/check-collider.js +3 -0
- package/build/contrib/systems/physics-system/subsystems/collision-detection/types.d.ts +14 -5
- package/build/contrib/systems/physics-system/subsystems/collision-detection/types.js +0 -3
- package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.d.ts +7 -10
- package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.js +117 -79
- package/build/contrib/systems/physics-system/subsystems/index.d.ts +0 -1
- package/build/contrib/systems/physics-system/subsystems/index.js +0 -1
- package/build/contrib/systems/physics-system/subsystems/physics/index.d.ts +3 -9
- package/build/contrib/systems/physics-system/subsystems/physics/index.js +57 -93
- package/build/contrib/systems/physics-system/types.d.ts +9 -0
- package/build/engine/math-lib/vector/ops.d.ts +3 -3
- package/build/engine/math-lib/vector/ops.js +8 -5
- package/build/engine/math-lib/vector/vector2.d.ts +22 -7
- package/build/engine/math-lib/vector/vector2.js +29 -5
- package/build/events/index.d.ts +2 -2
- package/build/events/index.js +1 -1
- package/package.json +1 -1
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-box-and-circle-intersection.d.ts +0 -16
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-box-and-circle-intersection.js +0 -80
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-boxes-intersection.d.ts +0 -6
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-boxes-intersection.js +0 -72
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-circles-intersection.d.ts +0 -11
- package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-circles-intersection.js +0 -39
- package/build/contrib/systems/physics-system/subsystems/collision-solver/index.d.ts +0 -10
- package/build/contrib/systems/physics-system/subsystems/collision-solver/index.js +0 -50
|
@@ -6,6 +6,7 @@ export interface ColliderConfig {
|
|
|
6
6
|
sizeX?: number;
|
|
7
7
|
sizeY?: number;
|
|
8
8
|
radius?: number;
|
|
9
|
+
layer: string;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Collider component for defining collision boundaries.
|
|
@@ -21,7 +22,8 @@ export interface ColliderConfig {
|
|
|
21
22
|
* centerX: 0,
|
|
22
23
|
* centerY: 0,
|
|
23
24
|
* sizeX: 64,
|
|
24
|
-
* sizeY: 64
|
|
25
|
+
* sizeY: 64,
|
|
26
|
+
* layer: 'default',
|
|
25
27
|
* });
|
|
26
28
|
*
|
|
27
29
|
* // Create a circle collider
|
|
@@ -29,7 +31,8 @@ export interface ColliderConfig {
|
|
|
29
31
|
* type: 'circle',
|
|
30
32
|
* centerX: 0,
|
|
31
33
|
* centerY: 0,
|
|
32
|
-
* radius: 32
|
|
34
|
+
* radius: 32,
|
|
35
|
+
* layer: 'default',
|
|
33
36
|
* });
|
|
34
37
|
*
|
|
35
38
|
* // Add to actor
|
|
@@ -45,6 +48,7 @@ export declare class Collider extends Component {
|
|
|
45
48
|
sizeX?: number;
|
|
46
49
|
sizeY?: number;
|
|
47
50
|
radius?: number;
|
|
51
|
+
layer: string;
|
|
48
52
|
constructor(config: ColliderConfig);
|
|
49
53
|
clone(): Collider;
|
|
50
54
|
}
|
|
@@ -13,7 +13,8 @@ import { Component } from '../../../engine/component';
|
|
|
13
13
|
* centerX: 0,
|
|
14
14
|
* centerY: 0,
|
|
15
15
|
* sizeX: 64,
|
|
16
|
-
* sizeY: 64
|
|
16
|
+
* sizeY: 64,
|
|
17
|
+
* layer: 'default',
|
|
17
18
|
* });
|
|
18
19
|
*
|
|
19
20
|
* // Create a circle collider
|
|
@@ -21,7 +22,8 @@ import { Component } from '../../../engine/component';
|
|
|
21
22
|
* type: 'circle',
|
|
22
23
|
* centerX: 0,
|
|
23
24
|
* centerY: 0,
|
|
24
|
-
* radius: 32
|
|
25
|
+
* radius: 32,
|
|
26
|
+
* layer: 'default',
|
|
25
27
|
* });
|
|
26
28
|
*
|
|
27
29
|
* // Add to actor
|
|
@@ -37,6 +39,7 @@ export class Collider extends Component {
|
|
|
37
39
|
sizeX;
|
|
38
40
|
sizeY;
|
|
39
41
|
radius;
|
|
42
|
+
layer;
|
|
40
43
|
constructor(config) {
|
|
41
44
|
super();
|
|
42
45
|
this.type = config.type;
|
|
@@ -45,6 +48,7 @@ export class Collider extends Component {
|
|
|
45
48
|
this.sizeX = config.sizeX;
|
|
46
49
|
this.sizeY = config.sizeY;
|
|
47
50
|
this.radius = config.radius;
|
|
51
|
+
this.layer = config.layer;
|
|
48
52
|
}
|
|
49
53
|
clone() {
|
|
50
54
|
return new Collider({
|
|
@@ -54,6 +58,7 @@ export class Collider extends Component {
|
|
|
54
58
|
sizeX: this.sizeX,
|
|
55
59
|
sizeY: this.sizeY,
|
|
56
60
|
radius: this.radius,
|
|
61
|
+
layer: this.layer,
|
|
57
62
|
});
|
|
58
63
|
}
|
|
59
64
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Component } from '../../../engine/component';
|
|
2
|
+
import { Vector2 } from '../../../engine/math-lib';
|
|
2
3
|
export type RigidBodyType = 'dynamic' | 'static';
|
|
3
4
|
export interface RigidBodyConfig {
|
|
4
5
|
type: RigidBodyType;
|
|
5
6
|
mass: number;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
ghost: boolean;
|
|
7
|
+
gravityScale: number;
|
|
8
|
+
linearDamping: number;
|
|
9
|
+
disabled: boolean;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* RigidBody component for defining rigid body physics.
|
|
@@ -20,10 +20,9 @@ export interface RigidBodyConfig {
|
|
|
20
20
|
* const rigidBody = new RigidBody({
|
|
21
21
|
* type: 'dynamic',
|
|
22
22
|
* mass: 10,
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* drag: 1,
|
|
23
|
+
* gravityScale: 1,
|
|
24
|
+
* linearDamping: 1,
|
|
25
|
+
* disabled: false,
|
|
27
26
|
* });
|
|
28
27
|
*
|
|
29
28
|
* // Add to actor
|
|
@@ -36,22 +35,35 @@ export interface RigidBodyConfig {
|
|
|
36
35
|
* @category Components
|
|
37
36
|
*/
|
|
38
37
|
export declare class RigidBody extends Component {
|
|
38
|
+
private _mass;
|
|
39
|
+
private _inverseMass;
|
|
39
40
|
/** Type of the rigid body */
|
|
40
41
|
type: RigidBodyType;
|
|
41
42
|
/** Mass of the rigid body */
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
/** Gravity scale of the rigid body */
|
|
44
|
+
gravityScale: number;
|
|
45
|
+
/** Linear damping value used to slow down movement over time */
|
|
46
|
+
linearDamping: number;
|
|
47
|
+
/** Current linear velocity of the rigid body */
|
|
48
|
+
linearVelocity: Vector2;
|
|
49
|
+
/** Whether rigid body simulation is disabled */
|
|
50
|
+
disabled: boolean;
|
|
51
|
+
/** Whether rigid body is sleeping */
|
|
52
|
+
sleeping: boolean;
|
|
53
|
+
force: Vector2;
|
|
54
|
+
impulse: Vector2;
|
|
51
55
|
/**
|
|
52
56
|
* Creates a new RigidBody component.
|
|
53
57
|
* @param config - Configuration for the rigid body
|
|
54
58
|
*/
|
|
55
59
|
constructor(config: RigidBodyConfig);
|
|
60
|
+
get mass(): number;
|
|
61
|
+
set mass(value: number);
|
|
62
|
+
get inverseMass(): number;
|
|
63
|
+
applyForce(force: Vector2): void;
|
|
64
|
+
applyImpulse(impulse: Vector2): void;
|
|
65
|
+
wakeUp(): void;
|
|
66
|
+
sleep(): void;
|
|
67
|
+
clearForces(): void;
|
|
56
68
|
clone(): RigidBody;
|
|
57
69
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Component } from '../../../engine/component';
|
|
2
|
+
import { Vector2 } from '../../../engine/math-lib';
|
|
2
3
|
/**
|
|
3
4
|
* RigidBody component for defining rigid body physics.
|
|
4
5
|
*
|
|
@@ -11,10 +12,9 @@ import { Component } from '../../../engine/component';
|
|
|
11
12
|
* const rigidBody = new RigidBody({
|
|
12
13
|
* type: 'dynamic',
|
|
13
14
|
* mass: 10,
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* drag: 1,
|
|
15
|
+
* gravityScale: 1,
|
|
16
|
+
* linearDamping: 1,
|
|
17
|
+
* disabled: false,
|
|
18
18
|
* });
|
|
19
19
|
*
|
|
20
20
|
* // Add to actor
|
|
@@ -27,39 +27,82 @@ import { Component } from '../../../engine/component';
|
|
|
27
27
|
* @category Components
|
|
28
28
|
*/
|
|
29
29
|
export class RigidBody extends Component {
|
|
30
|
+
_mass;
|
|
31
|
+
_inverseMass;
|
|
30
32
|
/** Type of the rigid body */
|
|
31
33
|
type;
|
|
32
34
|
/** Mass of the rigid body */
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
/** Gravity scale of the rigid body */
|
|
36
|
+
gravityScale;
|
|
37
|
+
/** Linear damping value used to slow down movement over time */
|
|
38
|
+
linearDamping;
|
|
39
|
+
/** Current linear velocity of the rigid body */
|
|
40
|
+
linearVelocity;
|
|
41
|
+
/** Whether rigid body simulation is disabled */
|
|
42
|
+
disabled;
|
|
43
|
+
/** Whether rigid body is sleeping */
|
|
44
|
+
sleeping;
|
|
45
|
+
force;
|
|
46
|
+
impulse;
|
|
42
47
|
/**
|
|
43
48
|
* Creates a new RigidBody component.
|
|
44
49
|
* @param config - Configuration for the rigid body
|
|
45
50
|
*/
|
|
46
51
|
constructor(config) {
|
|
47
52
|
super();
|
|
53
|
+
this._mass = 0;
|
|
54
|
+
this._inverseMass = 0;
|
|
48
55
|
this.type = config.type;
|
|
49
56
|
this.mass = config.mass;
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
57
|
+
this.gravityScale = config.gravityScale;
|
|
58
|
+
this.linearDamping = config.linearDamping;
|
|
59
|
+
this.linearVelocity = new Vector2(0, 0);
|
|
60
|
+
this.disabled = config.disabled;
|
|
61
|
+
this.sleeping = false;
|
|
62
|
+
this.force = new Vector2(0, 0);
|
|
63
|
+
this.impulse = new Vector2(0, 0);
|
|
64
|
+
}
|
|
65
|
+
get mass() {
|
|
66
|
+
return this._mass;
|
|
67
|
+
}
|
|
68
|
+
set mass(value) {
|
|
69
|
+
this._mass = value;
|
|
70
|
+
this._inverseMass = value > 0 ? 1 / value : 0;
|
|
71
|
+
}
|
|
72
|
+
get inverseMass() {
|
|
73
|
+
return this._inverseMass;
|
|
74
|
+
}
|
|
75
|
+
applyForce(force) {
|
|
76
|
+
if (this.disabled || this.type === 'static') {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this.wakeUp();
|
|
80
|
+
this.force.add(force);
|
|
81
|
+
}
|
|
82
|
+
applyImpulse(impulse) {
|
|
83
|
+
if (this.disabled || this.type === 'static') {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.wakeUp();
|
|
87
|
+
this.impulse.add(impulse);
|
|
88
|
+
}
|
|
89
|
+
wakeUp() {
|
|
90
|
+
this.sleeping = false;
|
|
91
|
+
}
|
|
92
|
+
sleep() {
|
|
93
|
+
this.sleeping = true;
|
|
94
|
+
}
|
|
95
|
+
clearForces() {
|
|
96
|
+
this.force.multiplyNumber(0);
|
|
97
|
+
this.impulse.multiplyNumber(0);
|
|
54
98
|
}
|
|
55
99
|
clone() {
|
|
56
100
|
return new RigidBody({
|
|
57
101
|
mass: this.mass,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
102
|
+
gravityScale: this.gravityScale,
|
|
103
|
+
linearDamping: this.linearDamping,
|
|
104
|
+
disabled: this.disabled,
|
|
61
105
|
type: this.type,
|
|
62
|
-
drag: this.drag,
|
|
63
106
|
});
|
|
64
107
|
}
|
|
65
108
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Actor } from '../../engine/actor';
|
|
2
2
|
import type { Vector2 } from '../../engine/math-lib';
|
|
3
3
|
import type { CustomMouseEvent, CustomKeyboardEvent } from '../types/input-events';
|
|
4
|
-
import type { ActorEvent,
|
|
4
|
+
import type { ActorEvent, WorldEvent } from '../../types/events';
|
|
5
5
|
/**
|
|
6
6
|
* Dispatched when game statistics are updated
|
|
7
7
|
*
|
|
@@ -11,15 +11,6 @@ import type { ActorEvent, SceneEvent, WorldEvent } from '../../types/events';
|
|
|
11
11
|
* @category Events
|
|
12
12
|
*/
|
|
13
13
|
export declare const GameStatsUpdate = "GameStatsUpdate";
|
|
14
|
-
/**
|
|
15
|
-
* Dispatched when two actors collide
|
|
16
|
-
*
|
|
17
|
-
* @event
|
|
18
|
-
* @type {CollisionEvent}
|
|
19
|
-
*
|
|
20
|
-
* @category Events
|
|
21
|
-
*/
|
|
22
|
-
export declare const Collision = "Collision";
|
|
23
14
|
/**
|
|
24
15
|
* Dispatched when keyboard input is received
|
|
25
16
|
*
|
|
@@ -65,33 +56,6 @@ export declare const CollisionStay = "CollisionStay";
|
|
|
65
56
|
* @category Events
|
|
66
57
|
*/
|
|
67
58
|
export declare const CollisionLeave = "CollisionLeave";
|
|
68
|
-
/**
|
|
69
|
-
* Dispatched to add force to an actor
|
|
70
|
-
*
|
|
71
|
-
* @event
|
|
72
|
-
* @type {AddForceEvent}
|
|
73
|
-
*
|
|
74
|
-
* @category Events
|
|
75
|
-
*/
|
|
76
|
-
export declare const AddForce = "AddForce";
|
|
77
|
-
/**
|
|
78
|
-
* Dispatched to add impulse to an actor
|
|
79
|
-
*
|
|
80
|
-
* @event
|
|
81
|
-
* @type {AddImpulseEvent}
|
|
82
|
-
*
|
|
83
|
-
* @category Events
|
|
84
|
-
*/
|
|
85
|
-
export declare const AddImpulse = "AddImpulse";
|
|
86
|
-
/**
|
|
87
|
-
* Dispatched to stop physical movement of an actor
|
|
88
|
-
*
|
|
89
|
-
* @event
|
|
90
|
-
* @type {ActorEvent}
|
|
91
|
-
*
|
|
92
|
-
* @category Events
|
|
93
|
-
*/
|
|
94
|
-
export declare const StopMovement = "StopMovement";
|
|
95
59
|
/**
|
|
96
60
|
* Dispatched to play audio on an actor
|
|
97
61
|
*
|
|
@@ -149,20 +113,6 @@ export type SetAudioGroupVolumeEvent = WorldEvent<{
|
|
|
149
113
|
/** Volume value (0.0 to 1.0) */
|
|
150
114
|
value: number;
|
|
151
115
|
}>;
|
|
152
|
-
/** Event signature for the {@link Collision} event
|
|
153
|
-
*
|
|
154
|
-
* @category Events
|
|
155
|
-
*/
|
|
156
|
-
export type CollisionEvent = SceneEvent<{
|
|
157
|
-
/** First actor involved in the collision */
|
|
158
|
-
actor1: Actor;
|
|
159
|
-
/** Second actor involved in the collision */
|
|
160
|
-
actor2: Actor;
|
|
161
|
-
/** Minimum translation vector for the first actor */
|
|
162
|
-
mtv1: Vector2;
|
|
163
|
-
/** Minimum translation vector for the second actor */
|
|
164
|
-
mtv2: Vector2;
|
|
165
|
-
}>;
|
|
166
116
|
/** Event signature for mouse control events
|
|
167
117
|
*
|
|
168
118
|
* @category Events
|
|
@@ -180,8 +130,15 @@ export type KeyboardControlEvent<T = Record<string, never>> = ActorEvent<T>;
|
|
|
180
130
|
type CollisionStateEvent = ActorEvent<{
|
|
181
131
|
/** Actor that is colliding with the target */
|
|
182
132
|
actor: Actor;
|
|
183
|
-
/**
|
|
184
|
-
|
|
133
|
+
/** Collision normal pointing from the target actor to the colliding actor */
|
|
134
|
+
normal: Vector2;
|
|
135
|
+
/** Depth of penetration along the collision normal */
|
|
136
|
+
penetration: number;
|
|
137
|
+
/** Contact manifold points in world space */
|
|
138
|
+
contactPoints: {
|
|
139
|
+
x: number;
|
|
140
|
+
y: number;
|
|
141
|
+
}[];
|
|
185
142
|
}>;
|
|
186
143
|
/** Event signature for the {@link CollisionEnter} event
|
|
187
144
|
*
|
|
@@ -198,22 +155,6 @@ export type CollisionStayEvent = CollisionStateEvent;
|
|
|
198
155
|
* @category Events
|
|
199
156
|
*/
|
|
200
157
|
export type CollisionLeaveEvent = CollisionStateEvent;
|
|
201
|
-
/** Event signature for the {@link AddForce} event
|
|
202
|
-
*
|
|
203
|
-
* @category Events
|
|
204
|
-
*/
|
|
205
|
-
export type AddForceEvent = ActorEvent<{
|
|
206
|
-
/** Force vector to apply to the actor */
|
|
207
|
-
value: Vector2;
|
|
208
|
-
}>;
|
|
209
|
-
/** Event signature for the {@link AddImpulse} event
|
|
210
|
-
*
|
|
211
|
-
* @category Events
|
|
212
|
-
*/
|
|
213
|
-
export type AddImpulseEvent = ActorEvent<{
|
|
214
|
-
/** Impulse vector to apply to the actor */
|
|
215
|
-
value: Vector2;
|
|
216
|
-
}>;
|
|
217
158
|
/** Event signature for the {@link SetAudioVolume} event when used on actor level
|
|
218
159
|
*
|
|
219
160
|
* @category Events
|
|
@@ -229,16 +170,10 @@ declare module '../../types/events' {
|
|
|
229
170
|
[GameStatsUpdate]: GameStatsUpdateEvent;
|
|
230
171
|
[SetAudioVolume]: SetAudioGroupVolumeEvent;
|
|
231
172
|
}
|
|
232
|
-
interface SceneEventMap {
|
|
233
|
-
[Collision]: CollisionEvent;
|
|
234
|
-
}
|
|
235
173
|
interface ActorEventMap {
|
|
236
174
|
[CollisionEnter]: CollisionEnterEvent;
|
|
237
175
|
[CollisionStay]: CollisionStayEvent;
|
|
238
176
|
[CollisionLeave]: CollisionLeaveEvent;
|
|
239
|
-
[AddForce]: AddForceEvent;
|
|
240
|
-
[AddImpulse]: AddImpulseEvent;
|
|
241
|
-
[StopMovement]: ActorEvent;
|
|
242
177
|
[PlayAudio]: ActorEvent;
|
|
243
178
|
[StopAudio]: ActorEvent;
|
|
244
179
|
[SetAudioVolume]: SetAudioSourceVolumeEvent;
|
|
@@ -7,15 +7,6 @@
|
|
|
7
7
|
* @category Events
|
|
8
8
|
*/
|
|
9
9
|
export const GameStatsUpdate = 'GameStatsUpdate';
|
|
10
|
-
/**
|
|
11
|
-
* Dispatched when two actors collide
|
|
12
|
-
*
|
|
13
|
-
* @event
|
|
14
|
-
* @type {CollisionEvent}
|
|
15
|
-
*
|
|
16
|
-
* @category Events
|
|
17
|
-
*/
|
|
18
|
-
export const Collision = 'Collision';
|
|
19
10
|
/**
|
|
20
11
|
* Dispatched when keyboard input is received
|
|
21
12
|
*
|
|
@@ -61,33 +52,6 @@ export const CollisionStay = 'CollisionStay';
|
|
|
61
52
|
* @category Events
|
|
62
53
|
*/
|
|
63
54
|
export const CollisionLeave = 'CollisionLeave';
|
|
64
|
-
/**
|
|
65
|
-
* Dispatched to add force to an actor
|
|
66
|
-
*
|
|
67
|
-
* @event
|
|
68
|
-
* @type {AddForceEvent}
|
|
69
|
-
*
|
|
70
|
-
* @category Events
|
|
71
|
-
*/
|
|
72
|
-
export const AddForce = 'AddForce';
|
|
73
|
-
/**
|
|
74
|
-
* Dispatched to add impulse to an actor
|
|
75
|
-
*
|
|
76
|
-
* @event
|
|
77
|
-
* @type {AddImpulseEvent}
|
|
78
|
-
*
|
|
79
|
-
* @category Events
|
|
80
|
-
*/
|
|
81
|
-
export const AddImpulse = 'AddImpulse';
|
|
82
|
-
/**
|
|
83
|
-
* Dispatched to stop physical movement of an actor
|
|
84
|
-
*
|
|
85
|
-
* @event
|
|
86
|
-
* @type {ActorEvent}
|
|
87
|
-
*
|
|
88
|
-
* @category Events
|
|
89
|
-
*/
|
|
90
|
-
export const StopMovement = 'StopMovement';
|
|
91
55
|
/**
|
|
92
56
|
* Dispatched to play audio on an actor
|
|
93
57
|
*
|
|
@@ -13,7 +13,6 @@ export declare class PhysicsSystem extends SceneSystem {
|
|
|
13
13
|
private physicsSubsystem;
|
|
14
14
|
private collisionDetectionSubsystem;
|
|
15
15
|
private collisionBroadcastSubsystem;
|
|
16
|
-
private collisionSolver;
|
|
17
16
|
private constraintSolver;
|
|
18
17
|
constructor(options: SceneSystemOptions);
|
|
19
18
|
onSceneDestroy(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SceneSystem } from '../../../engine/system';
|
|
2
|
-
import { PhysicsSubsystem, CollisionDetectionSubsystem, CollisionBroadcastSubsystem,
|
|
2
|
+
import { PhysicsSubsystem, CollisionDetectionSubsystem, CollisionBroadcastSubsystem, ConstraintSolver, } from './subsystems';
|
|
3
3
|
/**
|
|
4
4
|
* Physics system that handles 2D physics simulation and collision detection
|
|
5
5
|
*
|
|
@@ -13,28 +13,23 @@ export class PhysicsSystem extends SceneSystem {
|
|
|
13
13
|
physicsSubsystem;
|
|
14
14
|
collisionDetectionSubsystem;
|
|
15
15
|
collisionBroadcastSubsystem;
|
|
16
|
-
collisionSolver;
|
|
17
16
|
constraintSolver;
|
|
18
17
|
constructor(options) {
|
|
19
18
|
super();
|
|
20
19
|
this.physicsSubsystem = new PhysicsSubsystem(options);
|
|
21
20
|
this.collisionDetectionSubsystem = new CollisionDetectionSubsystem(options);
|
|
22
|
-
this.collisionBroadcastSubsystem = new CollisionBroadcastSubsystem(
|
|
23
|
-
this.
|
|
24
|
-
this.constraintSolver = new ConstraintSolver(options);
|
|
21
|
+
this.collisionBroadcastSubsystem = new CollisionBroadcastSubsystem();
|
|
22
|
+
this.constraintSolver = new ConstraintSolver();
|
|
25
23
|
}
|
|
26
24
|
onSceneDestroy() {
|
|
27
25
|
this.physicsSubsystem.destroy();
|
|
28
26
|
this.collisionDetectionSubsystem.destroy();
|
|
29
|
-
this.collisionSolver.destroy();
|
|
30
|
-
this.constraintSolver.destroy();
|
|
31
|
-
this.collisionBroadcastSubsystem.destroy();
|
|
32
27
|
}
|
|
33
28
|
fixedUpdate(options) {
|
|
34
29
|
this.physicsSubsystem.update(options);
|
|
35
|
-
this.collisionDetectionSubsystem.update();
|
|
36
|
-
this.constraintSolver.update();
|
|
37
|
-
this.collisionBroadcastSubsystem.update();
|
|
30
|
+
const contacts = this.collisionDetectionSubsystem.update();
|
|
31
|
+
this.constraintSolver.update(contacts);
|
|
32
|
+
this.collisionBroadcastSubsystem.update(contacts);
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
35
|
PhysicsSystem.systemName = 'PhysicsSystem';
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Actor } from '../../../../../engine/actor';
|
|
2
2
|
import type { Vector2 } from '../../../../../engine/math-lib';
|
|
3
|
+
import type { Point } from '../collision-detection/types';
|
|
3
4
|
export type CollisionState = 'enter' | 'stay' | 'leave';
|
|
4
5
|
export declare class Collision {
|
|
5
6
|
private lifetime;
|
|
6
7
|
actor1: Actor;
|
|
7
8
|
actor2: Actor;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
normal: Vector2;
|
|
10
|
+
penetration: number;
|
|
11
|
+
contactPoints: Point[];
|
|
12
|
+
constructor(actor1: Actor, actor2: Actor, normal: Vector2, penetration: number, contactPoints: Point[]);
|
|
11
13
|
isFinished(): boolean;
|
|
12
14
|
signal(): void;
|
|
13
15
|
tick(): void;
|
|
@@ -7,14 +7,16 @@ export class Collision {
|
|
|
7
7
|
lifetime;
|
|
8
8
|
actor1;
|
|
9
9
|
actor2;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
normal;
|
|
11
|
+
penetration;
|
|
12
|
+
contactPoints;
|
|
13
|
+
constructor(actor1, actor2, normal, penetration, contactPoints) {
|
|
13
14
|
this.actor1 = actor1;
|
|
14
15
|
this.actor2 = actor2;
|
|
15
16
|
this.lifetime = 2;
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
17
|
+
this.normal = normal;
|
|
18
|
+
this.penetration = penetration;
|
|
19
|
+
this.contactPoints = contactPoints;
|
|
18
20
|
}
|
|
19
21
|
isFinished() {
|
|
20
22
|
return this.lifetime < 0;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Contact } from '../collision-detection/types';
|
|
2
2
|
export declare class CollisionBroadcastSubsystem {
|
|
3
|
-
private scene;
|
|
4
3
|
private collisionMap;
|
|
5
4
|
private activeCollisions;
|
|
6
|
-
constructor(
|
|
7
|
-
|
|
8
|
-
private handleCollision;
|
|
5
|
+
constructor();
|
|
6
|
+
private trackCollision;
|
|
9
7
|
private publishEvent;
|
|
10
|
-
update(): void;
|
|
8
|
+
update(contacts: Contact[]): void;
|
|
11
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollisionEnter, CollisionStay, CollisionLeave, } from '../../../../events';
|
|
2
2
|
import { Collision } from './collision';
|
|
3
3
|
const STATE_TO_EVENT = {
|
|
4
4
|
enter: CollisionEnter,
|
|
@@ -6,40 +6,43 @@ const STATE_TO_EVENT = {
|
|
|
6
6
|
leave: CollisionLeave,
|
|
7
7
|
};
|
|
8
8
|
export class CollisionBroadcastSubsystem {
|
|
9
|
-
scene;
|
|
10
9
|
collisionMap;
|
|
11
10
|
activeCollisions;
|
|
12
|
-
constructor(
|
|
13
|
-
this.scene = options.scene;
|
|
11
|
+
constructor() {
|
|
14
12
|
this.collisionMap = {};
|
|
15
13
|
this.activeCollisions = [];
|
|
16
|
-
this.scene.addEventListener(RawCollision, this.handleCollision);
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
this.scene.removeEventListener(RawCollision, this.handleCollision);
|
|
20
|
-
}
|
|
21
|
-
handleCollision = (event) => {
|
|
22
|
-
const { actor1, actor2, mtv1, mtv2, } = event;
|
|
15
|
+
trackCollision(actor1, actor2, normal, penetration, contactPoints) {
|
|
23
16
|
this.collisionMap[actor1.id] = this.collisionMap[actor1.id] || {};
|
|
24
17
|
if (!this.collisionMap[actor1.id][actor2.id]) {
|
|
25
|
-
const collision = new Collision(actor1, actor2,
|
|
18
|
+
const collision = new Collision(actor1, actor2, normal, penetration, contactPoints);
|
|
26
19
|
this.collisionMap[actor1.id][actor2.id] = collision;
|
|
27
20
|
this.activeCollisions.push(collision);
|
|
28
21
|
}
|
|
29
22
|
else {
|
|
30
|
-
this.collisionMap[actor1.id][actor2.id].
|
|
31
|
-
this.collisionMap[actor1.id][actor2.id].
|
|
23
|
+
this.collisionMap[actor1.id][actor2.id].normal = normal;
|
|
24
|
+
this.collisionMap[actor1.id][actor2.id].penetration = penetration;
|
|
25
|
+
this.collisionMap[actor1.id][actor2.id].contactPoints = contactPoints;
|
|
32
26
|
this.collisionMap[actor1.id][actor2.id].signal();
|
|
33
27
|
}
|
|
34
|
-
}
|
|
28
|
+
}
|
|
35
29
|
publishEvent(collision) {
|
|
36
|
-
const { actor1, actor2,
|
|
30
|
+
const { actor1, actor2, normal, penetration, contactPoints } = collision;
|
|
37
31
|
actor1.dispatchEvent(STATE_TO_EVENT[collision.getState()], {
|
|
38
32
|
actor: actor2,
|
|
39
|
-
|
|
33
|
+
normal,
|
|
34
|
+
penetration,
|
|
35
|
+
contactPoints,
|
|
40
36
|
});
|
|
41
37
|
}
|
|
42
|
-
update() {
|
|
38
|
+
update(contacts) {
|
|
39
|
+
contacts.forEach((contact) => {
|
|
40
|
+
const { actor1, actor2, normal, penetration, contactPoints } = contact;
|
|
41
|
+
const normal2 = contact.normal.clone();
|
|
42
|
+
normal2.multiplyNumber(-1);
|
|
43
|
+
this.trackCollision(actor1, actor2, normal, penetration, contactPoints);
|
|
44
|
+
this.trackCollision(actor2, actor1, normal2, penetration, contactPoints);
|
|
45
|
+
});
|
|
43
46
|
this.activeCollisions = this.activeCollisions.filter((collision) => {
|
|
44
47
|
const { actor1, actor2 } = collision;
|
|
45
48
|
this.publishEvent(collision);
|
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
import type { SceneSystemOptions } from '../../../../../engine/system';
|
|
2
|
+
import type { Contact } from './types';
|
|
2
3
|
export declare class CollisionDetectionSubsystem {
|
|
3
4
|
private actorQuery;
|
|
4
|
-
private scene;
|
|
5
5
|
private axis;
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
private
|
|
6
|
+
private proxiesByActorId;
|
|
7
|
+
private proxyPairs;
|
|
8
|
+
private contacts;
|
|
9
|
+
private actorIdsToDelete;
|
|
10
|
+
private collisionMatrix;
|
|
9
11
|
constructor(options: SceneSystemOptions);
|
|
10
12
|
destroy(): void;
|
|
11
13
|
private handleActorAdd;
|
|
12
14
|
private handleActorRemove;
|
|
13
15
|
private checkOnReorientation;
|
|
14
16
|
private getOrientationData;
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
+
private addProxy;
|
|
18
|
+
private updateProxy;
|
|
17
19
|
private addToSortedList;
|
|
18
20
|
private updateSortedList;
|
|
19
21
|
private clearSortedList;
|
|
20
22
|
private getAxes;
|
|
21
23
|
private areStaticBodies;
|
|
22
24
|
private testAABB;
|
|
25
|
+
private testCollisionLayers;
|
|
23
26
|
private sweepAndPrune;
|
|
24
27
|
private checkOnIntersection;
|
|
25
|
-
private
|
|
26
|
-
private
|
|
27
|
-
update():
|
|
28
|
+
private storeContact;
|
|
29
|
+
private clearDeletedProxies;
|
|
30
|
+
update(): Contact[];
|
|
28
31
|
}
|