Resize worlds
This commit is contained in:
@@ -57,7 +57,7 @@ public abstract class Akari {
|
|||||||
/**
|
/**
|
||||||
* A common tick pool
|
* A common tick pool
|
||||||
*/
|
*/
|
||||||
public static final ExecutorCompletionService<?> STAGE_TICK = new ExecutorCompletionService<>(Executors.newFixedThreadPool(4, new AssignableFactory()));
|
public static ExecutorCompletionService<?> STAGE_TICK;
|
||||||
|
|
||||||
public static boolean isPrimaryThread() {
|
public static boolean isPrimaryThread() {
|
||||||
return isPrimaryThread(true);
|
return isPrimaryThread(true);
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import net.minecraft.server.WorldServer;
|
|||||||
@Mixin(value = MinecraftServer.class, remap = false)
|
@Mixin(value = MinecraftServer.class, remap = false)
|
||||||
public abstract class MixinMinecraftServer {
|
public abstract class MixinMinecraftServer {
|
||||||
@Shadow @Final public Thread primaryThread;
|
@Shadow @Final public Thread primaryThread;
|
||||||
|
private int cachedWorlds;
|
||||||
|
|
||||||
@Overwrite
|
@Overwrite
|
||||||
public String getServerModName() {
|
public String getServerModName() {
|
||||||
@@ -53,6 +54,8 @@ public abstract class MixinMinecraftServer {
|
|||||||
shift = At.Shift.BEFORE
|
shift = At.Shift.BEFORE
|
||||||
))
|
))
|
||||||
private void prerun(CallbackInfo info) {
|
private void prerun(CallbackInfo info) {
|
||||||
|
Akari.STAGE_TICK = new ExecutorCompletionService<>(Executors.newFixedThreadPool((cachedWorlds = worlds.size()), new AssignableFactory()));
|
||||||
|
|
||||||
primaryThread.setPriority(AkarinGlobalConfig.primaryThreadPriority < Thread.NORM_PRIORITY ? Thread.NORM_PRIORITY :
|
primaryThread.setPriority(AkarinGlobalConfig.primaryThreadPriority < Thread.NORM_PRIORITY ? Thread.NORM_PRIORITY :
|
||||||
(AkarinGlobalConfig.primaryThreadPriority > Thread.MAX_PRIORITY ? 10 : AkarinGlobalConfig.primaryThreadPriority));
|
(AkarinGlobalConfig.primaryThreadPriority > Thread.MAX_PRIORITY ? 10 : AkarinGlobalConfig.primaryThreadPriority));
|
||||||
|
|
||||||
@@ -178,6 +181,8 @@ public abstract class MixinMinecraftServer {
|
|||||||
|
|
||||||
@Overwrite
|
@Overwrite
|
||||||
public void D() throws InterruptedException {
|
public void D() throws InterruptedException {
|
||||||
|
if (worlds.size() != cachedWorlds) Akari.STAGE_TICK = new ExecutorCompletionService<>(Executors.newFixedThreadPool(cachedWorlds, new AssignableFactory())); // Resize
|
||||||
|
|
||||||
Runnable runnable;
|
Runnable runnable;
|
||||||
MinecraftTimings.bukkitSchedulerTimer.startTiming();
|
MinecraftTimings.bukkitSchedulerTimer.startTiming();
|
||||||
this.server.getScheduler().mainThreadHeartbeat(this.ticks);
|
this.server.getScheduler().mainThreadHeartbeat(this.ticks);
|
||||||
@@ -210,7 +215,7 @@ public abstract class MixinMinecraftServer {
|
|||||||
|
|
||||||
// Never tick one world concurrently!
|
// Never tick one world concurrently!
|
||||||
for (int i = 0; i < worlds.size(); i++) {
|
for (int i = 0; i < worlds.size(); i++) {
|
||||||
int interlace = i + 1;
|
int interlace = i + 1;
|
||||||
WorldServer entitiesWorld = worlds.get(interlace < worlds.size() ? interlace : 0);
|
WorldServer entitiesWorld = worlds.get(interlace < worlds.size() ? interlace : 0);
|
||||||
Akari.STAGE_TICK.submit(() -> {
|
Akari.STAGE_TICK.submit(() -> {
|
||||||
synchronized (((IMixinLockProvider) entitiesWorld).lock()) {
|
synchronized (((IMixinLockProvider) entitiesWorld).lock()) {
|
||||||
@@ -220,14 +225,14 @@ public abstract class MixinMinecraftServer {
|
|||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
WorldServer world = worlds.get(i);
|
WorldServer world = worlds.get(i);
|
||||||
synchronized (((IMixinLockProvider) world).lock()) {
|
synchronized (((IMixinLockProvider) world).lock()) {
|
||||||
tickWorld(world);
|
tickWorld(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Akari.entityCallbackTiming.startTiming();
|
Akari.entityCallbackTiming.startTiming();
|
||||||
for (int i = worlds.size(); i --> 0 ;) Akari.STAGE_TICK.take();
|
for (int i = worlds.size(); i --> 0 ;) Akari.STAGE_TICK.take();
|
||||||
Akari.entityCallbackTiming.stopTiming();
|
Akari.entityCallbackTiming.stopTiming();
|
||||||
|
|
||||||
Akari.worldTiming.stopTiming();
|
Akari.worldTiming.stopTiming();
|
||||||
|
|||||||
Reference in New Issue
Block a user