Removed all mention of SLF4J and Log4J

This commit is contained in:
Andrew Lalis 2022-07-29 18:54:24 +02:00
parent 29d44a5b01
commit 29eb46bcaf
11 changed files with 18 additions and 94 deletions

View File

@ -17,8 +17,6 @@ import nl.andrewl.aos_core.net.world.ChunkHashMessage;
import nl.andrewl.aos_core.net.world.ChunkUpdateMessage;
import nl.andrewl.record_net.Message;
import org.joml.Vector3f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.Path;
@ -29,8 +27,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
public class Client implements Runnable {
private static final Logger log = LoggerFactory.getLogger(Client.class);
private final ClientConfig config;
private final CommunicationHandler communicationHandler;
private final InputHandler inputHandler;
@ -79,13 +75,12 @@ public class Client implements Runnable {
try {
communicationHandler.establishConnection();
} catch (IOException e) {
log.error("Couldn't connect to the server: {}", e.getMessage());
System.err.println("Couldn't connect to the server: " + e.getMessage());
return;
}
gameRenderer = new GameRenderer(this, inputHandler);
soundManager = new SoundManager();
log.debug("Sound system initialized.");
long lastFrameAt = System.currentTimeMillis();
while (!gameRenderer.windowShouldClose() && !communicationHandler.isDone()) {

View File

@ -16,8 +16,6 @@ import nl.andrewl.record_net.Message;
import nl.andrewl.record_net.util.ExtendedDataInputStream;
import nl.andrewl.record_net.util.ExtendedDataOutputStream;
import org.joml.Vector3f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.DatagramPacket;
@ -31,8 +29,6 @@ import java.net.Socket;
* methods for sending messages and processing those we receive.
*/
public class CommunicationHandler {
private static final Logger log = LoggerFactory.getLogger(CommunicationHandler.class);
private final Client client;
private Socket socket;
private DatagramSocket datagramSocket;
@ -52,7 +48,7 @@ public class CommunicationHandler {
InetAddress address = InetAddress.getByName(client.getConfig().serverHost);
int port = client.getConfig().serverPort;
String username = client.getConfig().username;
log.info("Connecting to server at {}, port {}, with username \"{}\"...", address, port, username);
System.out.printf("Connecting to server at %s, port %d, with username \"%s\"...%n", address, port, username);
socket = new Socket(address, port);
socket.setSoTimeout(1000);
@ -66,12 +62,9 @@ public class CommunicationHandler {
}
if (response instanceof ConnectAcceptMessage acceptMessage) {
this.clientId = acceptMessage.clientId();
log.debug("Connection accepted. My client id is {}.", clientId);
client.setMyPlayer(new ClientPlayer(clientId, username));
receiveInitialData();
log.debug("Initial data received.");
establishDatagramConnection();
log.info("Connection to server established. My client id is {}.", clientId);
new Thread(new TcpReceiver(in, client::onMessageReceived).withShutdownHook(this::shutdown)).start();
new Thread(new UdpReceiver(datagramSocket, (msg, packet) -> client.onMessageReceived(msg))).start();
} else {
@ -138,7 +131,6 @@ public class CommunicationHandler {
if (!connectionEstablished) {
throw new IOException("Could not establish a datagram connection to the server after " + attempts + " attempts.");
}
log.debug("Established datagram communication with the server.");
}
public int getClientId() {

View File

@ -16,8 +16,6 @@ import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.GL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
@ -31,7 +29,6 @@ import static org.lwjgl.opengl.GL46.*;
* OpenGL context exists.
*/
public class GameRenderer {
private static final Logger log = LoggerFactory.getLogger(GameRenderer.class);
private static final float Z_NEAR = 0.01f;
private static final float Z_FAR = 500f;
@ -76,7 +73,6 @@ public class GameRenderer {
long monitorId = glfwGetPrimaryMonitor();
GLFWVidMode primaryMonitorSettings = glfwGetVideoMode(monitorId);
if (primaryMonitorSettings == null) throw new IllegalStateException("Could not get information about the primary monitory.");
log.debug("Primary monitor settings: Width: {}, Height: {}, FOV: {}", primaryMonitorSettings.width(), primaryMonitorSettings.height(), config.fov);
if (config.fullscreen) {
screenWidth = primaryMonitorSettings.width();
screenHeight = primaryMonitorSettings.height();
@ -88,7 +84,6 @@ public class GameRenderer {
}
if (windowHandle == 0) throw new RuntimeException("Failed to create GLFW window.");
inputHandler.setWindowId(windowHandle);
log.debug("Initialized GLFW window.");
// Setup callbacks.
glfwSetKeyCallback(windowHandle, new PlayerInputKeyCallback(inputHandler));
@ -101,7 +96,6 @@ public class GameRenderer {
}
glfwSetInputMode(windowHandle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
glfwSetCursorPos(windowHandle, 0, 0);
log.debug("Set up window callbacks.");
glfwMakeContextCurrent(windowHandle);
glfwSwapInterval(1);
@ -113,17 +107,14 @@ public class GameRenderer {
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glCullFace(GL_BACK);
log.debug("Initialized OpenGL context.");
this.chunkRenderer = new ChunkRenderer();
log.debug("Initialized chunk renderer.");
try {
this.guiRenderer = new GuiRenderer();
} catch (IOException e) {
throw new RuntimeException(e);
}
log.debug("Initialized GUI renderer.");
this.modelRenderer = new ModelRenderer();
try {
@ -137,7 +128,6 @@ public class GameRenderer {
} catch (IOException e) {
throw new RuntimeException(e);
}
log.debug("Initialized model renderer.");
updatePerspective(config.fov);
}

View File

@ -2,8 +2,6 @@ package nl.andrewl.aos2_client.render.chunk;
import nl.andrewl.aos_core.model.world.Chunk;
import nl.andrewl.aos_core.model.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.lwjgl.opengl.GL46.*;
@ -11,8 +9,6 @@ import static org.lwjgl.opengl.GL46.*;
* Represents a 3d mesh for a chunk.
*/
public class ChunkMesh {
private static final Logger log = LoggerFactory.getLogger(ChunkMesh.class);
private final int vboId;
private final int vaoId;
private final int eboId;
@ -49,20 +45,11 @@ public class ChunkMesh {
* Generates and loads this chunk's mesh into the allocated OpenGL buffers.
*/
private void loadMesh(ChunkMeshGenerator meshGenerator) {
// long start = System.nanoTime();
var meshData = meshGenerator.generateMesh(chunk, world);
// double dur = (System.nanoTime() - start) / 1_000_000.0;
this.indexCount = meshData.indexBuffer().limit();
// log.debug(
// "Generated mesh for chunk ({}, {}, {}) in {} ms. {} vertices and {} indices.",
// chunk.getPosition().x, chunk.getPosition().y, chunk.getPosition().z,
// dur,
// meshData.vertexBuffer().limit() / 9, indexCount
// );
glBindBuffer(GL_ARRAY_BUFFER, vboId);
glBufferData(GL_ARRAY_BUFFER, meshData.vertexBuffer(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eboId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, meshData.indexBuffer(), GL_STATIC_DRAW);
}

View File

@ -5,8 +5,6 @@ import org.joml.Vector3f;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.ALC;
import org.lwjgl.openal.ALCCapabilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
@ -21,8 +19,6 @@ import static org.lwjgl.openal.ALC10.*;
* Main class for managing the OpenAL audio interface.
*/
public class SoundManager {
private static final Logger log = LoggerFactory.getLogger(SoundManager.class);
private static final int SOURCE_COUNT = 32;
private final long alContext;
@ -101,7 +97,7 @@ public class SoundManager {
public void play(String soundName, float gain, Vector3f position, Vector3f velocity) {
Integer bufferId = getSoundBuffer(soundName);
if (bufferId == null) {
log.warn("Attempted to play unknown sound \"{}\"", soundName);
System.err.printf("Attempted to play unknown sound \"%s\".%n", soundName);
} else {
SoundSource source = getNextAvailableSoundSource();
if (source != null) {
@ -110,7 +106,7 @@ public class SoundManager {
source.setGain(gain);
source.play(bufferId);
} else {
log.warn("Couldn't get an available sound source to play sound \"{}\"", soundName);
System.err.printf("No sound sources available to play sound \"%s\".%n", soundName);
}
}
}

View File

@ -47,18 +47,6 @@
<artifactId>snakeyaml</artifactId>
<version>1.30</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.18.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->

View File

@ -18,8 +18,6 @@ import nl.andrewl.record_net.Message;
import nl.andrewl.record_net.util.ExtendedDataInputStream;
import nl.andrewl.record_net.util.ExtendedDataOutputStream;
import org.joml.Vector3i;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.*;
@ -35,8 +33,6 @@ import java.util.concurrent.ForkJoinPool;
* from them.
*/
public class ClientCommunicationHandler {
private static final Logger log = LoggerFactory.getLogger(ClientCommunicationHandler.class);
private final Server server;
private final Socket socket;
private final DatagramSocket datagramSocket;
@ -100,7 +96,6 @@ public class ClientCommunicationHandler {
try {
Message msg = Net.read(in);
if (msg instanceof ConnectRequestMessage connectMsg) {
log.debug("Received connect request from player \"{}\"", connectMsg.username());
// Ensure the connection is valid.
if (!UsernameChecker.isValid(connectMsg.username())) {
Net.write(new ConnectRejectMessage("Invalid username."), out);
@ -119,9 +114,7 @@ public class ClientCommunicationHandler {
connectionEstablished = true;
this.player = server.getPlayerManager().register(this, connectMsg.username());
Net.write(new ConnectAcceptMessage(player.getId()), out);
log.debug("Sent connect accept message.");
sendInitialData();
log.debug("Sent initial data.");
sendTcpMessage(ChatMessage.privateMessage("Welcome to the server, " + player.getUsername() + "."));
if (player.getTeam() != null) {
sendTcpMessage(ChatMessage.privateMessage("You've joined the " + player.getTeam().getName() + " team."));
@ -134,7 +127,7 @@ public class ClientCommunicationHandler {
} catch (SocketTimeoutException e) {
// Ignore this one, since this will happen if the client doesn't send data properly.
} catch (IOException e) {
log.warn("An IOException occurred while attempting to establish a connection to a client.", e);
System.err.println("An IOException occurred while attempting to establish a connection to a client: " + e.getMessage());
}
attempts++;
}
@ -144,7 +137,7 @@ public class ClientCommunicationHandler {
} catch (IOException e) {
e.printStackTrace();
}
log.warn("Player couldn't connect after {} attempts. Aborting connection.", attempts);
System.err.printf("Player couldn't connect after %d attempts. Aborting connection.%n", attempts);
socket.close();
}
}
@ -174,7 +167,7 @@ public class ClientCommunicationHandler {
DatagramPacket packet = new DatagramPacket(data, data.length, clientAddress, clientUdpPort);
sendDatagramPacket(packet);
} else {
log.warn("Can't send datagram packet because we don't know the client's UDP port yet.");
System.err.println("Can't send datagram packet because we don't know the client's UDP port yet.");
}
}

View File

@ -11,8 +11,6 @@ import nl.andrewl.aos_core.net.client.*;
import nl.andrewl.aos_core.net.connect.DatagramInit;
import nl.andrewl.record_net.Message;
import org.joml.Vector3f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.DatagramPacket;
@ -24,8 +22,6 @@ import java.util.regex.Pattern;
* the server, and components related to that.
*/
public class PlayerManager {
private static final Logger log = LoggerFactory.getLogger(PlayerManager.class);
private final Server server;
private final Map<Integer, ServerPlayer> players = new HashMap<>();
private final Map<Integer, ClientCommunicationHandler> clientHandlers = new HashMap<>();
@ -37,14 +33,14 @@ public class PlayerManager {
public synchronized ServerPlayer register(ClientCommunicationHandler handler, String username) {
ServerPlayer player = new ServerPlayer(nextClientId++, username);
log.info("Registered player \"{}\" with id {}", player.getUsername(), player.getId());
System.out.printf("Registered player \"%s\" with id %d.%n", player.getUsername(), player.getId());
players.put(player.getId(), player);
clientHandlers.put(player.getId(), handler);
String joinMessage;
Team team = findBestTeamForNewPlayer();
if (team != null) {
player.setTeam(team);
log.info("Player \"{}\" joined the \"{}\" team.", player.getUsername(), team.getName());
System.out.printf("Player \"%s\" joined the \"%s\" team.%n", player.getUsername(), team.getName());
joinMessage = String.format("%s joined the %s team.", username, team.getName());
} else {
joinMessage = username + " joined the game.";
@ -70,7 +66,7 @@ public class PlayerManager {
players.remove(player.getId());
clientHandlers.remove(player.getId());
broadcastTcpMessage(new PlayerLeaveMessage(player.getId()));
log.info("Deregistered player \"{}\" with id {}", player.getUsername(), player.getId());
System.out.printf("Deregistered player \"%s\" with id %d.%n", player.getUsername(), player.getId());
broadcastTcpMessage(ChatMessage.announce(player.getUsername() + " left the game."));
}
@ -207,7 +203,6 @@ public class PlayerManager {
if (handler != null) {
handler.setClientUdpPort(packet.getPort());
handler.sendDatagramPacket(init);
log.debug("Echoed player \"{}\"'s UDP init packet.", getPlayer(init.clientId()).getUsername());
}
}
@ -233,7 +228,7 @@ public class PlayerManager {
handler.sendDatagramPacket(packet);
}
} catch (IOException e) {
log.warn("An error occurred while broadcasting a UDP message.", e);
e.printStackTrace();
}
}
@ -247,7 +242,7 @@ public class PlayerManager {
}
}
} catch (IOException e) {
log.warn("An error occurred while broadcasting a UDP message.", e);
e.printStackTrace();
}
}
}

View File

@ -18,8 +18,6 @@ import nl.andrewl.aos_core.net.client.ClientOrientationState;
import nl.andrewl.aos_core.net.connect.DatagramInit;
import nl.andrewl.record_net.Message;
import org.joml.Vector3f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.*;
@ -29,8 +27,6 @@ import java.util.List;
import java.util.concurrent.ForkJoinPool;
public class Server implements Runnable {
private static final Logger log = LoggerFactory.getLogger(Server.class);
private final ServerSocket serverSocket;
private final DatagramSocket datagramSocket;
private volatile boolean running;
@ -68,7 +64,7 @@ public class Server implements Runnable {
if (Files.isReadable(worldFile)) {
this.world = WorldIO.read(worldFile);
} else {
log.error("Cannot read world file: {}", worldFile.toAbsolutePath());
System.err.println("Cannot read world file: " + worldFile.toAbsolutePath());
this.world = Worlds.arena();
}
}
@ -83,11 +79,11 @@ public class Server implements Runnable {
running = true;
new Thread(new UdpReceiver(datagramSocket, this::handleUdpMessage)).start();
new Thread(worldUpdater).start();
log.info("Started AoS2 Server on TCP/UDP port {}; now accepting connections.", serverSocket.getLocalPort());
System.out.printf("Started AoS2 Server on TCP/UDP port %d; now accepting connections.%n", serverSocket.getLocalPort());
while (running) {
acceptClientConnection();
}
log.info("Shutting down the server.");
System.out.println("Shutting down the server.");
playerManager.deregisterAll();
worldUpdater.shutdown();
datagramSocket.close(); // Shuts down the UdpReceiver.
@ -96,7 +92,6 @@ public class Server implements Runnable {
} catch (IOException e) {
throw new RuntimeException(e);
}
log.info("Shutdown complete.");
}
public boolean isRunning() {

View File

@ -2,8 +2,6 @@ package nl.andrewl.aos2_server.logic;
import nl.andrewl.aos2_server.Server;
import org.joml.Math;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A runnable to run as a separate thread, to periodically update the server's
@ -11,8 +9,6 @@ import org.slf4j.LoggerFactory;
* game engine, as it controls the game's main update pattern.
*/
public class WorldUpdater implements Runnable {
private static final Logger log = LoggerFactory.getLogger(WorldUpdater.class);
private final Server server;
private final float ticksPerSecond;
private final float secondsPerTick;
@ -30,15 +26,16 @@ public class WorldUpdater implements Runnable {
@Override
public void run() {
final long msPerTick = (long) (Math.floor(1.0 / ticksPerSecond) * 1_000);
final long nsPerTick = (long) Math.floor((1.0 / ticksPerSecond) * 1_000_000_000.0);
log.debug("Running world updater at {} ticks per second, or {} ns per tick.", ticksPerSecond, nsPerTick);
System.out.printf("Running world updater at %d ms/tick, or %d ns/tick.%n", msPerTick, nsPerTick);
running = true;
while (running) {
long start = System.nanoTime();
tick(System.currentTimeMillis());
long elapsedNs = System.nanoTime() - start;
if (elapsedNs > nsPerTick) {
log.warn("Took {} ns to do one tick, which is more than the desired {} ns per tick.", elapsedNs, nsPerTick);
System.err.printf("Took %d ns to do one tick, which is more than the desired %d ns per tick.%n", elapsedNs, nsPerTick);
} else {
long sleepTime = nsPerTick - elapsedNs;
long ms = sleepTime / 1_000_000;

View File

@ -7,8 +7,6 @@ import nl.andrewl.aos_core.model.item.GunItemStack;
import nl.andrewl.aos_core.model.item.Inventory;
import nl.andrewl.aos_core.model.item.ItemTypes;
import nl.andrewl.aos_core.net.client.PlayerUpdateMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
@ -17,8 +15,6 @@ import java.util.ArrayList;
* needed for the server.
*/
public class ServerPlayer extends Player {
private static final Logger log = LoggerFactory.getLogger(ServerPlayer.class);
private final PlayerActionManager actionManager;
private final Inventory inventory;