| 441 | } |
| 442 | |
| 443 | private request() { |
| 444 | if (!this.active) return; |
| 445 | |
| 446 | // TODO(konsti): make this loop not run when player is paused |
| 447 | |
| 448 | this.requestId ??= requestAnimationFrame(async time => { |
| 449 | this.requestId = null; |
| 450 | if (time - this.renderTime >= 1000 / (this.status.fps + 5)) { |
| 451 | this.renderTime = time; |
| 452 | await this.lock.acquire(); |
| 453 | try { |
| 454 | await this.run(); |
| 455 | } catch (e: any) { |
| 456 | this.logger.error(e); |
| 457 | } |
| 458 | this.lock.release(); |
| 459 | } else { |
| 460 | this.request(); |
| 461 | } |
| 462 | }); |
| 463 | } |
| 464 | |
| 465 | public clampRange(frame: number): number { |
| 466 | return clamp(this.startFrame, this.endFrame, frame); |