Created
August 12, 2017 22:34
-
-
Save adam-arold/1960812704e461ef934de9ef303498c8 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 com.valkryst.VTerminal.samples; | |
import com.valkryst.VTerminal.Panel; | |
import com.valkryst.VTerminal.builder.PanelBuilder; | |
import com.valkryst.VTerminal.font.Font; | |
import com.valkryst.VTerminal.font.FontLoader; | |
import java.awt.*; | |
import java.io.IOException; | |
import java.net.URISyntaxException; | |
public class SampleFPS { | |
public static void main(final String[] args) throws IOException, URISyntaxException, InterruptedException { | |
final Font font = FontLoader.loadFontFromJar("Fonts/DejaVu Sans Mono/18pt/bitmap.png", "Fonts/DejaVu Sans Mono/18pt/data.fnt", 1); | |
final PanelBuilder builder = new PanelBuilder(); | |
builder.setFont(font); | |
final Panel panel = builder.build(); | |
int temp = 45; | |
int measurements = 0; | |
long avgMs = 0; | |
long elapsedTime = 0; | |
while (true) { | |
long start = System.nanoTime(); | |
panel.getScreen().clear((char) temp); | |
panel.getScreen().setForegroundColor(new Color(255, 155, temp, 255)); | |
panel.getScreen().setBackgroundColor(new Color(temp, 155, 255, 255)); | |
panel.draw(); | |
long end = System.nanoTime(); | |
long totalMs = (end - start) / 1000 / 1000; | |
elapsedTime += totalMs; | |
avgMs = (avgMs * measurements + totalMs) / ++measurements; | |
if(measurements % 10 == 0) { | |
System.out.println(String.format("Current FPS is: '%d'. Elapsed time: '%d' seconds. Measurements: %d.", | |
1000 / avgMs, | |
elapsedTime / 1000, | |
measurements)); | |
} | |
temp++; | |
if (temp > 55) { | |
temp = 45; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment