use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.
the class TrackingUtil method tickRidingEntity.
public static void tickRidingEntity(net.minecraft.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!");
final IMixinEntity mixinEntity = EntityUtil.toMixin(entity);
if (!mixinEntity.shouldTick()) {
return;
}
final Optional<User> notifierUser = mixinEntity.getNotifierUser();
final Optional<User> creatorUser = mixinEntity.getCreatorUser();
final EntityTickContext tickContext = TickPhase.Tick.ENTITY.createPhaseContext().source(entity).notifier(() -> notifierUser).owner(() -> creatorUser);
try (final StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
final EntityTickContext context = tickContext.buildAndSwitch();
final Timing entityTiming = mixinEntity.getTimingsHandler().startTiming()) {
Sponge.getCauseStackManager().pushCause(entity);
notifierUser.ifPresent(notifier -> frame.addContext(EventContextKeys.NOTIFIER, notifier));
creatorUser.ifPresent(notifier -> frame.addContext(EventContextKeys.OWNER, notifier));
entity.updateRidden();
} catch (Exception | NoClassDefFoundError e) {
PhaseTracker.getInstance().printExceptionFromPhase(e, tickContext);
}
}
use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.
the class TrackingUtil method tickTileEntity.
@SuppressWarnings({ "unused", "try" })
public static void tickTileEntity(IMixinWorldServer mixinWorldServer, ITickable tile) {
checkArgument(tile instanceof TileEntity, "ITickable %s is not a TileEntity!", tile);
checkNotNull(tile, "Cannot capture on a null ticking tile entity!");
final net.minecraft.tileentity.TileEntity tileEntity = (net.minecraft.tileentity.TileEntity) tile;
final IMixinTileEntity mixinTileEntity = (IMixinTileEntity) tile;
final BlockPos pos = tileEntity.getPos();
final IMixinChunk chunk = ((IMixinTileEntity) tile).getActiveChunk();
if (!mixinTileEntity.shouldTick()) {
return;
}
final TileEntityTickContext context = TickPhase.Tick.TILE_ENTITY.createPhaseContext().source(tile);
try (final StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
final PhaseContext<?> phaseContext = context) {
Sponge.getCauseStackManager().pushCause(tile);
// Add notifier and owner so we don't have to perform lookups during the phases and other processing
chunk.getBlockNotifier(pos).ifPresent(notifier -> {
Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier);
phaseContext.notifier(notifier);
});
User blockOwner = mixinTileEntity.getSpongeOwner();
if (!mixinTileEntity.hasSetOwner()) {
blockOwner = chunk.getBlockOwner(pos).orElse(null);
mixinTileEntity.setSpongeOwner(blockOwner);
}
if (blockOwner != null) {
Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, blockOwner);
phaseContext.owner(blockOwner);
}
phaseContext.owner = blockOwner;
// Add the block snapshot of the tile entity for caches to avoid creating multiple snapshots during processing
// This is a lazy evaluating snapshot to avoid the overhead of snapshot creation
// Finally, switch the context now that we have the owner and notifier
phaseContext.buildAndSwitch();
try (Timing timing = mixinTileEntity.getTimingsHandler().startTiming()) {
tile.update();
}
} catch (Exception e) {
PhaseTracker.getInstance().printExceptionFromPhase(e, context);
}
}
use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.
the class TrackingUtil method tickEntity.
public static void tickEntity(net.minecraft.entity.Entity entityIn) {
checkArgument(entityIn instanceof Entity, "Entity %s is not an instance of SpongeAPI's Entity!", entityIn);
checkNotNull(entityIn, "Cannot capture on a null ticking entity!");
final IMixinEntity mixinEntity = EntityUtil.toMixin(entityIn);
if (!mixinEntity.shouldTick()) {
return;
}
final EntityTickContext tickContext = TickPhase.Tick.ENTITY.createPhaseContext().source(entityIn);
try (final StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
final EntityTickContext context = tickContext;
final Timing entityTiming = mixinEntity.getTimingsHandler().startTiming()) {
mixinEntity.getNotifierUser().ifPresent(notifier -> {
frame.addContext(EventContextKeys.NOTIFIER, notifier);
context.notifier(notifier);
});
mixinEntity.getCreatorUser().ifPresent(owner -> {
if (mixinEntity instanceof EntityFallingBlock) {
frame.pushCause(owner);
}
frame.addContext(EventContextKeys.OWNER, owner);
context.owner(owner);
});
context.buildAndSwitch();
entityIn.onUpdate();
} catch (Exception | NoClassDefFoundError e) {
PhaseTracker.getInstance().printExceptionFromPhase(e, tickContext);
}
}
use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.
the class SpongeChunkGenerator method populate.
@Override
public void populate(int chunkX, int chunkZ) {
IMixinWorldServer world = (IMixinWorldServer) this.world;
world.getTimingsHandler().chunkPopulate.startTimingIfSync();
this.chunkGeneratorTiming.startTimingIfSync();
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
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));
org.spongepowered.api.world.Chunk chunk = (org.spongepowered.api.world.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));
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) {
final PopulatorType type = populator.getType();
if (type == null) {
System.err.printf("Found a populator with a null type: %s populator%n", populator);
}
if (Sponge.getGame().getEventManager().post(SpongeEventFactory.createPopulateChunkEventPopulate(Sponge.getCauseStackManager().getCurrentCause(), populator, chunk))) {
continue;
}
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Timing timing = null;
if (Timings.isTimingsEnabled()) {
timing = this.populatorTimings.get(populator.getType().getId());
if (timing == null) {
// ,
timing = SpongeTimingsFactory.ofSafe("populate - " + populator.getType().getId());
// this.chunkGeneratorTiming);
this.populatorTimings.put(populator.getType().getId(), timing);
}
timing.startTimingIfSync();
}
try (PhaseContext<?> context = GenerationPhase.State.POPULATOR_RUNNING.createPhaseContext().world(world).populator(type).buildAndSwitch()) {
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();
}
}
}
}
// populate method so that its particular changes are used.
if (this.baseGenerator instanceof SpongeGenerationPopulator) {
Timing timing = null;
if (Timings.isTimingsEnabled()) {
IGenerationPopulator spongePopulator = (IGenerationPopulator) this.baseGenerator;
timing = spongePopulator.getTimingsHandler();
timing.startTimingIfSync();
}
((SpongeGenerationPopulator) this.baseGenerator).getHandle(this.world).populate(chunkX, chunkZ);
if (Timings.isTimingsEnabled()) {
timing.stopTimingIfSync();
}
}
PopulateChunkEvent.Post event = SpongeEventFactory.createPopulateChunkEventPost(Sponge.getCauseStackManager().getCurrentCause(), ImmutableList.copyOf(populators), chunk);
SpongeImpl.postEvent(event);
BlockFalling.fallInstantly = false;
this.chunkGeneratorTiming.stopTimingIfSync();
world.getTimingsHandler().chunkPopulate.stopTimingIfSync();
}
use of co.aikar.timings.Timing in project SpongeForge by SpongePowered.
the class MixinGameRegistry method onGenerateWorld.
@Redirect(method = "generateWorld", at = @At(value = "INVOKE", target = WORLD_GENERATOR_GENERATE, remap = false))
private static void onGenerateWorld(IWorldGenerator worldGenerator, Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
Timing timing = null;
if (Timings.isTimingsEnabled()) {
timing = worldGeneratorTimings.get(worldGenerator.getClass());
if (timing == null) {
String modId = StaticMixinForgeHelper.getModIdFromClass(worldGenerator.getClass());
timing = SpongeTimingsFactory.ofSafe("worldGenerator (" + modId + ":" + worldGenerator.getClass().getName() + ")");
worldGeneratorTimings.put(worldGenerator.getClass(), timing);
}
timing.startTimingIfSync();
}
worldGenerator.generate(random, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
if (Timings.isTimingsEnabled()) {
timing.stopTimingIfSync();
}
}
Aggregations