Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7e13d4c
refactor: create NetworkHandler for shared properties
orangishcat Aug 12, 2025
1a24258
feat: network optimizations, reflection handlers
orangishcat Sep 5, 2025
dc4832d
fix: network event fixes
orangishcat Sep 8, 2025
fb7aec3
perf: use shorts for colors
orangishcat Sep 8, 2025
f45056b
fix(network): network-related bug fixes
orangishcat Sep 9, 2025
7057b13
fix(EventTankUpdateHealth): shield fix
orangishcat Sep 10, 2025
5584102
style: minor code style changes
orangishcat Sep 10, 2025
817e29f
fix: shoot bullet event
orangishcat Sep 10, 2025
6c39fa7
fix: remove stacked group event
orangishcat Sep 10, 2025
c60e604
feat: more network validation checks
orangishcat Sep 10, 2025
ddda007
fix: interpolation bug
orangishcat Sep 10, 2025
096f35e
fix: more interpolation bugs
orangishcat Sep 10, 2025
c1082d4
fix: explosion bug
orangishcat Sep 11, 2025
8073cbc
fix: partial angle interpolation fix
orangishcat Sep 11, 2025
db1605a
fix: duplicate obstacle destroy events from explosion
orangishcat Sep 12, 2025
60b3738
refactor: extract duplicate code
orangishcat Sep 14, 2025
cf18fbb
fix: preserve order by batching all events
orangishcat Sep 14, 2025
8fc13e4
fix,style: make more events stackable, optimize imports
orangishcat Sep 14, 2025
f92fab3
perf: make instant waypoint events stackable
orangishcat Sep 14, 2025
d4a8853
perf: optimize network load of 0 cooldown items
orangishcat Sep 14, 2025
b8b0483
fix: change debug option back to false
orangishcat Sep 14, 2025
455f8c5
fix: stack bullet events only for zero cooldown shots
orangishcat Sep 14, 2025
0d47c5c
fix: continuous shooting only for low cooldown bullets,
orangishcat Sep 14, 2025
a8dfed6
fix: set event data debug to false
orangishcat Sep 14, 2025
3ff9442
perf: use int for quick actions encoding
orangishcat Sep 15, 2025
c91254a
Merge branch 'remote-master' into network-optimization-cleaned
orangishcat Nov 8, 2025
6db2cf0
chore: update branch
orangishcat Nov 8, 2025
b5f74cf
fix: event lay mine
orangishcat Nov 8, 2025
0b6a164
fix: sounds not playing on client side
orangishcat Dec 1, 2025
d96c4cf
fix: add sounds back, fix tank health inconsistency
orangishcat Dec 2, 2025
8d98c11
Merge branch 'remote-master' into network-optimization-cleaned
orangishcat Dec 2, 2025
058a962
chore: update branch
orangishcat Dec 2, 2025
188b8d4
Merge branch 'remote-master' into network-optimization-cleaned
orangishcat Dec 4, 2025
f7c9d1d
chore: update branch, fix build errors
orangishcat Dec 4, 2025
b4d0125
Merge branch 'remote-master' into network-optimization-cleaned
orangishcat Dec 7, 2025
abf94bf
Merge branch 'remote-master' into network-optimization-cleaned
orangishcat Mar 29, 2026
15c9203
chore: merge branch
orangishcat Mar 29, 2026
ef69f2b
chore: delete all the read and write methods
orangishcat Mar 29, 2026
207d90e
fix: delete unused methods, add comment
orangishcat Apr 1, 2026
bee413b
fix: explosion radius, move ReflectionHandle.java
orangishcat Apr 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/tanks/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public int hashCode()
public static boolean drawFaces = false;
public static boolean drawAvoidObjects = false;
public static boolean recordMovableData = false;
public static boolean recordEventData = false;
public static final boolean cinematic = false;

public static long steamLobbyInvite = -1;
Expand All @@ -159,7 +160,7 @@ public int hashCode()

public static boolean vsync = true;
public static int maxFPS = 0;
public static int networkRate = 60;
public static int networkRate = 20;
Comment thread
ghostlypi marked this conversation as resolved.

