It wasn't immediately obvious how to get my game running at a real framerate - the main thread needs to handle messages from the browser, and it does this by overriding a handle message call in the Instance class - unlike a good old Petzold-style windows app which can process the message queue on its own terms. Bottom line, you need to give up control of the main thread so the Pepper API can do its thing.
So, I should put my game on another thread, right? Well, so far, the Pepper API isn't happy about being called from other threads. And the GL stuff doesn't seem to support moving the gl context from one thread to another a la wGLMakeCurrent yet.
To get up-and-running, quick and dirty, I had the javascript regularly call the native client with a "tick" command. That was as slow as I expected.
What people seem to be doing for now is putting their game tick on a callback from the page flip, something like this:
void GameFrame(void* data, int32_t result)
{
// ... update logic ...
// ... render ...
renderSurface.SwapBuffers(pp::CompletionCallback(&GameFrame, data));
}
And now we've got some speed going!
A little work, and you could start logic updating before the swap is finished, for more more speed.
Comments