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,337 @@
1
+ /**
2
+ * @class Physics
3
+ * @description The game-facing front end of Emerald's own rigid-body engine
4
+ * (see `src/physics`). It owns the {@link World}, converts between world
5
+ * (pixel) units and physics units via `scale`, steps the simulation on a fixed
6
+ * timestep, and routes contacts to `onCollisionEnter`/`onCollisionExit` on your
7
+ * objects and {@link Behaviour} components.
8
+ * @param {number} gravity - The gravity of the physics engine
9
+ * @param {number} scale - Pixels per physics unit (meter)
10
+ * @param {number} velocityThreshold - Relative speed below which impacts stop
11
+ * bouncing, which is what lets resting bodies settle instead of jittering
12
+ */
13
+ export class Physics {
14
+ /**
15
+ * @method scheduleAction
16
+ * @description Schedules an action to be executed as soon as possible
17
+ * @param {Function} callback - The callback function to execute
18
+ */
19
+ static scheduleAction(callback: Function): void;
20
+ constructor(gravity: any, scale: any, velocityThreshold?: number);
21
+ world: World;
22
+ gravity: any;
23
+ scale: any;
24
+ fixedTimeStep: number;
25
+ maxSubSteps: number;
26
+ /** Largest slice the variable mode will simulate in one step. */
27
+ maxTimeStep: number;
28
+ /** "fixed" or "variable", see {@link Physics#setVariableTimeStep}. */
29
+ timeStepMode: string;
30
+ /** Steps taken by the last process() call. */
31
+ lastStepCount: number;
32
+ /** @private */
33
+ private _accumulator;
34
+ /** World-level listeners added via onCollisionEnter. @private */
35
+ private _enterCallbacks;
36
+ /** World-level listeners added via onCollisionExit. @private */
37
+ private _exitCallbacks;
38
+ /**
39
+ * @method _dispatchContacts
40
+ * @description Binds contact routing to the current world: owning objects (so
41
+ * Behaviour components receive onCollisionEnter/onCollisionExit) first, then
42
+ * any world-level listeners. Bodies created through RigidBody carry the owner
43
+ * via userData. Re-run whenever the world is replaced, so subscriptions
44
+ * survive a clear().
45
+ * @private
46
+ */
47
+ private _dispatchContacts;
48
+ /**
49
+ * @method raycast
50
+ * @description Casts a ray through the world and returns the closest hit.
51
+ * @param {Object} origin - World-space { x, y } start point
52
+ * @param {Object} direction - Ray direction { x, y } (need not be normalized)
53
+ * @param {number} maxDistance - Max ray length in world units
54
+ * @returns {{object, rigidBody, point, normal, fraction}|null}
55
+ */
56
+ raycast(origin: any, direction: any, maxDistance: number): {
57
+ object: any;
58
+ rigidBody: any;
59
+ point: any;
60
+ normal: any;
61
+ fraction: any;
62
+ } | null;
63
+ /**
64
+ * @method queryPoint
65
+ * @description Returns the objects whose colliders contain a world-space point.
66
+ * @param {Object} point - World-space { x, y }
67
+ * @returns {Array} - Owning objects at the point
68
+ */
69
+ queryPoint(point: any): any[];
70
+ /**
71
+ * @method setFixedTimeStep
72
+ * @description Runs the simulation in constant-size slices, independent of
73
+ * the frame rate: `process()` banks the elapsed time and steps as many whole
74
+ * slices as fit. This is the default and the safe choice: the same inputs
75
+ * produce the same result on every machine, and a slow frame can't destabilise
76
+ * the solver.
77
+ *
78
+ * The cost is that motion updates at the step rate, not the display rate. On
79
+ * a 120Hz screen with a 1/60 step, every simulated position is shown for two
80
+ * frames, so anything that moves in the render frame (a smoothly lerped
81
+ * camera, for instance) will slide against sprites that only move every other
82
+ * frame. Either drive those from the same fixed step, or use
83
+ * {@link Physics#setVariableTimeStep}.
84
+ *
85
+ * @param {number} step - Fixed step in seconds (e.g. 1/60)
86
+ * @param {number} [maxSubSteps] - Max steps per process() call (spiral guard)
87
+ * @returns {Physics} - this
88
+ */
89
+ setFixedTimeStep(step: number, maxSubSteps?: number): Physics;
90
+ /**
91
+ * @method setVariableTimeStep
92
+ * @description Advances the simulation once per `process()` call using the
93
+ * frame's own delta, so physics runs at exactly the rendering rate. Every
94
+ * rendered frame then shows a freshly simulated position, which is what
95
+ * removes the stepping you otherwise see when the display refreshes faster
96
+ * than the simulation.
97
+ *
98
+ * The trade-offs are real and worth knowing:
99
+ * - **Not deterministic.** Results depend on the frame timings the machine
100
+ * happened to produce, so replays and lockstep networking need fixed steps.
101
+ * - **Solver accuracy tracks the frame rate.** Contacts are resolved
102
+ * iteratively, so a long frame is a coarser solve; deep stacks and fast
103
+ * bodies are more forgiving under a fixed step.
104
+ *
105
+ * A frame longer than `maxStep` is split into several equal steps rather than
106
+ * simulated in one lump, up to `maxSubSteps`; beyond that the excess time is
107
+ * dropped instead of letting the world explode or spiral.
108
+ *
109
+ * @param {number} [maxStep=1/30] - Longest slice to simulate in one step
110
+ * @param {number} [maxSubSteps] - Max steps per process() call
111
+ * @returns {Physics} - this
112
+ */
113
+ setVariableTimeStep(maxStep?: number, maxSubSteps?: number): Physics;
114
+ /**
115
+ * @method getTimeStepMode
116
+ * @description Returns "fixed" or "variable".
117
+ * @returns {string}
118
+ */
119
+ getTimeStepMode(): string;
120
+ /**
121
+ * @method createBody
122
+ * @description Creates a body in the physics engine
123
+ * @param {string} type - The type of the body
124
+ * @param {Vector2} position - The position of the body
125
+ * @param {boolean} fixedRotation - Whether the body should have a fixed rotation
126
+ * @param {boolean} attachFixture - Whether the body should have a fixture
127
+ * @param {Vector2} fixtureSize - The size of the fixture
128
+ * @param {number} density - The density of the fixture
129
+ * @param {number} friction - The friction of the fixture
130
+ * @param {number} restitution - The restitution of the fixture
131
+ * @returns {Body} - The body
132
+ */
133
+ createBody(type: string, position?: Vector2, fixedRotation?: boolean, attachFixture?: boolean, fixtureSize?: Vector2, density?: number, friction?: number, restitution?: number): Body;
134
+ /**
135
+ * @method createDistanceJoint
136
+ * @description Connects two rigid bodies with a fixed-length rod between two
137
+ * world-space anchor points, or a damped spring toward that length when
138
+ * `frequencyHz` is set.
139
+ * @param {RigidBody} rigidBodyA
140
+ * @param {RigidBody} rigidBodyB
141
+ * @param {Object} [options] - `{ anchorA, anchorB, length, frequencyHz,
142
+ * dampingRatio, collideConnected }`. `anchorA`/`anchorB` are world-space
143
+ * pixel points; each defaults to its body's own center. `length` is in
144
+ * pixels; it defaults to the current distance between the anchors.
145
+ * @returns {DistanceJoint}
146
+ */
147
+ createDistanceJoint(rigidBodyA: RigidBody, rigidBodyB: RigidBody, options?: any): DistanceJoint;
148
+ /**
149
+ * @method createRevoluteJoint
150
+ * @description Pins two rigid bodies together at a shared world-space point,
151
+ * like a hinge: a door, a pendulum arm, a see-saw. Set `enableMotor` to
152
+ * drive it toward a target angular speed instead of swinging freely.
153
+ * @param {RigidBody} rigidBodyA
154
+ * @param {RigidBody} rigidBodyB
155
+ * @param {Object} anchor - World-space pixel point both bodies pin to
156
+ * @param {Object} [options] - `{ enableMotor, motorSpeed, maxMotorTorque,
157
+ * collideConnected }`
158
+ * @returns {RevoluteJoint}
159
+ */
160
+ createRevoluteJoint(rigidBodyA: RigidBody, rigidBodyB: RigidBody, anchor: any, options?: any): RevoluteJoint;
161
+ /**
162
+ * @method destroyJoint
163
+ * @description Removes a joint created by {@link Physics#createDistanceJoint}
164
+ * or {@link Physics#createRevoluteJoint}.
165
+ * @param {Joint} joint
166
+ */
167
+ destroyJoint(joint: Joint): void;
168
+ /**
169
+ * @method onCollisionEnter
170
+ * @description Registers a world-level listener called whenever any two
171
+ * fixtures start touching. Survives {@link Physics#clear}.
172
+ * @param {Function} callback - Called with (bodyA, bodyB, contact)
173
+ */
174
+ onCollisionEnter(callback: Function): void;
175
+ /**
176
+ * @method onCollisionExit
177
+ * @description Registers a world-level listener called whenever any two
178
+ * fixtures stop touching. Survives {@link Physics#clear}.
179
+ * @param {Function} callback - Called with (bodyA, bodyB, contact)
180
+ */
181
+ onCollisionExit(callback: Function): void;
182
+ /**
183
+ * @method process
184
+ * @description Advances the simulation by `dt` seconds, in whichever way the
185
+ * current time-step mode calls for. Call it once per frame.
186
+ * @param {number} dt - Seconds elapsed since the previous call
187
+ * @returns {number} - How many steps were simulated
188
+ */
189
+ process(dt: number): number;
190
+ /**
191
+ * @method _stepVariable
192
+ * @description Simulates the frame's own delta. Normally that is a single
193
+ * step of exactly `dt`, so physics advances in lock-step with rendering. Only
194
+ * an unusually long frame is divided, and only far enough to keep each slice
195
+ * within `maxTimeStep`.
196
+ * @param {number} dt
197
+ * @returns {number} - Steps taken
198
+ * @private
199
+ */
200
+ private _stepVariable;
201
+ /**
202
+ * @method _stepFixed
203
+ * @description Banks elapsed time and simulates as many constant-size slices
204
+ * as have accumulated, leaving the remainder for next frame.
205
+ * @param {number} dt
206
+ * @returns {number} - Steps taken
207
+ * @private
208
+ */
209
+ private _stepFixed;
210
+ /**
211
+ * @method getInterpolationAlpha
212
+ * @description How far the fixed-step simulation currently sits between its
213
+ * last completed step and the next one (0..1). Useful if you interpolate
214
+ * renderables between physics states. Always 0 in variable mode, where every
215
+ * frame already renders a freshly simulated position.
216
+ * @returns {number}
217
+ */
218
+ getInterpolationAlpha(): number;
219
+ /**
220
+ * @method clear
221
+ * @description Drops every body and starts a fresh world with the original
222
+ * gravity; use it when tearing a level down. Collision routing and any
223
+ * listeners added through onCollisionEnter/onCollisionExit are re-bound to
224
+ * the new world, so they keep working afterwards.
225
+ */
226
+ clear(): void;
227
+ /**
228
+ * @method getGravity
229
+ * @description Returns the gravity of the physics engine
230
+ * @returns {number} - The gravity of the physics engine
231
+ */
232
+ getGravity(): number;
233
+ /**
234
+ * @method getScale
235
+ * @description Returns the scale of the physics engine
236
+ * @returns {number} - The scale of the physics engine
237
+ */
238
+ getScale(): number;
239
+ }
240
+ /**
241
+ * @class Vector2
242
+ * @description Represents a 2D vector
243
+ * @param {number} x - The x coordinate of the vector
244
+ * @param {number} y - The y coordinate of the vector
245
+ */
246
+ export class Vector2 {
247
+ constructor(x?: number, y?: number);
248
+ x: number;
249
+ y: number;
250
+ /**
251
+ * @method set
252
+ * @description Sets the x and y coordinates in place
253
+ * @param {number} x - The x coordinate
254
+ * @param {number} y - The y coordinate
255
+ * @returns {Vector2} - This vector
256
+ */
257
+ set(x: number, y: number): Vector2;
258
+ /**
259
+ * @method clone
260
+ * @description Returns a copy of the vector
261
+ * @returns {Vector2} - The cloned vector
262
+ */
263
+ clone(): Vector2;
264
+ /**
265
+ * @method equals
266
+ * @description Checks if the vector is equal to another vector
267
+ * @param {Vector2} other - The other vector
268
+ * @returns {boolean} - True if the vector is equal to the other vector
269
+ */
270
+ equals(other: Vector2): boolean;
271
+ /**
272
+ * @method getX
273
+ * @description Returns the x coordinate of the vector
274
+ * @returns {number} - The x coordinate of the vector
275
+ */
276
+ getX(): number;
277
+ /**
278
+ * @method getY
279
+ * @description Returns the y coordinate of the vector
280
+ * @returns {number} - The y coordinate of the vector
281
+ */
282
+ getY(): number;
283
+ }
284
+ /**
285
+ * @class Vector3
286
+ * @description Represents a 3D vector
287
+ * @param {number} x - The x coordinate of the vector
288
+ * @param {number} y - The y coordinate of the vector
289
+ * @param {number} z - The z coordinate of the vector
290
+ */
291
+ export class Vector3 {
292
+ constructor(x?: number, y?: number, z?: number);
293
+ x: number;
294
+ y: number;
295
+ z: number;
296
+ /**
297
+ * @method set
298
+ * @description Sets the x, y and z coordinates in place
299
+ * @param {number} x - The x coordinate
300
+ * @param {number} y - The y coordinate
301
+ * @param {number} z - The z coordinate
302
+ * @returns {Vector3} - This vector
303
+ */
304
+ set(x: number, y: number, z: number): Vector3;
305
+ /**
306
+ * @method clone
307
+ * @description Returns a copy of the vector
308
+ * @returns {Vector3} - The cloned vector
309
+ */
310
+ clone(): Vector3;
311
+ /**
312
+ * @method equals
313
+ * @description Checks if the vector is equal to another vector
314
+ * @param {Vector3} other - The other vector
315
+ * @returns {boolean} - True if the vector is equal to the other vector
316
+ */
317
+ equals(other: Vector3): boolean;
318
+ /**
319
+ * @method getX
320
+ * @description Returns the x coordinate of the vector
321
+ * @returns {number} - The x coordinate of the vector
322
+ */
323
+ getX(): number;
324
+ /**
325
+ * @method getY
326
+ * @description Returns the y coordinate of the vector
327
+ * @returns {number} - The y coordinate of the vector
328
+ */
329
+ getY(): number;
330
+ /**
331
+ * @method getZ
332
+ * @description Returns the z coordinate of the vector
333
+ * @returns {number} - The z coordinate of the vector
334
+ */
335
+ getZ(): number;
336
+ }
337
+ import { World } from "./physics/index.js";
@@ -0,0 +1,53 @@
1
+ export default Pool;
2
+ /**
3
+ * @class Pool
4
+ * @description Generic object pool to avoid per-frame allocations for churny
5
+ * objects (bullets, particles, enemies). Provide a factory and an optional
6
+ * reset function; acquire reused objects and release them when done.
7
+ *
8
+ * @example
9
+ * const bullets = new Pool(() => new Bullet(), (b, x, y) => b.spawn(x, y), 50);
10
+ * const b = bullets.acquire(px, py);
11
+ * // later...
12
+ * bullets.release(b);
13
+ */
14
+ declare class Pool {
15
+ /**
16
+ * @param {Function} factory - Creates a new pooled object
17
+ * @param {Function} [reset] - Called on acquire as reset(obj, ...args)
18
+ * @param {number} [initialSize] - Number of objects to pre-create
19
+ */
20
+ constructor(factory: Function, reset?: Function, initialSize?: number);
21
+ factory: Function;
22
+ reset: Function;
23
+ available: any[];
24
+ active: Set<any>;
25
+ /**
26
+ * @method acquire
27
+ * @description Returns a pooled object (reused or freshly created). Extra
28
+ * arguments are forwarded to the reset function.
29
+ * @returns {*} - The acquired object
30
+ */
31
+ acquire(...args: any[]): any;
32
+ /**
33
+ * @method release
34
+ * @description Returns an object to the pool.
35
+ * @param {*} obj - The object to release
36
+ */
37
+ release(obj: any): void;
38
+ /**
39
+ * @method releaseAll
40
+ * @description Returns every active object to the pool.
41
+ */
42
+ releaseAll(): void;
43
+ /**
44
+ * @member activeCount
45
+ * @description Number of currently-acquired objects.
46
+ */
47
+ get activeCount(): number;
48
+ /**
49
+ * @member size
50
+ * @description Total objects managed by the pool (active + available).
51
+ */
52
+ get size(): number;
53
+ }
@@ -0,0 +1,68 @@
1
+ export default PostEffects;
2
+ declare namespace PostEffects {
3
+ /**
4
+ * @method grayscale
5
+ * @description Desaturates the image.
6
+ */
7
+ function grayscale(): PostEffect;
8
+ /**
9
+ * @method vignette
10
+ * @description Darkens the edges of the screen.
11
+ * @param {Object} [options] - { intensity = 0.5, radius = 0.75, softness = 0.45 }
12
+ */
13
+ function vignette(options?: any): PostEffect;
14
+ /**
15
+ * @method colorGrade
16
+ * @description Adjusts brightness, contrast and saturation.
17
+ * @param {Object} [options] - { brightness = 0, contrast = 1, saturation = 1 }
18
+ */
19
+ function colorGrade(options?: any): PostEffect;
20
+ /**
21
+ * @method chromaticAberration
22
+ * @description Splits the RGB channels toward the screen edges.
23
+ * @param {Object} [options] - { amount = 0.003 }
24
+ */
25
+ function chromaticAberration(options?: any): PostEffect;
26
+ /**
27
+ * @method scanlines
28
+ * @description Overlays horizontal scanlines.
29
+ * @param {Object} [options] - { intensity = 0.15, count = 480 }
30
+ */
31
+ function scanlines(options?: any): PostEffect;
32
+ /**
33
+ * @method crt
34
+ * @description Retro CRT look: barrel distortion, scanlines and edge vignette.
35
+ * @param {Object} [options] - { curvature = 4.0, scanlineIntensity = 0.2, vignette = 0.3 }
36
+ */
37
+ function crt(options?: any): PostEffect;
38
+ /**
39
+ * @method bloom
40
+ * @description Glow around bright areas (multi-pass).
41
+ * @param {Object} [options] - { threshold = 0.7, intensity = 1.0, spread = 1.0 }
42
+ */
43
+ function bloom(options?: any): BloomEffect;
44
+ }
45
+ /**
46
+ * @class BloomEffect
47
+ * @description Multi-pass bloom: extract bright pixels above a threshold, blur
48
+ * them with a separable Gaussian, then add the result back over the scene. Built
49
+ * via {@link PostEffects.bloom}.
50
+ */
51
+ export class BloomEffect extends PostEffect {
52
+ constructor(options?: {});
53
+ threshold: any;
54
+ intensity: any;
55
+ spread: any;
56
+ /** @private */
57
+ private _threshold;
58
+ /** @private */
59
+ private _blurH;
60
+ /** @private */
61
+ private _blurV;
62
+ /** @private */
63
+ private _composite;
64
+ render(ctx: any): void;
65
+ /** @private */
66
+ private _bloomTex;
67
+ }
68
+ import { PostEffect } from "./PostProcessor.js";
@@ -0,0 +1,124 @@
1
+ export default PostProcessor;
2
+ /**
3
+ * @class PostProcessor
4
+ * @description Drives a chain of full-screen {@link PostEffect}s. The scene is
5
+ * rendered into a texture, then each effect is applied in sequence (ping-ponging
6
+ * between two render targets), and the final result is drawn to the screen.
7
+ *
8
+ * Created and managed by Emerald when you call `emerald.enablePostProcessing()`;
9
+ * you usually just add effects via `emerald.addPostEffect(PostEffects.bloom())`.
10
+ */
11
+ declare class PostProcessor {
12
+ gl: WebGLRenderingContext;
13
+ effects: any[];
14
+ enabled: boolean;
15
+ /** @private */
16
+ private _quad;
17
+ /** @private */
18
+ private _rtA;
19
+ /** @private */
20
+ private _rtB;
21
+ /** @private */
22
+ private _temps;
23
+ /** @private */
24
+ private _width;
25
+ /** @private */
26
+ private _height;
27
+ /**
28
+ * @method _restoreGL
29
+ * @description Rebuilds the fullscreen quad, ping-pong render targets, and
30
+ * every effect's program after a WebGL context loss.
31
+ * @private
32
+ */
33
+ private _restoreGL;
34
+ /**
35
+ * @method addEffect
36
+ * @description Appends an effect to the chain.
37
+ * @param {PostEffect} effect
38
+ * @returns {PostProcessor} - this
39
+ */
40
+ addEffect(effect: PostEffect): PostProcessor;
41
+ /**
42
+ * @method removeEffect
43
+ * @description Removes an effect from the chain.
44
+ */
45
+ removeEffect(effect: any): this;
46
+ /**
47
+ * @method clear
48
+ * @description Removes all effects.
49
+ */
50
+ clear(): this;
51
+ /**
52
+ * @method hasEffects
53
+ * @returns {boolean} - Whether any enabled effects exist.
54
+ */
55
+ hasEffects(): boolean;
56
+ /** @private */
57
+ private _acquireTemp;
58
+ /**
59
+ * @method process
60
+ * @description Applies the effect chain, drawing the final image to the canvas.
61
+ * @param {WebGLTexture} sceneTexture - The rendered scene
62
+ * @param {number} width - Canvas width in pixels
63
+ * @param {number} height - Canvas height in pixels
64
+ * @param {number} time - Seconds (for time-based effects)
65
+ */
66
+ process(sceneTexture: WebGLTexture, width: number, height: number, time: number): void;
67
+ /**
68
+ * @method _blit
69
+ * @description Renders one effect program from `input` into `output` (null =
70
+ * screen), setting the standard uniforms.
71
+ * @private
72
+ */
73
+ private _blit;
74
+ /**
75
+ * @method dispose
76
+ * @description Frees the render targets owned by this processor.
77
+ */
78
+ dispose(): void;
79
+ }
80
+ /**
81
+ * @class PostEffect
82
+ * @description A single full-screen post-processing pass: a fragment shader that
83
+ * samples the previous pass (`uScene`) and writes the next image. The shader
84
+ * automatically has `vUV`, `uScene`, `uResolution`, and `uTime` available; add
85
+ * your own uniforms and set them with the `setUniforms` callback.
86
+ *
87
+ * @example
88
+ * const tint = new PostEffect("tint", `
89
+ * uniform vec3 uTint;
90
+ * void main() { gl_FragColor = texture2D(uScene, vUV) * vec4(uTint, 1.0); }
91
+ * `, { setUniforms: (gl, loc) => gl.uniform3f(loc("uTint"), 1.0, 0.8, 0.8) });
92
+ */
93
+ export class PostEffect {
94
+ /**
95
+ * @param {string} name - A label (for debugging)
96
+ * @param {string} fragmentSource - Fragment shader body (declares void main)
97
+ * @param {Object} [options] - { setUniforms(gl, loc, ctx), enabled = true }
98
+ */
99
+ constructor(name: string, fragmentSource: string, options?: any);
100
+ name: string;
101
+ fragmentSource: string;
102
+ setUniforms: any;
103
+ enabled: boolean;
104
+ program: any;
105
+ /** @private */
106
+ private _locCache;
107
+ /** @private */
108
+ private _compile;
109
+ /**
110
+ * @method _restoreGL
111
+ * @description Drops the dead program/locations after a context loss so the
112
+ * next _compile builds fresh ones.
113
+ * @private
114
+ */
115
+ private _restoreGL;
116
+ loc(gl: any, name: any): any;
117
+ /**
118
+ * @method render
119
+ * @description Renders this effect from ctx.input into ctx.output. Override for
120
+ * multi-pass effects.
121
+ * @param {Object} ctx - Provided by the PostProcessor
122
+ */
123
+ render(ctx: any): void;
124
+ }
@@ -0,0 +1,56 @@
1
+ export default RenderTarget;
2
+ /**
3
+ * @class RenderTarget
4
+ * @description An offscreen render surface: a framebuffer backed by a color
5
+ * texture (and an optional depth buffer). Bind it to render the scene (or a
6
+ * post-processing pass) into a texture instead of the screen. The resulting
7
+ * `texture` can then be sampled by another pass or drawn to the canvas.
8
+ *
9
+ * Used by the post-processing pipeline, but also useful on its own for
10
+ * minimaps, mirrors, render-to-texture effects, or picture-in-picture.
11
+ *
12
+ * @example
13
+ * const rt = new RenderTarget(512, 512);
14
+ * rt.bind();
15
+ * // ...draw...
16
+ * rt.unbind();
17
+ * // rt.texture now holds the rendered image
18
+ */
19
+ declare class RenderTarget {
20
+ /**
21
+ * @param {number} width - Width in pixels
22
+ * @param {number} height - Height in pixels
23
+ * @param {Object} [options] - { depth = false, pixelart = false }
24
+ */
25
+ constructor(width: number, height: number, options?: any);
26
+ gl: WebGLRenderingContext;
27
+ width: number;
28
+ height: number;
29
+ depth: boolean;
30
+ pixelart: boolean;
31
+ framebuffer: WebGLFramebuffer;
32
+ texture: WebGLTexture;
33
+ depthBuffer: WebGLRenderbuffer;
34
+ /** @private */
35
+ private _allocate;
36
+ /**
37
+ * @method resize
38
+ * @description Resizes the surface (reallocating storage) if dimensions change.
39
+ */
40
+ resize(width: any, height: any): void;
41
+ /**
42
+ * @method bind
43
+ * @description Binds this framebuffer and sets the viewport to its full size.
44
+ */
45
+ bind(): void;
46
+ /**
47
+ * @method unbind
48
+ * @description Restores the default framebuffer (the canvas).
49
+ */
50
+ unbind(): void;
51
+ /**
52
+ * @method dispose
53
+ * @description Frees all GL resources held by this target.
54
+ */
55
+ dispose(): void;
56
+ }