Add profiler instance back
This time we wrap the Vanilla profiler so that the F3 screen works.
This commit is contained in:
@@ -31,6 +31,8 @@ public final class ClientProfilerInstance implements ProfilerFiller {
|
||||
}
|
||||
}
|
||||
|
||||
private static final double LARGE_TICK_THRESHOLD = 1.0 - 0.05;
|
||||
|
||||
private final LProfilerRegistry registry = new LProfilerRegistry();
|
||||
private final TickAccumulator tickAccumulator = new TickAccumulator(TimeUnit.SECONDS.toNanos(1L));
|
||||
|
||||
@@ -44,20 +46,23 @@ public final class ClientProfilerInstance implements ProfilerFiller {
|
||||
private LeafProfiler delayedFrameProfiler;
|
||||
private LeafProfiler frameProfiler;
|
||||
|
||||
private static final double LARGE_TICK_THRESHOLD = 1.0 - 0.05;
|
||||
|
||||
private long tick;
|
||||
|
||||
private final List<LargeTick> largeTicks = new ArrayList<>();
|
||||
|
||||
private static record LargeTick(long tickNum, LeafProfiler.ProfilingData profile) {}
|
||||
|
||||
public void startProfiler() {
|
||||
this.delayedFrameProfiler = new LeafProfiler(this.registry, new LProfileGraph());
|
||||
public ClientProfilerInstance() {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
public void stopProfiler() {
|
||||
this.delayedFrameProfiler = null;
|
||||
public void reset() {
|
||||
this.previousTickStart = TickTime.DEADLINE_NOT_SET;
|
||||
this.tickStart = TickTime.DEADLINE_NOT_SET;
|
||||
this.tickStartCPU = TickTime.DEADLINE_NOT_SET;
|
||||
this.tick = 0L;
|
||||
this.largeTicks.clear();
|
||||
this.delayedFrameProfiler = new LeafProfiler(this.registry, new LProfileGraph());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,23 +3,19 @@ package ca.spottedleaf.moonrise.mixin.profiler;
|
||||
import ca.spottedleaf.leafprofiler.client.ClientProfilerInstance;
|
||||
import com.mojang.blaze3d.platform.WindowEventHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.profiling.ContinuousProfiler;
|
||||
import net.minecraft.util.profiling.InactiveProfiler;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.util.profiling.SingleTickProfiler;
|
||||
import net.minecraft.util.thread.ReentrantBlockableEventLoop;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
abstract class MinecraftMixin extends ReentrantBlockableEventLoop<Runnable> implements WindowEventHandler {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private ContinuousProfiler fpsPieProfiler;
|
||||
|
||||
public MinecraftMixin(String string) {
|
||||
super(string);
|
||||
}
|
||||
@@ -28,17 +24,25 @@ abstract class MinecraftMixin extends ReentrantBlockableEventLoop<Runnable> impl
|
||||
private final ClientProfilerInstance leafProfiler = new ClientProfilerInstance();
|
||||
|
||||
/**
|
||||
* @reason Use our own profiler for client
|
||||
* @reason Insert our own profiler for client
|
||||
* @author Spottedleaf
|
||||
*/
|
||||
@Overwrite
|
||||
public ProfilerFiller constructProfiler(final boolean shouldRenderFPSPie, final SingleTickProfiler singleTickProfiler) {
|
||||
if (shouldRenderFPSPie) {
|
||||
this.fpsPieProfiler.enable();
|
||||
} else {
|
||||
this.fpsPieProfiler.disable();
|
||||
@Inject(
|
||||
method = "constructProfiler",
|
||||
cancellable = true,
|
||||
at = @At(
|
||||
value = "RETURN"
|
||||
)
|
||||
)
|
||||
public void addOurProfiler(final boolean shouldRenderFPSPie, final SingleTickProfiler singleTickProfiler,
|
||||
final CallbackInfoReturnable<ProfilerFiller> cir) {
|
||||
final ProfilerFiller ret = cir.getReturnValue();
|
||||
|
||||
if (ret == null || ret == InactiveProfiler.INSTANCE) {
|
||||
this.leafProfiler.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
return this.leafProfiler;
|
||||
cir.setReturnValue(ProfilerFiller.tee(this.leafProfiler, ret));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
"collisions.LiquidBlockRendererMixin",
|
||||
"collisions.ParticleMixin",
|
||||
"loading_screen.LevelLoadStatusManagerMixin",
|
||||
"profiler.MinecraftMixin",
|
||||
"render.SectionRenderDispatcherMixin",
|
||||
"serverlist.ClientConnectionMixin",
|
||||
"serverlist.ServerAddressResolverMixin",
|
||||
|
||||
Reference in New Issue
Block a user