Last active
May 2, 2021 09:43
-
-
Save doriancransac/e23acc58761e29269f7ee110dd0cda6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package default; | |
import com.badlogic.gdx.Game; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.g2d.BitmapFont; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
import org.lwjgl.Sys; | |
public class FPSDropApp extends Game { | |
private BitmapFont font; | |
private SpriteBatch batch; | |
private long timeSinceLastRender; | |
private int timelyFramesNb = 0; | |
@Override | |
public void create() { | |
this.font = new BitmapFont(); | |
this.batch = new SpriteBatch(); | |
} | |
@Override | |
public void render() { | |
computeRenderStatsSinceLast(); | |
Gdx.gl.glClearColor(0, 0, 0, 1); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
drawFps(); | |
try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace();} | |
} | |
private void drawFps() { | |
int width = Gdx.graphics.getWidth(); | |
int height = Gdx.graphics.getHeight(); | |
batch.getProjectionMatrix().setToOrtho2D(0, 0, width, height); | |
batch.begin(); | |
font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 50, height - 50); | |
batch.end(); | |
} | |
private void computeRenderStatsSinceLast() { | |
long diffSinceLast = System.currentTimeMillis() - timeSinceLastRender; | |
if(diffSinceLast > 20) { | |
System.out.println(" -- Time since last render begin exceeded -- " + diffSinceLast + ", nb consecutive timely frames since last = " + timelyFramesNb); | |
timelyFramesNb = 0; | |
}else{ | |
this.timelyFramesNb++; | |
} | |
//logger.warn("Time since last render = " + diffSinceLast); | |
this.timeSinceLastRender = System.currentTimeMillis(); | |
} | |
@Override | |
public void resize(int width, int height) { | |
} | |
@Override | |
public void pause() { | |
} | |
@Override | |
public void resume() { | |
} | |
@Override | |
public void dispose() { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package default; | |
import com.badlogic.gdx.backends.lwjgl.LwjglApplication; | |
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.io.File; | |
public class FPSDropTestCaseStarter { | |
private static final Logger logger = LoggerFactory.getLogger(FPSDropTestCaseStarter.class); | |
private static File JGLLib; | |
public static void main(String... args){ | |
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); | |
config.width = 800; | |
config.height = 600; | |
config.foregroundFPS = 60; | |
LwjglApplication lwjglApplication = new LwjglApplication(new FPSDropApp(), config); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment