Search in sources :

Example 16 with Timing

use of co.aikar.timings.Timing in project SpongeForge by SpongePowered.

the class SpongeChunkGeneratorForge method populate.

@Override
public void populate(int chunkX, int chunkZ) {
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    this.chunkGeneratorTiming.startTimingIfSync();
    this.rand.setSeed(this.world.getSeed());
    long i1 = this.rand.nextLong() / 2L * 2L + 1L;
    long j1 = this.rand.nextLong() / 2L * 2L + 1L;
    this.rand.setSeed(chunkX * i1 + chunkZ * j1 ^ this.world.getSeed());
    BlockFalling.fallInstantly = true;
    // Have to regeneate the biomes so that any virtual biomes can be passed to the populator.
    this.cachedBiomes.reuse(new Vector3i(chunkX * 16, 0, chunkZ * 16));
    this.biomeGenerator.generateBiomes(this.cachedBiomes);
    ImmutableBiomeVolume biomeBuffer = this.cachedBiomes.getImmutableBiomeCopy();
    BlockPos blockpos = new BlockPos(chunkX * 16, 0, chunkZ * 16);
    BiomeType biome = (BiomeType) this.world.getBiome(blockpos.add(16, 0, 16));
    Chunk chunk = (Chunk) this.world.getChunkFromChunkCoords(chunkX, chunkZ);
    BiomeGenerationSettings settings = getBiomeSettings(biome);
    List<Populator> populators = new ArrayList<>(this.pop);
    Populator snowPopulator = null;
    Iterator<Populator> itr = populators.iterator();
    while (itr.hasNext()) {
        Populator populator = itr.next();
        if (populator instanceof SnowPopulator) {
            itr.remove();
            snowPopulator = populator;
            break;
        }
    }
    populators.addAll(settings.getPopulators());
    if (snowPopulator != null) {
        populators.add(snowPopulator);
    }
    Sponge.getGame().getEventManager().post(SpongeEventFactory.createPopulateChunkEventPre(Sponge.getCauseStackManager().getCurrentCause(), populators, chunk));
    MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(this, this.world, this.rand, chunkX, chunkZ, false));
    MinecraftForge.EVENT_BUS.post(new DecorateBiomeEvent.Pre(this.world, this.rand, blockpos));
    MinecraftForge.ORE_GEN_BUS.post(new OreGenEvent.Pre(this.world, this.rand, blockpos));
    List<String> flags = Lists.newArrayList();
    Vector3i min = new Vector3i(chunkX * 16 + 8, 0, chunkZ * 16 + 8);
    org.spongepowered.api.world.World spongeWorld = (org.spongepowered.api.world.World) this.world;
    Extent volume = new SoftBufferExtentViewDownsize(chunk.getWorld(), min, min.add(15, 255, 15), min.sub(8, 0, 8), min.add(23, 255, 23));
    for (Populator populator : populators) {
        if (!(populator instanceof PlainsGrassPopulator)) {
            if (!this.checkForgeEvent(populator, this, chunkX, chunkZ, flags, chunk)) {
                continue;
            }
        } else {
            final PlainsGrassPopulator grassPop = (PlainsGrassPopulator) populator;
            if (!this.checkForgeEvent(grassPop.getFlowers(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateFlowers(false);
            }
            if (!this.checkForgeEvent(grassPop.getGrass(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateGrass(false);
            }
            if (!this.checkForgeEvent(grassPop.getPlant(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateGrass(false);
            }
            if (!grassPop.isPopulateFlowers() && !grassPop.isPopulateGrass()) {
                continue;
            }
        }
        final PopulatorType type = populator.getType();
        if (Sponge.getGame().getEventManager().post(SpongeEventFactory.createPopulateChunkEventPopulate(Sponge.getCauseStackManager().getCurrentCause(), populator, chunk))) {
            continue;
        }
        try (PopulatorPhaseContext context = GenerationPhase.State.POPULATOR_RUNNING.createPhaseContext().world(this.world).populator(type).buildAndSwitch()) {
            Timing timing = null;
            if (Timings.isTimingsEnabled()) {
                timing = this.populatorTimings.get(populator.getType().getId());
                if (timing == null) {
                    timing = SpongeTimingsFactory.ofSafe(populator.getType().getId());
                    this.populatorTimings.put(populator.getType().getId(), timing);
                }
                timing.startTimingIfSync();
            }
            if (populator instanceof IFlaggedPopulator) {
                ((IFlaggedPopulator) populator).populate(spongeWorld, volume, this.rand, biomeBuffer, flags);
            } else {
                populator.populate(spongeWorld, volume, this.rand, biomeBuffer);
            }
            if (Timings.isTimingsEnabled()) {
                timing.stopTimingIfSync();
            }
        }
    }
    MinecraftForge.ORE_GEN_BUS.post(new OreGenEvent.Post(this.world, this.rand, blockpos));
    MinecraftForge.EVENT_BUS.post(new DecorateBiomeEvent.Post(this.world, this.rand, blockpos));
    MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(this, this.world, this.rand, chunkX, chunkZ, false));
    // populate method so that its particular changes are used.
    if (this.baseGenerator instanceof SpongeGenerationPopulator) {
        Timing timing = null;
        IChunkGenerator chunkGenerator = ((SpongeGenerationPopulator) this.baseGenerator).getHandle(this.world);
        if (Timings.isTimingsEnabled()) {
            IGenerationPopulator spongePopulator = (IGenerationPopulator) this.baseGenerator;
            timing = spongePopulator.getTimingsHandler();
            timing.startTimingIfSync();
        }
        chunkGenerator.populate(chunkX, chunkZ);
        if (Timings.isTimingsEnabled()) {
            timing.stopTimingIfSync();
        }
    }
    org.spongepowered.api.event.world.chunk.PopulateChunkEvent.Post event = SpongeEventFactory.createPopulateChunkEventPost(Sponge.getCauseStackManager().getCurrentCause(), ImmutableList.copyOf(populators), chunk);
    SpongeImpl.postEvent(event);
    BlockFalling.fallInstantly = false;
    this.chunkGeneratorTiming.stopTimingIfSync();
    ((IMixinWorldServer) spongeWorld).getTimingsHandler().chunkPopulate.stopTimingIfSync();
}
Also used : PlainsGrassPopulator(org.spongepowered.common.world.gen.populators.PlainsGrassPopulator) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) OreGenEvent(net.minecraftforge.event.terraingen.OreGenEvent) Extent(org.spongepowered.api.world.extent.Extent) ArrayList(java.util.ArrayList) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) PopulatorType(org.spongepowered.api.world.gen.PopulatorType) World(net.minecraft.world.World) BiomeType(org.spongepowered.api.world.biome.BiomeType) SoftBufferExtentViewDownsize(org.spongepowered.common.world.extent.SoftBufferExtentViewDownsize) BlockPos(net.minecraft.util.math.BlockPos) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator) PlainsGrassPopulator(org.spongepowered.common.world.gen.populators.PlainsGrassPopulator) SpongeGenerationPopulator(org.spongepowered.common.world.gen.SpongeGenerationPopulator) Populator(org.spongepowered.api.world.gen.Populator) AnimalPopulator(org.spongepowered.common.world.gen.populators.AnimalPopulator) IFlaggedPopulator(org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator) SnowPopulator(org.spongepowered.common.world.gen.populators.SnowPopulator) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) DecorateBiomeEvent(net.minecraftforge.event.terraingen.DecorateBiomeEvent) ImmutableBiomeVolume(org.spongepowered.api.world.extent.ImmutableBiomeVolume) PopulatorPhaseContext(org.spongepowered.common.event.tracking.phase.generation.PopulatorPhaseContext) IFlaggedPopulator(org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator) SpongeGenerationPopulator(org.spongepowered.common.world.gen.SpongeGenerationPopulator) PopulateChunkEvent(net.minecraftforge.event.terraingen.PopulateChunkEvent) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) Chunk(org.spongepowered.api.world.Chunk) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Vector3i(com.flowpowered.math.vector.Vector3i) SnowPopulator(org.spongepowered.common.world.gen.populators.SnowPopulator) Timing(co.aikar.timings.Timing)

