Merged in better multithreading
This commit is contained in:
@@ -9,8 +9,6 @@ import io.anuke.ucore.util.Pooling;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.net.Net.packetPoolLock;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ByteSerializer implements Serialization {
|
||||
|
||||
@@ -36,11 +34,9 @@ public class ByteSerializer implements Serialization {
|
||||
if(id == -2){
|
||||
return FrameworkSerializer.read(byteBuffer);
|
||||
}else{
|
||||
synchronized (packetPoolLock) {
|
||||
Packet packet = Pooling.obtain((Class<Packet>) Registrator.getByID(id).type, (Supplier<Packet>) Registrator.getByID(id).constructor);
|
||||
packet.read(byteBuffer);
|
||||
return packet;
|
||||
}
|
||||
Packet packet = Pooling.obtain((Class<Packet>) Registrator.getByID(id).type, (Supplier<Packet>) Registrator.getByID(id).constructor);
|
||||
packet.read(byteBuffer);
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,27 @@
|
||||
package io.anuke.kryonet;
|
||||
|
||||
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
|
||||
import io.anuke.ucore.util.Threads;
|
||||
import io.anuke.ucore.util.Threads.ThreadInfoProvider;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
public class DefaultThreadImpl implements ThreadProvider {
|
||||
public class DefaultThreadImpl implements ThreadProvider, ThreadInfoProvider{
|
||||
private Thread thread;
|
||||
|
||||
public DefaultThreadImpl(){
|
||||
Threads.setThreadInfoProvider(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnLogicThread(){
|
||||
return thread == null || isOnThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnGraphicsThread(){
|
||||
return thread == null || !isOnThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnThread() {
|
||||
return Thread.currentThread() == thread;
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedSelectorException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.net.Net.packetPoolLock;
|
||||
|
||||
public class KryoClient implements ClientProvider{
|
||||
Client client;
|
||||
@@ -159,9 +158,7 @@ public class KryoClient implements ClientProvider{
|
||||
client.sendUDP(object);
|
||||
}
|
||||
|
||||
synchronized (packetPoolLock) {
|
||||
Pooling.free(object);
|
||||
}
|
||||
Pooling.free(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user