Skip to content

Commit

Permalink
SDL + Libretro: Reorganize frame limit code location here as well
Browse files Browse the repository at this point in the history
This should get them up to speed with the (currently) main AWT
UI.
  • Loading branch information
AShiningRay committed Sep 20, 2024
1 parent 0bf1ff6 commit 98db548
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
24 changes: 13 additions & 11 deletions src/org/recompile/freej2me/Anbu.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,32 @@ public void run()
{
int[] data;

if(limitFPS>0)
{
requiredFrametime = 1000 / limitFPS;
elapsedTime = System.currentTimeMillis() - lastRenderTime;
sleepTime = requiredFrametime - elapsedTime;

if (sleepTime > 0) { Thread.sleep(sleepTime); }
}

// Send Frame to SDL interface
if(!config.isRunning) { data = Mobile.getPlatform().getLCD().getRGB(0, 0, lcdWidth, lcdHeight, null, 0, lcdWidth); }
else { data = config.getLCD().getRGB(0, 0, lcdWidth, lcdHeight, null, 0, lcdWidth);}
byte[] frame = new byte[data.length * 3];
int cb = 0;

for(int i = 0; i < data.length; i++)
{
frame[cb + 0] = (byte)(data[i] >> 16);
frame[cb + 1] = (byte)(data[i] >> 8);
frame[cb + 2] = (byte)(data[i]);
cb += 3;
}
sdl.frame.write(frame);

lastRenderTime = System.currentTimeMillis();
if(limitFPS>0)
{
requiredFrametime = 1000 / limitFPS;
elapsedTime = System.currentTimeMillis() - lastRenderTime;
sleepTime = requiredFrametime - elapsedTime;

if (sleepTime > 0) { Thread.sleep(sleepTime); }

if(limitFPS>0) { lastRenderTime = System.currentTimeMillis(); }

sdl.frame.write(frame);
} else { sdl.frame.write(frame); }
}
catch (Exception e) { }
}
Expand Down
33 changes: 20 additions & 13 deletions src/org/recompile/freej2me/Libretro.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,6 @@ public void run()
{
int[] data;

if(limitFPS>0)
{
requiredFrametime = 1000 / limitFPS;
elapsedTime = System.currentTimeMillis() - lastRenderTime;
sleepTime = requiredFrametime - elapsedTime;

if (sleepTime > 0) { Thread.sleep(sleepTime); }
}

if(config.isRunning)
{
data = config.getLCD().getRGB(0, 0, lcdWidth, lcdHeight, null, 0, lcdWidth);
Expand All @@ -428,11 +419,27 @@ public void run()
frameHeader[3] = (byte)((lcdHeight>>8)&0xFF);
frameHeader[4] = (byte)((lcdHeight)&0xFF);
//frameHeader[5] = rotate - set from config
System.out.write(frameHeader, 0, 6);
System.out.write(frameBuffer, 0, bufferLength);
System.out.flush();

lastRenderTime = System.currentTimeMillis();
if(limitFPS>0)
{
requiredFrametime = 1000 / limitFPS;
elapsedTime = System.currentTimeMillis() - lastRenderTime;
sleepTime = requiredFrametime - elapsedTime;

if (sleepTime > 0) { Thread.sleep(sleepTime); }

System.out.write(frameHeader, 0, 6);
System.out.write(frameBuffer, 0, bufferLength);
System.out.flush();

lastRenderTime = System.currentTimeMillis();
}
else
{
System.out.write(frameHeader, 0, 6);
System.out.write(frameBuffer, 0, bufferLength);
System.out.flush();
}
}
catch (Exception e)
{
Expand Down

0 comments on commit 98db548

Please sign in to comment.