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.
- package/README.md +2198 -968
- package/dist/types/index.d.ts +75 -32
- package/dist/types/src/Animator.d.ts +50 -0
- package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
- package/dist/types/src/Camera.d.ts +122 -0
- package/dist/types/src/CameraController.d.ts +107 -0
- package/dist/types/src/CanvasText.d.ts +91 -0
- package/dist/types/src/CollisionLayers.d.ts +58 -0
- package/dist/types/{Color.d.ts → src/Color.d.ts} +6 -6
- package/dist/types/src/Coroutine.d.ts +111 -0
- package/dist/types/src/DebugOverlay.d.ts +86 -0
- package/dist/types/src/Drawable.d.ts +271 -0
- package/dist/types/src/Easing.d.ts +22 -0
- package/dist/types/src/Emerald.d.ts +420 -0
- package/dist/types/src/EmeraldDB.d.ts +159 -0
- package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
- package/dist/types/src/GLUtils.d.ts +4 -0
- package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
- package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +75 -23
- package/dist/types/src/Interpolator.d.ts +66 -0
- package/dist/types/src/Material.d.ts +87 -0
- package/dist/types/src/MathUtils.d.ts +81 -0
- package/dist/types/src/ParticleEmitter.d.ts +131 -0
- package/dist/types/src/Physics.d.ts +337 -0
- package/dist/types/src/Pool.d.ts +53 -0
- package/dist/types/src/PostEffects.d.ts +68 -0
- package/dist/types/src/PostProcessor.d.ts +124 -0
- package/dist/types/src/RenderTarget.d.ts +56 -0
- package/dist/types/src/Scene.d.ts +62 -0
- package/dist/types/src/ScreenEffects.d.ts +111 -0
- package/dist/types/src/Serializer.d.ts +86 -0
- package/dist/types/src/Shaders.d.ts +2 -0
- package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
- package/dist/types/src/SpatialGrid.d.ts +50 -0
- package/dist/types/src/SpriteBatch.d.ts +89 -0
- package/dist/types/src/StateMachine.d.ts +59 -0
- package/dist/types/src/Storage.d.ts +89 -0
- package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
- package/dist/types/src/TextureAtlas.d.ts +55 -0
- package/dist/types/src/Tilemap.d.ts +91 -0
- package/dist/types/src/Time.d.ts +53 -0
- package/dist/types/src/Timer.d.ts +54 -0
- package/dist/types/src/Transform.d.ts +94 -0
- package/dist/types/src/Tween.d.ts +81 -0
- package/dist/types/src/UI.d.ts +121 -0
- package/dist/types/src/components/Behaviour.d.ts +71 -0
- package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
- package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
- package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
- package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
- package/dist/types/src/components/Collider.d.ts +102 -0
- package/dist/types/src/components/GameObject.d.ts +135 -0
- package/dist/types/src/components/PolygonCollider.d.ts +33 -0
- package/dist/types/src/components/RigidBody.d.ts +456 -0
- package/dist/types/src/importers/Aseprite.d.ts +79 -0
- package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
- package/dist/types/src/importers/TiledMap.d.ts +62 -0
- package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
- package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
- package/dist/types/src/managers/AssetManager.d.ts +116 -0
- package/dist/types/src/managers/AudioManager.d.ts +259 -0
- package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
- package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
- package/dist/types/src/managers/GLManager.d.ts +84 -0
- package/dist/types/src/managers/GLState.d.ts +37 -0
- package/dist/types/src/managers/Gamepad.d.ts +102 -0
- package/dist/types/src/managers/IDManager.d.ts +31 -0
- package/dist/types/src/managers/InputManager.d.ts +381 -0
- package/dist/types/src/managers/NetworkManager.d.ts +93 -0
- package/dist/types/src/managers/RenderStats.d.ts +34 -0
- package/dist/types/src/managers/SceneManager.d.ts +44 -0
- package/dist/types/src/managers/ShaderManager.d.ts +55 -0
- package/dist/types/src/managers/TextureManager.d.ts +102 -0
- package/dist/types/src/particlesystem/Particle.d.ts +64 -0
- package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
- package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
- package/dist/types/src/physics/AABB.d.ts +92 -0
- package/dist/types/src/physics/Body.d.ts +435 -0
- package/dist/types/src/physics/BodyType.d.ts +6 -0
- package/dist/types/src/physics/BroadPhase.d.ts +210 -0
- package/dist/types/src/physics/Collision.d.ts +102 -0
- package/dist/types/src/physics/Contact.d.ts +206 -0
- package/dist/types/src/physics/ContactSolver.d.ts +108 -0
- package/dist/types/src/physics/Distance.d.ts +54 -0
- package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
- package/dist/types/src/physics/Fixture.d.ts +221 -0
- package/dist/types/src/physics/Island.d.ts +52 -0
- package/dist/types/src/physics/Joint.d.ts +59 -0
- package/dist/types/src/physics/Math2D.d.ts +371 -0
- package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
- package/dist/types/src/physics/Settings.d.ts +22 -0
- package/dist/types/src/physics/Shapes.d.ts +207 -0
- package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
- package/dist/types/src/physics/World.d.ts +274 -0
- package/dist/types/src/physics/index.d.ts +34 -0
- package/index.js +78 -0
- package/package.json +73 -60
- package/src/Animator.js +95 -0
- package/src/BitmapText.js +6 -5
- package/src/Camera.js +183 -0
- package/src/CameraController.js +192 -0
- package/src/CanvasText.js +281 -0
- package/src/CollisionLayers.js +86 -0
- package/src/Color.js +26 -18
- package/src/Coroutine.js +259 -0
- package/src/DebugOverlay.js +246 -0
- package/src/Drawable.js +842 -582
- package/src/Easing.js +57 -0
- package/src/Emerald.js +1150 -459
- package/src/EmeraldDB.js +328 -0
- package/src/FPSCounter.js +43 -43
- package/src/GLUtils.js +60 -67
- package/src/Instance.js +41 -5
- package/src/InstancedTexture.js +308 -127
- package/src/Interpolator.js +124 -0
- package/src/Material.js +202 -0
- package/src/MathUtils.js +134 -0
- package/src/ParticleEmitter.js +284 -0
- package/src/Physics.js +431 -40
- package/src/Pool.js +85 -0
- package/src/PostEffects.js +296 -0
- package/src/PostProcessor.js +304 -0
- package/src/RenderTarget.js +134 -0
- package/src/Scene.js +115 -83
- package/src/ScreenEffects.js +266 -0
- package/src/Serializer.js +131 -0
- package/src/Shaders.js +150 -165
- package/src/Shapes.js +118 -129
- package/src/SpatialGrid.js +111 -0
- package/src/SpriteBatch.js +299 -0
- package/src/StateMachine.js +82 -0
- package/src/Storage.js +175 -47
- package/src/Texture.js +58 -67
- package/src/TextureAtlas.js +96 -0
- package/src/Tilemap.js +274 -0
- package/src/Time.js +51 -6
- package/src/Timer.js +99 -0
- package/src/Transform.js +100 -7
- package/src/Tween.js +160 -0
- package/src/UI.js +394 -0
- package/src/components/Behaviour.js +90 -0
- package/src/components/BoxCollider.js +29 -12
- package/src/components/BoxColliderDebug.js +3 -4
- package/src/components/CircleCollider.js +26 -12
- package/src/components/CircleColliderDebug.js +25 -24
- package/src/components/Collider.js +150 -34
- package/src/components/GameObject.js +130 -21
- package/src/components/PolygonCollider.js +55 -0
- package/src/components/RigidBody.js +556 -8
- package/src/importers/Aseprite.js +142 -0
- package/src/importers/ForgeLevel.js +581 -0
- package/src/importers/TiledMap.js +158 -0
- package/src/lights/DirectionalLight.js +6 -15
- package/src/lights/PointLight.js +4 -4
- package/src/managers/AssetManager.js +239 -0
- package/src/managers/AudioManager.js +565 -146
- package/src/managers/EventManager.js +488 -477
- package/src/managers/GLManager.js +57 -0
- package/src/managers/GLState.js +70 -0
- package/src/managers/Gamepad.js +126 -0
- package/src/managers/IDManager.js +24 -2
- package/src/managers/InputManager.js +905 -0
- package/src/managers/NetworkManager.js +178 -0
- package/src/managers/RenderStats.js +34 -0
- package/src/managers/SceneManager.js +30 -0
- package/src/managers/ShaderManager.js +0 -2
- package/src/managers/TextureManager.js +218 -0
- package/src/particlesystem/Particle.js +82 -7
- package/src/particlesystem/ParticleSettings.js +21 -3
- package/src/particlesystem/Particles.js +80 -31
- package/src/physics/AABB.js +207 -0
- package/src/physics/Body.js +862 -0
- package/src/physics/BodyType.js +16 -0
- package/src/physics/BroadPhase.js +641 -0
- package/src/physics/Collision.js +534 -0
- package/src/physics/Contact.js +500 -0
- package/src/physics/ContactSolver.js +526 -0
- package/src/physics/Distance.js +403 -0
- package/src/physics/DistanceJoint.js +227 -0
- package/src/physics/Fixture.js +346 -0
- package/src/physics/Island.js +203 -0
- package/src/physics/Joint.js +78 -0
- package/src/physics/Math2D.js +573 -0
- package/src/physics/RevoluteJoint.js +278 -0
- package/src/physics/Settings.js +78 -0
- package/src/physics/Shapes.js +549 -0
- package/src/physics/TimeOfImpact.js +87 -0
- package/src/physics/World.js +731 -0
- package/src/physics/index.js +79 -0
- package/dist/types/Drawable.d.ts +0 -157
- package/dist/types/Emerald.d.ts +0 -73
- package/dist/types/GLUtils.d.ts +0 -6
- package/dist/types/Physics.d.ts +0 -139
- package/dist/types/Scene.d.ts +0 -39
- package/dist/types/Shaders.d.ts +0 -4
- package/dist/types/Storage.d.ts +0 -46
- package/dist/types/Time.d.ts +0 -22
- package/dist/types/Transform.d.ts +0 -41
- package/dist/types/components/BoxColliderDebug.d.ts +0 -19
- package/dist/types/components/CircleColliderDebug.d.ts +0 -19
- package/dist/types/components/Collider.d.ts +0 -53
- package/dist/types/components/GameObject.d.ts +0 -72
- package/dist/types/components/RigidBody.d.ts +0 -104
- package/dist/types/managers/AudioManager.d.ts +0 -60
- package/dist/types/managers/GLManager.d.ts +0 -47
- package/dist/types/managers/IDManager.d.ts +0 -21
- package/dist/types/managers/SceneManager.d.ts +0 -22
- package/dist/types/particlesystem/Particle.d.ts +0 -42
|
@@ -56,10 +56,67 @@ class GLManager {
|
|
|
56
56
|
static getCanvas() {
|
|
57
57
|
return GLManager.canvas;
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @method registerRestorable
|
|
62
|
+
* @description Registers an object holding GL resources (buffers, textures,
|
|
63
|
+
* programs) for re-creation after a WebGL context loss. The object must
|
|
64
|
+
* implement `_restoreGL()`. Drawables register themselves automatically and
|
|
65
|
+
* unregister on dispose().
|
|
66
|
+
* @param {Object} obj - An object with a _restoreGL() method
|
|
67
|
+
*/
|
|
68
|
+
static registerRestorable(obj) {
|
|
69
|
+
GLManager.restorables.add(obj);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @method unregisterRestorable
|
|
74
|
+
* @description Removes an object from the context-restore registry.
|
|
75
|
+
*/
|
|
76
|
+
static unregisterRestorable(obj) {
|
|
77
|
+
GLManager.restorables.delete(obj);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @method restoreAll
|
|
82
|
+
* @description Calls _restoreGL() on every registered object. Invoked by
|
|
83
|
+
* Emerald after the context is restored and the default shaders/textures
|
|
84
|
+
* have been rebuilt.
|
|
85
|
+
*/
|
|
86
|
+
static restoreAll() {
|
|
87
|
+
for (const obj of GLManager.restorables) {
|
|
88
|
+
try {
|
|
89
|
+
obj._restoreGL();
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.error("[GLManager] > restore failed for", obj, e);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @method setProjection
|
|
98
|
+
* @description Stores the current camera's projection matrix so custom
|
|
99
|
+
* Materials (which use their own shader program) can upload it.
|
|
100
|
+
* @param {Float32Array} matrix - The projection matrix
|
|
101
|
+
*/
|
|
102
|
+
static setProjection(matrix) {
|
|
103
|
+
GLManager.projection = matrix;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @method getProjection
|
|
108
|
+
* @description Returns the last projection matrix set by the renderer.
|
|
109
|
+
* @returns {Float32Array}
|
|
110
|
+
*/
|
|
111
|
+
static getProjection() {
|
|
112
|
+
return GLManager.projection;
|
|
113
|
+
}
|
|
59
114
|
}
|
|
60
115
|
|
|
61
116
|
GLManager.gl = null;
|
|
62
117
|
GLManager.programInfo = null;
|
|
63
118
|
GLManager.canvas = null;
|
|
119
|
+
GLManager.projection = null;
|
|
120
|
+
GLManager.restorables = new Set();
|
|
64
121
|
|
|
65
122
|
export default GLManager;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class GLState
|
|
3
|
+
* @description Tiny redundant-uniform filter. The renderer sets the same handful
|
|
4
|
+
* of per-object uniforms (useTexture, useInstances, useLighting, color, opacity)
|
|
5
|
+
* for every object every frame; most calls repeat the previous value. These
|
|
6
|
+
* helpers skip the GL call when the value is unchanged. Keyed by uniform
|
|
7
|
+
* location, which is program-specific, so the cache is safe across objects.
|
|
8
|
+
*/
|
|
9
|
+
class GLState {
|
|
10
|
+
/**
|
|
11
|
+
* @method reset
|
|
12
|
+
* @description Clears the cache. Called at the start of each frame so the
|
|
13
|
+
* first object always re-establishes state.
|
|
14
|
+
*/
|
|
15
|
+
static reset() {
|
|
16
|
+
GLState.ints.clear();
|
|
17
|
+
GLState.floats.clear();
|
|
18
|
+
GLState.vec4s.clear();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @method uniform1i
|
|
23
|
+
* @description Cached gl.uniform1i (accepts booleans, coerced like WebGL does).
|
|
24
|
+
*/
|
|
25
|
+
static uniform1i(gl, location, value) {
|
|
26
|
+
if (location == null) return;
|
|
27
|
+
const v = value === true ? 1 : value === false ? 0 : value;
|
|
28
|
+
if (GLState.ints.get(location) !== v) {
|
|
29
|
+
gl.uniform1i(location, v);
|
|
30
|
+
GLState.ints.set(location, v);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @method uniform1f
|
|
36
|
+
* @description Cached gl.uniform1f.
|
|
37
|
+
*/
|
|
38
|
+
static uniform1f(gl, location, value) {
|
|
39
|
+
if (location == null) return;
|
|
40
|
+
if (GLState.floats.get(location) !== value) {
|
|
41
|
+
gl.uniform1f(location, value);
|
|
42
|
+
GLState.floats.set(location, value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @method uniform4fv
|
|
48
|
+
* @description Cached gl.uniform4fv (compares the four components).
|
|
49
|
+
*/
|
|
50
|
+
static uniform4fv(gl, location, value) {
|
|
51
|
+
if (location == null) return;
|
|
52
|
+
const cached = GLState.vec4s.get(location);
|
|
53
|
+
if (
|
|
54
|
+
!cached ||
|
|
55
|
+
cached[0] !== value[0] ||
|
|
56
|
+
cached[1] !== value[1] ||
|
|
57
|
+
cached[2] !== value[2] ||
|
|
58
|
+
cached[3] !== value[3]
|
|
59
|
+
) {
|
|
60
|
+
gl.uniform4fv(location, value);
|
|
61
|
+
GLState.vec4s.set(location, [value[0], value[1], value[2], value[3]]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
GLState.ints = new Map();
|
|
67
|
+
GLState.floats = new Map();
|
|
68
|
+
GLState.vec4s = new Map();
|
|
69
|
+
|
|
70
|
+
export default GLState;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class Gamepad
|
|
3
|
+
* @description An autocomplete-friendly way to build the raw gamepad token
|
|
4
|
+
* strings InputManager already understands ("pad:0:south", etc.). It does
|
|
5
|
+
* not read input itself, and it is unrelated to the browser's own native
|
|
6
|
+
* `Gamepad` interface (the objects `navigator.getGamepads()` returns). It
|
|
7
|
+
* exists purely so you don't have to remember button-name spelling: every
|
|
8
|
+
* button/stick-direction name InputManager's standard mapping recognizes is
|
|
9
|
+
* a static constant here, so typing `Gamepad.` in an editor lists them the
|
|
10
|
+
* way an enum's members would.
|
|
11
|
+
*
|
|
12
|
+
* `Gamepad.get(index).key(name)` produces exactly the same string as writing
|
|
13
|
+
* the token by hand, so the two are fully interchangeable anywhere
|
|
14
|
+
* InputManager takes one: `mapAction`, `isDown`, `justPressed`,
|
|
15
|
+
* `justReleased`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { Gamepad, InputManager } from "./index.js";
|
|
19
|
+
*
|
|
20
|
+
* const input = new InputManager();
|
|
21
|
+
* const pad = Gamepad.get(0); // the first controller
|
|
22
|
+
*
|
|
23
|
+
* input.mapAction("jump", [pad.key(Gamepad.SOUTH)]);
|
|
24
|
+
* input.mapAction("left", [pad.key(Gamepad.DPAD_LEFT), pad.key(Gamepad.LEFT_STICK_LEFT)]);
|
|
25
|
+
*
|
|
26
|
+
* // in the loop:
|
|
27
|
+
* if (input.justPressed("jump")) player.jump();
|
|
28
|
+
*/
|
|
29
|
+
class Gamepad {
|
|
30
|
+
/**
|
|
31
|
+
* @method get
|
|
32
|
+
* @description Returns the (cached) handle for a pad index: 0 for the
|
|
33
|
+
* first controller, 1 for the second, and so on.
|
|
34
|
+
* @param {number} [index=0]
|
|
35
|
+
* @returns {Gamepad}
|
|
36
|
+
*/
|
|
37
|
+
static get(index = 0) {
|
|
38
|
+
let pad = Gamepad._instances.get(index);
|
|
39
|
+
if (!pad) {
|
|
40
|
+
pad = new Gamepad(index);
|
|
41
|
+
Gamepad._instances.set(index, pad);
|
|
42
|
+
}
|
|
43
|
+
return pad;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @private Use `Gamepad.get(index)` rather than constructing directly, so
|
|
48
|
+
* every caller asking for the same pad index shares one instance.
|
|
49
|
+
*/
|
|
50
|
+
constructor(index) {
|
|
51
|
+
this.index = index;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @method key
|
|
56
|
+
* @description A face/shoulder/centre/d-pad/stick-as-button token for this
|
|
57
|
+
* pad. Pass one of the `Gamepad.*` constants (`Gamepad.SOUTH`,
|
|
58
|
+
* `Gamepad.DPAD_UP`, …). InputManager's standard mapping also accepts a
|
|
59
|
+
* few vendor aliases these don't cover (e.g. "a", "cross" for `SOUTH`) if
|
|
60
|
+
* you'd rather think in Xbox/PlayStation terms; those still work as plain
|
|
61
|
+
* strings, `key()` just doesn't need to name them since `SOUTH` already
|
|
62
|
+
* reads the same on every pad.
|
|
63
|
+
* @param {string} name - One of the `Gamepad.*` button constants
|
|
64
|
+
* @returns {string}
|
|
65
|
+
*/
|
|
66
|
+
key(name) {
|
|
67
|
+
return `pad:${this.index}:${name}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @method button
|
|
72
|
+
* @description A raw button index, mapping-independent: an escape hatch
|
|
73
|
+
* for a pad whose layout the standard/custom mapping tables don't cover.
|
|
74
|
+
* @param {number} n
|
|
75
|
+
* @returns {string}
|
|
76
|
+
*/
|
|
77
|
+
button(n) {
|
|
78
|
+
return `pad:${this.index}:${n}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @method axis
|
|
83
|
+
* @description A raw analog axis past the deadzone, in one direction.
|
|
84
|
+
* @param {number} n - Axis index (0/1 = left stick X/Y, 2/3 = right stick X/Y on a standard pad)
|
|
85
|
+
* @param {"+"|"-"} [sign="+"]
|
|
86
|
+
* @returns {string}
|
|
87
|
+
*/
|
|
88
|
+
axis(n, sign = "+") {
|
|
89
|
+
return `pad:${this.index}:axis${n}${sign}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Gamepad._instances = new Map();
|
|
94
|
+
|
|
95
|
+
Gamepad.SOUTH = "south";
|
|
96
|
+
Gamepad.EAST = "east";
|
|
97
|
+
Gamepad.WEST = "west";
|
|
98
|
+
Gamepad.NORTH = "north";
|
|
99
|
+
|
|
100
|
+
Gamepad.L1 = "l1";
|
|
101
|
+
Gamepad.R1 = "r1";
|
|
102
|
+
Gamepad.L2 = "l2";
|
|
103
|
+
Gamepad.R2 = "r2";
|
|
104
|
+
|
|
105
|
+
Gamepad.SELECT = "select";
|
|
106
|
+
Gamepad.START = "start";
|
|
107
|
+
Gamepad.HOME = "home";
|
|
108
|
+
|
|
109
|
+
Gamepad.L3 = "l3";
|
|
110
|
+
Gamepad.R3 = "r3";
|
|
111
|
+
|
|
112
|
+
Gamepad.DPAD_UP = "dpadUp";
|
|
113
|
+
Gamepad.DPAD_DOWN = "dpadDown";
|
|
114
|
+
Gamepad.DPAD_LEFT = "dpadLeft";
|
|
115
|
+
Gamepad.DPAD_RIGHT = "dpadRight";
|
|
116
|
+
|
|
117
|
+
Gamepad.LEFT_STICK_UP = "leftStickUp";
|
|
118
|
+
Gamepad.LEFT_STICK_DOWN = "leftStickDown";
|
|
119
|
+
Gamepad.LEFT_STICK_LEFT = "leftStickLeft";
|
|
120
|
+
Gamepad.LEFT_STICK_RIGHT = "leftStickRight";
|
|
121
|
+
Gamepad.RIGHT_STICK_UP = "rightStickUp";
|
|
122
|
+
Gamepad.RIGHT_STICK_DOWN = "rightStickDown";
|
|
123
|
+
Gamepad.RIGHT_STICK_LEFT = "rightStickLeft";
|
|
124
|
+
Gamepad.RIGHT_STICK_RIGHT = "rightStickRight";
|
|
125
|
+
|
|
126
|
+
export default Gamepad;
|
|
@@ -5,11 +5,22 @@
|
|
|
5
5
|
class IDManager {
|
|
6
6
|
/**
|
|
7
7
|
* @method generateID
|
|
8
|
-
* @description Generates a random ID
|
|
8
|
+
* @description Generates a random ID, preferring the collision-resistant
|
|
9
|
+
* crypto.randomUUID when available and falling back to a random string.
|
|
9
10
|
* @returns {string} - The random ID
|
|
10
11
|
*/
|
|
11
12
|
static generateID() {
|
|
12
|
-
|
|
13
|
+
if (
|
|
14
|
+
typeof globalThis !== "undefined" &&
|
|
15
|
+
globalThis.crypto &&
|
|
16
|
+
typeof globalThis.crypto.randomUUID === "function"
|
|
17
|
+
) {
|
|
18
|
+
return globalThis.crypto.randomUUID();
|
|
19
|
+
}
|
|
20
|
+
return (
|
|
21
|
+
Math.random().toString(36).substring(2, 10) +
|
|
22
|
+
Math.random().toString(36).substring(2, 10)
|
|
23
|
+
);
|
|
13
24
|
}
|
|
14
25
|
|
|
15
26
|
/**
|
|
@@ -25,6 +36,17 @@ class IDManager {
|
|
|
25
36
|
IDManager.existingIDs.add(id);
|
|
26
37
|
return id;
|
|
27
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @method release
|
|
42
|
+
* @description Releases a previously-generated ID so the global registry
|
|
43
|
+
* doesn't grow without bound. Call this when an object/instance is destroyed
|
|
44
|
+
* (e.g. particles removed from an InstancedTexture).
|
|
45
|
+
* @param {string} id - The ID to release
|
|
46
|
+
*/
|
|
47
|
+
static release(id) {
|
|
48
|
+
if (id != null) IDManager.existingIDs.delete(id);
|
|
49
|
+
}
|
|
28
50
|
}
|
|
29
51
|
|
|
30
52
|
IDManager.existingIDs = new Set();
|