Files
MinecraftForge/patches/minecraft/net/minecraft/server/management/ServerConfigurationManager.java.patch
T
Travis Watkins e6bbcf6a3d Load chunks asynchronously for players.
When a player triggers a chunk load via walking around or teleporting
there is no need to stop everything and get this chunk on the main thread.
The client is used to having to wait some time for this chunk and the
server doesn't immediately do anything with it except send it to the
player. At the same time chunk loading is the last major source of file IO
that still runs on the main thread.

These two facts make it possible to offload chunks loaded for this reason
to another thread. However, not all parts of chunk loading can happen off
the main thread. For this we use the new AsynchronousExecutor system to
split chunk loading in to three pieces. The first is loading data from
disk, decompressing it, and parsing it in to an NBT structure.  The second
piece is creating entities and tile entities in the chunk and adding them
to the world, this is still done on the main thread. The third piece is
informing everyone who requested a chunk load that the load is finished.
For this we register callbacks and then run them on the main thread once
the previous two stages are finished.

There are still cases where a chunk is needed immediately and these will
still trigger chunk loading entirely on the main thread. The most obvious
case is plugins using the API to request a chunk load. We also must load
the chunk immediately when something in the world tries to access it. In
these cases we ignore any possibly pending or in progress chunk loading
that is happening asynchronously as we will have the chunk loaded by the
time they are finished.

The hope is that overall this system will result in less CPU time and
pauses due to blocking file IO on the main thread thus giving more
consistent performance. Testing so far has shown that this also speeds up
chunk loading client side although some of this is likely to be because
we are sending less chunks at once for the client to process.

Thanks for ammaraskar for help with the implementation of this feature.

This commit is based off the following :

Bukkit/CraftBukkit@b8fc6ab2c1
Bukkit/CraftBukkit@85f5776df2
Bukkit/CraftBukkit@0714971ca2
Bukkit/CraftBukkit@7f49722f45
Bukkit/CraftBukkit@53ad0cf1ab
2014-06-12 16:51:17 -04:00

175 lines
8.0 KiB
Diff

