1
0
Fork 0
This commit is contained in:
Sen 2025-07-12 16:48:23 +02:00
parent c126bdd8b0
commit 318a8885ba
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
53 changed files with 990 additions and 5887 deletions

View file

@ -23,10 +23,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.function.Function;
import javax.imageio.ImageIO;
@ -120,10 +116,6 @@ import common.entity.npc.EntityNPC;
import common.entity.npc.EntityWaterNPC;
import common.entity.npc.PlayerCharacter;
import common.entity.types.EntityLiving;
import common.future.Futures;
import common.future.ListenableFuture;
import common.future.ListenableFutureTask;
import common.future.ThreadFactoryBuilder;
import common.init.BlockRegistry;
import common.init.Blocks;
import common.init.EntityRegistry;
@ -171,7 +163,6 @@ import common.util.CharValidator;
import common.util.ExtMath;
import common.util.Facing;
import common.util.HitPosition;
import common.util.LazyLoader;
import common.util.Util;
import common.util.Var;
import common.util.HitPosition.ObjectType;
@ -281,15 +272,11 @@ public class Client implements IThreadListener {
public static final int LOG_BUFFER = 32768;
public static final int MIN_WIDTH = 800;
public static final int MIN_HEIGHT = 450;
private static final LazyLoader<NioEventLoopGroup> CLIENT_NIO_EVENTLOOP = new LazyLoader<NioEventLoopGroup>() {
protected NioEventLoopGroup load() {
return new NioEventLoopGroup(0, new ThreadFactoryBuilder().setNameFormat("Netty Client IO #%d").setDaemon(true).build());
}
};
private final Queue<FutureTask<?>> tasks = new ArrayDeque<FutureTask<?>>();
private final Thread thread = Thread.currentThread();
private final NioEventLoopGroup eventGroup = new NioEventLoopGroup(0, Util.getThreadFactory("Netty Client IO"));
private final Queue<Runnable> tasks = new ArrayDeque<Runnable>();
private final Map<Integer, Long> bars = Maps.newTreeMap();
private final Thread clThread = Thread.currentThread();
private final Map<String, CVar> cvars = Maps.newTreeMap();
private final Map<String, Field> synced = Maps.newTreeMap();
private final Map<Keysym, DebugFunction> debug = Maps.newTreeMap();
@ -537,7 +524,7 @@ public class Client implements IThreadListener {
private NetConnection connect(InetAddress address, int port) {
final NetConnection connection = new NetConnection();
new Bootstrap().group(CLIENT_NIO_EVENTLOOP.getValue()).handler(new ChannelInitializer<Channel>() {
new Bootstrap().group(this.eventGroup).handler(new ChannelInitializer<Channel>() {
protected void initChannel(Channel channel) throws Exception {
try {
channel.config().setOption(ChannelOption.TCP_NODELAY, true);
@ -708,17 +695,13 @@ public class Client implements IThreadListener {
{
while (!this.tasks.isEmpty())
{
FutureTask<?> task = this.tasks.poll();
Runnable task = this.tasks.poll();
try {
task.run();
task.get();
}
catch(ExecutionException e1) {
if(!(e1.getCause() instanceof ThreadQuickExitException))
Log.SYSTEM.error(e1, "Fehler beim Ausführen von Render-Task " + task);
}
catch(InterruptedException e2) {
Log.SYSTEM.error(e2, "Fehler beim Ausführen von Render-Task " + task);
catch(Throwable e) {
if(!(e instanceof ThreadQuickExitException))
Log.SYSTEM.error(e, "Fehler beim Ausführen von Render-Task " + task);
}
}
}
@ -1605,40 +1588,25 @@ public class Client implements IThreadListener {
this.viewEntity = viewingEntity;
}
private <V> ListenableFuture<V> addScheduledTask(Callable<V> callableToSchedule)
{
if (!this.isMainThread())
{
ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callableToSchedule);
synchronized (this.tasks)
{
this.tasks.add(listenablefuturetask);
return listenablefuturetask;
}
}
else
{
try
{
return Futures.<V>immediateFuture(callableToSchedule.call());
}
catch (Exception exception)
{
Log.SYSTEM.error(exception, "Fehler beim sofortigen Ausführen von Render-Task " + callableToSchedule);
return Futures.immediateFailedFuture(exception);
}
}
}
public ListenableFuture<Object> schedule(Runnable runnableToSchedule)
{
return this.<Object>addScheduledTask(Executors.callable(runnableToSchedule));
}
public void schedule(Runnable task) {
if(!this.isMainThread()) {
synchronized(this.tasks) {
this.tasks.add(task);
}
}
else {
try {
task.run();
}
catch(Throwable e) {
Log.SYSTEM.error(e, "Fehler beim sofortigen Ausführen von Render-Task " + task);
}
}
}
public boolean isMainThread()
{
return Thread.currentThread() == this.clThread;
return Thread.currentThread() == this.thread;
}
public BlockRenderer getBlockRendererDispatcher()