Rewrite tracking code for game load/world join timing
This commit is contained in:
parent
62ea11ef7b
commit
201db412a4
|
|
@ -3,9 +3,6 @@ package org.embeddedt.modernfix;
|
|||
import com.mojang.datafixers.util.Pair;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.ConnectScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
|
@ -24,6 +21,7 @@ import java.util.*;
|
|||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class ModernFixClient {
|
||||
public static ModernFixClient INSTANCE;
|
||||
public static long worldLoadStartTime;
|
||||
private static int numRenderTicks;
|
||||
|
||||
|
|
@ -39,6 +37,7 @@ public class ModernFixClient {
|
|||
public static List<ModernFixClientIntegration> CLIENT_INTEGRATIONS = new CopyOnWriteArrayList<>();
|
||||
|
||||
public ModernFixClient() {
|
||||
INSTANCE = this;
|
||||
// clear reserve as it's not needed
|
||||
Minecraft.reserve = new byte[0];
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.branding.F3Screen")) {
|
||||
|
|
@ -60,16 +59,14 @@ public class ModernFixClient {
|
|||
tagsUpdated = false;
|
||||
}
|
||||
|
||||
public void onScreenOpening(Screen openingScreen) {
|
||||
if(openingScreen instanceof ConnectScreen) {
|
||||
worldLoadStartTime = System.nanoTime();
|
||||
} else if (openingScreen instanceof TitleScreen && gameStartTimeSeconds < 0) {
|
||||
gameStartTimeSeconds = ManagementFactory.getRuntimeMXBean().getUptime() / 1000f;
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.measure_time.GameLoad"))
|
||||
ModernFix.LOGGER.warn("Game took " + gameStartTimeSeconds + " seconds to start");
|
||||
ModernFixPlatformHooks.INSTANCE.onLaunchComplete();
|
||||
ClassInfoManager.clear();
|
||||
}
|
||||
public void onGameLaunchFinish() {
|
||||
if(gameStartTimeSeconds >= 0)
|
||||
return;
|
||||
gameStartTimeSeconds = ManagementFactory.getRuntimeMXBean().getUptime() / 1000f;
|
||||
if(ModernFixMixinPlugin.instance.isOptionEnabled("feature.measure_time.GameLoad"))
|
||||
ModernFix.LOGGER.warn("Game took " + gameStartTimeSeconds + " seconds to start");
|
||||
ModernFixPlatformHooks.INSTANCE.onLaunchComplete();
|
||||
ClassInfoManager.clear();
|
||||
}
|
||||
|
||||
public void onRecipesUpdated() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package org.embeddedt.modernfix.common.mixin.feature.measure_time;
|
||||
|
||||
import net.minecraft.client.gui.screens.ConnectScreen;
|
||||
import org.embeddedt.modernfix.ModernFixClient;
|
||||
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ConnectScreen.class)
|
||||
@ClientOnlyMixin
|
||||
public class ConnectScreenMixin {
|
||||
@Inject(method = "connect", at = @At("HEAD"))
|
||||
private void recordConnectStartTime(CallbackInfo ci) {
|
||||
ModernFixClient.worldLoadStartTime = System.nanoTime();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,16 +2,21 @@ package org.embeddedt.modernfix.common.mixin.feature.measure_time;
|
|||
|
||||
import com.mojang.datafixers.util.Function4;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Overlay;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.world.level.DataPackConfig;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.embeddedt.modernfix.ModernFixClient;
|
||||
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
|
@ -19,6 +24,7 @@ import java.util.function.Function;
|
|||
@Mixin(Minecraft.class)
|
||||
@ClientOnlyMixin
|
||||
public class MinecraftMixin {
|
||||
@Shadow @Nullable public Overlay overlay;
|
||||
private long datapackReloadStartTime;
|
||||
|
||||
@Inject(method = "makeServerStem", at = @At(value = "HEAD"))
|
||||
|
|
@ -31,4 +37,11 @@ public class MinecraftMixin {
|
|||
float timeSpentReloading = ((float)(System.nanoTime() - datapackReloadStartTime) / 1000000000f);
|
||||
ModernFix.LOGGER.warn("Datapack reload took " + timeSpentReloading + " seconds.");
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"))
|
||||
private void onClientTick(CallbackInfo ci) {
|
||||
if(this.overlay == null) {
|
||||
ModernFixClient.INSTANCE.onGameLaunchFinish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ dependencies {
|
|||
|
||||
modIncludeImplementation(fabricApi.module("fabric-api-base", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
modIncludeImplementation(fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
modIncludeImplementation(fabricApi.module("fabric-screen-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
modImplementation(fabricApi.module("fabric-screen-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
modIncludeImplementation(fabricApi.module("fabric-command-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
modIncludeImplementation(fabricApi.module("fabric-models-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
|
||||
|
|
|
|||
|
|
@ -2,11 +2,7 @@ package org.embeddedt.modernfix;
|
|||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class ModernFixClientFabric implements ClientModInitializer {
|
||||
public static ModernFixClient commonMod;
|
||||
|
|
@ -16,16 +12,6 @@ public class ModernFixClientFabric implements ClientModInitializer {
|
|||
commonMod = new ModernFixClient();
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register((mc) -> commonMod.onRenderTickEnd());
|
||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
||||
AtomicBoolean hasOpened = new AtomicBoolean(false);
|
||||
ScreenEvents.beforeTick(screen).register(screen1 -> {
|
||||
if(Minecraft.getInstance().getOverlay() != null)
|
||||
return;
|
||||
if(!hasOpened.getAndSet(true)) {
|
||||
commonMod.onScreenOpening(screen1);
|
||||
}
|
||||
});
|
||||
});
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||
commonMod.onServerStarted(server);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
],
|
||||
"depends": {
|
||||
"fabric-lifecycle-events-v1": "*",
|
||||
"fabric-screen-api-v1": "*",
|
||||
"fabric-command-api-v1": "*",
|
||||
"fabric-models-v0": "*",
|
||||
"minecraft": ">=1.16.2"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import com.mojang.blaze3d.platform.InputConstants;
|
|||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.DebugScreenOverlay;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.client.event.RecipesUpdatedEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.gui.ForgeIngameGui;
|
||||
|
|
@ -89,11 +88,4 @@ public class ModernFixClientForge {
|
|||
public void onTags(TagsUpdatedEvent e) {
|
||||
commonMod.onTagsUpdated();
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void onScreen(GuiScreenEvent.InitGuiEvent.Pre event) {
|
||||
if(event.isCanceled())
|
||||
return;
|
||||
commonMod.onScreenOpening(event.getGui());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user