From 29eb46bcaffeba81d0c353608f3bf73ed2585152 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Fri, 29 Jul 2022 18:54:24 +0200 Subject: [PATCH] Removed all mention of SLF4J and Log4J --- .../main/java/nl/andrewl/aos2_client/Client.java | 7 +------ .../andrewl/aos2_client/CommunicationHandler.java | 10 +--------- .../andrewl/aos2_client/render/GameRenderer.java | 10 ---------- .../aos2_client/render/chunk/ChunkMesh.java | 13 ------------- .../andrewl/aos2_client/sound/SoundManager.java | 8 ++------ core/pom.xml | 12 ------------ .../aos2_server/ClientCommunicationHandler.java | 13 +++---------- .../nl/andrewl/aos2_server/PlayerManager.java | 15 +++++---------- .../main/java/nl/andrewl/aos2_server/Server.java | 11 +++-------- .../andrewl/aos2_server/logic/WorldUpdater.java | 9 +++------ .../andrewl/aos2_server/model/ServerPlayer.java | 4 ---- 11 files changed, 18 insertions(+), 94 deletions(-) diff --git a/client/src/main/java/nl/andrewl/aos2_client/Client.java b/client/src/main/java/nl/andrewl/aos2_client/Client.java index e127b72..e193b37 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/Client.java +++ b/client/src/main/java/nl/andrewl/aos2_client/Client.java @@ -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()) { diff --git a/client/src/main/java/nl/andrewl/aos2_client/CommunicationHandler.java b/client/src/main/java/nl/andrewl/aos2_client/CommunicationHandler.java index c44631f..55e0128 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/CommunicationHandler.java +++ b/client/src/main/java/nl/andrewl/aos2_client/CommunicationHandler.java @@ -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() { diff --git a/client/src/main/java/nl/andrewl/aos2_client/render/GameRenderer.java b/client/src/main/java/nl/andrewl/aos2_client/render/GameRenderer.java index 4579105..d1cc73a 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/render/GameRenderer.java +++ b/client/src/main/java/nl/andrewl/aos2_client/render/GameRenderer.java @@ -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); } diff --git a/client/src/main/java/nl/andrewl/aos2_client/render/chunk/ChunkMesh.java b/client/src/main/java/nl/andrewl/aos2_client/render/chunk/ChunkMesh.java index d0f3e12..80cd3ea 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/render/chunk/ChunkMesh.java +++ b/client/src/main/java/nl/andrewl/aos2_client/render/chunk/ChunkMesh.java @@ -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); } diff --git a/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java b/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java index 8b12991..bcac781 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java +++ b/client/src/main/java/nl/andrewl/aos2_client/sound/SoundManager.java @@ -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); } } } diff --git a/core/pom.xml b/core/pom.xml index ebada06..bbd5151 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -47,18 +47,6 @@ snakeyaml 1.30 - - - org.slf4j - slf4j-api - 1.7.36 - - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.18.0 - diff --git a/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java b/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java index 11e2f61..f68b59d 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java +++ b/server/src/main/java/nl/andrewl/aos2_server/ClientCommunicationHandler.java @@ -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."); } } diff --git a/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java b/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java index 33f23d8..daac8d7 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java +++ b/server/src/main/java/nl/andrewl/aos2_server/PlayerManager.java @@ -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 players = new HashMap<>(); private final Map 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(); } } } diff --git a/server/src/main/java/nl/andrewl/aos2_server/Server.java b/server/src/main/java/nl/andrewl/aos2_server/Server.java index b1612f4..3bcdffb 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/Server.java +++ b/server/src/main/java/nl/andrewl/aos2_server/Server.java @@ -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() { diff --git a/server/src/main/java/nl/andrewl/aos2_server/logic/WorldUpdater.java b/server/src/main/java/nl/andrewl/aos2_server/logic/WorldUpdater.java index 77dee8a..abd5839 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/logic/WorldUpdater.java +++ b/server/src/main/java/nl/andrewl/aos2_server/logic/WorldUpdater.java @@ -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; diff --git a/server/src/main/java/nl/andrewl/aos2_server/model/ServerPlayer.java b/server/src/main/java/nl/andrewl/aos2_server/model/ServerPlayer.java index f3ed0ad..c96d10d 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/model/ServerPlayer.java +++ b/server/src/main/java/nl/andrewl/aos2_server/model/ServerPlayer.java @@ -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;