Example 17 with Timing

use of co.aikar.timings.Timing in project core by CubeEngine.

the class ProxyCallable method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    try {
        CommandInvocation invocation = newInvocation(source, arguments.isEmpty() ? alias : alias + " " + arguments);
        long delta = System.currentTimeMillis();
        boolean ran;
        try (Timing timing = Timings.ofStart(manager.getPlugin(), "CE Command Execute " + alias);
            Summary.Timer t = commandTimeSummary.startTimer()) {
            ran = manager.execute(invocation);
        }
        delta = System.currentTimeMillis() - delta;
        if (// third of a tick
        delta > 1000 / 20 / 3) {
            logger.warn("Command Execute Timing: {} {} | {}ms ({}%)", this.alias, arguments, delta, delta * 100 / (1000 / 20));
        }
        manager.logExecution(source, ran, alias, arguments);
        return CommandResult.success();
    } catch (Exception e) {
        logger.error(e, "An Unknown Exception occurred while executing a command! Command: {}", alias + " " + arguments);
        return CommandResult.empty();
    }
}
Also used : Summary(io.prometheus.client.Summary) Timing(co.aikar.timings.Timing) CommandException(org.spongepowered.api.command.CommandException) CommandInvocation(org.cubeengine.butler.CommandInvocation)

Example 18 with Timing

use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.

the class ServerLevelMixin_Tracker method tracker$wrapBlockRandomTick.

/**
 * For PhaseTracking, we need to wrap around the
 * {@link BlockState#tick(ServerLevel, BlockPos, Random)} method, and the ScheduledTickList uses a lambda method
 * to {@code ServerWorld#tickBlock(NextTickListEntry)}, so it's either we customize the ScheduledTickList
 * or we wrap in this method here.
 *
 * @author gabizou - January 11th, 2020 - Minecraft 1.14.3
 */
