korge icon indicating copy to clipboard operation
korge copied to clipboard

[Important] Hugely simplify GameWindow and rendering

Open soywiz opened this issue 2 years ago • 0 comments
trafficstars

Right now GameWindow and rendering is super complicated on the korgw side.

We should simplificate it as much as possible, specially now that we have less targets.

On JS?

  • setInterval(60ms): update
  • requestAnimationFrame: render

On JVM / Android / Native:

  • Thread handling the event loop with a timer every 60 fps: so we have consisent updating. In that thread we don't sleep while we are handling events. Updating the game grabs a lock. After updating if something change, we request a frame update. We can prepare a frame on this thread in a renderbuffer when required.
  • On the UI thread, handle frame render requests and just blit the generated renderbuffer in the current frame, do vsync here. Handle also events here. We should either create a shared opengl context, or use a locking mechanism to grab the opengl context.

This should also avoid I/O delays because events are only handled in the event loop and right now that event loop is in a thread that is sleeping on vsync. This should alos fix flickering on windows JVM When not rendering in continuous mode.

This is a long-standing issue, so this task is important. It should also make the code more mainteintable for the long run.

Might worth exploring and create a new simpler API, and then migrate to the old one once we get it right on all the targets.

soywiz avatar Oct 05 '23 12:10 soywiz