Remove Spigot timings

This commit is contained in:
Aikar
2016-03-03 04:00:11 -06:00
parent a371d5fefe
commit 770ee3eebd
19 changed files with 475 additions and 926 deletions

View File

@@ -35,13 +35,12 @@
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.BooleanOp;
@@ -173,6 +175,17 @@
@@ -173,6 +175,16 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.ticks.LevelTicks;
import org.slf4j.Logger;
+import org.bukkit.Bukkit;
+import org.bukkit.WeatherType;
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.generator.CustomWorldChunkManager;
+import org.bukkit.craftbukkit.util.WorldUUID;
@@ -53,7 +52,7 @@
public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLevel {
@@ -187,7 +200,7 @@
@@ -187,7 +199,7 @@
final List<ServerPlayer> players = Lists.newArrayList();
public final ServerChunkCache chunkSource;
private final MinecraftServer server;
@@ -62,7 +61,7 @@
private int lastSpawnChunkRadius;
final EntityTickList entityTickList = new EntityTickList();
public final PersistentEntitySectionManager<Entity> entityManager;
@@ -214,52 +227,184 @@
@@ -214,52 +226,184 @@
private final boolean tickTime;
private final RandomSequences randomSequences;
@@ -79,7 +78,7 @@
+ // CraftBukkit start
+ public final LevelStorageSource.LevelStorageAccess convertable;
+ public final UUID uuid;
+
+ public LevelChunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunk(x, z, false);
+ }
@@ -200,7 +199,7 @@
+ ChunkGenerator chunkgenerator = worlddimension.generator();
+ // CraftBukkit start
+ this.serverLevelData.setWorld(this);
+
+ if (biomeProvider != null) {
+ BiomeSource worldChunkManager = new CustomWorldChunkManager(this.getWorld(), biomeProvider, this.server.registryAccess().lookupOrThrow(Registries.BIOME));
+ if (chunkgenerator instanceof NoiseBasedChunkGenerator cga) {
@@ -271,7 +270,7 @@
}
/** @deprecated */
@@ -305,12 +450,20 @@
@@ -305,12 +449,20 @@
long j;
if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) {
@@ -295,30 +294,7 @@
if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) {
this.resetWeatherCycle();
}
@@ -322,6 +475,7 @@
}
gameprofilerfiller.push("tickPending");
+ this.timings.doTickPending.startTiming(); // Spigot
if (!this.isDebug() && flag) {
j = this.getGameTime();
gameprofilerfiller.push("blockTicks");
@@ -330,6 +484,7 @@
this.fluidTicks.tick(j, 65536, this::tickFluid);
gameprofilerfiller.pop();
}
+ this.timings.doTickPending.stopTiming(); // Spigot
gameprofilerfiller.popPush("raid");
if (flag) {
@@ -340,12 +495,14 @@
this.getChunkSource().tick(shouldKeepTicking, true);
gameprofilerfiller.popPush("blockEvents");
if (flag) {
+ this.timings.doSounds.startTiming(); // Spigot
this.runBlockEvents();
+ this.timings.doSounds.stopTiming(); // Spigot
}
@@ -345,7 +497,7 @@
this.handlingTick = false;
gameprofilerfiller.pop();
@@ -327,32 +303,15 @@
if (flag1) {
this.resetEmptyTime();
@@ -353,12 +510,15 @@
if (flag1 || this.emptyTime++ < 300) {
gameprofilerfiller.push("entities");
+ this.timings.tickEntities.startTiming(); // Spigot
if (this.dragonFight != null && flag) {
gameprofilerfiller.push("dragonFight");
this.dragonFight.tick();
@@ -359,6 +511,7 @@
gameprofilerfiller.pop();
}
+ org.spigotmc.ActivationRange.activateEntities(this); // Spigot
+ this.timings.entityTick.startTiming(); // Spigot
this.entityTickList.forEach((entity) -> {
if (!entity.isRemoved()) {
if (!tickratemanager.isEntityFrozen(entity)) {
@@ -383,6 +543,8 @@
}
}
});
+ this.timings.entityTick.stopTiming(); // Spigot
+ this.timings.tickEntities.stopTiming(); // Spigot
gameprofilerfiller.pop();
this.tickBlockEntities();
}
@@ -429,7 +591,7 @@
@@ -429,7 +582,7 @@
private void wakeUpAllPlayers() {
this.sleepStatus.removeAllSleepers();
@@ -361,7 +320,7 @@
entityplayer.stopSleepInBed(false, false);
});
}
@@ -442,7 +604,7 @@
@@ -442,7 +595,7 @@
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("thunder");
@@ -370,7 +329,7 @@
BlockPos blockposition = this.findLightningTargetAround(this.getBlockRandomPos(j, 0, k, 15));
if (this.isRainingAt(blockposition)) {
@@ -456,7 +618,7 @@
@@ -456,7 +609,7 @@
entityhorseskeleton.setTrap(true);
entityhorseskeleton.setAge(0);
entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
@@ -379,7 +338,7 @@
}
}
@@ -465,7 +627,7 @@
@@ -465,7 +618,7 @@
if (entitylightning != null) {
entitylightning.moveTo(Vec3.atBottomCenterOf(blockposition));
entitylightning.setVisualOnly(flag1);
@@ -388,7 +347,7 @@
}
}
}
@@ -521,7 +683,7 @@
@@ -521,7 +674,7 @@
Biome biomebase = (Biome) this.getBiome(blockposition1).value();
if (biomebase.shouldFreeze(this, blockposition2)) {
@@ -397,7 +356,7 @@
}
if (this.isRaining()) {
@@ -537,10 +699,10 @@
@@ -537,10 +690,10 @@
BlockState iblockdata1 = (BlockState) iblockdata.setValue(SnowLayerBlock.LAYERS, j + 1);
Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1);
@@ -410,7 +369,7 @@
}
}
@@ -701,33 +863,67 @@
@@ -701,33 +854,67 @@
this.rainLevel = Mth.clamp(this.rainLevel, 0.0F, 1.0F);
}
@@ -428,10 +387,9 @@
if (flag != this.isRaining()) {
if (flag) {
- this.server.getPlayerList().broadcastAll(new ClientboundGameEventPacket(ClientboundGameEventPacket.STOP_RAINING, 0.0F));
- } else {
- this.server.getPlayerList().broadcastAll(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0F));
+ this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.STOP_RAINING, 0.0F));
+ } else {
} else {
- this.server.getPlayerList().broadcastAll(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0F));
+ this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.START_RAINING, 0.0F));
}
@@ -446,7 +404,7 @@
+ ((ServerPlayer) this.players.get(idx)).tickWeather();
+ }
+ }
+
+ if (flag != this.isRaining()) {
+ // Only send weather packets to those affected
+ for (int idx = 0; idx < this.players.size(); ++idx) {
@@ -461,7 +419,7 @@
+ }
+ }
+ // CraftBukkit end
+
}
@VisibleForTesting
@@ -487,7 +445,7 @@
}
public void resetEmptyTime() {
@@ -754,6 +950,14 @@
@@ -754,6 +941,13 @@
}
public void tickNonPassenger(Entity entity) {
@@ -498,11 +456,10 @@
+ return;
+ }
+ // Spigot end
+ entity.tickTimer.startTiming(); // Spigot
entity.setOldPosAndRot();
ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -763,6 +967,7 @@
@@ -763,6 +957,7 @@
});
gameprofilerfiller.incrementCounter("tickNonPassenger");
entity.tick();
@@ -510,15 +467,7 @@
gameprofilerfiller.pop();
Iterator iterator = entity.getPassengers().iterator();
@@ -771,6 +976,7 @@
this.tickPassenger(entity, entity1);
}
+ entity.tickTimer.stopTiming(); // Spigot
}
@@ -786,6 +992,7 @@
@@ -786,6 +981,7 @@
});
gameprofilerfiller.incrementCounter("tickPassenger");
passenger.rideTick();
@@ -526,7 +475,7 @@
gameprofilerfiller.pop();
Iterator iterator = passenger.getPassengers().iterator();
@@ -810,6 +1017,7 @@
@@ -810,6 +1006,7 @@
ServerChunkCache chunkproviderserver = this.getChunkSource();
if (!savingDisabled) {
@@ -534,7 +483,7 @@
if (progressListener != null) {
progressListener.progressStartNoAbort(Component.translatable("menu.savingLevel"));
}
@@ -827,11 +1035,19 @@
@@ -827,11 +1024,19 @@
}
}
@@ -555,7 +504,7 @@
}
DimensionDataStorage worldpersistentdata = this.getChunkSource().getDataStorage();
@@ -903,18 +1119,40 @@
@@ -903,18 +1108,40 @@
@Override
public boolean addFreshEntity(Entity entity) {
@@ -599,7 +548,7 @@
}
}
@@ -939,41 +1177,86 @@
@@ -939,41 +1166,86 @@
this.entityManager.addNewEntity(player);
}
@@ -691,20 +640,20 @@
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
@@ -981,6 +1264,12 @@
double d0 = (double) pos.getX() - entityplayer.getX();
@@ -982,6 +1254,12 @@
double d1 = (double) pos.getY() - entityplayer.getY();
double d2 = (double) pos.getZ() - entityplayer.getZ();
+
+ // CraftBukkit start
+ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) {
+ continue;
+ }
+ // CraftBukkit end
+
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress));
@@ -1060,7 +1349,18 @@
}
@@ -1060,7 +1338,18 @@
Iterator iterator = this.navigatingMobs.iterator();
while (iterator.hasNext()) {
@@ -724,7 +673,7 @@
PathNavigation navigationabstract = entityinsentient.getNavigation();
if (navigationabstract.shouldRecomputePath(pos)) {
@@ -1126,9 +1426,15 @@
@@ -1126,9 +1415,15 @@
@Override
public void explode(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Level.ExplosionInteraction explosionSourceType, ParticleOptions smallParticle, ParticleOptions largeParticle, Holder<SoundEvent> soundEvent) {
@@ -741,7 +690,7 @@
case NONE:
explosion_effect = Explosion.BlockInteraction.KEEP;
break;
@@ -1144,16 +1450,26 @@
@@ -1144,16 +1439,26 @@
case TRIGGER:
explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK;
break;
@@ -771,7 +720,7 @@
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
@@ -1162,10 +1478,11 @@
@@ -1162,10 +1467,11 @@
if (entityplayer.distanceToSqr(vec3d) < 4096.0D) {
Optional<Vec3> optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer));
@@ -784,7 +733,7 @@
}
private Explosion.BlockInteraction getDestroyType(GameRules.Key<GameRules.BooleanValue> decayRule) {
@@ -1226,17 +1543,24 @@
@@ -1226,17 +1532,24 @@
}
public <T extends ParticleOptions> int sendParticles(T parameters, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double speed) {
@@ -812,7 +761,7 @@
++j;
}
}
@@ -1292,7 +1616,7 @@
@@ -1292,7 +1605,7 @@
@Nullable
public BlockPos findNearestMapStructure(TagKey<Structure> structureTag, BlockPos pos, int radius, boolean skipReferencedStructures) {
@@ -821,7 +770,7 @@
return null;
} else {
Optional<HolderSet.Named<Structure>> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(structureTag);
@@ -1334,11 +1658,22 @@
@@ -1334,11 +1647,22 @@
@Nullable
@Override
public MapItemSavedData getMapData(MapId id) {
@@ -845,7 +794,7 @@
this.getServer().overworld().getDataStorage().set(id.key(), state);
}
@@ -1649,6 +1984,11 @@
@@ -1649,6 +1973,11 @@
@Override
public void blockUpdated(BlockPos pos, Block block) {
if (!this.isDebug()) {
@@ -857,7 +806,7 @@
this.updateNeighborsAt(pos, block);
}
@@ -1668,12 +2008,12 @@
@@ -1668,12 +1997,12 @@
}
public boolean isFlat() {
@@ -872,7 +821,7 @@
}
@Nullable
@@ -1696,7 +2036,7 @@
@@ -1696,7 +2025,7 @@
private static <T> String getTypeCount(Iterable<T> items, Function<T, String> classifier) {
try {
Object2IntOpenHashMap<String> object2intopenhashmap = new Object2IntOpenHashMap();
@@ -881,7 +830,7 @@
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -1705,7 +2045,7 @@
@@ -1705,7 +2034,7 @@
object2intopenhashmap.addTo(s, 1);
}
@@ -890,7 +839,7 @@
String s1 = (String) entry.getKey();
return s1 + ":" + entry.getIntValue();
@@ -1717,6 +2057,7 @@
@@ -1717,6 +2046,7 @@
@Override
public LevelEntityGetter<Entity> getEntities() {
@@ -898,7 +847,7 @@
return this.entityManager.getEntityGetter();
}
@@ -1836,6 +2177,7 @@
@@ -1836,6 +2166,7 @@
}
public void onTrackingStart(Entity entity) {
@@ -906,7 +855,7 @@
ServerLevel.this.getChunkSource().addEntity(entity);
if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.add(entityplayer);
@@ -1864,9 +2206,42 @@
@@ -1864,9 +2195,42 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@@ -949,7 +898,7 @@
ServerLevel.this.getChunkSource().removeEntity(entity);
if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.remove(entityplayer);
@@ -1895,6 +2270,14 @@
@@ -1895,6 +2259,14 @@
}
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);