@Redirect(method = "tickChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;randomTick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Ljava/util/Random;)V"))
private void tracker$wrapBlockRandomTick(final BlockState blockState, final ServerLevel worldIn, final BlockPos posIn, final Random randomIn) {
    try (final Timing timing = ((TimingBridge) blockState.getBlock()).bridge$timings()) {
        timing.startTiming();
        TrackingUtil.randomTickBlock(this, blockState, posIn, this.random);
    }
}
Also used : Timing(co.aikar.timings.Timing) TimingBridge(org.spongepowered.common.bridge.TimingBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 19 with Timing

use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.

the class ServerLevelMixin_Tracker method tracker$wrapNormalEntityTick.

@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;guardEntityTick(Ljava/util/function/Consumer;Lnet/minecraft/world/entity/Entity;)V"), slice = @Slice(from = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;push(Ljava/lang/String;)V", args = "ldc=tick"), to = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;push(Ljava/lang/String;)V", args = "ldc=remove")))
private void tracker$wrapNormalEntityTick(final ServerLevel level, final Consumer<Entity> entityUpdateConsumer, final Entity entity) {
    final Timing entityTickTiming = ((TimingBridge) entity.getType()).bridge$timings();
    entityTickTiming.startTiming();
    final PhaseContext<@NonNull ?> currentState = PhaseTracker.SERVER.getPhaseContext();
    TrackingUtil.tickEntity(entityUpdateConsumer, entity);
    entityTickTiming.stopTiming();
}
Also used : Timing(co.aikar.timings.Timing) TimingBridge(org.spongepowered.common.bridge.TimingBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 20 with Timing

use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.

the class TrackingUtil method tickEntity.

public static void tickEntity(final Consumer<net.minecraft.world.entity.Entity> consumer, final net.minecraft.world.entity.Entity entity) {
    checkArgument(entity instanceof Entity, "Entity %s is not an instance of SpongeAPI's Entity!", entity);
    checkNotNull(entity, "Cannot capture on a null ticking entity!");
    if (!((TrackableBridge) entity).bridge$shouldTick()) {
        return;
    }
    final EntityTickContext tickContext = TickPhase.Tick.ENTITY.createPhaseContext(PhaseTracker.SERVER).source(entity);
    try (final EntityTickContext context = tickContext;
        final Timing entityTiming = ((TimingBridge) entity.getType()).bridge$timings()) {
        if (entity instanceof CreatorTrackedBridge) {
            ((CreatorTrackedBridge) entity).tracker$getNotifierUUID().ifPresent(context::notifier);
            ((CreatorTrackedBridge) entity).tracker$getCreatorUUID().ifPresent(context::creator);
        }
        context.buildAndSwitch();
        entityTiming.startTiming();
        consumer.accept(entity);
        if (ShouldFire.MOVE_ENTITY_EVENT) {
            SpongeCommonEventFactory.callNaturalMoveEntityEvent(entity);
        }
        if (ShouldFire.ROTATE_ENTITY_EVENT) {
            SpongeCommonEventFactory.callNaturalRotateEntityEvent(entity);
        }
    } catch (final Exception e) {
        PhasePrinter.printExceptionFromPhase(PhaseTracker.getInstance().stack, e, tickContext);
    }
}
Also used : TickableBlockEntity(net.minecraft.world.level.block.entity.TickableBlockEntity) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) Entity(org.spongepowered.api.entity.Entity) EntityTickContext(org.spongepowered.common.event.tracking.phase.tick.EntityTickContext) TileEntityTickContext(org.spongepowered.common.event.tracking.phase.tick.TileEntityTickContext) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) Timing(co.aikar.timings.Timing) TimingBridge(org.spongepowered.common.bridge.TimingBridge)

Aggregations

Timing (co.aikar.timings.Timing)22 TileEntityTickContext (org.spongepowered.common.event.tracking.phase.tick.TileEntityTickContext)6 TimingBridge (org.spongepowered.common.bridge.TimingBridge)5 DataPacketSendEvent (cn.nukkit.event.server.DataPacketSendEvent)4 Entity (org.spongepowered.api.entity.Entity)4 EntityTickContext (org.spongepowered.common.event.tracking.phase.tick.EntityTickContext)4 BlockPos (net.minecraft.util.math.BlockPos)3 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)3 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)3 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)3 TickableBlockEntity (net.minecraft.world.level.block.entity.TickableBlockEntity)2 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)2 User (org.spongepowered.api.entity.living.player.User)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 CreatorTrackedBridge (org.spongepowered.common.bridge.CreatorTrackedBridge)2 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)2 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)2 Type (cn.nukkit.AdventureSettings.Type)1 cn.nukkit.block (cn.nukkit.block)1 BlockEntity (cn.nukkit.blockentity.BlockEntity)1