Add support for SLF4J logging in :api
This commit is contained in:
@@ -11,4 +11,5 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation "org.joml:joml:${jomlVersion}"
|
||||
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.bartlomiejpluta.base.api.util.profiler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -10,6 +13,8 @@ import static java.util.stream.Collectors.counting;
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
public class FPSProfiler {
|
||||
private static final Logger log = LoggerFactory.getLogger(FPSProfiler.class);
|
||||
|
||||
private static final int MOD = 30;
|
||||
private final List<Double> values = new LinkedList<>();
|
||||
private float fpsAccumulator = 0;
|
||||
@@ -29,7 +34,7 @@ public class FPSProfiler {
|
||||
}
|
||||
|
||||
public void printResult() {
|
||||
System.out.format("Min FPS: %f, max FPS: %f, avg FPS: %f",
|
||||
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()
|
||||
@@ -51,6 +56,6 @@ public class FPSProfiler {
|
||||
.entrySet()
|
||||
.stream()
|
||||
.sorted(comparingInt(Map.Entry::getKey))
|
||||
.forEach(e -> System.out.printf("%s FPS: %f%% (%d occurrences)", e.getKey(), e.getValue() * 100.0f / values.size(), e.getValue()));
|
||||
.forEach(e -> log.info("{} FPS: {}% ({} occurrences)", e.getKey(), e.getValue() * 100.0f / values.size(), e.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package com.bartlomiejpluta.base.api.util.profiler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class TimeProfiler {
|
||||
private static final Logger log = LoggerFactory.getLogger(TimeProfiler.class);
|
||||
|
||||
private static final DecimalFormat DF = new DecimalFormat("0.00");
|
||||
private final Map<String, Double> averages = new HashMap<>();
|
||||
|
||||
@@ -24,7 +29,7 @@ public class TimeProfiler {
|
||||
public void printResult() {
|
||||
averages.entrySet().stream()
|
||||
.sorted(Entry.<String, Double>comparingByValue().reversed())
|
||||
.forEachOrdered(entry -> System.out.format("[%s]: [%sms] [%sus] [%sns]",
|
||||
.forEachOrdered(entry -> log.info("[{}]: [{}sms] [{}sus] [{}ns]",
|
||||
entry.getKey(),
|
||||
DF.format(entry.getValue() / 1_000_000),
|
||||
DF.format(entry.getValue() / 1_000),
|
||||
|
||||
@@ -44,10 +44,10 @@ dependencies {
|
||||
implementation "org.codehaus.janino:janino:${janinoVersion}"
|
||||
implementation "org.codehaus.janino:commons-compiler:${janinoVersion}"
|
||||
|
||||
|
||||
// Spring
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
|
||||
implementation "org.slf4j:jul-to-slf4j:${slf4jVersion}"
|
||||
}
|
||||
|
||||
task provideGameEngine(type: Copy) {
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package ${package};
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.context.Context;
|
||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
import com.bartlomiejpluta.base.api.game.runner.GameRunner;
|
||||
|
||||
public class ${className} implements GameRunner {
|
||||
private static final Logger log = LoggerFactory.getLogger(${className}.class);
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
log.info("The game runner is not implemented yet...");
|
||||
throw new RuntimeException("Not implemented yet");
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ dependencies {
|
||||
|
||||
// Spring
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
implementation "org.slf4j:jul-to-slf4j:${slf4jVersion}"
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
|
||||
|
||||
@@ -42,6 +42,6 @@ public class DefaultTextureManager implements TextureManager {
|
||||
public void cleanUp() {
|
||||
log.info("Disposing textures");
|
||||
loadedTextures.forEach((name, texture) -> texture.dispose());
|
||||
log.info("{} textures has been disposed", loadedTextures.size());
|
||||
log.info("{} textures have been disposed", loadedTextures.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,6 @@ public class DefaultShaderManager implements ShaderManager {
|
||||
public void cleanUp() {
|
||||
log.info("Disposing shaders");
|
||||
shaders.forEach((name, program) -> program.dispose());
|
||||
log.info("{} shaders has been disposed", shaders.size());
|
||||
log.info("{} shaders have been disposed", shaders.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DefaultMeshManager implements MeshManager {
|
||||
public void cleanUp() {
|
||||
log.info("Disposing meshes");
|
||||
quads.forEach((dim, mesh) -> mesh.dispose());
|
||||
log.info("{} meshes has been disposed", quads.size());
|
||||
log.info("{} meshes have been disposed", quads.size());
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
lwjglVersion=3.2.3
|
||||
springBootVersion=2.4.2
|
||||
springDependencyManagementVersion=1.0.11.RELEASE
|
||||
slf4jVersion=1.7.30
|
||||
jomlVersion=1.10.0
|
||||
guavaVersion=29.0-jre
|
||||
javaFxVersion=15.0.1
|
||||
|
||||
Reference in New Issue
Block a user