feat: support lower framerate

This commit is contained in:
aarthificial
2022-04-09 20:07:13 +02:00
parent 57719638cb
commit 3c81086829
3 changed files with 22 additions and 9 deletions

View File

@@ -23,7 +23,7 @@ export class Project extends Stage {
public readonly foreground: Layer;
public readonly center: Vector2d;
public threadsCallback: ThreadsCallback;
public framesPerSeconds = 60;
public framesPerSeconds = 30;
public frame: number = 0;
public get time(): number {

View File

@@ -18,7 +18,7 @@ export function hot(player: Player, root: typeof module) {
}
player.project.reload(runners);
player.requestSeek(player.project.frame);
player.reload();
};
const scenePaths = require.cache[root.id].children.filter(name =>

View File

@@ -46,6 +46,8 @@ export class Player {
private readonly audio: HTMLAudioElement = null;
private startTime: number;
private renderTime: number = 0;
private requestId: number = null;
private audioError = false;
private state: PlayerState = {
@@ -109,6 +111,13 @@ export class Player {
this.request();
}
public reload() {
this.requestSeek(this.project.frame);
if (this.requestId === null) {
this.request();
}
}
public requestNextFrame(): void {
this.commands.seek = this.state.frame + 1;
}
@@ -258,13 +267,17 @@ export class Player {
}
private request() {
requestAnimationFrame(async () => {
try {
// this.updateState({loading: true});
await this.run();
// this.updateState({loading: false});
} catch (e) {
console.error(e);
this.requestId = requestAnimationFrame(async time => {
if (time - this.renderTime >= 990 / this.project.framesPerSeconds) {
this.renderTime = time;
try {
await this.run();
} catch (e) {
this.requestId = null;
console.error(e);
}
} else {
this.request();
}
});
}