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

api to skip frames #767

Open
yamt opened this issue Oct 1, 2024 · 1 comment
Open

api to skip frames #767

yamt opened this issue Oct 1, 2024 · 1 comment

Comments

@yamt
Copy link
Contributor

yamt commented Oct 1, 2024

for games, it's often more important to provide a constant game speed than drawing every single frames.
it would be nicer for wasm4 to provide a mechanism for skipping frames.
especially for graphics-heavy games on slow hardware.

eg. a simple timestamp (maybe in fps) on the shared memory area.

static unsigned int n = 0;

update()
{
  if (TIMESTAMP > n++) {
    /* somehow reduce computation for this frame */
  }
}
@JerwuQu
Copy link
Contributor

JerwuQu commented Dec 3, 2024

You could set the SYSTEM_PRESERVE_FRAMEBUFFER flag in SYSTEM_FLAGS and then skip drawing depending on frame number.

Example drawing at 30fps:

#include "wasm4.h"

const size_t FRAME_SKIP = 2; // Draw every 2nd frame

void start() {
    *SYSTEM_FLAGS |= SYSTEM_PRESERVE_FRAMEBUFFER;
}

size_t frame = 0;
void update() {
    frame++;
    if ((frame % FRAME_SKIP) == 0) {
        // Regular processing here
        rect(10, 10, 32, 32);
    }
}

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

No branches or pull requests

2 participants