Skip to content

Commit

Permalink
feat: store the frame number with the delta
Browse files Browse the repository at this point in the history
  • Loading branch information
seankmartin committed Oct 21, 2024
1 parent 9e4e07d commit 60447d2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/util/framerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ interface QueryInfo {
wasEnded: boolean;
}

interface FrameDeltaInfo {
frameDelta: number;
frameNumber: number;
}

export class FramerateMonitor {
private timeElapsedQueries: QueryInfo[] = [];
private warnedAboutMissingExtension = false;
private storedTimeDeltas: number[] = [];
private storedTimeDeltas: FrameDeltaInfo[] = [];

constructor(
private numStoredTimes: number = 10,
Expand Down Expand Up @@ -135,7 +140,10 @@ export class FramerateMonitor {
} else if (available) {
const result =
gl.getQueryParameter(query.glQuery, gl.QUERY_RESULT) / 1e6;
this.storedTimeDeltas.push(result);
this.storedTimeDeltas.push({
frameDelta: result,
frameNumber: query.frameNumber,
});
gl.deleteQuery(query.glQuery);
deletedQueryIndices.push(i);
}
Expand All @@ -151,7 +159,9 @@ export class FramerateMonitor {
}

getLastFrameTimesInMs(numberOfFrames: number = 10) {
return this.storedTimeDeltas.slice(-numberOfFrames);
return this.storedTimeDeltas
.slice(-numberOfFrames)
.map((frameDeltaInfo) => frameDeltaInfo.frameDelta);
}

getQueries() {
Expand Down

0 comments on commit 60447d2

Please sign in to comment.