Skip to content

Commit f493e4c

Browse files
author
Julien
committed
fix(SDK): refactor asynchronous updates code
1 parent 0a6e82b commit f493e4c

File tree

1 file changed

+21
-11
lines changed
  • engine/core/src/main/resources/view/core

1 file changed

+21
-11
lines changed

engine/core/src/main/resources/view/core/Drawer.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,11 @@ export class Drawer {
435435
}
436436
}
437437

438-
updateScene (scope, question, frames, frameNumber, progress, speed, reason, demo, forReal) {
438+
updateScene (scope, question, frames, frameNumber, progress, speed, reason, demo, force) {
439439
const parsedFrame = frames[frameNumber]
440-
if (!forReal && this.stepByStepAnimateSpeed) {
441-
scope.targetProgress = progress
442-
// Detect step to next frame
443-
if (scope.currentFrame && scope.currentFrame !== parsedFrame && scope.currentFrame === parsedFrame.previous && this.speed === 0) {
444-
scope.currentProgress = 0
445-
scope.currentFrame = parsedFrame
446-
return
447-
}
440+
if (!force && this.checkSteppedToNextFrame(scope, parsedFrame)) {
441+
this.startAsynchronousAnimation(scope, progress, parsedFrame)
442+
return
448443
}
449444

450445
/** ************************************* */
@@ -467,6 +462,16 @@ export class Drawer {
467462
}
468463
}
469464

465+
startAsynchronousAnimation (scope, progress, currentFrame) {
466+
scope.targetProgress = progress
467+
scope.currentProgress = 0
468+
scope.currentFrame = currentFrame
469+
}
470+
471+
checkSteppedToNextFrame (scope, parsedFrame) {
472+
return scope.currentFrame && scope.currentFrame !== parsedFrame && scope.currentFrame === parsedFrame.previous && this.speed === 0
473+
}
474+
470475
initEndScene (scope, failure) {
471476
scope.endSceneViewed = false
472477
}
@@ -507,7 +512,7 @@ export class Drawer {
507512
scope.endTime = 0
508513
}
509514

510-
if (this.stepByStepAnimateSpeed && scope.currentProgress !== scope.targetProgress) {
515+
if (this.stepByStepAnimateSpeed && this.isAsynchronousAnimationOngoing(scope)) {
511516
var p = scope.currentProgress + step / 200 * this.getFrameSpeed(this.currentFrame) * this.stepByStepAnimateSpeed
512517
p = Math.min(scope.targetProgress, p)
513518
this.updateScene(this.scope, this.question, this.frames, this.currentFrame, p, this.speed, this.reasons[this.currentFrame], false, true)
@@ -526,6 +531,10 @@ export class Drawer {
526531
return true
527532
}
528533

534+
isAsynchronousAnimationOngoing (scope) {
535+
return scope.targetProgress != null && scope.currentProgress !== scope.targetProgress
536+
}
537+
529538
getFrameSpeed (frameNumber) {
530539
return BASE_FRAME_DURATION / this.getFrameDuration(frameNumber)
531540
}
@@ -695,7 +704,8 @@ export class Drawer {
695704
number: index,
696705
index: agent.index,
697706
type: agent.type,
698-
isMe: agent.type === 'CODINGAMER' && agent.typeData.me,
707+
// isMe: agent.type === 'CODINGAMER' && agent.typeData.me,
708+
isMe: index === 0,
699709
avatar: null
700710
}
701711

0 commit comments

Comments
 (0)