2021-08-11 00:20:51 +02:00
|
|
|
package com.jozufozu.flywheel.backend;
|
|
|
|
|
|
|
|
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
2022-01-13 06:25:03 +01:00
|
|
|
import com.jozufozu.flywheel.core.GameStateRegistry;
|
2021-08-11 00:20:51 +02:00
|
|
|
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
|
2022-01-13 06:25:03 +01:00
|
|
|
import com.jozufozu.flywheel.core.source.Resolver;
|
|
|
|
import com.jozufozu.flywheel.core.source.ShaderSources;
|
2021-08-11 00:20:51 +02:00
|
|
|
import com.jozufozu.flywheel.event.GatherContextEvent;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
2021-09-15 08:45:29 +02:00
|
|
|
import net.minecraft.client.multiplayer.ClientLevel;
|
|
|
|
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
|
|
|
import net.minecraft.server.packs.resources.ResourceManager;
|
2021-09-15 09:26:51 +02:00
|
|
|
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
2021-08-11 00:20:51 +02:00
|
|
|
import net.minecraftforge.fml.ModLoader;
|
2021-09-15 09:26:51 +02:00
|
|
|
|
2021-08-11 00:20:51 +02:00
|
|
|
/**
|
|
|
|
* The main entity for loading shaders.
|
|
|
|
*
|
|
|
|
* <p>
|
2021-09-15 09:26:51 +02:00
|
|
|
* This class is responsible for invoking the loading, parsing, and compilation stages.
|
2021-08-11 00:20:51 +02:00
|
|
|
* </p>
|
|
|
|
*/
|
2021-09-15 09:26:51 +02:00
|
|
|
public class Loader implements ResourceManagerReloadListener {
|
2021-08-13 20:23:09 +02:00
|
|
|
private boolean firstLoad = true;
|
|
|
|
|
2022-01-13 06:25:03 +01:00
|
|
|
Loader() {
|
2021-08-11 02:39:11 +02:00
|
|
|
// Can be null when running datagenerators due to the unfortunate time we call this
|
|
|
|
Minecraft minecraft = Minecraft.getInstance();
|
|
|
|
if (minecraft != null) {
|
2021-09-15 08:45:29 +02:00
|
|
|
ResourceManager manager = minecraft.getResourceManager();
|
|
|
|
if (manager instanceof ReloadableResourceManager) {
|
|
|
|
((ReloadableResourceManager) manager).registerReloadListener(this);
|
2021-08-11 02:39:11 +02:00
|
|
|
}
|
2021-08-11 00:20:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-09-15 09:26:51 +02:00
|
|
|
public void onResourceManagerReload(ResourceManager manager) {
|
2022-01-13 06:25:03 +01:00
|
|
|
Backend.refresh();
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-01-13 06:25:03 +01:00
|
|
|
GameStateRegistry._clear();
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2021-12-23 06:35:48 +01:00
|
|
|
Resolver.INSTANCE.invalidate();
|
|
|
|
ModLoader.get()
|
2022-01-13 06:25:03 +01:00
|
|
|
.postEvent(new GatherContextEvent(firstLoad));
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2021-12-23 06:35:48 +01:00
|
|
|
ShaderSources sources = new ShaderSources(manager);
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-01-08 07:46:29 +01:00
|
|
|
Resolver.INSTANCE.run(sources);
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2022-01-08 07:46:29 +01:00
|
|
|
Backend.LOGGER.info("Loaded all shader sources.");
|
2021-08-11 00:20:51 +02:00
|
|
|
|
2021-12-23 06:35:48 +01:00
|
|
|
ClientLevel world = Minecraft.getInstance().level;
|
2021-12-31 00:15:25 +01:00
|
|
|
if (Backend.canUseInstancing(world)) {
|
2021-12-23 06:35:48 +01:00
|
|
|
// TODO: looks like it might be good to have another event here
|
|
|
|
InstancedRenderDispatcher.resetInstanceWorld(world);
|
|
|
|
CrumblingRenderer.reset();
|
2021-08-11 00:20:51 +02:00
|
|
|
}
|
2021-09-15 09:26:51 +02:00
|
|
|
|
|
|
|
firstLoad = false;
|
2021-08-11 00:20:51 +02:00
|
|
|
}
|
|
|
|
}
|