public static boolean enable3d = true;
public static boolean enable3dBg = true;
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/tanks/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import basewindow.InputCodes;
import tanks.extension.Extension;
import tanks.gui.*;
import tanks.gui.ScreenElement.CenterMessage;
import tanks.gui.ScreenElement.Notification;
import tanks.gui.ScreenElement.*;
import tanks.gui.screen.*;
import tanks.gui.screen.leveleditor.ScreenLevelEditor;
import tanks.gui.screen.leveleditor.ScreenLevelEditorOverlay;
import tanks.gui.screen.leveleditor.*;
import tanks.item.Item;
import tanks.network.*;
import tanks.network.event.*;
Expand All @@ -16,8 +14,7 @@
import tanks.rendering.*;
import tanks.tank.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.*;

public class Panel
{
Expand Down Expand Up @@ -911,6 +908,15 @@ public void draw()
this.drawBar();
}

if (Game.recordEventData && (ScreenPartyHost.isServer || ScreenPartyLobby.isClient))
{
Drawing.drawing.setColor(255, 255, 255);
Drawing.drawing.setInterfaceFontSize(16);
double y = Drawing.drawing.getInterfaceEdgeY(true) - 20;
for (String s : MessageReader.eventBytesPerSecText)
Drawing.drawing.drawUncenteredInterfaceText(10, y -= 20, s);
}

if (!notifications.isEmpty())
{
double sy = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tanks/bullet/BulletReboundIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public BulletReboundIndicator(Bullet b)
Game.eventsOut.add(new EventBulletReboundIndicator(this));
}

public BulletReboundIndicator(double posX, double posY, double posZ, double size, double maxAge, double r1, double g1, double b1, double r2, double g2, double b2)
public BulletReboundIndicator(double posX, double posY, double posZ, double size, double maxAge, Color color, Color color2)
{
super(posX, posY);
this.posZ = posZ;
this.size = size;
this.color.set(r1, g1, b1);
this.color2.set(r2, g2, b2);
this.color = color;
this.color2 = color2;
this.maxAge = maxAge;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/tanks/gui/screen/ScreenDebug.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public class ScreenDebug extends Screen
Button drawAvoidObjects = createToggle("Draw avoid objects: ", b -> Game.drawAvoidObjects = b, () -> Game.drawAvoidObjects);
Button disableFixes = createToggle("Disable fixes: ", b -> Game.disableErrorFixing = b, () -> Game.disableErrorFixing);
Button recordMovableData = createToggle("Record movable data: ", b -> Game.recordMovableData = b, () -> Game.recordMovableData);
Button recordEventData = createToggle("Record event data: ", b -> Game.recordEventData = b, () -> Game.recordEventData);

Button back = new Button(Drawing.drawing.interfaceSizeX / 2, Drawing.drawing.interfaceSizeY / 2 + this.objYSpace * 5, this.objWidth, this.objHeight, "Back", () -> Game.screen = new ScreenTitle());

public ButtonList debugButtons = new ButtonList(new ArrayList<>(Arrays.asList(
test, traceAllRays, firstPerson, followingCam, destroyCheat, invulnerable,
fancyLighting, tankIDs, showPathfinding, drawFaces, showUpdatingObstacles,
drawAutoZoom, immutableFaces, drawAvoidObjects, disableFixes, recordMovableData
drawAutoZoom, immutableFaces, drawAvoidObjects, disableFixes, recordMovableData, recordEventData
)), 0, 0, -30);

public Button createToggle(String text, Consumer<Boolean> setter, Producer<Boolean> getter)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tanks/gui/screen/ScreenGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@ public void draw()
}
}

