Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple changes for dynamic VRAM allocation, and compat with FalseTweaks threaded rendering and OptiFine shaders #57

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(project.enable_lombok.toBoolean()) {
apply plugin: 'io.freefair.lombok'
lombok {
// the version of the lombok plugin we use would use 1.18.16 by default
version = '1.18.30'
version = '1.18.32'
}
}

Expand Down
8 changes: 4 additions & 4 deletions buildscript/forge-1.7.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ ext.publishDir = project.multiproject_structure.toBoolean() ? "${projectDir}/../

def getCommitVersion(){
try {
def commitHashProc = "python3 ${ext.publishDir}/get_version.py".execute()
def commitHashProc = "git describe --always --dirty".execute()
commitHashProc.waitFor()
if(commitHashProc.exitValue() == 0){
def commitHash = commitHashProc.text.trim()

return commitHash
} else {
println commitHashProc.err.text
throw new Exception("get_version.py exited with non-zero return value")
throw new Exception("git describe exited with non-zero return value")
}
} catch(Exception e){
println "Failed to run get_version.py: " + e.getMessage()
println "Failed to get commit version: " + e.getMessage()
}
return "UNKNOWN" // fallback
}
Expand Down
10 changes: 10 additions & 0 deletions project.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ repositories {
maven {
url = "https://mvn.falsepattern.com/releases"
}
maven {
url = "https://mvn.falsepattern.com/stripped"
}
}

dependencies {
compileOnly("com.falsepattern:triangulator-mc1.7.10:1.7.0:api")

compileOnly("com.falsepattern:rple-mc1.7.10:1.0.0-rc8:api")
compileOnly("com.falsepattern:falsetweaks-mc1.7.10:2.7.4:api")

compileOnly("optifine:shadersmod-stripped:1.7.10-hd_u7")

// LWJGL 2
implementation("org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209")
implementation("org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209")
implementation("org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209")
}

