emeraldengine 2.2.0 → 3.0.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 +2359 -968
- package/dist/types/index.d.ts +72 -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} +5 -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} +60 -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 +80 -0
- package/dist/types/src/ParticleEmitter.d.ts +131 -0
- package/dist/types/{Physics.d.ts → src/Physics.d.ts} +88 -20
- 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 +96 -0
- package/dist/types/src/components/GameObject.d.ts +135 -0
- package/dist/types/src/components/RigidBody.d.ts +183 -0
- package/dist/types/src/importers/Aseprite.d.ts +79 -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/IDManager.d.ts +31 -0
- package/dist/types/src/managers/InputManager.d.ts +290 -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/index.js +72 -0
- package/package.json +74 -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 +18 -18
- package/src/Coroutine.js +259 -0
- package/src/DebugOverlay.js +246 -0
- package/src/Drawable.js +842 -555
- 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 +251 -118
- package/src/Interpolator.js +124 -0
- package/src/Material.js +202 -0
- package/src/MathUtils.js +133 -0
- package/src/ParticleEmitter.js +284 -0
- package/src/Physics.js +186 -5
- 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 +22 -3
- package/src/components/CircleCollider.js +19 -3
- package/src/components/CircleColliderDebug.js +24 -24
- package/src/components/Collider.js +140 -34
- package/src/components/GameObject.js +130 -21
- package/src/components/RigidBody.js +123 -2
- package/src/importers/Aseprite.js +142 -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/IDManager.js +24 -2
- package/src/managers/InputManager.js +779 -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/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/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;
|
|
@@ -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();
|