Skip to content

Commit

Permalink
add rendering skipping when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
spessasus committed Aug 18, 2024
1 parent 7be6b3a commit cc4a76d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 67 deletions.
27 changes: 22 additions & 5 deletions src/website/js/renderer/render.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
import { FONT_SIZE } from './renderer.js'
import { drawNotes } from './draw_notes.js'

let hasRenderedNoVoices = false;
/**
* Renders a single frame
* @this {Renderer}
* @param auto {boolean} if set to false, the renderer won't clear the screen or request an animation frame. Defaults to true.
* @param force {boolean} ignores nothing to do
*/
export function render(auto = true)
export function render(auto = true, force = false)
{
if (!this.renderBool)
let nothingToDo = (this.seq === undefined || this?.seq?.paused === true) && this.synth.voicesAmount === 0 && !force;
if (!this.renderBool || nothingToDo)
{
if (auto)
console.log(hasRenderedNoVoices)
if(hasRenderedNoVoices)
{
// no frames shall be drawn. Redo!
if (auto)
{
requestAnimationFrame(this.render.bind(this));
}
return;
}
else
{
requestAnimationFrame(this.render.bind(this));
hasRenderedNoVoices = true;
}
return;
}
else
{
hasRenderedNoVoices = false;
}

if (auto)
Expand Down
2 changes: 2 additions & 0 deletions src/website/manager/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class Manager
}

}
this.renderer.render(false, true);
}
checkResize();
window.addEventListener("resize", checkResize.bind(this));
Expand Down Expand Up @@ -291,6 +292,7 @@ class Manager
break;
}
});
this.renderer.render(false, true);
}

/**
Expand Down
64 changes: 32 additions & 32 deletions src/website/minified/demo_main.min.js

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions src/website/minified/local_main.min.js

Large diffs are not rendered by default.

0 comments on commit cc4a76d

Please sign in to comment.