@flare-engine/render 0.2.0 → 0.2.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/dist/index.js CHANGED
@@ -1052,6 +1052,11 @@ function createFrameRenderer(Skia) {
1052
1052
  const stretchSrcRects = [];
1053
1053
  const stretchDstRects = [];
1054
1054
  let stretchPaint = null;
1055
+ const zoneBgRects = [];
1056
+ let _cachedSrcSlice = null;
1057
+ let _cachedSrcSliceLen = 0;
1058
+ let _cachedXformSlice = null;
1059
+ let _cachedXformSliceLen = 0;
1055
1060
  const clearColor = new Float32Array(4);
1056
1061
  const tintColor = new Float32Array(4);
1057
1062
  const flashColor = new Float32Array(4);
@@ -1107,6 +1112,23 @@ function createFrameRenderer(Skia) {
1107
1112
  stretchDstRects.push(Skia.XYWHRect(0, 0, 0, 0));
1108
1113
  }
1109
1114
  }
1115
+ function ensureZoneBgPoolCapacity(n) {
1116
+ while (zoneBgRects.length < n) {
1117
+ zoneBgRects.push(Skia.XYWHRect(0, 0, 0, 0));
1118
+ }
1119
+ }
1120
+ function getCachedSrcSlice(n) {
1121
+ if (_cachedSrcSlice !== null && _cachedSrcSliceLen === n) return _cachedSrcSlice;
1122
+ _cachedSrcSlice = srcRects.length === n ? srcRects : srcRects.slice(0, n);
1123
+ _cachedSrcSliceLen = n;
1124
+ return _cachedSrcSlice;
1125
+ }
1126
+ function getCachedXformSlice(n) {
1127
+ if (_cachedXformSlice !== null && _cachedXformSliceLen === n) return _cachedXformSlice;
1128
+ _cachedXformSlice = xforms.length === n ? xforms : xforms.slice(0, n);
1129
+ _cachedXformSliceLen = n;
1130
+ return _cachedXformSlice;
1131
+ }
1110
1132
  function fillSrcRects(commands, n) {
1111
1133
  for (let i = 0; i < n; i++) {
1112
1134
  const cmd = commands[i];
@@ -1380,17 +1402,17 @@ function createFrameRenderer(Skia) {
1380
1402
  function drawOutlined(cvs, image, commands, n, effect, alpha) {
1381
1403
  const paint = applyOutlinePaint(effect);
1382
1404
  paint.setAlphaf(alpha);
1383
- const srcs = srcRects.length === n ? srcRects : srcRects.slice(0, n);
1405
+ const srcs = getCachedSrcSlice(n);
1384
1406
  for (let k = 0; k < OUTLINE_OFFSETS.length; k++) {
1385
1407
  const offset = OUTLINE_OFFSETS[k];
1386
1408
  fillXforms(commands, n, offset[0] * effect.width, offset[1] * effect.width);
1387
- const dsts = xforms.length === n ? xforms : xforms.slice(0, n);
1409
+ const dsts = getCachedXformSlice(n);
1388
1410
  cvs.drawAtlas(image, srcs, dsts, paint);
1389
1411
  }
1390
1412
  paint.setAlphaf(1);
1391
1413
  defaultPaint.setAlphaf(alpha);
1392
1414
  fillXforms(commands, n, 0, 0);
1393
- const mainDsts = xforms.length === n ? xforms : xforms.slice(0, n);
1415
+ const mainDsts = getCachedXformSlice(n);
1394
1416
  cvs.drawAtlas(image, srcs, mainDsts, defaultPaint);
1395
1417
  defaultPaint.setAlphaf(1);
1396
1418
  }
@@ -1449,10 +1471,11 @@ function createFrameRenderer(Skia) {
1449
1471
  if (effect?.type === "roofs-city" || effect?.type === "forest-canopy" || effect?.type === "river-wave" || effect?.type === "moon-crater" || effect?.type === "cave-interior" || effect?.type === "mountain-hills") {
1450
1472
  const paint2 = resolveEffectPaint(effect);
1451
1473
  paint2.setAlphaf(alpha);
1474
+ ensureZoneBgPoolCapacity(n);
1452
1475
  for (let i = 0; i < n; i++) {
1453
1476
  const cmd = commands[i];
1454
- const rect = Skia.XYWHRect(cmd.dstX, cmd.dstY, cmd.dstW, cmd.dstH);
1455
- current.drawRect(rect, paint2);
1477
+ zoneBgRects[i].setXYWH(cmd.dstX, cmd.dstY, cmd.dstW, cmd.dstH);
1478
+ current.drawRect(zoneBgRects[i], paint2);
1456
1479
  }
1457
1480
  paint2.setAlphaf(1);
1458
1481
  return;
@@ -1479,8 +1502,8 @@ function createFrameRenderer(Skia) {
1479
1502
  return;
1480
1503
  }
1481
1504
  fillXforms(commands, n, 0, 0);
1482
- const srcs = srcRects.length === n ? srcRects : srcRects.slice(0, n);
1483
- const dsts = xforms.length === n ? xforms : xforms.slice(0, n);
1505
+ const srcs = getCachedSrcSlice(n);
1506
+ const dsts = getCachedXformSlice(n);
1484
1507
  const paint = effect === void 0 ? defaultPaint : resolveEffectPaint(effect);
1485
1508
  paint.setAlphaf(alpha);
1486
1509
  current.drawAtlas(image, srcs, dsts, paint);