emeraldengine 2.2.1 → 3.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.
Files changed (208) hide show
  1. package/README.md +2198 -968
  2. package/dist/types/index.d.ts +75 -32
  3. package/dist/types/src/Animator.d.ts +50 -0
  4. package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
  5. package/dist/types/src/Camera.d.ts +122 -0
  6. package/dist/types/src/CameraController.d.ts +107 -0
  7. package/dist/types/src/CanvasText.d.ts +91 -0
  8. package/dist/types/src/CollisionLayers.d.ts +58 -0
  9. package/dist/types/{Color.d.ts → src/Color.d.ts} +6 -6
  10. package/dist/types/src/Coroutine.d.ts +111 -0
  11. package/dist/types/src/DebugOverlay.d.ts +86 -0
  12. package/dist/types/src/Drawable.d.ts +271 -0
  13. package/dist/types/src/Easing.d.ts +22 -0
  14. package/dist/types/src/Emerald.d.ts +420 -0
  15. package/dist/types/src/EmeraldDB.d.ts +159 -0
  16. package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
  17. package/dist/types/src/GLUtils.d.ts +4 -0
  18. package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
  19. package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +75 -23
  20. package/dist/types/src/Interpolator.d.ts +66 -0
  21. package/dist/types/src/Material.d.ts +87 -0
  22. package/dist/types/src/MathUtils.d.ts +81 -0
  23. package/dist/types/src/ParticleEmitter.d.ts +131 -0
  24. package/dist/types/src/Physics.d.ts +337 -0
  25. package/dist/types/src/Pool.d.ts +53 -0
  26. package/dist/types/src/PostEffects.d.ts +68 -0
  27. package/dist/types/src/PostProcessor.d.ts +124 -0
  28. package/dist/types/src/RenderTarget.d.ts +56 -0
  29. package/dist/types/src/Scene.d.ts +62 -0
  30. package/dist/types/src/ScreenEffects.d.ts +111 -0
  31. package/dist/types/src/Serializer.d.ts +86 -0
  32. package/dist/types/src/Shaders.d.ts +2 -0
  33. package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
  34. package/dist/types/src/SpatialGrid.d.ts +50 -0
  35. package/dist/types/src/SpriteBatch.d.ts +89 -0
  36. package/dist/types/src/StateMachine.d.ts +59 -0
  37. package/dist/types/src/Storage.d.ts +89 -0
  38. package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
  39. package/dist/types/src/TextureAtlas.d.ts +55 -0
  40. package/dist/types/src/Tilemap.d.ts +91 -0
  41. package/dist/types/src/Time.d.ts +53 -0
  42. package/dist/types/src/Timer.d.ts +54 -0
  43. package/dist/types/src/Transform.d.ts +94 -0
  44. package/dist/types/src/Tween.d.ts +81 -0
  45. package/dist/types/src/UI.d.ts +121 -0
  46. package/dist/types/src/components/Behaviour.d.ts +71 -0
  47. package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
  48. package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
  49. package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
  50. package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
  51. package/dist/types/src/components/Collider.d.ts +102 -0
  52. package/dist/types/src/components/GameObject.d.ts +135 -0
  53. package/dist/types/src/components/PolygonCollider.d.ts +33 -0
  54. package/dist/types/src/components/RigidBody.d.ts +456 -0
  55. package/dist/types/src/importers/Aseprite.d.ts +79 -0
  56. package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
  57. package/dist/types/src/importers/TiledMap.d.ts +62 -0
  58. package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
  59. package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
  60. package/dist/types/src/managers/AssetManager.d.ts +116 -0
  61. package/dist/types/src/managers/AudioManager.d.ts +259 -0
  62. package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
  63. package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
  64. package/dist/types/src/managers/GLManager.d.ts +84 -0
  65. package/dist/types/src/managers/GLState.d.ts +37 -0
  66. package/dist/types/src/managers/Gamepad.d.ts +102 -0
  67. package/dist/types/src/managers/IDManager.d.ts +31 -0
  68. package/dist/types/src/managers/InputManager.d.ts +381 -0
  69. package/dist/types/src/managers/NetworkManager.d.ts +93 -0
  70. package/dist/types/src/managers/RenderStats.d.ts +34 -0
  71. package/dist/types/src/managers/SceneManager.d.ts +44 -0
  72. package/dist/types/src/managers/ShaderManager.d.ts +55 -0
  73. package/dist/types/src/managers/TextureManager.d.ts +102 -0
  74. package/dist/types/src/particlesystem/Particle.d.ts +64 -0
  75. package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
  76. package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
  77. package/dist/types/src/physics/AABB.d.ts +92 -0
  78. package/dist/types/src/physics/Body.d.ts +435 -0
  79. package/dist/types/src/physics/BodyType.d.ts +6 -0
  80. package/dist/types/src/physics/BroadPhase.d.ts +210 -0
  81. package/dist/types/src/physics/Collision.d.ts +102 -0
  82. package/dist/types/src/physics/Contact.d.ts +206 -0
  83. package/dist/types/src/physics/ContactSolver.d.ts +108 -0
  84. package/dist/types/src/physics/Distance.d.ts +54 -0
  85. package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
  86. package/dist/types/src/physics/Fixture.d.ts +221 -0
  87. package/dist/types/src/physics/Island.d.ts +52 -0
  88. package/dist/types/src/physics/Joint.d.ts +59 -0
  89. package/dist/types/src/physics/Math2D.d.ts +371 -0
  90. package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
  91. package/dist/types/src/physics/Settings.d.ts +22 -0
  92. package/dist/types/src/physics/Shapes.d.ts +207 -0
  93. package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
  94. package/dist/types/src/physics/World.d.ts +274 -0
  95. package/dist/types/src/physics/index.d.ts +34 -0
  96. package/index.js +78 -0
  97. package/package.json +73 -60
  98. package/src/Animator.js +95 -0
  99. package/src/BitmapText.js +6 -5
  100. package/src/Camera.js +183 -0
  101. package/src/CameraController.js +192 -0
  102. package/src/CanvasText.js +281 -0
  103. package/src/CollisionLayers.js +86 -0
  104. package/src/Color.js +26 -18
  105. package/src/Coroutine.js +259 -0
  106. package/src/DebugOverlay.js +246 -0
  107. package/src/Drawable.js +842 -582
  108. package/src/Easing.js +57 -0
  109. package/src/Emerald.js +1150 -459
  110. package/src/EmeraldDB.js +328 -0
  111. package/src/FPSCounter.js +43 -43
  112. package/src/GLUtils.js +60 -67
  113. package/src/Instance.js +41 -5
  114. package/src/InstancedTexture.js +308 -127
  115. package/src/Interpolator.js +124 -0
  116. package/src/Material.js +202 -0
  117. package/src/MathUtils.js +134 -0
  118. package/src/ParticleEmitter.js +284 -0
  119. package/src/Physics.js +431 -40
  120. package/src/Pool.js +85 -0
  121. package/src/PostEffects.js +296 -0
  122. package/src/PostProcessor.js +304 -0
  123. package/src/RenderTarget.js +134 -0
  124. package/src/Scene.js +115 -83
  125. package/src/ScreenEffects.js +266 -0
  126. package/src/Serializer.js +131 -0
  127. package/src/Shaders.js +150 -165
  128. package/src/Shapes.js +118 -129
  129. package/src/SpatialGrid.js +111 -0
  130. package/src/SpriteBatch.js +299 -0
  131. package/src/StateMachine.js +82 -0
  132. package/src/Storage.js +175 -47
  133. package/src/Texture.js +58 -67
  134. package/src/TextureAtlas.js +96 -0
  135. package/src/Tilemap.js +274 -0
  136. package/src/Time.js +51 -6
  137. package/src/Timer.js +99 -0
  138. package/src/Transform.js +100 -7
  139. package/src/Tween.js +160 -0
  140. package/src/UI.js +394 -0
  141. package/src/components/Behaviour.js +90 -0
  142. package/src/components/BoxCollider.js +29 -12
  143. package/src/components/BoxColliderDebug.js +3 -4
  144. package/src/components/CircleCollider.js +26 -12
  145. package/src/components/CircleColliderDebug.js +25 -24
  146. package/src/components/Collider.js +150 -34
  147. package/src/components/GameObject.js +130 -21
  148. package/src/components/PolygonCollider.js +55 -0
  149. package/src/components/RigidBody.js +556 -8
  150. package/src/importers/Aseprite.js +142 -0
  151. package/src/importers/ForgeLevel.js +581 -0
  152. package/src/importers/TiledMap.js +158 -0
  153. package/src/lights/DirectionalLight.js +6 -15
  154. package/src/lights/PointLight.js +4 -4
  155. package/src/managers/AssetManager.js +239 -0
  156. package/src/managers/AudioManager.js +565 -146
  157. package/src/managers/EventManager.js +488 -477
  158. package/src/managers/GLManager.js +57 -0
  159. package/src/managers/GLState.js +70 -0
  160. package/src/managers/Gamepad.js +126 -0
  161. package/src/managers/IDManager.js +24 -2
  162. package/src/managers/InputManager.js +905 -0
  163. package/src/managers/NetworkManager.js +178 -0
  164. package/src/managers/RenderStats.js +34 -0
  165. package/src/managers/SceneManager.js +30 -0
  166. package/src/managers/ShaderManager.js +0 -2
  167. package/src/managers/TextureManager.js +218 -0
  168. package/src/particlesystem/Particle.js +82 -7
  169. package/src/particlesystem/ParticleSettings.js +21 -3
  170. package/src/particlesystem/Particles.js +80 -31
  171. package/src/physics/AABB.js +207 -0
  172. package/src/physics/Body.js +862 -0
  173. package/src/physics/BodyType.js +16 -0
  174. package/src/physics/BroadPhase.js +641 -0
  175. package/src/physics/Collision.js +534 -0
  176. package/src/physics/Contact.js +500 -0
  177. package/src/physics/ContactSolver.js +526 -0
  178. package/src/physics/Distance.js +403 -0
  179. package/src/physics/DistanceJoint.js +227 -0
  180. package/src/physics/Fixture.js +346 -0
  181. package/src/physics/Island.js +203 -0
  182. package/src/physics/Joint.js +78 -0
  183. package/src/physics/Math2D.js +573 -0
  184. package/src/physics/RevoluteJoint.js +278 -0
  185. package/src/physics/Settings.js +78 -0
  186. package/src/physics/Shapes.js +549 -0
  187. package/src/physics/TimeOfImpact.js +87 -0
  188. package/src/physics/World.js +731 -0
  189. package/src/physics/index.js +79 -0
  190. package/dist/types/Drawable.d.ts +0 -157
  191. package/dist/types/Emerald.d.ts +0 -73
  192. package/dist/types/GLUtils.d.ts +0 -6
  193. package/dist/types/Physics.d.ts +0 -139
  194. package/dist/types/Scene.d.ts +0 -39
  195. package/dist/types/Shaders.d.ts +0 -4
  196. package/dist/types/Storage.d.ts +0 -46
  197. package/dist/types/Time.d.ts +0 -22
  198. package/dist/types/Transform.d.ts +0 -41
  199. package/dist/types/components/BoxColliderDebug.d.ts +0 -19
  200. package/dist/types/components/CircleColliderDebug.d.ts +0 -19
  201. package/dist/types/components/Collider.d.ts +0 -53
  202. package/dist/types/components/GameObject.d.ts +0 -72
  203. package/dist/types/components/RigidBody.d.ts +0 -104
  204. package/dist/types/managers/AudioManager.d.ts +0 -60
  205. package/dist/types/managers/GLManager.d.ts +0 -47
  206. package/dist/types/managers/IDManager.d.ts +0 -21
  207. package/dist/types/managers/SceneManager.d.ts +0 -22
  208. package/dist/types/particlesystem/Particle.d.ts +0 -42