runClient {
Expand Down
8 changes: 4 additions & 4 deletions publish/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import java.util.concurrent.TimeUnit

def getCommitVersion(){
try {
def commitHashProc = "python3 ${projectDir}/get_version.py".execute()
def commitHashProc = "git describe --always --dirty".execute()
commitHashProc.waitFor()
if(commitHashProc.exitValue() == 0){
def commitHash = commitHashProc.text.trim()

return commitHash
} else {
println commitHashProc.err.text
throw new Exception("get_version.py exited with non-zero return value")
throw new Exception("git describe exited with non-zero return value")
}
} catch(Exception e){
println "Failed to run get_version.py: " + e.getMessage()
println "Failed to get commit version: " + e.getMessage()
}
return "UNKNOWN" // fallback
}
Expand Down
96 changes: 57 additions & 39 deletions src/main/java/makamys/neodymium/Compat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package makamys.neodymium;

import com.falsepattern.falsetweaks.api.ThreadedChunkUpdates;
import com.falsepattern.triangulator.api.ToggleableTessellator;
import cpw.mods.fml.common.Loader;
import makamys.neodymium.config.Config;
Expand All @@ -8,9 +9,13 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.launchwrapper.Launch;

import org.lwjgl.opengl.GLContext;
import shadersmod.client.Shaders;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

Expand All @@ -22,17 +27,18 @@ public class Compat {

private static boolean wasAdvancedOpenGLEnabled;

private static int notEnoughVRAMAmountMB = -1;

private static boolean IS_RPLE_PRESENT;

private static boolean IS_FALSE_TWEAKS_PRESENT;

private static boolean IS_HODGEPODGE_SPEEDUP_ANIMATIONS_ENABLED;
private static boolean IS_ANGELICA_SPEEDUP_ANIMATIONS_ENABLED;

private static boolean IS_SHADERS_MOD_PRESENT;

private static boolean isShadersEnabled;



public static void init() {
isGL33Supported = GLContext.getCapabilities().OpenGL33;

Expand All @@ -47,16 +53,25 @@ public static void init() {
if (Loader.isModLoaded("falsetweaks")) {
IS_FALSE_TWEAKS_PRESENT = true;
}


try {
if (Launch.classLoader.getClassBytes("shadersmod.client.Shaders") != null) {
IS_SHADERS_MOD_PRESENT = true;
}
} catch (IOException e) {
IS_SHADERS_MOD_PRESENT = false;
}


IS_HODGEPODGE_SPEEDUP_ANIMATIONS_ENABLED = checkIfHodgepodgeSpeedupAnimationsIsEnabled();
IS_ANGELICA_SPEEDUP_ANIMATIONS_ENABLED = checkIfAngelicaSpeedupAnimationsIsEnabled();
LOGGER.debug("speedupAnimations compat fix will " + (isSpeedupAnimationsEnabled() ? "" : "not ") + "be enabled");
}

public static boolean enableVanillaChunkMeshes() {
return Config.enableVanillaChunkMeshes && !isFalseTweaksModPresent();
}

public static boolean keepRenderListLogic() {
return enableVanillaChunkMeshes() || Constants.KEEP_RENDER_LIST_LOGIC;
}
Expand Down Expand Up @@ -94,7 +109,7 @@ private static boolean checkIfHodgepodgeSpeedupAnimationsIsEnabled() {
}
return result;
}

private static boolean checkIfAngelicaSpeedupAnimationsIsEnabled() {
Boolean result = null;
if (Loader.isModLoaded("angelica")) {
Expand Down Expand Up @@ -125,7 +140,15 @@ public static boolean isRPLEModPresent() {
public static boolean isFalseTweaksModPresent() {
return IS_FALSE_TWEAKS_PRESENT;
}


public static Tessellator tessellator() {
if (IS_FALSE_TWEAKS_PRESENT) {
return FalseTweaksCompat.getThreadTessellator();
} else {
return Tessellator.instance;
}
}

public static boolean isSpeedupAnimationsEnabled() {
return IS_HODGEPODGE_SPEEDUP_ANIMATIONS_ENABLED || IS_ANGELICA_SPEEDUP_ANIMATIONS_ENABLED;
}
Expand All @@ -135,22 +158,20 @@ public static boolean isOptiFineShadersEnabled() {
}

public static void updateOptiFineShadersState() {
try {
Class<?> shaders = Class.forName("shadersmod.client.Shaders");
try {
String shaderPack = (String)shaders.getMethod("getShaderPackName").invoke(null);
if(shaderPack != null) {
isShadersEnabled = true;
return;
}
} catch(Exception e) {
LOGGER.warn("Failed to get shader pack name");
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
isShadersEnabled = false;
if (!IS_SHADERS_MOD_PRESENT)
return;

if (Shaders.getShaderPackName() != null) {
isShadersEnabled = true;
}
isShadersEnabled = false;
}

public static boolean isShadersShadowPass() {
if (!IS_SHADERS_MOD_PRESENT)
return false;

return Shaders.isShadowPass;
}

private static void disableTriangulator() {
Expand All @@ -165,9 +186,6 @@ public static void getCompatibilityWarnings(List<Warning> warns, List<Warning> c
if(!isGL33Supported) {
criticalWarns.add(new Warning("OpenGL 3.3 is not supported."));
}
if(detectedNotEnoughVRAM()) {
criticalWarns.add(new Warning("Not enough VRAM"));
}
}

public static boolean hasChanged() {
Expand All @@ -182,18 +200,6 @@ public static boolean hasChanged() {
return changed;
}

public static void onNotEnoughVRAM(int amountMB) {
notEnoughVRAMAmountMB = amountMB;
}

public static void reset() {
notEnoughVRAMAmountMB = -1;
}

private static boolean detectedNotEnoughVRAM() {
return Config.VRAMSize == notEnoughVRAMAmountMB;
}

public static void forceEnableOptiFineDetectionOfFastCraft() {
if(Compat.class.getResource("/fastcraft/Tweaker.class") != null) {
// If OptiFine is present, it's already on the class path at this point, so our virtual jar won't override it.
Expand Down Expand Up @@ -232,7 +238,19 @@ public InputStream getInputStream(String path) {
}

}


//This extra bit of indirection is needed to avoid accidentally trying to load ThreadedChunkUpdates when FalseTweaks
// is not installed.
private static class FalseTweaksCompat {
public static Tessellator getThreadTessellator() {
if (ThreadedChunkUpdates.isEnabled()) {
return ThreadedChunkUpdates.getThreadTessellator();
} else {
return Tessellator.instance;
}
}
}

public static class Warning {
public String text;
public String chatAction;
Expand Down
40 changes: 26 additions & 14 deletions src/main/java/makamys/neodymium/Neodymium.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.List;

import lombok.val;
import makamys.neodymium.renderer.compat.RenderUtil;
import makamys.neodymium.renderer.compat.RenderUtilRPLE;
import makamys.neodymium.renderer.compat.RenderUtilShaderRPLE;
Expand Down Expand Up @@ -69,12 +70,16 @@ public static class ModContainer {
private static World rendererWorld;

public void construct(FMLConstructionEvent event) {
MCLib.init();
if (Config.updateChecker) {
MCLib.init();
}
Compat.init();
}

public void preInit(FMLPreInitializationEvent event) {
MCLibModules.updateCheckAPI.submitModTask(MODID, "@UPDATE_URL@");
if (Config.updateChecker) {
MCLibModules.updateCheckAPI.submitModTask(MODID, "@UPDATE_URL@");
}

if(VERSION.equals("@VERSION@")) {
// Allow using config GUI in dev env
Expand Down Expand Up @@ -108,17 +113,7 @@ private void onPlayerWorldChanged(World newWorld) {
List<Warning> criticalWarns = warnsAndCriticalWarns.getRight();

if(criticalWarns.isEmpty()) {
boolean rple = Compat.isRPLEModPresent();
boolean optiFineShaders = Compat.isOptiFineShadersEnabled();
if (rple && optiFineShaders) {
util = RenderUtilShaderRPLE.INSTANCE;
} else if (optiFineShaders) {
util = RenderUtilShaders.INSTANCE;
} else if (rple) {
util = RenderUtilRPLE.INSTANCE;
} else {
util = RenderUtilVanilla.INSTANCE;
}
updateRenderUtil();
renderer = new NeoRenderer(newWorld);
renderer.hasIncompatibilities = !warns.isEmpty() || !criticalWarns.isEmpty();
}
Expand All @@ -141,7 +136,6 @@ public void onWorldUnload(WorldEvent.Unload event) {
public void onConnectToServer(ClientConnectedToServerEvent event) {
Config.reloadConfig();
ChatUtil.resetShownChatMessages();
Compat.reset();
WarningHelper.reset();
}

Expand Down Expand Up @@ -261,4 +255,22 @@ public static Pair<List<Warning>, List<Warning>> showCompatStatus(boolean status
return Pair.of(warns, criticalWarns);
}

private static void updateRenderUtil() {
val hasRPLE = Compat.isRPLEModPresent();
val hasShaders = Compat.isOptiFineShadersEnabled();

if (hasShaders) {
if (hasRPLE) {
util = RenderUtilShaderRPLE.INSTANCE;
} else {
util = RenderUtilShaders.INSTANCE;
}
} else {
if (hasRPLE) {
util = RenderUtilRPLE.INSTANCE;
} else {
util = RenderUtilVanilla.INSTANCE;
}
}
}
}
11 changes: 7 additions & 4 deletions src/main/java/makamys/neodymium/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class Config {
public static boolean enabled;
@ConfigBoolean(cat="_general", def=false, com="Apply changes made in the config file immediately without having to manually reload the renderer. Off by default because it could potentially cause poor performance on certain platforms.")
public static boolean hotswap;
@ConfigBoolean(cat="_general", def=true, com="Set this to false to disable update checking.")
public static boolean updateChecker;

@ConfigBoolean(cat="render", def=true, com="Don't submit faces for rendering if they are facing away from the camera. Reduces GPU workload at the cost of increasing driver overhead. This will improve the framerate most of the time, but may reduce it if you are not fillrate-limited (such as when playing on a small resolution).")
public static boolean cullFaces;
Expand All @@ -58,14 +60,15 @@ public class Config {
@ConfigBoolean(cat="render", def=false, com="Do fog occlusion even if fog is disabled.")
public static boolean fogOcclusionWithoutFog;

@NeedsReload
@ConfigInt(cat="render", def=512, min=1, max=Integer.MAX_VALUE, com="VRAM buffer size (MB). 512 seems to be a good value on Normal render distance. Increase this if you encounter warnings about the VRAM getting full. Does not affect RAM usage.")
public static int VRAMSize;
@ConfigEnum(cat="render", def="auto", clazz=AutomatableBoolean.class, com="Render fog? Slightly reduces framerate. `auto` means the OpenGL setting will be respected (as set by mods like OptiFine).\nValid values: true, false, auto")
public static AutomatableBoolean renderFog;
@ConfigInt(cat="render", def=Integer.MAX_VALUE, min=0, max=Integer.MAX_VALUE, com="Chunks further away than this distance (in chunks) will not have unaligned quads such as tall grass rendered.")
public static int maxUnalignedQuadDistance;

@ConfigInt(cat="render", def=256,min=16,max=1024,com = "The size of the allocation chunks for opaque geometry (in Megabytes). Requires game restart to apply.")
public static int bufferSizePass0;
@ConfigInt(cat="render", def=64,min=16,max=1024,com = "The size of the allocation chunks for transparent geometry (in Megabytes). Requires game restart to apply.")
public static int bufferSizePass1;

@ConfigBoolean(cat="misc", def=true, com="Replace splash that says 'OpenGL 1.2!' with 'OpenGL 3.3!'. Just for fun.")
public static boolean replaceOpenGLSplash;
@ConfigBoolean(cat="misc", def=false, com="Don't warn about incompatibilities in chat, and activate renderer even in spite of critical ones.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package makamys.neodymium.ducks;

public interface IMixinGameSettings_OptiFine {

public int getOfFogType();

int nd$getOfFogType();
}
7 changes: 0 additions & 7 deletions src/main/java/makamys/neodymium/ducks/ITessellator.java

This file was deleted.

10 changes: 0 additions & 10 deletions src/main/java/makamys/neodymium/ducks/IWorldRenderer.java

This file was deleted.

Loading