Skip to content

Commit

Permalink
fix(Player): latest frame not render #68
Browse files Browse the repository at this point in the history
  • Loading branch information
oct16 committed Nov 9, 2020
1 parent ae10273 commit aa9ec7b
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/player/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class PlayerComponent {
window.G_REPLAY_DATA = firstData
}

async switchNextView() {
getNextReplayData() {
const { G_REPLAY_DATA: rData, G_REPLAY_PACKS: packs } = window as {
G_REPLAY_DATA: ReplayData
G_REPLAY_PACKS: ReplayPack[]
Expand All @@ -164,11 +164,7 @@ export class PlayerComponent {
return
}

const nextData = getNextData(rData)

if (!nextData) {
return
}
return getNextData(rData)

function getNextData(curData: ReplayData) {
for (let i = 0; i < packs.length; i++) {
Expand All @@ -182,13 +178,15 @@ export class PlayerComponent {
} else if (nextPackBody && nextPackBody.length) {
return nextPackBody[0]
}
return null
return
}
}
}
return null
return
}
}

async switchNextView(nextData: ReplayData) {
const curEndTime = this.records.slice(-1)[0].time
const nextStartTime = nextData.records[0].time
this.curViewDiffTime += nextStartTime - curEndTime
Expand Down Expand Up @@ -245,17 +243,18 @@ export class PlayerComponent {
const currTime = this.startTime + timeStamp * this.speed
let nextTime = this.frames[this.frameIndex]

if (nextTime > this.curViewEndTime - this.curViewDiffTime) {
await this.switchNextView()
}

while (nextTime && currTime >= nextTime) {
observer.emit(PlayerEventTypes.PROGRESS, this.frameIndex, this.frames.length - 1)
this.renderEachFrame()
this.frameIndex++
this.renderEachFrame()
nextTime = this.frames[this.frameIndex]
}

if (nextTime > this.curViewEndTime - this.curViewDiffTime) {
const nextReplayData = this.getNextReplayData()
nextReplayData && (await this.switchNextView(nextReplayData))
}

this.elapsedTime = (currTime - this.frames[0]) / 1000

// sync audio time
Expand Down

0 comments on commit aa9ec7b

Please sign in to comment.