@@ -0,0 +1,435 @@
1
+ /**
2
+ * @class Body
3
+ * @description A rigid body: a position, an orientation, and the velocity and
4
+ * mass that go with them. Collision geometry lives on its fixtures, added with
5
+ * {@link Body#createFixture}. Bodies are created through
6
+ * {@link World#createBody}, never with `new`.
7
+ *
8
+ * Everything here is in physics units (meters, radians, seconds). The engine's
9
+ * {@link RigidBody} component is the pixel-space wrapper around this class.
10
+ *
11
+ * @param {World} world - The owning world
12
+ * @param {Object} [def] - `{ type, position, angle, linearVelocity,
13
+ * angularVelocity, linearDamping, angularDamping, fixedRotation, bullet,
14
+ * allowSleep, awake, active, gravityScale, userData }`
15
+ */
16
+ export class Body {
17
+ constructor(world: any, def?: {});
18
+ world: any;
19
+ type: any;
20
+ xf: Transform2;
21
+ sweep: Sweep;
22
+ linearVelocity: Vec2;
23
+ angularVelocity: any;
24
+ force: Vec2;
25
+ torque: number;
26
+ linearDamping: any;
27
+ angularDamping: any;
28
+ gravityScale: any;
29
+ mass: number;
30
+ invMass: number;
31
+ I: number;
32
+ invI: number;
33
+ fixedRotation: boolean;
34
+ bullet: boolean;
35
+ allowSleep: boolean;
36
+ awake: boolean;
37
+ active: boolean;
38
+ sleepTime: number;
39
+ userData: any;
40
+ /** Head of this body's fixture list. @private */
41
+ private fixtureList;
42
+ /** @private */
43
+ private fixtureCount;
44
+ /** Contacts this body currently takes part in. @private */
45
+ private contacts;
46
+ /** Joints this body currently takes part in. @private */
47
+ private joints;
48
+ /** @private */
49
+ private prev;
50
+ /** @private */
51
+ private next;
52
+ /** Scratch flag used while building solver islands. @private */
53
+ private islandFlag;
54
+ /** Index into the current island's body array. @private */
55
+ private islandIndex;
56
+ /**
57
+ * @method createFixture
58
+ * @description Attaches a shape to this body. The second argument may be a
59
+ * plain density number or a definition object.
60
+ * @param {Shape} shape - A CircleShape or PolygonShape
61
+ * @param {Object|number} [def] - `{ density, friction, restitution, isSensor,
62
+ * filterCategoryBits, filterMaskBits, filterGroupIndex, userData }`
63
+ * @returns {Fixture} - The new fixture
64
+ */
65
+ createFixture(shape: Shape, def?: any | number): Fixture;
66
+ /**
67
+ * @method destroyFixture
68
+ * @description Removes a fixture and every contact it was part of.
69
+ * @param {Fixture} fixture
70
+ */
71
+ destroyFixture(fixture: Fixture): void;
72
+ /**
73
+ * @method getFixtureList
74
+ * @description Returns the first fixture; walk the rest with
75
+ * {@link Fixture#getNext}.
76
+ * @returns {Fixture|null}
77
+ */
78
+ getFixtureList(): Fixture | null;
79
+ /**
80
+ * @method getNext
81
+ * @description Returns the next body in the world's list.
82
+ * @returns {Body|null}
83
+ */
84
+ getNext(): Body | null;
85
+ /**
86
+ * @method setUserData
87
+ * @description Attaches arbitrary data to the body. The engine stores the
88
+ * owning {@link RigidBody} here so contacts can be traced back to game
89
+ * objects.
90
+ * @param {*} data
91
+ */
92
+ setUserData(data: any): void;
93
+ /**
94
+ * @method getUserData
95
+ * @description Returns the attached data.
96
+ * @returns {*}
97
+ */
98
+ getUserData(): any;
99
+ /**
100
+ * @method getWorld
101
+ * @description Returns the owning world.
102
+ * @returns {World}
103
+ */
104
+ getWorld(): World;
105
+ /**
106
+ * @method getType
107
+ * @description Returns "static", "kinematic" or "dynamic".
108
+ * @returns {string}
109
+ */
110
+ getType(): string;
111
+ /**
112
+ * @method setType
113
+ * @description Changes the body type at runtime, resetting velocities and
114
+ * re-deriving mass. Existing contacts are dropped so they rebuild against the
115
+ * new type.
116
+ * @param {string} type - "static", "kinematic" or "dynamic"
117
+ */
118
+ setType(type: string): void;
119
+ /**
120
+ * @method setTransform
121
+ * @description Teleports the body: sets position and angle directly, without
122
+ * any velocity implied by the move.
123
+ *
124
+ * A teleport wakes the body. Contacts are only re-evaluated for bodies that
125
+ * are awake, so a sleeping body dropped into a new spot would otherwise sit
126
+ * there without noticing what it now overlaps: respawning a player onto a
127
+ * pickup, for instance, would silently miss it.
128
+ *
129
+ * @param {Object} position - `{ x, y }` in physics units
130
+ * @param {number} angle - Radians
131
+ */
132
+ setTransform(position: any, angle: number): void;
133
+ /**
134
+ * @method setPosition
135
+ * @description Moves the body, keeping its angle.
136
+ * @param {Object} position - `{ x, y }` in physics units
137
+ */
138
+ setPosition(position: any): void;
139
+ /**
140
+ * @method setAngle
141
+ * @description Rotates the body, keeping its position.
142
+ * @param {number} angle - Radians
143
+ */
144
+ setAngle(angle: number): void;
145
+ /**
146
+ * @method getTransform
147
+ * @description Returns the body's transform (live reference).
148
+ * @returns {Transform2}
149
+ */
150
+ getTransform(): Transform2;
151
+ /**
152
+ * @method getPosition
153
+ * @description Returns the body origin in world space (live reference).
154
+ * @returns {Vec2}
155
+ */
156
+ getPosition(): Vec2;
157
+ /**
158
+ * @method getAngle
159
+ * @description Returns the body's angle in radians.
160
+ * @returns {number}
161
+ */
162
+ getAngle(): number;
163
+ /**
164
+ * @method getWorldCenter
165
+ * @description Returns the center of mass in world space.
166
+ * @returns {Vec2}
167
+ */
168
+ getWorldCenter(): Vec2;
169
+ /**
170
+ * @method getLocalCenter
171
+ * @description Returns the center of mass in the body's frame.
172
+ * @returns {Vec2}
173
+ */
174
+ getLocalCenter(): Vec2;
175
+ /**
176
+ * @method getWorldPoint
177
+ * @description Converts a local point to world space.
178
+ * @param {Object} localPoint
179
+ * @returns {Vec2}
180
+ */
181
+ getWorldPoint(localPoint: any): Vec2;
182
+ /**
183
+ * @method getLocalPoint
184
+ * @description Converts a world point to the body's frame.
185
+ * @param {Object} worldPoint
186
+ * @returns {Vec2}
187
+ */
188
+ getLocalPoint(worldPoint: any): Vec2;
189
+ /**
190
+ * @method getWorldVector
191
+ * @description Rotates a local direction into world space.
192
+ * @param {Object} localVector
193
+ * @returns {Vec2}
194
+ */
195
+ getWorldVector(localVector: any): Vec2;
196
+ /**
197
+ * @method getLocalVector
198
+ * @description Rotates a world direction into the body's frame.
199
+ * @param {Object} worldVector
200
+ * @returns {Vec2}
201
+ */
202
+ getLocalVector(worldVector: any): Vec2;
203
+ /**
204
+ * @method setLinearVelocity
205
+ * @description Sets the velocity of the center of mass.
206
+ * @param {Object} velocity - `{ x, y }` in physics units per second
207
+ */
208
+ setLinearVelocity(velocity: any): void;
209
+ /**
210
+ * @method getLinearVelocity
211
+ * @description Returns the velocity of the center of mass (live reference).
212
+ * @returns {Vec2}
213
+ */
214
+ getLinearVelocity(): Vec2;
215
+ /**
216
+ * @method getLinearVelocityFromWorldPoint
217
+ * @description Velocity of the material point of this body that currently
218
+ * coincides with a world point (linear plus the spin contribution).
219
+ * @param {Object} worldPoint
220
+ * @returns {Vec2}
221
+ */
222
+ getLinearVelocityFromWorldPoint(worldPoint: any): Vec2;
223
+ /**
224
+ * @method setAngularVelocity
225
+ * @description Sets the spin in radians per second.
226
+ * @param {number} omega
227
+ */
228
+ setAngularVelocity(omega: number): void;
229
+ /**
230
+ * @method getAngularVelocity
231
+ * @description Returns the spin in radians per second.
232
+ * @returns {number}
233
+ */
234
+ getAngularVelocity(): number;
235
+ /**
236
+ * @method applyForce
237
+ * @description Applies a force at a world point. Forces are cleared at the
238
+ * end of every step, so this belongs in your update loop.
239
+ * @param {Object} force
240
+ * @param {Object} [point] - Defaults to the center of mass
241
+ * @param {boolean} [wake=true]
242
+ */
243
+ applyForce(force: any, point?: any, wake?: boolean): void;
244
+ /**
245
+ * @method applyForceToCenter
246
+ * @description Applies a force at the center of mass (no torque).
247
+ * @param {Object} force
248
+ * @param {boolean} [wake=true]
249
+ */
250
+ applyForceToCenter(force: any, wake?: boolean): void;
251
+ /**
252
+ * @method applyTorque
253
+ * @description Applies a torque about the center of mass.
254
+ * @param {number} torque
255
+ * @param {boolean} [wake=true]
256
+ */
257
+ applyTorque(torque: number, wake?: boolean): void;
258
+ /**
259
+ * @method applyLinearImpulse
260
+ * @description Applies an instantaneous change in momentum at a world point.
261
+ * Unlike a force, an impulse takes effect immediately: this is what a jump
262
+ * or a knockback should use.
263
+ * @param {Object} impulse
264
+ * @param {Object} [point] - Defaults to the center of mass
265
+ * @param {boolean} [wake=true]
266
+ */
267
+ applyLinearImpulse(impulse: any, point?: any, wake?: boolean): void;
268
+ /**
269
+ * @method applyAngularImpulse
270
+ * @description Applies an instantaneous change in angular momentum.
271
+ * @param {number} impulse
272
+ * @param {boolean} [wake=true]
273
+ */
274
+ applyAngularImpulse(impulse: number, wake?: boolean): void;
275
+ /**
276
+ * @method getMass
277
+ * @description Returns the body's mass.
278
+ * @returns {number}
279
+ */
280
+ getMass(): number;
281
+ /**
282
+ * @method getInertia
283
+ * @description Returns the rotational inertia about the center of mass.
284
+ * @returns {number}
285
+ */
286
+ getInertia(): number;
287
+ /**
288
+ * @method resetMassData
289
+ * @description Recomputes mass, center of mass and inertia from the
290
+ * fixtures' densities. Called automatically when fixtures change.
291
+ */
292
+ resetMassData(): void;
293
+ /**
294
+ * @method setMassData
295
+ * @description Overrides the computed mass properties.
296
+ * @param {Object} massData - `{ mass, center, I }`
297
+ */
298
+ setMassData(massData: any): void;
299
+ /**
300
+ * @method setAwake
301
+ * @description Wakes the body or puts it to sleep. A sleeping body is skipped
302
+ * by the solver until something touches it, which is what keeps a settled
303
+ * pile of crates free.
304
+ * @param {boolean} flag
305
+ */
306
+ setAwake(flag: boolean): void;
307
+ /**
308
+ * @method isAwake
309
+ * @description Whether the body is currently simulated.
310
+ * @returns {boolean}
311
+ */
312
+ isAwake(): boolean;
313
+ /**
314
+ * @method setSleepingAllowed
315
+ * @description Allows or forbids this body from ever sleeping.
316
+ * @param {boolean} flag
317
+ */
318
+ setSleepingAllowed(flag: boolean): void;
319
+ /**
320
+ * @method isSleepingAllowed
321
+ * @description Whether this body may sleep.
322
+ * @returns {boolean}
323
+ */
324
+ isSleepingAllowed(): boolean;
325
+ /**
326
+ * @method setActive
327
+ * @description Adds or removes the body from collision detection without
328
+ * destroying it.
329
+ * @param {boolean} flag
330
+ */
331
+ setActive(flag: boolean): void;
332
+ /**
333
+ * @method isActive
334
+ * @description Whether the body takes part in collision detection.
335
+ * @returns {boolean}
336
+ */
337
+ isActive(): boolean;
338
+ /**
339
+ * @method setFixedRotation
340
+ * @description Locks or unlocks the body's rotation. Locking is the usual
341
+ * choice for player characters, which should never topple over.
342
+ * @param {boolean} flag
343
+ */
344
+ setFixedRotation(flag: boolean): void;
345
+ /**
346
+ * @method isFixedRotation
347
+ * @description Whether rotation is locked.
348
+ * @returns {boolean}
349
+ */
350
+ isFixedRotation(): boolean;
351
+ /**
352
+ * @method setBullet
353
+ * @description Turns continuous collision detection on for this body, so it
354
+ * is swept against static geometry instead of teleporting between steps.
355
+ * @param {boolean} flag
356
+ */
357
+ setBullet(flag: boolean): void;
358
+ /**
359
+ * @method isBullet
360
+ * @description Whether continuous collision detection is enabled.
361
+ * @returns {boolean}
362
+ */
363
+ isBullet(): boolean;
364
+ /**
365
+ * @method setLinearDamping
366
+ * @description Sets the drag applied to linear motion each step.
367
+ * @param {number} damping
368
+ */
369
+ setLinearDamping(damping: number): void;
370
+ /**
371
+ * @method getLinearDamping
372
+ * @description Returns the linear damping.
373
+ * @returns {number}
374
+ */
375
+ getLinearDamping(): number;
376
+ /**
377
+ * @method setAngularDamping
378
+ * @description Sets the drag applied to rotation each step.
379
+ * @param {number} damping
380
+ */
381
+ setAngularDamping(damping: number): void;
382
+ /**
383
+ * @method getAngularDamping
384
+ * @description Returns the angular damping.
385
+ * @returns {number}
386
+ */
387
+ getAngularDamping(): number;
388
+ /**
389
+ * @method setGravityScale
390
+ * @description Scales how strongly gravity pulls on this body (0 disables it,
391
+ * 2 makes it twice as heavy-feeling).
392
+ * @param {number} scale
393
+ */
394
+ setGravityScale(scale: number): void;
395
+ /**
396
+ * @method getGravityScale
397
+ * @description Returns the gravity multiplier.
398
+ * @returns {number}
399
+ */
400
+ getGravityScale(): number;
401
+ /**
402
+ * @method getContactList
403
+ * @description Returns the contacts this body is part of.
404
+ * @returns {Array<Contact>}
405
+ */
406
+ getContactList(): Array<Contact>;
407
+ /**
408
+ * @method synchronizeTransform
409
+ * @description Rebuilds the body transform from the sweep's current state.
410
+ * @private
411
+ */
412
+ private synchronizeTransform;
413
+ /**
414
+ * @method synchronizeFixtures
415
+ * @description Updates the broadphase proxies to span where the body was at
416
+ * the start of the step and where it is now.
417
+ * @param {Transform2} [xf1] - Optional explicit "before" transform
418
+ * @private
419
+ */
420
+ private synchronizeFixtures;
421
+ /**
422
+ * @method advance
423
+ * @description Moves the body to a fraction of its sweep, used by continuous
424
+ * collision detection when an impact is found mid-step.
425
+ * @param {number} alpha
426
+ * @private
427
+ */
428
+ private advance;
429
+ }
430
+ import { BodyType } from "./BodyType.js";
431
+ import { Transform2 } from "./Math2D.js";
432
+ import { Sweep } from "./Math2D.js";
433
+ import { Vec2 } from "./Math2D.js";
434
+ import { Fixture } from "./Fixture.js";
435
+ export { BodyType };
@@ -0,0 +1,6 @@
1
+ export type BodyType = BodyType;
2
+ export namespace BodyType {
3
+ let STATIC: string;
4
+ let KINEMATIC: string;
5
+ let DYNAMIC: string;
6
+ }
@@ -0,0 +1,210 @@
1
+ /**
2
+ * @class BroadPhase
3
+ * @description Keeps the AABB tree and the list of proxies that moved since the
4
+ * last step, and turns those into the candidate pairs the narrowphase looks at.
5
+ */
6
+ export class BroadPhase {
7
+ /** @private */
8
+ private tree;
9
+ /** @private */
10
+ private moveBuffer;
11
+ /** @private */
12
+ private proxyCount;
13
+ /**
14
+ * @method createProxy
15
+ * @description Adds a fixture proxy and queues it for pairing.
16
+ * @param {AABB} aabb
17
+ * @param {Object} userData
18
+ * @returns {number} - Proxy id
19
+ */
20
+ createProxy(aabb: AABB, userData: any): number;
21
+ /**
22
+ * @method destroyProxy
23
+ * @description Removes a fixture proxy.
24
+ * @param {number} id
25
+ */
26
+ destroyProxy(id: number): void;
27
+ /**
28
+ * @method moveProxy
29
+ * @description Updates a proxy's box, queueing it for re-pairing if the tree
30
+ * actually had to move it.
31
+ * @param {number} id
32
+ * @param {AABB} aabb
33
+ * @param {Object} displacement
34
+ */
35
+ moveProxy(id: number, aabb: AABB, displacement: any): void;
36
+ /**
37
+ * @method touchProxy
38
+ * @description Forces a proxy to be re-paired next update even though it
39
+ * didn't move (used when a fixture's filter changes).
40
+ * @param {number} id
41
+ */
42
+ touchProxy(id: number): void;
43
+ /** @private */
44
+ private bufferMove;
45
+ /** @private */
46
+ private unbufferMove;
47
+ /**
48
+ * @method getFatAABB
49
+ * @description Returns a proxy's fattened AABB.
50
+ * @param {number} id
51
+ * @returns {AABB}
52
+ */
53
+ getFatAABB(id: number): AABB;
54
+ /**
55
+ * @method getUserData
56
+ * @description Returns a proxy's payload.
57
+ * @param {number} id
58
+ * @returns {Object}
59
+ */
60
+ getUserData(id: number): any;
61
+ /**
62
+ * @method testOverlap
63
+ * @description True when two proxies' fat AABBs overlap.
64
+ * @param {number} idA
65
+ * @param {number} idB
66
+ * @returns {boolean}
67
+ */
68
+ testOverlap(idA: number, idB: number): boolean;
69
+ /**
70
+ * @method query
71
+ * @description Forwards an AABB query to the tree.
72
+ * @param {AABB} aabb
73
+ * @param {Function} callback
74
+ */
75
+ query(aabb: AABB, callback: Function): void;
76
+ /**
77
+ * @method rayCast
78
+ * @description Forwards a ray cast to the tree.
79
+ * @param {Object} input
80
+ * @param {Function} callback
81
+ */
82
+ rayCast(input: any, callback: Function): void;
83
+ /**
84
+ * @method updatePairs
85
+ * @description Emits `callback(userDataA, userDataB)` once for every new
86
+ * overlapping pair among the proxies that moved. Pairs are de-duplicated, so
87
+ * two proxies moving towards each other still report once.
88
+ * @param {Function} callback
89
+ */
90
+ updatePairs(callback: Function): void;
91
+ }
92
+ /**
93
+ * @class DynamicTree
94
+ * @description A balanced tree of axis-aligned boxes over every fixture in the
95
+ * world. Leaves are stored with a "fat" AABB so a body can jiggle a little
96
+ * without forcing a re-insert, and the tree is rebalanced with rotations on the
97
+ * way back up after each change. Every broadphase query, world raycast and
98
+ * continuous-collision sweep goes through it.
99
+ */
100
+ export class DynamicTree {
101
+ /** @private */
102
+ private root;
103
+ /** @private */
104
+ private nodes;
105
+ /** @private */
106
+ private freeList;
107
+ /** @private */
108
+ private nodeCount;
109
+ /**
110
+ * @method allocateNode
111
+ * @description Takes a node from the free list, growing the pool if needed.
112
+ * @returns {number} - The node id
113
+ * @private
114
+ */
115
+ private allocateNode;
116
+ /**
117
+ * @method freeNode
118
+ * @description Returns a node to the free list.
119
+ * @param {number} id
120
+ * @private
121
+ */
122
+ private freeNode;
123
+ /**
124
+ * @method createProxy
125
+ * @description Adds a fixture proxy to the tree.
126
+ * @param {AABB} aabb - The tight world AABB
127
+ * @param {Object} userData - The FixtureProxy this leaf stands for
128
+ * @returns {number} - The proxy id
129
+ */
130
+ createProxy(aabb: AABB, userData: any): number;
131
+ /**
132
+ * @method destroyProxy
133
+ * @description Removes a proxy from the tree.
134
+ * @param {number} id
135
+ */
136
+ destroyProxy(id: number): void;
137
+ /**
138
+ * @method moveProxy
139
+ * @description Re-fits a proxy whose fixture moved. Returns false (and does
140
+ * nothing) while the new box still fits inside the fat one.
141
+ * @param {number} id
142
+ * @param {AABB} aabb - The new tight AABB
143
+ * @param {Object} displacement - How far the body moved this step
144
+ * @returns {boolean} - Whether the proxy was actually re-inserted
145
+ */
146
+ moveProxy(id: number, aabb: AABB, displacement: any): boolean;
147
+ /**
148
+ * @method getFatAABB
149
+ * @description Returns the stored (fattened) AABB of a proxy.
150
+ * @param {number} id
151
+ * @returns {AABB}
152
+ */
153
+ getFatAABB(id: number): AABB;
154
+ /**
155
+ * @method getUserData
156
+ * @description Returns the proxy payload of a leaf.
157
+ * @param {number} id
158
+ * @returns {Object}
159
+ */
160
+ getUserData(id: number): any;
161
+ /**
162
+ * @method insertLeaf
163
+ * @description Inserts a leaf, choosing the sibling that grows the tree's
164
+ * total surface area least, then rebalancing on the way back to the root.
165
+ * @param {number} leaf
166
+ * @private
167
+ */
168
+ private insertLeaf;
169
+ /**
170
+ * @method removeLeaf
171
+ * @description Unlinks a leaf and collapses its now-single-child parent.
172
+ * @param {number} leaf
173
+ * @private
174
+ */
175
+ private removeLeaf;
176
+ /**
177
+ * @method balance
178
+ * @description One AVL-style rotation at `iA` if its subtrees differ in
179
+ * height by more than one. Keeps queries logarithmic.
180
+ * @param {number} iA
181
+ * @returns {number} - The new root of that subtree
182
+ * @private
183
+ */
184
+ private balance;
185
+ /**
186
+ * @method query
187
+ * @description Calls `callback(proxyId)` for every leaf whose fat AABB
188
+ * overlaps `aabb`. Returning false from the callback stops the query.
189
+ * @param {AABB} aabb
190
+ * @param {Function} callback
191
+ */
192
+ query(aabb: AABB, callback: Function): void;
193
+ /**
194
+ * @method rayCast
195
+ * @description Walks the tree along a ray, calling
196
+ * `callback(subInput, proxyId)`. The callback returns the new max fraction
197
+ * (0 terminates the cast), which lets the traversal shrink as it finds hits.
198
+ * @param {Object} input - `{ p1, p2, maxFraction }`
199
+ * @param {Function} callback
200
+ */
201
+ rayCast(input: any, callback: Function): void;
202
+ /**
203
+ * @method getHeight
204
+ * @description Height of the tree (0 when empty), useful when profiling.
205
+ * @returns {number}
206
+ */
207
+ getHeight(): number;
208
+ }
209
+ export const NULL_NODE: -1;
210
+ import AABB from "./AABB.js";