Added a sprite in preparation for incoming updates & added delta counter.

This commit is contained in:
Jeasonfire 2015-05-15 20:53:36 +03:00
parent bf915e7daa
commit f87f44da51
2 changed files with 33 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 901 KiB

View File

@ -25,7 +25,6 @@ import com.saltosion.gladiator.gui.TextNode;
import com.saltosion.gladiator.gui.TextProperty;
import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Global;
import com.saltosion.gladiator.util.Log;
import com.saltosion.gladiator.util.SpriteSequence;
import java.util.ArrayList;
import java.util.List;
@ -48,6 +47,11 @@ public class RenderingSystem extends EntitySystem {
private boolean debug = true;
private final Color debugColor = new Color(0, 1, 0, 1);
private float deltaDelay = 0;
private double deltaAvgSum;
private long deltaAvgTimes;
private String deltaString = "0";
private List<TextObject> drawableText;
@Override
@ -90,10 +94,33 @@ public class RenderingSystem extends EntitySystem {
renderGUI(new Vector2(0, 0));
renderDebug(camera);
drawString("FPS: " + Gdx.graphics.getFramesPerSecond(), new Vector2(camera.position.x - 12, camera.position.y + 8));
if (debug) {
drawString("FPS: " + Gdx.graphics.getFramesPerSecond(), new Vector2(camera.position.x - 12, camera.position.y + 8));
drawString("Delta (ms): " + getDeltaWithDelay(deltaTime, 0.1f), new Vector2(camera.position.x - 12, camera.position.y + 7));
}
renderFont(fontCamera);
}
/**
* A debugging function for easier performance logging.
*
* @param deltaTime The delta of the current frame
* @param delay The delay between deltaString updates
* @return A string that has the delta formatted
*/
private String getDeltaWithDelay(float deltaTime, float delay) {
this.deltaDelay += deltaTime;
this.deltaAvgSum += Gdx.graphics.getDeltaTime() * 1000;
this.deltaAvgTimes++;
if (this.deltaDelay >= delay) {
this.deltaDelay = 0;
this.deltaString = String.format("%.2f", this.deltaAvgSum / this.deltaAvgTimes);
this.deltaAvgSum = 0;
this.deltaAvgTimes = 0;
}
return deltaString;
}
private void renderEntities(float deltaTime) {
batch.setProjectionMatrix(camera.combined);
batch.begin();