Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reindernijhoff committed Nov 9, 2023
1 parent bf7e5e8 commit f062144
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib/ImageEffectRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class ImageEffectRenderer {
}
}

private static drawInstances(time: number): void {
private static drawInstances(time: number = 0): void {
window.requestAnimationFrame(time => this.drawInstances(time));

time /= 1000;
Expand All @@ -94,7 +94,7 @@ export default class ImageEffectRenderer {
let maxWidth = 0, maxHeight = 0;

pool.forEach(ier => {
ier.update(time);
ier.update(dt);
});

pool.forEach(ier => {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/RendererInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export class RendererInstance extends Renderer {
public canvas: HTMLCanvasElement;
public buffers: RendererBuffer[] = [];
public options: ImageEffectRendererOptions;
public time: number = 0;

private index: number;

private tickFuncs: ((dt:number) => void) [] = [];
private readyFuncs: (() => void) [] = [];

private startTime: number = -1;
private time: number = 0;
private drawOneFrame: boolean = false;
private container: HTMLElement;

Expand Down Expand Up @@ -154,7 +154,7 @@ export class RendererInstance extends Renderer {
return this.shaderCompiled && this.buffers.every(buffer => buffer && buffer.shaderCompiled);
}

public update(time: number) {
public update(dt: number) {
if (this.allShadersCompiled) {
if (!this._ready) {
this._ready = true;
Expand All @@ -175,15 +175,15 @@ export class RendererInstance extends Renderer {
}
}

private drawingLoop(time: number) {
private drawingLoop(time: number = 0) {
this.animationRequestId = window.requestAnimationFrame(time => this.drawingLoop(time));

time /= 1000;

const dt = this.startTime < 0 ? 1 / 60 : time - this.startTime;
this.startTime = time > 0 ? time : -1;

this.update(time);
this.update(dt);

if (this.drawThisFrame) {
this.drawInstance(dt);
Expand Down

0 comments on commit f062144

Please sign in to comment.