mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-10 06:16:07 +01:00
f72abf8e1d
- Rename ReloadRenderersEvent to ReloadLevelRendererEvent - Rename Engine#renderCrumblingInstances to #renderCrumbling - Make all mixin classes package-private and abstract - Make all event classes final and document which event bus they are posted on - Add EndClientResourceReloadEvent - Replace some usages of ReloadLevelRendererEvent with EndClientResourceReloadEvent, including ModelHolder and ModelCache - Always add all existing entities from world to VisualizationManagerImpl on construction if level is instanceof Level - Delete all VisualizationManagerImpls on resource reload - Improve MemoryBlock utility - Add MemoryBlock#copyTo(MemoryBlock) - Remove MemoryBlock#reallocTracked and make #realloc create a tracked block if and only if the existing block is tracked - Fix reallocating a debug memory block creating a regular memory block - Change BakedModelBufferer to only invoke the result consumer if the data is not empty - Improve BackendArgument - Fix classloading BackendArgument early causing it to return incomplete suggestions - Always allow specifying namespace, allow matching only by path, and always display suggested IDs with namespace
102 lines
2.9 KiB
Java
102 lines
2.9 KiB
Java
package com.jozufozu.flywheel.impl;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import com.jozufozu.flywheel.Flywheel;
|
|
import com.jozufozu.flywheel.api.backend.Backend;
|
|
import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent;
|
|
import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent;
|
|
import com.jozufozu.flywheel.backend.Backends;
|
|
import com.jozufozu.flywheel.config.FlwConfig;
|
|
import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl;
|
|
import com.jozufozu.flywheel.lib.backend.SimpleBackend;
|
|
import com.mojang.logging.LogUtils;
|
|
|
|
import net.minecraft.ChatFormatting;
|
|
import net.minecraft.client.multiplayer.ClientLevel;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraftforge.fml.CrashReportCallables;
|
|
|
|
public final class BackendManagerImpl {
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
|
|
private static final Backend OFF_BACKEND = SimpleBackend.builder()
|
|
.engineMessage(Component.literal("Disabled Flywheel")
|
|
.withStyle(ChatFormatting.RED))
|
|
.engineFactory(level -> {
|
|
throw new UnsupportedOperationException("Cannot create engine when backend is off.");
|
|
})
|
|
.supported(() -> true)
|
|
.register(Flywheel.rl("off"));
|
|
|
|
private static final Backend DEFAULT_BACKEND = findDefaultBackend();
|
|
|
|
private static Backend backend = OFF_BACKEND;
|
|
|
|
private BackendManagerImpl() {
|
|
}
|
|
|
|
public static Backend getBackend() {
|
|
return backend;
|
|
}
|
|
|
|
public static boolean isOn() {
|
|
return backend != OFF_BACKEND;
|
|
}
|
|
|
|
public static Backend getOffBackend() {
|
|
return OFF_BACKEND;
|
|
}
|
|
|
|
public static Backend getDefaultBackend() {
|
|
return DEFAULT_BACKEND;
|
|
}
|
|
|
|
private static Backend findDefaultBackend() {
|
|
// TODO: Automatically select the best default config based on the user's driver
|
|
// TODO: Figure out how this will work if custom backends are registered and without hardcoding the default backends
|
|
return Backends.INDIRECT;
|
|
}
|
|
|
|
private static void chooseBackend() {
|
|
var preferred = FlwConfig.get().getBackend();
|
|
var actual = preferred.findFallback();
|
|
|
|
if (preferred != actual) {
|
|
LOGGER.warn("Flywheel backend fell back from '{}' to '{}'", Backend.REGISTRY.getIdOrThrow(preferred), Backend.REGISTRY.getIdOrThrow(actual));
|
|
}
|
|
|
|
backend = actual;
|
|
}
|
|
|
|
public static String getBackendString() {
|
|
ResourceLocation backendId = Backend.REGISTRY.getId(backend);
|
|
if (backendId == null) {
|
|
return "[unregistered]";
|
|
}
|
|
return backendId.toString();
|
|
}
|
|
|
|
public static void init() {
|
|
CrashReportCallables.registerCrashCallable("Flywheel Backend", BackendManagerImpl::getBackendString);
|
|
}
|
|
|
|
public static void onEndClientResourceReload(EndClientResourceReloadEvent event) {
|
|
if (event.getError().isPresent()) {
|
|
return;
|
|
}
|
|
|
|
chooseBackend();
|
|
VisualizationManagerImpl.resetAll();
|
|
}
|
|
|
|
public static void onReloadLevelRenderer(ReloadLevelRendererEvent event) {
|
|
chooseBackend();
|
|
|
|
ClientLevel level = event.getLevel();
|
|
if (level != null) {
|
|
VisualizationManagerImpl.reset(level);
|
|
}
|
|
}
|
|
}
|