|
@@ -49,141 +49,36 @@ function getSceneManager(i, e) {
|
|
|
|
|
|
export default class EngineProxy{
|
|
export default class EngineProxy{
|
|
constructor(xverseRoom) {
|
|
constructor(xverseRoom) {
|
|
- E(this, "_tvs", []);
|
|
|
|
- E(this, "isRenderFirstFrame", !1);
|
|
|
|
- E(this, "_idleTime", 0);
|
|
|
|
- E(this, "renderTimer");
|
|
|
|
- E(this, "lightManager");
|
|
|
|
- E(this, "_checkSceneNotReadyCount", 0);
|
|
|
|
- E(this, "_checkSceneDurationFrameNum", 0);
|
|
|
|
- E(this, "_checkSceneFrameCount", 0);
|
|
|
|
- E(this, "timeoutCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "frameCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "interFrameCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "drawCallCntCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "activeFacesCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "renderTimeCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "drawCallTimeCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "animationCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "meshSelectCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "renderTargetCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "regBeforeRenderCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "regAfterRenderCircularArray", new CircularArray(120,!1,[]));
|
|
|
|
- E(this, "renderCnt", 0);
|
|
|
|
- E(this, "renderErrorCount", 0);
|
|
|
|
- E(this, "engineSloppyCnt", 0);
|
|
|
|
- E(this, "systemStuckCnt", 0);
|
|
|
|
- E(this, "frameRenderNumber", 0);
|
|
|
|
- E(this, "_setFPS", (sceneManager,t=25)=>{
|
|
|
|
- logger.info("Set fps to", t);
|
|
|
|
- const r = t > 60 ? 60 : t < 24 ? 24 : t;
|
|
|
|
- sceneManager.Engine.stopRenderLoop();
|
|
|
|
- const n = 1e3 / r;
|
|
|
|
- let o = Date.now()
|
|
|
|
- , a = Date.now()
|
|
|
|
- , s = n
|
|
|
|
- , l = 1;
|
|
|
|
- const u = ()=>{
|
|
|
|
- var T;
|
|
|
|
- const c = Date.now()
|
|
|
|
- , h = c - o
|
|
|
|
- , f = c - a;
|
|
|
|
- a = c,
|
|
|
|
- this.frameCircularArray.add(f),
|
|
|
|
- h - s > n && (this.systemStuckCnt += 1);
|
|
|
|
- const d = h / s;
|
|
|
|
- l = .9 * l + .1 * d;
|
|
|
|
- const _ = Date.now();
|
|
|
|
- let g = 0
|
|
|
|
- , m = 0;
|
|
|
|
- if (this.room.isUpdatedRawYUVData || this.room.isPano) {
|
|
|
|
- this.isRenderFirstFrame = !0
|
|
|
|
- if (this._checkSceneDurationFrameNum > 0)
|
|
|
|
- {
|
|
|
|
- this._checkSceneFrameCount++,
|
|
|
|
- this.room.sceneManager.isReadyToRender({}) && this._checkSceneDurationFrameNum--,
|
|
|
|
- this._checkSceneFrameCount > EngineProxy._CHECK_DURATION && (this._checkSceneDurationFrameNum = EngineProxy._CHECK_DURATION,
|
|
|
|
- this._checkSceneFrameCount = 0,
|
|
|
|
- this._checkSceneNotReadyCount++,
|
|
|
|
- (this._checkSceneNotReadyCount == 1 || this._checkSceneNotReadyCount % 100 == 0) && logger.error(`[SDK] Scene not ready, skip render. loop: ${this._checkSceneNotReadyCount}`),
|
|
|
|
- this._checkSceneNotReadyCount > 10 && (logger.error("[SDK] Scene not ready, reload later"),
|
|
|
|
- this.room.proxyEvents("renderError", {
|
|
|
|
- error: new Error("[SDK] Scene not ready, skip render and reload.")
|
|
|
|
- })),
|
|
|
|
- this.room.stats.assign({
|
|
|
|
- renderErrorCount: this._checkSceneNotReadyCount
|
|
|
|
- }),
|
|
|
|
- logger.infoAndReportMeasurement({
|
|
|
|
- value: 0,
|
|
|
|
- startTime: Date.now(),
|
|
|
|
- metric: "renderError",
|
|
|
|
- error: new Error("[SDK] Scene not ready, skip render and reload."),
|
|
|
|
- reportOptions: {
|
|
|
|
- sampleRate: .1
|
|
|
|
- }
|
|
|
|
- }));
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- try {
|
|
|
|
- sceneManager.render()
|
|
|
|
- }
|
|
|
|
- catch (C) {
|
|
|
|
- this.renderErrorCount++,
|
|
|
|
- this.renderErrorCount > 10 && this.room.proxyEvents("renderError", {
|
|
|
|
- error: C
|
|
|
|
- }),
|
|
|
|
- this.room.stats.assign({
|
|
|
|
- renderErrorCount: this.renderErrorCount
|
|
|
|
- }),
|
|
|
|
- logger.infoAndReportMeasurement({
|
|
|
|
- value: 0,
|
|
|
|
- startTime: Date.now(),
|
|
|
|
- metric: "renderError",
|
|
|
|
- error: C,
|
|
|
|
- reportOptions: {
|
|
|
|
- sampleRate: .1
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- g = Date.now() - _,
|
|
|
|
- this.frameRenderNumber < 1e3 && this.frameRenderNumber++,
|
|
|
|
- this.room.networkController.rtcp.workers.UpdateYUV(),
|
|
|
|
- m = Date.now() - _ - g
|
|
|
|
- }
|
|
|
|
- this.isRenderFirstFrame || this.room.networkController.rtcp.workers.UpdateYUV();
|
|
|
|
- const y = Date.now() - _;
|
|
|
|
- o = c + y,
|
|
|
|
- s = Math.min(Math.max((n - y) / l, 5), 200),
|
|
|
|
- y > n && (s = 10,
|
|
|
|
- this.engineSloppyCnt += 1),
|
|
|
|
- this._idleTime = s;
|
|
|
|
- const b = s;
|
|
|
|
- if (s > 150 && console.log("lastGap is ", s, ", ratio is ", l, ", usedTimeMs is ", y, ", cpuRenderTime is ", g, ", cpuUpdateYUVTime is ", m),
|
|
|
|
- this.timeoutCircularArray.add(b),
|
|
|
|
- this.renderCnt % 25 == 0) {
|
|
|
|
- const C = this.frameCircularArray.getAvg()
|
|
|
|
- , A = this.timeoutCircularArray.getAvg()
|
|
|
|
- , S = this.frameCircularArray.getMax()
|
|
|
|
- , P = this.timeoutCircularArray.getMax();
|
|
|
|
- (T = this.room.stats) == null || T.assign({
|
|
|
|
- avgFrameTime: C,
|
|
|
|
- avgTimeoutTime: A,
|
|
|
|
- maxFrameTime: S,
|
|
|
|
- maxTimeoutTime: P,
|
|
|
|
- systemStuckCnt: this.systemStuckCnt
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- this.renderTimer = window.setTimeout(u, s)
|
|
|
|
- }
|
|
|
|
- ;
|
|
|
|
- this.renderTimer = window.setTimeout(u, n / l)
|
|
|
|
- });
|
|
|
|
|
|
+ this._tvs = []
|
|
|
|
+ this.isRenderFirstFrame = !1
|
|
|
|
+ this._idleTime = 0
|
|
|
|
+ this.renderTimer
|
|
|
|
+ this.lightManager
|
|
|
|
+ this._checkSceneNotReadyCount = 0
|
|
|
|
+ this._checkSceneDurationFrameNum = 0
|
|
|
|
+ this._checkSceneFrameCount = 0
|
|
|
|
+ this.timeoutCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.frameCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.interFrameCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.drawCallCntCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.activeFacesCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.renderTimeCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.drawCallTimeCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.animationCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.meshSelectCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.renderTargetCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.regBeforeRenderCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.regAfterRenderCircularArray = new CircularArray(120, !1, [])
|
|
|
|
+ this.renderCnt = 0
|
|
|
|
+ this.renderErrorCount = 0
|
|
|
|
+ this.engineSloppyCnt = 0
|
|
|
|
+ this.systemStuckCnt = 0
|
|
|
|
+ this.frameRenderNumber = 0
|
|
|
|
|
|
- E(this, "updateStats", ()=>{
|
|
|
|
- var e;
|
|
|
|
- (e = this.room.stats) == null || e.assign({
|
|
|
|
|
|
+ this.room = xverseRoom
|
|
|
|
+
|
|
|
|
+ this.updateStats = ()=>{
|
|
|
|
+ this.room.stats && this.room.stats.assign({
|
|
renderFrameTime: this.renderTimeCircularArray.getAvg(),
|
|
renderFrameTime: this.renderTimeCircularArray.getAvg(),
|
|
maxRenderFrameTime: this.renderTimeCircularArray.getMax(),
|
|
maxRenderFrameTime: this.renderTimeCircularArray.getMax(),
|
|
interFrameTime: this.interFrameCircularArray.getAvg(),
|
|
interFrameTime: this.interFrameCircularArray.getAvg(),
|
|
@@ -210,9 +105,125 @@ export default class EngineProxy{
|
|
maxTimeoutTime: this.timeoutCircularArray.getMax()
|
|
maxTimeoutTime: this.timeoutCircularArray.getMax()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- );
|
|
|
|
- this.room = xverseRoom
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ _setFPS(sceneManager, fps=25) {
|
|
|
|
+ logger.info("Set fps to", fps);
|
|
|
|
+ const protectFps = fps > 60 ? 60 : fps < 24 ? 24 : fps;
|
|
|
|
+ sceneManager.Engine.stopRenderLoop();
|
|
|
|
+ const mspf = 1e3 / protectFps; //毫秒每帧
|
|
|
|
+ let o = Date.now()
|
|
|
|
+ , a = Date.now()
|
|
|
|
+ , lastGap = mspf
|
|
|
|
+ , ratio = 1;
|
|
|
|
+
|
|
|
|
+ const updatePerGap = ()=>{
|
|
|
|
+ const c = Date.now()
|
|
|
|
+ , h = c - o
|
|
|
|
+ , f = c - a;
|
|
|
|
+
|
|
|
|
+ a = c
|
|
|
|
+ this.frameCircularArray.add(f)
|
|
|
|
+ h - lastGap > mspf && (this.systemStuckCnt += 1)
|
|
|
|
+
|
|
|
|
+ const d = h / lastGap;
|
|
|
|
+ ratio = .9 * ratio + .1 * d;
|
|
|
|
+ const _ = Date.now();
|
|
|
|
+ let cpuRenderTime = 0, cpuUpdateYUVTime = 0;
|
|
|
|
+
|
|
|
|
+ if (this.room.isUpdatedRawYUVData || this.room.isPano) {
|
|
|
|
+ this.isRenderFirstFrame = !0
|
|
|
|
+ if (this._checkSceneDurationFrameNum > 0)
|
|
|
|
+ {
|
|
|
|
+ this._checkSceneFrameCount++,
|
|
|
|
+ this.room.sceneManager.isReadyToRender({}) && this._checkSceneDurationFrameNum--,
|
|
|
|
+ this._checkSceneFrameCount > EngineProxy._CHECK_DURATION && (this._checkSceneDurationFrameNum = EngineProxy._CHECK_DURATION,
|
|
|
|
+ this._checkSceneFrameCount = 0,
|
|
|
|
+ this._checkSceneNotReadyCount++,
|
|
|
|
+
|
|
|
|
+ (
|
|
|
|
+ this._checkSceneNotReadyCount == 1 ||
|
|
|
|
+ this._checkSceneNotReadyCount % 100 == 0
|
|
|
|
+ ) && logger.error(`[SDK] Scene not ready, skip render. loop: ${this._checkSceneNotReadyCount}`),
|
|
|
|
+
|
|
|
|
+ this._checkSceneNotReadyCount > 10 && (
|
|
|
|
+ logger.error("[SDK] Scene not ready, reload later"),
|
|
|
|
+ this.room.proxyEvents("renderError", {
|
|
|
|
+ error: new Error("[SDK] Scene not ready, skip render and reload.")
|
|
|
|
+ })
|
|
|
|
+ ),
|
|
|
|
+ this.room.stats.assign({
|
|
|
|
+ renderErrorCount: this._checkSceneNotReadyCount
|
|
|
|
+ }),
|
|
|
|
+ logger.infoAndReportMeasurement({
|
|
|
|
+ value: 0,
|
|
|
|
+ startTime: Date.now(),
|
|
|
|
+ metric: "renderError",
|
|
|
|
+ error: new Error("[SDK] Scene not ready, skip render and reload."),
|
|
|
|
+ reportOptions: {
|
|
|
|
+ sampleRate: .1
|
|
|
|
+ }
|
|
|
|
+ }));
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ sceneManager.render()
|
|
|
|
+ }
|
|
|
|
+ catch (e) {
|
|
|
|
+ this.renderErrorCount++,
|
|
|
|
+ this.renderErrorCount > 10 && this.room.proxyEvents("renderError", {
|
|
|
|
+ error: e
|
|
|
|
+ }),
|
|
|
|
+ this.room.stats.assign({
|
|
|
|
+ renderErrorCount: this.renderErrorCount
|
|
|
|
+ }),
|
|
|
|
+ logger.infoAndReportMeasurement({
|
|
|
|
+ value: 0,
|
|
|
|
+ startTime: Date.now(),
|
|
|
|
+ metric: "renderError",
|
|
|
|
+ error: e,
|
|
|
|
+ reportOptions: {
|
|
|
|
+ sampleRate: .1
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ cpuRenderTime = Date.now() - _,
|
|
|
|
+ this.frameRenderNumber < 1e3 && this.frameRenderNumber++,
|
|
|
|
+ this.room.networkController.rtcp.workers.UpdateYUV(),
|
|
|
|
+ cpuUpdateYUVTime = Date.now() - _ - cpuRenderTime
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.isRenderFirstFrame || this.room.networkController.rtcp.workers.UpdateYUV();
|
|
|
|
+
|
|
|
|
+ const usedTimeMs = Date.now() - _;
|
|
|
|
+ o = c + usedTimeMs,
|
|
|
|
+ lastGap = Math.min(Math.max((mspf - usedTimeMs) / ratio, 5), 200),
|
|
|
|
+ usedTimeMs > mspf && (
|
|
|
|
+ lastGap = 10,
|
|
|
|
+ this.engineSloppyCnt += 1
|
|
|
|
+ ),
|
|
|
|
+ this._idleTime = lastGap;
|
|
|
|
+
|
|
|
|
+ lastGap > 150 && console.log("lastGap is ", lastGap, ", ratio is ", ratio, ", usedTimeMs is ", usedTimeMs,
|
|
|
|
+ ", cpuRenderTime is ", cpuRenderTime, ", cpuUpdateYUVTime is ", cpuUpdateYUVTime)
|
|
|
|
+
|
|
|
|
+ const b = lastGap;
|
|
|
|
+ this.timeoutCircularArray.add(b)
|
|
|
|
+
|
|
|
|
+ if (this.renderCnt % 25 == 0) {
|
|
|
|
+ this.room.stats && this.room.stats.assign({
|
|
|
|
+ avgFrameTime: this.frameCircularArray.getAvg(),
|
|
|
|
+ avgTimeoutTime: this.frameCircularArray.getMax(),
|
|
|
|
+ maxFrameTime: this.frameCircularArray.getMax(),
|
|
|
|
+ maxTimeoutTime: this.timeoutCircularArray.getMax(),
|
|
|
|
+ systemStuckCnt: this.systemStuckCnt
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ this.renderTimer = window.setTimeout(updatePerGap, lastGap)
|
|
|
|
+ }
|
|
|
|
+ this.renderTimer = window.setTimeout(updatePerGap, mspf / ratio)
|
|
|
|
+ }
|
|
|
|
+
|
|
async initEngine(e) {
|
|
async initEngine(e) {
|
|
await this.updateBillboard();
|
|
await this.updateBillboard();
|
|
logger.info("engine version:", VERSION$1);
|
|
logger.info("engine version:", VERSION$1);
|