--- ../src-base/minecraft/net/minecraft/server/management/ServerConfigurationManager.java
+++ ../src-work/minecraft/net/minecraft/server/management/ServerConfigurationManager.java
@@ -7,6 +7,7 @@
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+
import java.io.File;
import java.net.SocketAddress;
import java.text.SimpleDateFormat;
@@ -18,6 +19,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
+
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
@@ -54,11 +56,15 @@
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.MathHelper;
+import net.minecraft.world.Teleporter;
import net.minecraft.world.World;
+import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.demo.DemoWorldManager;
import net.minecraft.world.storage.IPlayerFileData;
+import net.minecraftforge.common.chunkio.ChunkIOExecutor;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -244,6 +250,7 @@
this.func_148540_a(new S38PacketPlayerListItem(p_72377_1_.func_70005_c_(), true, 1000));
this.field_72404_b.add(p_72377_1_);
WorldServer worldserver = this.field_72400_f.func_71218_a(p_72377_1_.field_71093_bK);
+ ChunkIOExecutor.adjustPoolSize(this.func_72394_k());
worldserver.func_72838_d(p_72377_1_);
this.func_72375_a(p_72377_1_, (WorldServer)null);
@@ -276,6 +283,7 @@
worldserver.func_73040_p().func_72695_c(p_72367_1_);
this.field_72404_b.remove(p_72367_1_);
this.field_148547_k.remove(p_72367_1_.func_70005_c_());
+ ChunkIOExecutor.adjustPoolSize(this.func_72394_k());
this.func_148540_a(new S38PacketPlayerListItem(p_72367_1_.func_70005_c_(), false, 9999));
}
@@ -361,13 +369,23 @@
public EntityPlayerMP func_72368_a(EntityPlayerMP p_72368_1_, int p_72368_2_, boolean p_72368_3_)
{
+ World world = field_72400_f.func_71218_a(p_72368_2_);
+ if (world == null)
+ {
+ p_72368_2_ = 0;
+ }
+ else if (!world.field_73011_w.func_76567_e())
+ {
+ p_72368_2_ = world.field_73011_w.getRespawnDimension(p_72368_1_);
+ }
+
p_72368_1_.func_71121_q().func_73039_n().func_72787_a(p_72368_1_);
p_72368_1_.func_71121_q().func_73039_n().func_72790_b(p_72368_1_);
p_72368_1_.func_71121_q().func_73040_p().func_72695_c(p_72368_1_);
this.field_72404_b.remove(p_72368_1_);
this.field_72400_f.func_71218_a(p_72368_1_.field_71093_bK).func_72973_f(p_72368_1_);
- ChunkCoordinates chunkcoordinates = p_72368_1_.func_70997_bJ();
- boolean flag1 = p_72368_1_.func_82245_bX();
+ ChunkCoordinates chunkcoordinates = p_72368_1_.getBedLocation(p_72368_2_);
+ boolean flag1 = p_72368_1_.isSpawnForced(p_72368_2_);
p_72368_1_.field_71093_bK = p_72368_2_;
Object object;
@@ -383,6 +401,7 @@
EntityPlayerMP entityplayermp1 = new EntityPlayerMP(this.field_72400_f, this.field_72400_f.func_71218_a(p_72368_1_.field_71093_bK), p_72368_1_.func_146103_bH(), (ItemInWorldManager)object);
entityplayermp1.field_71135_a = p_72368_1_.field_71135_a;
entityplayermp1.func_71049_a(p_72368_1_, p_72368_3_);
+ entityplayermp1.field_71093_bK = p_72368_2_;
entityplayermp1.func_145769_d(p_72368_1_.func_145782_y());
WorldServer worldserver = this.field_72400_f.func_71218_a(p_72368_1_.field_71093_bK);
this.func_72381_a(entityplayermp1, p_72368_1_, worldserver);
@@ -427,6 +446,11 @@
public void func_72356_a(EntityPlayerMP p_72356_1_, int p_72356_2_)
{
+ transferPlayerToDimension(p_72356_1_, p_72356_2_, field_72400_f.func_71218_a(p_72356_2_).func_85176_s());
+ }
+
+ public void transferPlayerToDimension(EntityPlayerMP p_72356_1_, int p_72356_2_, Teleporter teleporter)
+ {
int j = p_72356_1_.field_71093_bK;
WorldServer worldserver = this.field_72400_f.func_71218_a(p_72356_1_.field_71093_bK);
p_72356_1_.field_71093_bK = p_72356_2_;
@@ -434,7 +458,7 @@
p_72356_1_.field_71135_a.func_147359_a(new S07PacketRespawn(p_72356_1_.field_71093_bK, p_72356_1_.field_70170_p.field_73013_u, p_72356_1_.field_70170_p.func_72912_H().func_76067_t(), p_72356_1_.field_71134_c.func_73081_b()));
worldserver.func_72973_f(p_72356_1_);
p_72356_1_.field_70128_L = false;
- this.func_82448_a(p_72356_1_, j, worldserver, worldserver1);
+ this.transferEntityToWorld(p_72356_1_, j, worldserver, worldserver1, teleporter);
this.func_72375_a(p_72356_1_, worldserver);
p_72356_1_.field_71135_a.func_147364_a(p_72356_1_.field_70165_t, p_72356_1_.field_70163_u, p_72356_1_.field_70161_v, p_72356_1_.field_70177_z, p_72356_1_.field_70125_A);
p_72356_1_.field_71134_c.func_73080_a(worldserver1);
@@ -452,38 +476,47 @@
public void func_82448_a(Entity p_82448_1_, int p_82448_2_, WorldServer p_82448_3_, WorldServer p_82448_4_)
{
- double d0 = p_82448_1_.field_70165_t;
- double d1 = p_82448_1_.field_70161_v;
- double d2 = 8.0D;
+ transferEntityToWorld(p_82448_1_, p_82448_2_, p_82448_3_, p_82448_4_, p_82448_4_.func_85176_s());
+ }
+
+ public void transferEntityToWorld(Entity p_82448_1_, int p_82448_2_, WorldServer p_82448_3_, WorldServer p_82448_4_, Teleporter teleporter)
+ {
+ WorldProvider pOld = p_82448_3_.field_73011_w;
+ WorldProvider pNew = p_82448_4_.field_73011_w;
+ double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor();
+ double d0 = p_82448_1_.field_70165_t * moveFactor;
+ double d1 = p_82448_1_.field_70161_v * moveFactor;
double d3 = p_82448_1_.field_70165_t;
double d4 = p_82448_1_.field_70163_u;
double d5 = p_82448_1_.field_70161_v;
float f = p_82448_1_.field_70177_z;
p_82448_3_.field_72984_F.func_76320_a("moving");
- if (p_82448_1_.field_71093_bK == -1)
+ /*
+ if (par1Entity.dimension == -1)
{
d0 /= d2;
d1 /= d2;
- p_82448_1_.func_70012_b(d0, p_82448_1_.field_70163_u, d1, p_82448_1_.field_70177_z, p_82448_1_.field_70125_A);
+ par1Entity.setLocationAndAngles(d0, par1Entity.posY, d1, par1Entity.rotationYaw, par1Entity.rotationPitch);
- if (p_82448_1_.func_70089_S())
+ if (par1Entity.isEntityAlive())
{
- p_82448_3_.func_72866_a(p_82448_1_, false);
+ par3WorldServer.updateEntityWithOptionalForce(par1Entity, false);
}
}
- else if (p_82448_1_.field_71093_bK == 0)
+ else if (par1Entity.dimension == 0)
{
d0 *= d2;
d1 *= d2;
- p_82448_1_.func_70012_b(d0, p_82448_1_.field_70163_u, d1, p_82448_1_.field_70177_z, p_82448_1_.field_70125_A);
+ par1Entity.setLocationAndAngles(d0, par1Entity.posY, d1, par1Entity.rotationYaw, par1Entity.rotationPitch);
- if (p_82448_1_.func_70089_S())
+ if (par1Entity.isEntityAlive())
{
- p_82448_3_.func_72866_a(p_82448_1_, false);
+ par3WorldServer.updateEntityWithOptionalForce(par1Entity, false);
}
}
- else
+ */
+ if (p_82448_1_.field_71093_bK == 1)
{
ChunkCoordinates chunkcoordinates;
@@ -518,7 +551,7 @@
if (p_82448_1_.func_70089_S())
{
p_82448_1_.func_70012_b(d0, p_82448_1_.field_70163_u, d1, p_82448_1_.field_70177_z, p_82448_1_.field_70125_A);
- p_82448_4_.func_85176_s().func_77185_a(p_82448_1_, d3, d4, d5, f);
+ teleporter.func_77185_a(p_82448_1_, d3, d4, d5, f);
p_82448_4_.func_72838_d(p_82448_1_);
p_82448_4_.func_72866_a(p_82448_1_, false);
}