if (Crusade.crusadeMode)
if (Crusade.crusadeMode && Crusade.currentCrusade != null /* lag */)
{
if (Level.isDark())
Drawing.drawing.setColor(255, 255, 255, 127);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/tanks/network/ClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ public synchronized void sendEvent(INetworkEvent e, boolean flush)
e.write(b);

ByteBuf b2 = ctx.channel().alloc().buffer();
b2.writeInt(b.readableBytes());
MessageReader.upstreamBytes += b.readableBytes() + 4;
int rb = b.readableBytes();
b2.writeInt(rb);
MessageReader.upstreamBytes += rb + 4;
MessageReader.eventBytes.put(i, MessageReader.eventBytes.getOrDefault(i, 0) + rb + 4);
MessageReader.updateLastMessageTime();
b2.writeBytes(b);

Expand Down
19 changes: 13 additions & 6 deletions src/main/java/tanks/network/MessageReader.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package tanks.network;

import io.netty.buffer.ByteBuf;
import tanks.Game;
import tanks.gui.screen.ScreenPartyHost;
import tanks.gui.screen.ScreenPartyLobby;
import tanks.gui.screen.*;
import tanks.network.event.*;
import tanks.network.event.online.IOnlineServerEvent;
import tanks.translation.Translation;

import io.netty.buffer.ByteBuf;

import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;

public class MessageReader
{
Expand All @@ -18,8 +18,11 @@ public class MessageReader
public static int upstreamBytes;
public static long lastMessageTime;

public static HashMap<Integer, Integer> eventBytes = new HashMap<>();

public static int upstreamBytesPerSec;
public static int downstreamBytesPerSec;
public static List<String> eventBytesPerSecText = new ArrayList<>();

public boolean useQueue = true;
public ByteBuf queue;
Expand All @@ -33,7 +36,6 @@ public void queueMessage(ClientHandler c, ByteBuf m, UUID clientID)
this.queueMessage(null, c, m, clientID);
}


public void queueMessage(ServerHandler s, ByteBuf m, UUID clientID)
{
this.queueMessage(s, null, m, clientID);
Expand Down Expand Up @@ -215,6 +217,11 @@ public static void updateLastMessageTime()
lastMessageTime = time;
upstreamBytesPerSec = upstreamBytes;
downstreamBytesPerSec = downstreamBytes;
eventBytesPerSecText = eventBytes.entrySet().stream()
.sorted(Comparator.comparingInt(Map.Entry::getValue))
.map(entry -> Translation.translate("%s: %.2f KB/s", NetworkEventMap.get(entry.getKey()).getSimpleName(), entry.getValue() / 1024.))
.collect(Collectors.toList());
eventBytes.clear();
upstreamBytes = 0;
downstreamBytes = 0;
}
Expand Down
36 changes: 32 additions & 4 deletions src/main/java/tanks/network/NetworkEventMap.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tanks.network;

import io.netty.buffer.*;
import tanks.Game;
import tanks.network.event.INetworkEvent;

Expand All @@ -13,18 +14,45 @@ public class NetworkEventMap

public static void register(Class<? extends INetworkEvent> c)
{
map1.put(id, c);
map2.put(c, id);
id++;

if (!Game.debug)
return;

try
{
c.getConstructor();
}
catch (Exception e)
{
Game.exitToCrash(new RuntimeException("The network event " + c + " does not have a no-parameter constructor. Please give it one."));
Game.exitToCrash(new RuntimeException("The network event " + c + " does not have a no-parameter" +
" constructor. Please give it one."));
}

map1.put(id, c);
map2.put(c, id);
id++;
ByteBuf b = Unpooled.buffer();
INetworkEvent e;
try
{
e = c.getConstructor().newInstance();
e.write(b);
e.read(b);
if (b.readableBytes() > 0)
throw new IndexOutOfBoundsException("Readable bytes > 0 after read");
}
catch (ReflectionHandle.MissingHandleException exc)
{
throw new RuntimeException("Missing handle in " + c.getSimpleName() + ": " + exc.getMessage());
}
catch (IndexOutOfBoundsException exc)
{
throw new RuntimeException("Read does not match write in " + c.getSimpleName() + ": " + exc.getMessage());
}
catch (Exception ignored)
{

}
}

public static int get(Class<? extends INetworkEvent> c)
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/tanks/network/NetworkUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package tanks.network;

import basewindow.Color;

import io.netty.buffer.ByteBuf;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.*;

public class NetworkUtils
{
Expand Down
Loading
Loading