Merge remote-tracking branch 'origin/1.18/dev' into 1.18/fabric/dev

Conflicts:
	build.gradle
	gradle.properties
	src/main/java/com/jozufozu/flywheel/Flywheel.java
	src/main/java/com/jozufozu/flywheel/backend/Backend.java
	src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java
	src/main/java/com/jozufozu/flywheel/config/FlwCommands.java
	src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java
	src/main/java/com/jozufozu/flywheel/core/vertex/BlockVertexList.java
	src/main/java/com/jozufozu/flywheel/mixin/FrustumMixin.java
	src/main/resources/META-INF/mods.toml
This commit is contained in:
PepperCode1 2022-07-16 21:00:15 -07:00
commit 473b1af5c6
126 changed files with 679 additions and 471 deletions

View file

@ -59,6 +59,8 @@ body:
label: Mod Version
description: The version of the mod you were using when the bug occured
options:
- "0.6.4"
- "0.6.3"
- "0.6.2"
- "0.6.1"
- "0.6.0"

View file

@ -7,11 +7,10 @@ plugins {
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false');
ext.buildNumber = System.getenv('BUILD_NUMBER')
if (buildNumber == null) buildNumber = 'custom'
version = "${mc_update_version}-${mod_version}" + (dev ? ".${buildNumber}" : '')
group = 'com.jozufozu.flywheel'
archivesBaseName = 'flywheel-fabric'
archivesBaseName = "flywheel-fabric-${artifact_minecraft_version}"
version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '')
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
@ -41,6 +40,13 @@ repositories {
maven {
url 'https://maven.vram.io'
}
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
dependencies {
@ -57,12 +63,12 @@ dependencies {
modCompileOnly 'curse.maven:starlight-521783:3667443'
modCompileOnly 'maven.modrinth:iris:1.18.x-v1.2.2'
modCompileOnly 'maven.modrinth:iris:1.18.x-v1.2.5'
modCompileOnly 'maven.modrinth:sodium:mc1.18.2-0.4.1'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
modCompileOnly 'maven.modrinth:indium:1.0.2+mc1.18.2'
modCompileOnly 'io.vram:frex-fabric-mc118:6.0.242'
modCompileOnly 'maven.modrinth:indium:1.0.6+mc1.18.2'
modCompileOnly 'io.vram:frex-fabric-mc118:6.0.263'
}
processResources {
@ -76,35 +82,7 @@ processResources {
tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {
from('LICENSE') {
rename { "${it}_${archivesBaseName}" }
}
}
// Example for how to get properties into the manifest for reading by the runtime..
jar {
manifest {
attributes([
'Specification-Title' : 'flywheel',
//'Specification-Vendor': 'flywheel authors',
'Specification-Version' : '1', // We are version 1 of ourselves
'Implementation-Title' : project.name,
'Implementation-Version' : project.version,
//'Implementation-Vendor': 'flywheel authors',
'MixinConfigs' : 'flywheel.mixins.json',
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
javadoc {
@ -113,24 +91,40 @@ javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
}
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
archiveClassifier.set('javadoc')
jar {
manifest {
attributes([
'Specification-Title' : 'flywheel',
//'Specification-Vendor': 'flywheel authors',
'Specification-Version' : '1', // We are version 1 of ourselves
'Implementation-Title' : project.jar.baseName,
'Implementation-Version' : project.jar.archiveVersion,
//'Implementation-Vendor': 'flywheel authors',
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'MixinConfigs' : 'flywheel.mixins.json'
])
}
}
artifacts {
archives remapJar, sourcesJar, javadocJar
java {
withSourcesJar()
withJavadocJar()
}
void addLicense(jarTask) {
jarTask.from('LICENSE.md') {
rename '(.*)\\.(.*)', '$1_' + archivesBaseName + '.$2'
}
}
addLicense(jar)
publishing {
tasks.publish.dependsOn 'build'
publications {
mavenJava(MavenPublication) {
artifact remapJar
artifact(sourcesJar) {
builtBy remapSourcesJar
}
artifact javadocJar
artifactId = archivesBaseName
from components.java
}
}

View file

@ -1,3 +1,16 @@
0.6.4:
Fixes
- Fix shader detection with oculus
Technical/API
- LightUpdater is simplified to increase reliability and reflect how it is actually used
- ModelUtil is superseded by model builders, to be improved more in 0.7.0
- VertexLists now copy input buffers to reduce memory usage
0.6.3:
Technical/API
- Light updates are now processed in parallel.
- The light updater is now more selective of the levels it processes, fixing a memory leak.
0.6.2:
Update to 1.18.2

View file

@ -2,16 +2,17 @@ org.gradle.jvmargs = -Xmx3G
org.gradle.daemon = false
# mod version info
mod_version = 0.6.3
mc_update_version = 1.18
mod_version = 0.6.4
artifact_minecraft_version = 1.18.2
minecraft_version = 1.18.2
loader_version = 0.13.3
fabric_version = 0.48.0+1.18.2
loader_version = 0.14.8
fabric_version = 0.56.1+1.18.2
# build dependency versions
loom_version = 0.10-SNAPSHOT
loom_version = 0.12-SNAPSHOT
cursegradle_version = 1.4.0
parchment_version = 2022.03.13
parchment_version = 2022.07.10
# curseforge info
projectId = 486392

Binary file not shown.

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

10
gradlew vendored
View file

@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#

View file

@ -5,6 +5,7 @@ import org.slf4j.Logger;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.Loader;
import com.jozufozu.flywheel.backend.RenderWork;
import com.jozufozu.flywheel.backend.ShadersModHandler;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.core.Contexts;
@ -51,6 +52,7 @@ public class Flywheel implements ClientModInitializer {
FlwConfig.init();
ShadersModHandler.init();
Backend.init();
FlywheelEvents.RELOAD_RENDERERS.register(ProgramCompiler::invalidateAll);

View file

@ -7,8 +7,8 @@ import org.slf4j.Logger;
import com.jozufozu.flywheel.api.FlywheelWorld;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.jozufozu.flywheel.backend.instancing.ParallelTaskEngine;
import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.config.BackendType;
import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.core.shader.ProgramSpec;
import com.mojang.logging.LogUtils;
@ -96,7 +96,7 @@ public class Backend {
BackendType preferredChoice = FlwConfig.get()
.getBackendType();
boolean usingShaders = IrisShaderHandler.isShaderPackInUse();
boolean usingShaders = ShadersModHandler.isShaderPackInUse();
boolean canUseEngine = switch (preferredChoice) {
case OFF -> true;
case BATCHING -> !usingShaders;

View file

@ -1,51 +0,0 @@
package com.jozufozu.flywheel.backend;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.api.v0.IrisApi;
public class IrisShaderHandler {
public static final boolean IRIS_LOADED = FabricLoader.getInstance().isModLoaded("iris");
private static final InternalHandler HANDLER;
static {
if (IRIS_LOADED) {
HANDLER = new InternalHandlerImpl();
} else {
HANDLER = new InternalHandler() {};
}
}
private IrisShaderHandler() {
}
public static boolean isShaderPackInUse() {
return HANDLER.isShaderPackInUse();
}
public static boolean isRenderingShadowPass() {
return HANDLER.isRenderingShadowPass();
}
private interface InternalHandler {
default boolean isShaderPackInUse() {
return false;
};
default boolean isRenderingShadowPass() {
return false;
};
}
private static class InternalHandlerImpl implements InternalHandler {
@Override
public boolean isShaderPackInUse() {
return IrisApi.getInstance().isShaderPackInUse();
};
@Override
public boolean isRenderingShadowPass() {
return IrisApi.getInstance().isRenderingShadowPass();
};
}
}

View file

@ -93,10 +93,8 @@ public class Loader {
Collection<ResourceLocation> programSpecs = manager.listResources(PROGRAM_DIR, s -> s.endsWith(".json"));
for (ResourceLocation location : programSpecs) {
try {
Resource file = manager.getResource(location);
String s = StringUtil.readToString(file.getInputStream());
try (Resource resource = manager.getResource(location)) {
String s = StringUtil.readToString(resource.getInputStream());
ResourceLocation specName = ResourceUtil.trim(location, PROGRAM_DIR, ".json");

View file

@ -0,0 +1,179 @@
package com.jozufozu.flywheel.backend;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.function.BooleanSupplier;
import javax.annotation.Nullable;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.culling.Frustum;
public final class ShadersModHandler {
public static final String OPTIFINE_ROOT_PACKAGE = "net.optifine";
public static final String SHADER_PACKAGE = "net.optifine.shaders";
private static final boolean isIrisLoaded;
private static final boolean isOptifineInstalled;
private static final InternalHandler internalHandler;
static {
Package optifinePackage = Package.getPackage(OPTIFINE_ROOT_PACKAGE);
isOptifineInstalled = optifinePackage != null;
isIrisLoaded = FabricLoader.getInstance()
.isModLoaded("iris");
// optfine and oculus are assumed to be mutually exclusive
if (isOptifineInstalled) {
Backend.LOGGER.info("Optifine detected.");
internalHandler = new Optifine();
} else if (isIrisLoaded) {
Backend.LOGGER.info("Iris detected.");
internalHandler = new Iris();
} else {
Backend.LOGGER.info("No shaders mod detected.");
internalHandler = new InternalHandler() {};
}
}
private ShadersModHandler() {
}
public static void init() {
// noop, load statics
}
public static boolean isOptifineInstalled() {
return isOptifineInstalled;
}
public static boolean isIrisLoaded() {
return isIrisLoaded;
}
public static boolean isShaderPackInUse() {
return internalHandler.isShaderPackInUse();
}
public static boolean isRenderingShadowPass() {
return internalHandler.isRenderingShadowPass();
}
private interface InternalHandler {
default boolean isShaderPackInUse() {
return false;
};
default boolean isRenderingShadowPass() {
return false;
};
}
// simple, lovely api calls
private static class Iris implements InternalHandler {
@Override
public boolean isShaderPackInUse() {
return IrisApi.getInstance()
.isShaderPackInUse();
}
@Override
public boolean isRenderingShadowPass() {
return IrisApi.getInstance()
.isRenderingShadowPass();
}
}
// evil reflection
private static class Optifine implements InternalHandler {
private final BooleanSupplier shadersEnabledSupplier;
private final BooleanSupplier shadowPassSupplier;
private final FrustumConstructor shadowFrustumConstructor;
Optifine() {
shadersEnabledSupplier = createShadersEnabledSupplier();
shadowPassSupplier = createShadowPassSupplier();
shadowFrustumConstructor = createShadowFrustumConstructor();
}
@Override
public boolean isShaderPackInUse() {
return shadersEnabledSupplier.getAsBoolean();
}
@Override
public boolean isRenderingShadowPass() {
return shadowPassSupplier.getAsBoolean();
}
@Nullable
public Frustum createShadowFrustum(Camera camera, float partialTicks) {
var frustum = shadowFrustumConstructor.create(camera, partialTicks);
if (frustum != null) {
var position = camera.getPosition();
frustum.prepare(position.x, position.y, position.z);
}
return frustum;
}
private static FrustumConstructor createShadowFrustumConstructor() {
try {
Class<?> ofShaders = Class.forName("net.optifine.shaders.ShadersRender");
Method method = ofShaders.getDeclaredMethod("makeShadowFrustum", Camera.class, Float.TYPE);
method.setAccessible(true);
return (cam, pt) -> {
try {
return (Frustum) method.invoke(null, cam, pt);
} catch (Exception ignored) {
return null;
}
};
} catch (Exception ignored) {
return ($, $$) -> null;
}
}
private static BooleanSupplier createShadowPassSupplier() {
try {
Class<?> ofShaders = Class.forName("net.optifine.shaders.Shaders");
Field field = ofShaders.getDeclaredField("isShadowPass");
field.setAccessible(true);
return () -> {
try {
return field.getBoolean(null);
} catch (IllegalAccessException ignored) {
return false;
}
};
} catch (Exception ignored) {
return () -> false;
}
}
private static BooleanSupplier createShadersEnabledSupplier() {
try {
Class<?> ofShaders = Class.forName("net.optifine.shaders.Shaders");
Field field = ofShaders.getDeclaredField("shaderPackLoaded");
field.setAccessible(true);
return () -> {
try {
return field.getBoolean(null);
} catch (IllegalAccessException ignored) {
return false;
}
};
} catch (Exception ignored) {
return () -> false;
}
}
@FunctionalInterface
public interface FrustumConstructor {
@Nullable
Frustum create(Camera camera, float partialTicks);
}
}
}

View file

@ -10,8 +10,6 @@ import com.jozufozu.flywheel.api.instance.TickableInstance;
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager;
import com.jozufozu.flywheel.core.materials.FlatLit;
import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.ListenerStatus;
import com.jozufozu.flywheel.util.box.ImmutableBox;
import net.minecraft.core.BlockPos;
@ -26,6 +24,7 @@ public abstract class AbstractInstance implements Instance, LightListener {
protected final MaterialManager materialManager;
public final Level world;
protected boolean removed = false;
public AbstractInstance(MaterialManager materialManager, Level world) {
this.materialManager = materialManager;
@ -39,10 +38,19 @@ public abstract class AbstractInstance implements Instance, LightListener {
}
public final void removeAndMark() {
if (removed) {
return;
}
remove();
removed = true;
}
/**
* Free any acquired resources.
*/
public abstract void remove();
protected abstract void remove();
/**
* Update instance data here. Good for when data doesn't change very often and when animations are GPU based.
@ -78,12 +86,12 @@ public abstract class AbstractInstance implements Instance, LightListener {
}
@Override
public ListenerStatus status() {
return ListenerStatus.OKAY;
public boolean isListenerInvalid() {
return removed;
}
@Override
public void onLightUpdate(LightProvider world, LightLayer type, ImmutableBox changed) {
public void onLightUpdate(LightLayer type, ImmutableBox changed) {
updateLight();
}
@ -103,4 +111,5 @@ public abstract class AbstractInstance implements Instance, LightListener {
models.forEach(model -> model.setBlockLight(block)
.setSkyLight(sky));
}
}

View file

@ -260,7 +260,7 @@ public abstract class InstanceManager<T> implements InstancingEngine.OriginShift
}
public void invalidate() {
instances.values().forEach(AbstractInstance::remove);
instances.values().forEach(AbstractInstance::removeAndMark);
instances.clear();
dynamicInstances.clear();
tickableInstances.clear();
@ -314,7 +314,7 @@ public abstract class InstanceManager<T> implements InstancingEngine.OriginShift
}
protected void removeInternal(T obj, AbstractInstance instance) {
instance.remove();
instance.removeAndMark();
instances.remove(obj);
dynamicInstances.remove(obj);
tickableInstances.remove(obj);

View file

@ -7,7 +7,7 @@ import com.jozufozu.flywheel.api.InstanceData;
import com.jozufozu.flywheel.api.MaterialGroup;
import com.jozufozu.flywheel.api.struct.Batched;
import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.backend.IrisShaderHandler;
import com.jozufozu.flywheel.backend.ShadersModHandler;
import com.jozufozu.flywheel.backend.instancing.BatchDrawingTracker;
import com.jozufozu.flywheel.backend.instancing.TaskEngine;
import com.jozufozu.flywheel.backend.model.DirectVertexConsumer;
@ -56,7 +56,7 @@ public class BatchedMaterialGroup implements MaterialGroup {
for (BatchedMaterial<?> material : materials.values()) {
for (CPUInstancer<?> instancer : material.models.values()) {
instancer.sbb.context.outputColorDiffuse = !consumer.hasOverlay() && !IrisShaderHandler.isShaderPackInUse();
instancer.sbb.context.outputColorDiffuse = !consumer.hasOverlay() && !ShadersModHandler.isShaderPackInUse();
instancer.submitTasks(stack, pool, consumer);
}
}

View file

@ -6,8 +6,7 @@ import com.jozufozu.flywheel.api.instance.TickableInstance;
import com.jozufozu.flywheel.backend.instancing.AbstractInstance;
import com.jozufozu.flywheel.backend.instancing.blockentity.BlockEntityInstanceManager;
import com.jozufozu.flywheel.light.LightListener;
import com.jozufozu.flywheel.light.LightProvider;
import com.jozufozu.flywheel.light.MovingListener;
import com.jozufozu.flywheel.light.TickingLightListener;
import com.jozufozu.flywheel.util.box.GridAlignedBB;
import com.mojang.math.Vector3f;
@ -34,7 +33,7 @@ import net.minecraft.world.phys.Vec3;
*
* @param <E> The type of {@link Entity} your class is an instance of.
*/
public abstract class EntityInstance<E extends Entity> extends AbstractInstance implements LightListener, MovingListener {
public abstract class EntityInstance<E extends Entity> extends AbstractInstance implements LightListener, TickingLightListener {
protected final E entity;
protected final GridAlignedBB bounds;
@ -51,7 +50,7 @@ public abstract class EntityInstance<E extends Entity> extends AbstractInstance
}
@Override
public boolean update(LightProvider provider) {
public boolean tickLightListener() {
AABB boundsNow = entity.getBoundingBox();
if (bounds.sameAs(boundsNow)) return false;

View file

@ -12,7 +12,6 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
@ -104,17 +103,7 @@ public final class FlwCommands {
return switch (type) {
case OFF -> new TextComponent("Disabled Flywheel").withStyle(ChatFormatting.RED);
case INSTANCING -> new TextComponent("Using Instancing Engine").withStyle(ChatFormatting.GREEN);
case BATCHING -> {
MutableComponent msg = new TextComponent("Using Batching Engine").withStyle(ChatFormatting.GREEN);
if (FabricLoader.getInstance()
.isModLoaded("create")) {
// FIXME: batching engine contraption lighting issues
msg.append(new TextComponent("\nWARNING: May cause issues with Create Contraptions").withStyle(ChatFormatting.RED));
}
yield msg;
}
case BATCHING -> new TextComponent("Using Batching Engine").withStyle(ChatFormatting.GREEN);
};
}

Some files were not shown because too many files have changed in this diff Show more