Skip to content

Commit

Permalink
tweaks needed for libtas (#23)
Browse files Browse the repository at this point in the history
Normally, input reading should not be tied to the render logic, because that would softlock jars that only send new render data after an input is registered (Ex: JBenchmark 2 and some other jars that use Form UI).

But for determinism in libTAS, inputs must be pulled synchronously with rendering, because libTAS processes inputs (and a lot of other things) during frame boundaries, which is when the program calls its render function.

Of course, this will break jars that require the async input logic, but some sort of workaround should be possible, as input in general still requires some work.
  • Loading branch information
vadosnaprimer authored Oct 30, 2024
1 parent 5129cc0 commit a771ecb
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/org/recompile/freej2me/Anbu.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,7 @@ public void start(String args[])
// Create a renderer, and a texture where drawing can take place, streaming for constant updates.
renderer = SDL_CreateRenderer(window, -1, 0);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, lcdWidth, lcdHeight);
pixels = new Memory(lcdWidth * lcdHeight * 4);

/*
* Input reading should not be tied to the render logic, otherwise jars that only send new render data
* after an input is registered (Ex: JBenchmark 2 and some other jars that use Form UI) will get softlocked.
*/
keytimer = new Timer();
keytask = new TimerTask() { public void run() { processEvents(); } };
keytimer.schedule(keytask, 0, 1);
pixels = new Memory(lcdWidth * lcdHeight * 4);

SDL_JoystickEventState(SDL_ENABLE);

Expand All @@ -279,6 +271,13 @@ public void stop()

public void paint()
{
/*
* Normally, input reading should not be tied to the render logic, because that would softlock jars that only
* send new render data after an input is registered (Ex: JBenchmark 2 and some other jars that use Form UI).
* But for determinism in libTAS, inputs must be pulled synchronously with rendering, because libTAS processes
* inputs (and a lot of other things) during frame boundaries, which is when the program calls its render function.
*/
processEvents();

/*
* Let's make resolution changes and adjust any relevant objects here, as it's right on the render path
Expand Down

0 comments on commit a771ecb

Please sign in to comment.