Working on actually hook up events to use new one

This commit is contained in:
TomTheFurry
2022-06-01 22:55:57 +08:00
parent 94b20a363d
commit f4f186ff78
6 changed files with 40 additions and 76 deletions
@@ -61,6 +61,7 @@ import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
* @author James Seibel
* @version 2022-4-27
*/
@Deprecated
public class ClientApi
{
public static final Logger LOGGER = LogManager.getLogger(ClientApi.class.getSimpleName());
@@ -48,6 +48,7 @@ import java.lang.invoke.MethodHandles;
* @author James Seibel
* @version 2021-11-12
*/
@Deprecated
public class EventApi
{
public static final boolean ENABLE_STACK_DUMP_LOGGING = false;
@@ -34,6 +34,7 @@ import com.seibel.lod.core.objects.lod.LodWorld;
* @author James Seibel
* @version 2022-4-24
*/
@Deprecated
public class InternalApiShared
{
public InternalApiShared INSTANCE = new InternalApiShared();
@@ -67,8 +67,8 @@ public class ClientApi
public static final long LAG_SPIKE_THRESHOLD_NS = TimeUnit.NANOSECONDS.convert(16, TimeUnit.MILLISECONDS);
public static final long SPAM_LOGGER_FLUSH_NS = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS);
public static class LagSpikeCatcher {
public static class LagSpikeCatcher {
long timer = System.nanoTime();
public LagSpikeCatcher() {}
public void end(String source) {
@@ -139,10 +139,25 @@ public class ClientApi
private long lastFlush = 0;
public void preRender() {
public void rendererShutdownEvent() {
IProfilerWrapper profiler = MC.getProfiler();
profiler.pop(); // get out of "terrain"
profiler.push("DH-PreRender");
profiler.push("DH-RendererShutdown");
profiler.pop();
}
public void rendererStartupEvent() {
IProfilerWrapper profiler = MC.getProfiler();
profiler.push("DH-RendererStartup");
// make sure the GLProxy is created before the LodBufferBuilder needs it
GLProxy.getInstance();
profiler.pop();
}
public void clientTickEvent() {
IProfilerWrapper profiler = MC.getProfiler();
profiler.push("DH-ClientTick");
boolean doFlush = System.nanoTime() - lastFlush >= SPAM_LOGGER_FLUSH_NS;
if (doFlush) {
lastFlush = System.nanoTime();
@@ -150,20 +165,18 @@ public class ClientApi
}
ConfigBasedLogger.updateAll();
ConfigBasedSpamLogger.updateAll(doFlush);
// only run the first time setup once
if (!firstTimeSetupComplete) firstFrameSetup();
if (ModInfo.IS_DEV_BUILD)
{
// config overrides should only be used in the developer builds
applyDeveloperConfigOverrides();
}
if (SharedApi.currentServer == null && SharedApi.currentWorld != null) {
// In single player.
SharedApi.currentWorld.asyncTick();
if (SharedApi.currentWorld != null) {
if (ModInfo.IS_DEV_BUILD) {
// config overrides should only be used in the developer builds
applyDeveloperConfigOverrides();
}
if (SharedApi.currentServer == null) {
// In single player. Do client-side ticking system.
SharedApi.currentWorld.asyncTick();
}
}
//FIXME: Is it always 'terrain' that is the previous thing in the profiler?
profiler.push("terrain"); // go back into "terrain"
profiler.pop();
}
public void renderLods(IWorldWrapper world, Mat4f mcModelViewMatrix, Mat4f mcProjectionMatrix, float partialTicks)
@@ -280,28 +293,6 @@ public class ClientApi
MC.sendChatMessage("P: Debug Pref Logger is " + (prefLoggerEnabled ? "enabled" : "disabled"));
}
}
//=================//
// Lod maintenance //
//=================//
// FIXME: I need a onLastFrameCleanup() callback in Render Thread... Which calls renderer.cleanup()
/** This event is called once during the first frame Minecraft renders in the world. */
public void firstFrameSetup()
{
// make sure the GLProxy is created before the LodBufferBuilder needs it
GLProxy.getInstance();
firstTimeSetupComplete = true;
}
}
@@ -90,4 +90,7 @@ public class ServerApi
public void chunkSaveEvent(IChunkWrapper chunk, IWorldWrapper world) {
//TODO
}
public void serverChunkLoadEvent(IChunkWrapper chunk, IWorldWrapper world) {
}
}
@@ -1,51 +1,18 @@
package com.seibel.lod.core.api.internal.a7;
import com.seibel.lod.core.logging.DhLoggerBuilder;
import com.seibel.lod.core.objects.a7.DHWorld;
import com.seibel.lod.core.objects.a7.Server;
import com.seibel.lod.core.util.LodUtil;
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IWorldWrapper;
import org.apache.logging.log4j.Logger;
public class SharedApi {
public static DHWorld currentWorld;
public static Server currentServer;
public static IMinecraftSharedWrapper MC;
public static IMinecraftClientWrapper MC_CLIENT;
public static void onServerStart() {
if (MC.isServerJar()) {
ServerApi.INSTANCE.serverWorldLoadEvent();
} else if (MC_CLIENT.hasSinglePlayerServer()) {
ServerApi.INSTANCE.serverWorldLoadEvent();
} // else do nothing
}
public static void onServerStop() {
if (MC.isServerJar()) {
ServerApi.INSTANCE.serverWorldUnloadEvent();
} else if (MC_CLIENT.hasSinglePlayerServer()) {
ServerApi.INSTANCE.serverWorldUnloadEvent();
} // else do nothing
}
public static void onLevelLoad(IWorldWrapper world) {
if (MC.isServerJar()) {
ServerApi.INSTANCE.serverLevelLoadEvent(world);
} else if (MC_CLIENT.hasSinglePlayerServer()) {
ServerApi.INSTANCE.serverLevelLoadEvent(world);
} else {
ClientApi.INSTANCE.clientLevelLoadEvent(world);
}
}
public static void onLevelUnload(IWorldWrapper world) {
if (MC.isServerJar()) {
ServerApi.INSTANCE.serverLevelUnloadEvent(world);
} else if (MC_CLIENT.hasSinglePlayerServer()) {
ServerApi.INSTANCE.serverLevelUnloadEvent(world);
} else {
ClientApi.INSTANCE.clientLevelUnloadEvent(world);
}
}
public static Logger LOGGER = DhLoggerBuilder.getLogger("DH Events");
}