Skip to content

Conversation

@lfrati
Copy link

@lfrati lfrati commented Aug 23, 2024

Looking at the examples in https://znah.net/alife24 I've noticed that some rely on frameCount to perform initialization.

I like how time is available from glsl.loop({time} => ... so I propose to also add frameCount i.e. glsl.loop({time, frameCount} => ...
This can also be used to easily measure FPS e.g. fpsDisplay.textContent = `FPS: ${Math.round(frameCount / time)}`;

Additionally, the fact that time is set by the requestAnimationFrame function makes resetting time tricky so I propose adding glsl.restart() that resets both time and frameCount to 0.

Note: The proposed changes effectively move the code used in the above link inside swissgl itself i.e.

let frameCount = 0;
canvas.onclick = ()=>{
	frameCount = 0;
}
glsl.loop(args=>{
	if (frameFunc) {
		glsl.adjustCanvas();
		try {
			frameFunc({...args, frameCount});
			frameCount++;
		...
});

@google-cla
Copy link

google-cla bot commented Aug 23, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@lfrati lfrati changed the title Patch 1 Add frameCount to glsl.loop and restart() to restart time Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant