Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic random splats on timer. #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ let config = {
SUNRAYS: true,
SUNRAYS_RESOLUTION: 196,
SUNRAYS_WEIGHT: 1.0,
AUTOSPLAT_ENABLED: false,
AUTOSPLAT_DELAY: 1,
AUTOSPLAT_COUNT: 1
}

function pointerPrototype () {
Expand Down Expand Up @@ -194,6 +197,11 @@ function startGUI () {
splatStack.push(parseInt(Math.random() * 20) + 5);
} }, 'fun').name('Random splats');

let autosplatFolder = gui.addFolder('Auto-splat');
autosplatFolder.add(config, 'AUTOSPLAT_ENABLED').name('enable auto-splat').listen();
autosplatFolder.add(config, 'AUTOSPLAT_DELAY', 0.1, 30.0).name('auto-splat interval seconds');
autosplatFolder.add(config, 'AUTOSPLAT_COUNT', 1, 10, 1).name('number of auto-splats');

let bloomFolder = gui.addFolder('Bloom');
bloomFolder.add(config, 'BLOOM').name('enabled').onFinishChange(updateKeywords);
bloomFolder.add(config, 'BLOOM_INTENSITY', 0.1, 2.0).name('intensity');
Expand Down Expand Up @@ -1115,6 +1123,16 @@ updateKeywords();
initFramebuffers();
multipleSplats(parseInt(Math.random() * 20) + 5);

var autosplat = function() {
if(config.AUTOSPLAT_ENABLED && !config.PAUSED) {
splatStack.push(config.AUTOSPLAT_COUNT);
}

setTimeout(autosplat, config.AUTOSPLAT_DELAY*1000);
}

setTimeout(autosplat, config.AUTOSPLAT_DELAY*1000);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but won't this recursion trigger a stack overflow over time?
If that's the case, how about using a setInterval instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a few hours of runtime, I didn't observe any significant slowdown or memory increase. You may be right that this could happen, but I wanted to use a repeated setTimeout to enable the user to change the splat interval after start.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular kind of stack-buildup is only an issue if you have asynchronous stack traces enabled (and by extension the debugger open), which can be disabled in chrome:
image


let lastUpdateTime = Date.now();
let colorUpdateTimer = 0.0;
update();
Expand Down