Move spriting water particle to off thread

This commit is contained in:
Sotr
2019-03-22 05:10:45 +08:00
parent f8efc6d057
commit c3f70996fe
4 changed files with 23 additions and 10 deletions

View File

@@ -1,13 +1,13 @@
package io.akarin.server.core;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.server.MinecraftServer;
public class AkarinAsyncExecutor extends Thread {
private final static Logger LOGGER = LogManager.getLogger("Akarin");
private final static Logger LOGGER = LogManager.getLogger("Akarin");
private final static int STD_TICK_TIME = 20;
public static AkarinAsyncExecutor initalise() {
return Singleton.instance;
@@ -30,10 +30,15 @@ public class AkarinAsyncExecutor extends Thread {
MinecraftServer server = MinecraftServer.getServer();
while (server.isRunning()) {
server.getWorlds().forEach(world -> world.entityList.forEach(entity -> {
if (!entity.dead && entity.spirtingWaterParticle) {
entity.populateSprintingWaterParticles();
entity.spirtingWaterParticle = false;
}
}));
try {
Thread.sleep(100);
Thread.sleep(STD_TICK_TIME);
} catch (InterruptedException interrupted) {
continue;
}

View File

@@ -188,7 +188,10 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
public boolean fromMobSpawner;
public boolean spawnedViaMobSpawner; // Paper - Yes this name is similar to above, upstream took the better one
protected int numCollisions = 0; // Paper
public boolean joinedWorld; // Akarin
// Akarin start
public boolean enderTeleport;
public boolean spirtingWaterParticle;
// Akarin end
public void inactiveTick() { }
// Spigot end
@@ -460,7 +463,10 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
*/
this.av();
// Akarin start - async executor
//this.av();
this.spirtingWaterParticle = true;
// Akarin end
this.r();
if (this.world.isClientSide) {
this.extinguish();
@@ -1279,6 +1285,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
public void populateSprintingWaterParticles() { this.av(); } // Akarin - OBFHELPER
public void av() {
if (this.isSprinting() && !this.isInWater()) {
this.aw();
@@ -2806,9 +2813,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
public void enderTeleportTo(double d0, double d1, double d2) {
this.enderTeleport = true; // Akarin
this.aK = true;
this.setPositionRotation(d0, d1, d2, this.yaw, this.pitch);
this.world.entityJoinedWorld(this, false);
this.enderTeleport = false; // Akarin
}
public void a(DataWatcherObject<?> datawatcherobject) {}

View File

@@ -1210,7 +1210,7 @@ public abstract class EntityLiving extends Entity {
}
public void die(DamageSource damagesource) {
if (!this.killed && !this.joinedWorld) { // Akarin
if (!this.killed && !this.enderTeleport) { // Akarin
Entity entity = damagesource.getEntity();
EntityLiving entityliving = this.cv();

View File

@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -192,7 +193,7 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
this.ticksPerMonsterSpawns = this.getServer().getTicksPerMonsterSpawns(); // CraftBukkit
// CraftBukkit end
this.v = Lists.newArrayList(new IWorldAccess[] { this.u});
this.v = new CopyOnWriteArrayList<IWorldAccess>(new IWorldAccess[] { this.u}); // Akarin - ArrayList -> CopyOnWriteArrayList
this.allowMonsters = true;
this.allowAnimals = true;
this.E = new int['\u8000'];
@@ -1554,7 +1555,6 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
return;
}
// CraftBukkit end
entity.joinedWorld = true; // Akarin
entity.N = entity.locX;
entity.O = entity.locY;
@@ -1629,7 +1629,6 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
}
}
}
entity.joinedWorld = false; // Akarin
}
// Paper start - Based on method below