写点什么

基于 iOS14 系统的游戏卡顿问题解决方案

用户头像
白开水
关注
发布于: 2020 年 09 月 27 日

在iOS14系统正式发布后,使用Egret Engine的部分开发者碰到了游戏卡顿问题,目前有以下2种解决方案:

第一种方案:一键升级引擎至Egret Engine5.3.10版,虽然此版本引擎依然属测试版,但产品功能已趋于稳定,建议有卡顿问题的开发者升级处理!

第二种方案:已上线项目使用的是Egret Engine 5.2系列的稳定版,且不想升级引擎版本解决卡顿问题,需要手动修改2个位置的代码:

位置1:WebGLVertexArrayObject.ts

cacheArrays方法

.......

if (meshVertices) {
let vertData = [];
// 计算索引位置与赋值
const vertices = this.vertices;
const verticesUint32View = this._verticesUint32View;
let index = this.vertexIndex * this.vertSize;
// 缓存顶点数组
let i = 0, iD = 0, l = 0;
let u = 0, v = 0, x = 0, y = 0;
for (i = 0, l = meshUVs.length; i < l; i += 2) {
iD = index + i * 5 / 2;
x = meshVertices[i];
y = meshVertices[i + 1];
u = meshUVs[i];
v = meshUVs[i + 1];

if (rotated) {
vertData.push([
a * x + c * y + tx,
b * x + d * y + ty,
(sourceX + (1.0 - v) * sourceHeight) / textureSourceWidth,
(sourceY + u * sourceWidth) / textureSourceHeight,
]);
} else {
vertData.push([
a * x + c * y + tx,
b * x + d * y + ty,
(sourceX + u * sourceWidth) / textureSourceWidth,
(sourceY + v * sourceHeight) / textureSourceHeight,
]);
}
verticesUint32View[iD + 4] = alpha;
}
for (let i = 0; i < meshIndices.length; i += 3) {
let data0 = vertData[meshIndices[i]];
vertices[index++] = data0[0];
vertices[index++] = data0[1];
vertices[index++] = data0[2];
vertices[index++] = data0[3];
verticesUint32View[index++] = alpha;

let data1 = vertData[meshIndices[i + 1]];
vertices[index++] = data1[0];
vertices[index++] = data1[1];
vertices[index++] = data1[2];
vertices[index++] = data1[3];
verticesUint32View[index++] = alpha;

let data2 = vertData[meshIndices[i + 2]];
vertices[index++] = data2[0];
vertices[index++] = data2[1];
vertices[index++] = data2[2];
vertices[index++] = data2[3];
verticesUint32View[index++] = alpha;

// 填充数据
vertices[index++] = data2[0];
vertices[index++] = data2[1];
vertices[index++] = data2[2];
vertices[index++] = data2[3];
verticesUint32View[index++] = alpha;
}

let meshNum = meshIndices.length / 3;
this.vertexIndex += 4 * meshNum;
this.indexIndex += 6 * meshNum;

} else {
......



位置2:WebGLRenderContext.ts



drawTexture方法



let buffer = this.currentBuffer;
if (this.contextLost || !texture || !buffer) {
return;
}

let meshNum = meshIndices && (meshIndices.length / 3) || 0;
if (meshIndices) {
if (this.vao.reachMaxSize(meshNum * 4, meshNum * 6)) {
this.$drawWebGL();
}
} else {
if (this.vao.reachMaxSize()) {
this.$drawWebGL();
}
}

if (smoothing != undefined && texture["smoothing"] != smoothing) {
this.drawCmdManager.pushChangeSmoothing(texture, smoothing);
}

// if (meshUVs) {
// this.vao.changeToMeshIndices();
// }

let count = meshIndices ? meshNum * 2 : 2;
.........

以上2种方案均可解决基于iOS14系统带来的卡顿问题,大家可根据项目情况自行选择。使用Egret Engine期间如若遇到问题,可联系官方客服微信号:egretengine,会第一时间帮您解决!



用户头像

白开水

关注

还未添加个人签名 2020.06.15 加入

还未添加个人简介

评论

发布
暂无评论
基于 iOS14 系统的游戏卡顿问题解决方案