diff --git a/src/main/java/tanks/Game.java b/src/main/java/tanks/Game.java index a9f3b431..8dfae33e 100644 --- a/src/main/java/tanks/Game.java +++ b/src/main/java/tanks/Game.java @@ -95,7 +95,7 @@ public enum Framework {lwjgl, libgdx} public static double[][] tilesDepth = new double[28][18]; //Remember to change the version in android's build.gradle and ios's robovm.properties - public static final String version = "Tanks v1.4.1a"; + public static final String version = "Tanks v1.4.1b"; public static final int network_protocol = 46; public static boolean debug = false; public static boolean traceAllRays = false; diff --git a/src/main/java/tanks/Panel.java b/src/main/java/tanks/Panel.java index e241137b..edfac1fa 100644 --- a/src/main/java/tanks/Panel.java +++ b/src/main/java/tanks/Panel.java @@ -14,6 +14,7 @@ import tanks.hotbar.Hotbar; import tanks.network.Client; import tanks.network.ClientHandler; +import tanks.network.MessageReader; import tanks.obstacle.Obstacle; import tanks.tank.*; @@ -866,6 +867,13 @@ public void drawBar(double offset) Drawing.drawing.setColor(col[0], col[1], col[2]); Game.game.window.fontRenderer.drawString(boundary + 150, offset + (int) (Panel.windowHeight - 40 + 6), 0.4, 0.4, "Latency: " + ClientHandler.lastLatencyAverage + "ms"); } + + if (ScreenPartyLobby.isClient || ScreenPartyHost.isServer) + { + Drawing.drawing.setColor(255, 227, 186); + Game.game.window.fontRenderer.drawString(boundary + 400, offset + (int) (Panel.windowHeight - 40 + 6), 0.4, 0.4, "Upstream: " + MessageReader.upstreamBytesPerSec / 1024 + "KB/s"); + Game.game.window.fontRenderer.drawString(boundary + 400, offset + (int) (Panel.windowHeight - 40 + 22), 0.4, 0.4, "Downstream: " + MessageReader.downstreamBytesPerSec / 1024 + "KB/s"); + } } public double[] getLatencyColor(long l) diff --git a/src/main/java/tanks/bullet/Bullet.java b/src/main/java/tanks/bullet/Bullet.java index 1d911ca4..e2dd87df 100644 --- a/src/main/java/tanks/bullet/Bullet.java +++ b/src/main/java/tanks/bullet/Bullet.java @@ -598,7 +598,7 @@ public Ray getRay() @Override public void update() { - if (!this.isRemote && (this.vX != this.lastVX || this.lastVY != this.lastVY)) + if (!this.isRemote && (this.vX != this.lastVX || this.vY != this.lastVY)) Game.eventsOut.add(new EventBulletUpdate(this)); super.update(); diff --git a/src/main/java/tanks/gui/screen/ScreenChangelog.java b/src/main/java/tanks/gui/screen/ScreenChangelog.java index e78de244..d7fdc6d5 100644 --- a/src/main/java/tanks/gui/screen/ScreenChangelog.java +++ b/src/main/java/tanks/gui/screen/ScreenChangelog.java @@ -414,6 +414,13 @@ public static void setupLogs() "*What's new in Tanks v1.4.1a:\n\n" + "Fixed a memory leak with custom tank music\n" }); + + new Changelog("v1.4.1b", new String[] + { + "*What's new in Tanks v1.4.1b:\n\n" + + "Added bandwidth usage to info bar\n" + + "Fixed a bug with spawning tanks in multiplayer\n" + }); } } } diff --git a/src/main/java/tanks/network/ClientHandler.java b/src/main/java/tanks/network/ClientHandler.java index eb125a4d..48dbc31c 100644 --- a/src/main/java/tanks/network/ClientHandler.java +++ b/src/main/java/tanks/network/ClientHandler.java @@ -125,6 +125,8 @@ public synchronized void sendEvent(INetworkEvent e, boolean flush) ByteBuf b2 = ctx.channel().alloc().buffer(); b2.writeInt(b.readableBytes()); + MessageReader.upstreamBytes += b.readableBytes() + 4; + MessageReader.updateLastMessageTime(); b2.writeBytes(b); if (flush) diff --git a/src/main/java/tanks/network/MessageReader.java b/src/main/java/tanks/network/MessageReader.java index c97dbb66..0faaa6b6 100644 --- a/src/main/java/tanks/network/MessageReader.java +++ b/src/main/java/tanks/network/MessageReader.java @@ -13,6 +13,13 @@ public class MessageReader { public static final int max_event_size = 1048576; + public static int downstreamBytes; + public static int upstreamBytes; + public static long lastMessageTime; + + public static int upstreamBytesPerSec; + public static int downstreamBytesPerSec; + public boolean useQueue = true; public ByteBuf queue; protected boolean reading = false; @@ -42,6 +49,8 @@ public synchronized boolean queueMessage(ServerHandler s, ByteBuf m, UUID client if (!reading) { endpoint = queue.readInt(); + downstreamBytes += endpoint + 4; + updateLastMessageTime(); if (endpoint > max_event_size) { @@ -167,4 +176,18 @@ else if (e instanceof IServerThreadEvent) return false; } + + public static void updateLastMessageTime() + { + long time = System.currentTimeMillis() / 1000; + + if (lastMessageTime < time) + { + lastMessageTime = time; + upstreamBytesPerSec = upstreamBytes; + downstreamBytesPerSec = downstreamBytes; + upstreamBytes = 0; + downstreamBytes = 0; + } + } } diff --git a/src/main/java/tanks/network/ServerHandler.java b/src/main/java/tanks/network/ServerHandler.java index f3e5803a..716792c6 100644 --- a/src/main/java/tanks/network/ServerHandler.java +++ b/src/main/java/tanks/network/ServerHandler.java @@ -13,6 +13,7 @@ import tanks.gui.ChatMessage; import tanks.gui.screen.ScreenPartyHost; +import java.util.HashMap; import java.util.UUID; public class ServerHandler extends ChannelInboundHandlerAdapter @@ -82,6 +83,8 @@ public void channelInactive(ChannelHandlerContext ctx) ScreenPartyHost.chat.add(0, new ChatMessage("\u00A7000127255255" + this.username + " has left the party\u00A7000000000255")); } } + + System.out.println(eventFrequencies); } @Override @@ -144,8 +147,13 @@ public synchronized void sendEvent(INetworkEvent e) this.sendEvent(e, true); } + public HashMap eventFrequencies = new HashMap<>(); + public synchronized void sendEvent(INetworkEvent e, boolean flush) { + eventFrequencies.putIfAbsent(e.getClass().getSimpleName(), 0); + eventFrequencies.put(e.getClass().getSimpleName(), eventFrequencies.get(e.getClass().getSimpleName()) + 1); + if (steamID != null) { SteamNetworking.P2PSend sendType = SteamNetworking.P2PSend.ReliableWithBuffering; @@ -168,6 +176,8 @@ public synchronized void sendEvent(INetworkEvent e, boolean flush) ByteBuf b2 = ctx.channel().alloc().buffer(); b2.writeInt(b.readableBytes()); + MessageReader.upstreamBytes += b.readableBytes() + 4; + MessageReader.updateLastMessageTime(); b2.writeBytes(b); if (flush) diff --git a/src/main/java/tanks/tank/TankAIControlled.java b/src/main/java/tanks/tank/TankAIControlled.java index 8fba04b9..34bbcbca 100644 --- a/src/main/java/tanks/tank/TankAIControlled.java +++ b/src/main/java/tanks/tank/TankAIControlled.java @@ -223,6 +223,12 @@ public SpawnedTankEntry(TankAIControlled t, double weight) { this.tank = t; this.weight = weight; + + if (ScreenPartyHost.isServer) + { + Tank.freeIDs.add(t.networkID); + Tank.idMap.remove(t.networkID); + } } public String toString()