@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 +30 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -6
package/dist/index.mjs
CHANGED
|
@@ -989,6 +989,11 @@ function createFrameRenderer(Skia) {
|
|
|
989
989
|
const stretchSrcRects = [];
|
|
990
990
|
const stretchDstRects = [];
|
|
991
991
|
let stretchPaint = null;
|
|
992
|
+
const zoneBgRects = [];
|
|
993
|
+
let _cachedSrcSlice = null;
|
|
994
|
+
let _cachedSrcSliceLen = 0;
|
|
995
|
+
let _cachedXformSlice = null;
|
|
996
|
+
let _cachedXformSliceLen = 0;
|
|
992
997
|
const clearColor = new Float32Array(4);
|
|
993
998
|
const tintColor = new Float32Array(4);
|
|
994
999
|
const flashColor = new Float32Array(4);
|
|
@@ -1044,6 +1049,23 @@ function createFrameRenderer(Skia) {
|
|
|
1044
1049
|
stretchDstRects.push(Skia.XYWHRect(0, 0, 0, 0));
|
|
1045
1050
|
}
|
|
1046
1051
|
}
|
|
1052
|
+
function ensureZoneBgPoolCapacity(n) {
|
|
1053
|
+
while (zoneBgRects.length < n) {
|
|
1054
|
+
zoneBgRects.push(Skia.XYWHRect(0, 0, 0, 0));
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
function getCachedSrcSlice(n) {
|
|
1058
|
+
if (_cachedSrcSlice !== null && _cachedSrcSliceLen === n) return _cachedSrcSlice;
|
|
1059
|
+
_cachedSrcSlice = srcRects.length === n ? srcRects : srcRects.slice(0, n);
|
|
1060
|
+
_cachedSrcSliceLen = n;
|
|
1061
|
+
return _cachedSrcSlice;
|
|
1062
|
+
}
|
|
1063
|
+
function getCachedXformSlice(n) {
|
|
1064
|
+
if (_cachedXformSlice !== null && _cachedXformSliceLen === n) return _cachedXformSlice;
|
|
1065
|
+
_cachedXformSlice = xforms.length === n ? xforms : xforms.slice(0, n);
|
|
1066
|
+
_cachedXformSliceLen = n;
|
|
1067
|
+
return _cachedXformSlice;
|
|
1068
|
+
}
|
|
1047
1069
|
function fillSrcRects(commands, n) {
|
|
1048
1070
|
for (let i = 0; i < n; i++) {
|
|
1049
1071
|
const cmd = commands[i];
|
|
@@ -1317,17 +1339,17 @@ function createFrameRenderer(Skia) {
|
|
|
1317
1339
|
function drawOutlined(cvs, image, commands, n, effect, alpha) {
|
|
1318
1340
|
const paint = applyOutlinePaint(effect);
|
|
1319
1341
|
paint.setAlphaf(alpha);
|
|
1320
|
-
const srcs =
|
|
1342
|
+
const srcs = getCachedSrcSlice(n);
|
|
1321
1343
|
for (let k = 0; k < OUTLINE_OFFSETS.length; k++) {
|
|
1322
1344
|
const offset = OUTLINE_OFFSETS[k];
|
|
1323
1345
|
fillXforms(commands, n, offset[0] * effect.width, offset[1] * effect.width);
|
|
1324
|
-
const dsts =
|
|
1346
|
+
const dsts = getCachedXformSlice(n);
|
|
1325
1347
|
cvs.drawAtlas(image, srcs, dsts, paint);
|
|
1326
1348
|
}
|
|
1327
1349
|
paint.setAlphaf(1);
|
|
1328
1350
|
defaultPaint.setAlphaf(alpha);
|
|
1329
1351
|
fillXforms(commands, n, 0, 0);
|
|
1330
|
-
const mainDsts =
|
|
1352
|
+
const mainDsts = getCachedXformSlice(n);
|
|
1331
1353
|
cvs.drawAtlas(image, srcs, mainDsts, defaultPaint);
|
|
1332
1354
|
defaultPaint.setAlphaf(1);
|
|
1333
1355
|
}
|
|
@@ -1386,10 +1408,11 @@ function createFrameRenderer(Skia) {
|
|
|
1386
1408
|
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") {
|
|
1387
1409
|
const paint2 = resolveEffectPaint(effect);
|
|
1388
1410
|
paint2.setAlphaf(alpha);
|
|
1411
|
+
ensureZoneBgPoolCapacity(n);
|
|
1389
1412
|
for (let i = 0; i < n; i++) {
|
|
1390
1413
|
const cmd = commands[i];
|
|
1391
|
-
|
|
1392
|
-
current.drawRect(
|
|
1414
|
+
zoneBgRects[i].setXYWH(cmd.dstX, cmd.dstY, cmd.dstW, cmd.dstH);
|
|
1415
|
+
current.drawRect(zoneBgRects[i], paint2);
|
|
1393
1416
|
}
|
|
1394
1417
|
paint2.setAlphaf(1);
|
|
1395
1418
|
return;
|
|
@@ -1416,8 +1439,8 @@ function createFrameRenderer(Skia) {
|
|
|
1416
1439
|
return;
|
|
1417
1440
|
}
|
|
1418
1441
|
fillXforms(commands, n, 0, 0);
|
|
1419
|
-
const srcs =
|
|
1420
|
-
const dsts =
|
|
1442
|
+
const srcs = getCachedSrcSlice(n);
|
|
1443
|
+
const dsts = getCachedXformSlice(n);
|
|
1421
1444
|
const paint = effect === void 0 ? defaultPaint : resolveEffectPaint(effect);
|
|
1422
1445
|
paint.setAlphaf(alpha);
|
|
1423
1446
|
current.drawAtlas(image, srcs, dsts, paint);
|