Added freebuild / Power system fix / Net packet pool fix / Crash fixes
This commit is contained in:
@@ -26,9 +26,6 @@ public class ByteSerializer implements Serialization {
|
||||
throw new RuntimeException("Unregistered class: " + ClassReflection.getSimpleName(o.getClass()));
|
||||
byteBuffer.put(id);
|
||||
((Packet) o).write(byteBuffer);
|
||||
synchronized (packetPoolLock) {
|
||||
Pooling.free(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.anuke.mindustry.net.NetworkIO;
|
||||
import io.anuke.mindustry.net.Packets.Connect;
|
||||
import io.anuke.mindustry.net.Packets.Disconnect;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.util.Pooling;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -26,6 +27,7 @@ import java.nio.channels.ClosedSelectorException;
|
||||
import java.util.List;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.net.Net.packetPoolLock;
|
||||
|
||||
public class KryoClient implements ClientProvider{
|
||||
Client client;
|
||||
@@ -134,6 +136,10 @@ public class KryoClient implements ClientProvider{
|
||||
}else{
|
||||
client.sendUDP(object);
|
||||
}
|
||||
|
||||
synchronized (packetPoolLock) {
|
||||
Pooling.free(object);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,9 +6,7 @@ import io.anuke.ucore.util.ColorCodes;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.headless;
|
||||
|
||||
@@ -65,25 +63,4 @@ public class KryoCore {
|
||||
private static int calculateLag() {
|
||||
return fakeLagMin + (int)(Math.random() * (fakeLagMax - fakeLagMin));
|
||||
}
|
||||
|
||||
/**Executes something in a potentially unreliable way. Used to simulate lag and packet errors with UDP.*/
|
||||
public static void recieveUnreliable(Runnable run){
|
||||
if(fakeLag && threadPool == null){
|
||||
threadPool = Executors.newScheduledThreadPool(1, r -> {
|
||||
Thread t = Executors.defaultThreadFactory().newThread(r);
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
}
|
||||
|
||||
if(fakeLag){
|
||||
do {
|
||||
if (Math.random() >= fakeLagDrop) {
|
||||
threadPool.schedule(run, calculateLag(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
} while (Math.random() < fakeLagDuplicate);
|
||||
}else{
|
||||
run.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,7 @@ import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Net.ServerProvider;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.net.NetworkIO;
|
||||
import io.anuke.mindustry.net.Packets.Connect;
|
||||
import io.anuke.mindustry.net.Packets.Disconnect;
|
||||
import io.anuke.mindustry.net.Packets.StreamBegin;
|
||||
import io.anuke.mindustry.net.Packets.StreamChunk;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.net.Streamable;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
Reference in New Issue
Block a user