Create FPS monitor
This commit is contained in:
7
engine/src/main/java/com/bartlomiejpluta/base/core/stat/FPSMonitor.java
Executable file
7
engine/src/main/java/com/bartlomiejpluta/base/core/stat/FPSMonitor.java
Executable file
@@ -0,0 +1,7 @@
|
||||
package com.bartlomiejpluta.base.core.stat;
|
||||
|
||||
import com.bartlomiejpluta.base.core.gc.Cleanable;
|
||||
import com.bartlomiejpluta.base.core.logic.Updatable;
|
||||
|
||||
public interface FPSMonitor extends Updatable, Cleanable {
|
||||
}
|
||||
63
engine/src/main/java/com/bartlomiejpluta/base/core/stat/LogFPSMonitor.java
Executable file
63
engine/src/main/java/com/bartlomiejpluta/base/core/stat/LogFPSMonitor.java
Executable file
@@ -0,0 +1,63 @@
|
||||
package com.bartlomiejpluta.base.core.stat;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Comparator.comparingInt;
|
||||
import static java.util.function.Function.identity;
|
||||
import static java.util.stream.Collectors.counting;
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LogFPSMonitor implements FPSMonitor {
|
||||
private static final int MOD = 30;
|
||||
private final List<Double> values = new LinkedList<>();
|
||||
private float fpsAccumulator = 0;
|
||||
private int pointer = 0;
|
||||
private double fps = 0;
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
fpsAccumulator += dt;
|
||||
|
||||
if (++pointer % MOD == 0) {
|
||||
fps = pointer / fpsAccumulator;
|
||||
fpsAccumulator = 0;
|
||||
pointer = 0;
|
||||
|
||||
values.add(fps);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
log.info("Min FPS: {}, max FPS: {}, avg FPS: {}",
|
||||
values.stream().min(Double::compareTo).orElse(-1.0),
|
||||
values.stream().max(Double::compareTo).orElse(-1.0),
|
||||
totalAverage()
|
||||
);
|
||||
|
||||
printHistogram();
|
||||
}
|
||||
|
||||
private double totalAverage() {
|
||||
return values.stream().reduce(0.0, Double::sum) / values.size();
|
||||
}
|
||||
|
||||
private void printHistogram() {
|
||||
values
|
||||
.stream()
|
||||
.mapToInt(Double::intValue)
|
||||
.boxed()
|
||||
.collect(groupingBy(identity(), counting()))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.sorted(comparingInt(Map.Entry::getKey))
|
||||
.forEach(e -> log.info("{} FPS: {}% ({} occurrences)", e.getKey(), e.getValue() * 100.0f / values.size(), e.getValue()));
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.joml.Vector2f;
|
||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.opengl.GL;
|
||||
@@ -76,7 +77,7 @@ public class Window {
|
||||
glfwMakeContextCurrent(windowHandle);
|
||||
|
||||
// Enable V-Sync
|
||||
glfwSwapInterval(1);
|
||||
// glfwSwapInterval(1);
|
||||
|
||||
// Make the window visible
|
||||
glfwShowWindow(windowHandle);
|
||||
@@ -108,6 +109,10 @@ public class Window {
|
||||
return glfwWindowShouldClose(windowHandle);
|
||||
}
|
||||
|
||||
public Vector2f getSize() {
|
||||
return new Vector2f(width, height);
|
||||
}
|
||||
|
||||
public static Window create(String title, int width, int height) {
|
||||
return new Window(title, -1, width, height, false);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.bartlomiejpluta.base.core.util.math;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
public class MathUtil {
|
||||
public static int gcdEuclidean(int a, int b) {
|
||||
int x = a;
|
||||
@@ -14,4 +17,16 @@ public class MathUtil {
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public static int clamp(int value, int min, int max) {
|
||||
return min(max, max(value, min));
|
||||
}
|
||||
|
||||
public static float clamp(float value, float min, float max) {
|
||||
return min(max, max(value, min));
|
||||
}
|
||||
|
||||
public static double clamp(double value, double min, double max) {
|
||||
return min(max, max(value, min));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@ public class GameMap implements Renderable, Updatable {
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2f getSize() {
|
||||
return new Vector2f(columns * stepSize.x, rows * stepSize.y);
|
||||
}
|
||||
|
||||
public GameMap createObjectLayer() {
|
||||
var passageMap = new PassageAbility[rows][columns];
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
|
||||
@@ -29,10 +29,12 @@ public class TileLayer implements Layer {
|
||||
|
||||
@Override
|
||||
public void render(Window window, ShaderManager shaderManager) {
|
||||
for(var row : layer) {
|
||||
for(var tile : row) {
|
||||
shaderManager.setUniform(UniformName.UNI_MODEL_MATRIX, tile.getModelMatrix());
|
||||
tile.render(window, shaderManager);
|
||||
for (var row : layer) {
|
||||
for (var tile : row) {
|
||||
if (tile != null) {
|
||||
shaderManager.setUniform(UniformName.UNI_MODEL_MATRIX, tile.getModelMatrix());
|
||||
tile.render(window, shaderManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user