littlejsengine 1.6.92 → 1.7.1
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 +31 -24
- package/build/littlejs.d.ts +87 -60
- package/build/littlejs.esm.js +322 -189
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +316 -185
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +296 -182
- package/examples/breakout/index.html +3 -3
- package/examples/breakoutTutorial/index.html +2 -2
- package/examples/electron/index.html +2 -2
- package/examples/js13k/index.html +13 -13
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +1 -1
- package/examples/platformer/gameEffects.js +11 -10
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/index.html +2 -2
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +4 -4
- package/examples/typescript/index.html +1 -1
- package/package.json +1 -1
- package/src/engine.js +2 -2
- package/src/engineAudio.js +43 -15
- package/src/engineBuild.js +18 -5
- package/src/engineDebug.js +21 -5
- package/src/engineDraw.js +61 -60
- package/src/engineExport.js +6 -4
- package/src/engineInput.js +26 -34
- package/src/engineObject.js +2 -2
- package/src/engineRelease.js +1 -2
- package/src/engineSettings.js +1 -0
- package/src/engineUtilities.js +95 -40
- package/src/engineWebGL.js +63 -27
package/src/engineWebGL.js
CHANGED
|
@@ -203,8 +203,8 @@ function glFlush()
|
|
|
203
203
|
|
|
204
204
|
// draw all the sprites in the batch and reset the buffer
|
|
205
205
|
glContext.bufferSubData(gl_ARRAY_BUFFER, 0,
|
|
206
|
-
glPositionData.subarray(0, glBatchCount *
|
|
207
|
-
glContext.drawArrays(
|
|
206
|
+
glPositionData.subarray(0, glBatchCount * gl_INDICIES_PER_VERT));
|
|
207
|
+
glContext.drawArrays(gl_TRIANGLE_STRIP, 0, glBatchCount);
|
|
208
208
|
glBatchCount = 0;
|
|
209
209
|
glBatchAdditive = glAdditive;
|
|
210
210
|
}
|
|
@@ -225,39 +225,75 @@ function glCopyToContext(context, forceDraw)
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
/** Add a sprite to the gl draw list, used by all gl draw functions
|
|
228
|
-
* @param x
|
|
229
|
-
* @param y
|
|
230
|
-
* @param sizeX
|
|
231
|
-
* @param sizeY
|
|
232
|
-
* @param angle
|
|
233
|
-
* @param uv0X
|
|
234
|
-
* @param uv0Y
|
|
235
|
-
* @param uv1X
|
|
236
|
-
* @param uv1Y
|
|
237
|
-
* @param rgba
|
|
238
|
-
* @param [rgbaAdditive=0]
|
|
228
|
+
* @param {Number} x
|
|
229
|
+
* @param {Number} y
|
|
230
|
+
* @param {Number} sizeX
|
|
231
|
+
* @param {Number} sizeY
|
|
232
|
+
* @param {Number} angle
|
|
233
|
+
* @param {Number} uv0X
|
|
234
|
+
* @param {Number} uv0Y
|
|
235
|
+
* @param {Number} uv1X
|
|
236
|
+
* @param {Number} uv1Y
|
|
237
|
+
* @param {Number} rgba
|
|
238
|
+
* @param {Number} [rgbaAdditive=0]
|
|
239
239
|
* @memberof WebGL */
|
|
240
240
|
function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba, rgbaAdditive=0)
|
|
241
241
|
{
|
|
242
|
-
// flush if there is
|
|
243
|
-
|
|
242
|
+
// flush if there is not enough room or if different blend mode
|
|
243
|
+
const vertCount = 6;
|
|
244
|
+
if (glBatchCount >= gl_MAX_BATCH-vertCount || glBatchAdditive != glAdditive)
|
|
244
245
|
glFlush();
|
|
245
246
|
|
|
246
247
|
// prepare to create the verts from size and angle
|
|
247
248
|
const c = Math.cos(angle)/2, s = Math.sin(angle)/2;
|
|
248
249
|
const cx = c*sizeX, cy = c*sizeY, sx = s*sizeX, sy = s*sizeY;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
const positionData =
|
|
251
|
+
[
|
|
252
|
+
x-cx+sy, y+cy+sx, uv0X, uv0Y,
|
|
253
|
+
x-cx-sy, y-cy+sx, uv0X, uv1Y,
|
|
254
|
+
x+cx+sy, y+cy-sx, uv1X, uv0Y,
|
|
255
|
+
x+cx-sy, y-cy-sx, uv1X, uv1Y,
|
|
256
|
+
];
|
|
257
|
+
|
|
258
|
+
// setup 2 triangle strip quad
|
|
259
|
+
for(let i = vertCount, offset = glBatchCount * gl_INDICIES_PER_VERT; i--;)
|
|
252
260
|
{
|
|
253
|
-
|
|
254
|
-
glPositionData[offset++] =
|
|
255
|
-
glPositionData[offset++] =
|
|
256
|
-
glPositionData[offset++] =
|
|
257
|
-
glPositionData[offset++] =
|
|
261
|
+
let j = clamp(i-1, 0, 3)*4; // degenerate tri at ends
|
|
262
|
+
glPositionData[offset++] = positionData[j++];
|
|
263
|
+
glPositionData[offset++] = positionData[j++];
|
|
264
|
+
glPositionData[offset++] = positionData[j++];
|
|
265
|
+
glPositionData[offset++] = positionData[j++];
|
|
258
266
|
glColorData[offset++] = rgba;
|
|
259
267
|
glColorData[offset++] = rgbaAdditive;
|
|
260
268
|
}
|
|
269
|
+
glBatchCount += vertCount;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Add a convex polygon to the gl draw list
|
|
273
|
+
* @param {Array} points - Array of Vector2 points
|
|
274
|
+
* @param {Number} rgba - Color of the polygon
|
|
275
|
+
* @memberof WebGL */
|
|
276
|
+
function glDrawPoints(points, rgba)
|
|
277
|
+
{
|
|
278
|
+
// flush if there is not enough room or if different blend mode
|
|
279
|
+
const vertCount = points.length + 2;
|
|
280
|
+
if (glBatchCount >= gl_MAX_BATCH-vertCount || glBatchAdditive != glAdditive)
|
|
281
|
+
glFlush();
|
|
282
|
+
|
|
283
|
+
// setup triangle strip from list of points
|
|
284
|
+
for(let i = vertCount, offset = glBatchCount * gl_INDICIES_PER_VERT; i--;)
|
|
285
|
+
{
|
|
286
|
+
const j = clamp(i-1, 0, vertCount-3); // degenerate tri at ends
|
|
287
|
+
const h = j>>1;
|
|
288
|
+
const point = points[j%2? h : vertCount-3-h];
|
|
289
|
+
glPositionData[offset++] = point.x;
|
|
290
|
+
glPositionData[offset++] = point.y;
|
|
291
|
+
glPositionData[offset++] = 0; // uvx
|
|
292
|
+
glPositionData[offset++] = 0; // uvy
|
|
293
|
+
glColorData[offset++] = 0; // nothing to tint
|
|
294
|
+
glColorData[offset++] = rgba; // apply rgba via additive
|
|
295
|
+
}
|
|
296
|
+
glBatchCount += vertCount;
|
|
261
297
|
}
|
|
262
298
|
|
|
263
299
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -351,14 +387,14 @@ function glRenderPostProcess()
|
|
|
351
387
|
glContext.uniform1i(uniformLocation('iChannel0'), 0);
|
|
352
388
|
glContext.uniform1f(uniformLocation('iTime'), time);
|
|
353
389
|
glContext.uniform3f(uniformLocation('iResolution'), mainCanvas.width, mainCanvas.height, 1);
|
|
354
|
-
glContext.drawArrays(
|
|
390
|
+
glContext.drawArrays(gl_TRIANGLE_STRIP, 0, 3);
|
|
355
391
|
}
|
|
356
392
|
|
|
357
393
|
///////////////////////////////////////////////////////////////////////////////
|
|
358
394
|
// store gl constants as integers so their name doesn't use space in minifed
|
|
359
395
|
const
|
|
360
396
|
gl_ONE = 1,
|
|
361
|
-
|
|
397
|
+
gl_TRIANGLE_STRIP = 5,
|
|
362
398
|
gl_SRC_ALPHA = 770,
|
|
363
399
|
gl_ONE_MINUS_SRC_ALPHA = 771,
|
|
364
400
|
gl_BLEND = 3042,
|
|
@@ -389,6 +425,6 @@ gl_UNPACK_FLIP_Y_WEBGL = 37440,
|
|
|
389
425
|
// constants for batch rendering
|
|
390
426
|
gl_VERTICES_PER_QUAD = 6,
|
|
391
427
|
gl_INDICIES_PER_VERT = 6,
|
|
392
|
-
gl_MAX_BATCH =
|
|
428
|
+
gl_MAX_BATCH = 1e5,
|
|
393
429
|
gl_VERTEX_BYTE_STRIDE = (4 * 2) * 2 + (4) * 2, // vec2 * 2 + (char * 4) * 2
|
|
394
|
-
gl_VERTEX_BUFFER_SIZE = gl_MAX_BATCH *
|
|
430
|
+
gl_VERTEX_BUFFER_SIZE = gl_MAX_BATCH * gl_VERTEX_BYTE_STRIDE;
|