Update #35 - Fixes, improved dynamic lighting

This commit is contained in:
lax1dude
2024-06-16 16:47:12 -07:00
parent ad3579659d
commit 77c6c217f4
42 changed files with 385 additions and 172 deletions

View File

@ -121,20 +121,24 @@ public class EaglerInputStream extends InputStream {
}
public static byte[] inputStreamToBytes(InputStream is) throws IOException {
if (is instanceof EaglerInputStream) {
return ((EaglerInputStream) is).getAsArray();
} else if (is instanceof ByteArrayInputStream) {
byte[] ret = new byte[is.available()];
is.read(ret);
return ret;
} else {
EaglerOutputStream os = new EaglerOutputStream(1024);
byte[] buf = new byte[1024];
int i;
while ((i = is.read(buf)) != -1) {
os.write(buf, 0, i);
try {
if (is instanceof EaglerInputStream) {
return ((EaglerInputStream) is).getAsArray();
} else if (is instanceof ByteArrayInputStream) {
byte[] ret = new byte[is.available()];
is.read(ret);
return ret;
} else {
EaglerOutputStream os = new EaglerOutputStream(1024);
byte[] buf = new byte[1024];
int i;
while ((i = is.read(buf)) != -1) {
os.write(buf, 0, i);
}
return os.toByteArray();
}
return os.toByteArray();
}finally {
is.close();
}
}

View File

@ -10,7 +10,7 @@ public class EaglercraftVersion {
/// Customize these to fit your fork:
public static final String projectForkName = "EaglercraftX";
public static final String projectForkVersion = "u34";
public static final String projectForkVersion = "u35";
public static final String projectForkVendor = "lax1dude";
public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8";
@ -20,7 +20,7 @@ public class EaglercraftVersion {
public static final String projectOriginName = "EaglercraftX";
public static final String projectOriginAuthor = "lax1dude";
public static final String projectOriginRevision = "1.8";
public static final String projectOriginVersion = "u34";
public static final String projectOriginVersion = "u35";
public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace
@ -31,7 +31,7 @@ public class EaglercraftVersion {
public static final boolean enableUpdateService = true;
public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client";
public static final int updateBundlePackageVersionInt = 34;
public static final int updateBundlePackageVersionInt = 35;
public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName;

View File

@ -74,6 +74,8 @@ public interface IClientConfigAdapter {
String getLocalStorageNamespace();
boolean isEnableMinceraft();
IClientConfigAdapterHooks getHooks();
}

View File

@ -66,7 +66,6 @@ import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

View File

@ -3,6 +3,7 @@ package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
import java.io.IOException;
import java.io.InputStream;
import net.lax1dude.eaglercraft.v1_8.IOUtils;
import net.lax1dude.eaglercraft.v1_8.opengl.ImageData;
/**
@ -75,4 +76,15 @@ public class EaglerBitwisePackedTexture {
return img;
}
public static ImageData loadTextureSafe(InputStream is, int alpha) throws IOException {
ImageData bufferedimage;
try {
bufferedimage = loadTexture(is, alpha);
} finally {
IOUtils.closeQuietly(is);
}
return bufferedimage;
}
}

View File

@ -73,7 +73,7 @@ public class PBRTextureMapUtils {
}catch(Throwable t) {
}
try {
return EaglerBitwisePackedTexture.loadTexture(resMgr.getResource(new ResourceLocation("eagler:glsl/deferred/assets_pbr/" + fname + ".ebp")).getInputStream(), 255);
return EaglerBitwisePackedTexture.loadTextureSafe(resMgr.getResource(new ResourceLocation("eagler:glsl/deferred/assets_pbr/" + fname + ".ebp")).getInputStream(), 255);
}catch(Throwable t) {
// dead code because teavm
t.toString();

View File

@ -4,7 +4,6 @@ import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

View File

@ -17,30 +17,21 @@ package net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights;
*/
class DynamicLightInstance {
public final String lightName;
long lastCacheHit = 0l;
double posX;
double posY;
double posZ;
float radius;
public DynamicLightInstance(String lightName) {
this.lightName = lightName;
public DynamicLightInstance() {
}
public void updateLight(double posX, double posY, double posZ, float radius) {
this.lastCacheHit = System.currentTimeMillis();
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
this.radius = radius;
}
public void destroy() {
}
public float getRadiusInWorld() {
return radius;
}

View File

@ -8,7 +8,6 @@ import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionSta
import net.lax1dude.eaglercraft.v1_8.opengl.IExtPipelineCompiler;
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.ShaderSource;
import net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights.program.DynamicLightsExtPipelineShader;
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
import net.minecraft.client.renderer.GLAllocation;
/**

View File

@ -1,10 +1,9 @@
package net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionPipeline;
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
@ -31,14 +30,15 @@ import net.minecraft.util.MathHelper;
public class DynamicLightsStateManager {
static final DynamicLightsPipelineCompiler deferredExtPipeline = new DynamicLightsPipelineCompiler();
static final Map<String, DynamicLightInstance> lightRenderers = new HashMap();
private static List<DynamicLightInstance> lightInstancePool = new ArrayList();
private static int instancePoolIndex = 0;
private static int maxListLengthTracker = 0;
static final List<DynamicLightInstance> lightRenderList = new LinkedList();
static final Matrix4f inverseViewMatrix = new Matrix4f();
static int inverseViewMatrixSerial = 0;
static DynamicLightBucketLoader bucketLoader = null;
static DynamicLightsAcceleratedEffectRenderer accelParticleRenderer = null;
static int lastTotal = 0;
static long renderTimeout = 5000l;
private static long lastTick = 0l;
public static final void enableDynamicLightsRender() {
@ -52,6 +52,9 @@ public class DynamicLightsStateManager {
accelParticleRenderer = new DynamicLightsAcceleratedEffectRenderer();
accelParticleRenderer.initialize();
}
lightRenderList.clear();
instancePoolIndex = 0;
maxListLengthTracker = 0;
}
public static final void bindAcceleratedEffectRenderer(EffectRenderer renderer) {
@ -72,6 +75,8 @@ public class DynamicLightsStateManager {
}
destroyAll();
lightRenderList.clear();
instancePoolIndex = 0;
maxListLengthTracker = 0;
}
public static final boolean isDynamicLightsRender() {
@ -99,21 +104,27 @@ public class DynamicLightsStateManager {
public static final void renderDynamicLight(String lightName, double posX, double posY, double posZ, float radius) {
if(bucketLoader != null) {
DynamicLightInstance dl = lightRenderers.get(lightName);
if(dl == null) {
lightRenderers.put(lightName, dl = new DynamicLightInstance(lightName));
DynamicLightInstance dl;
if(instancePoolIndex < lightInstancePool.size()) {
dl = lightInstancePool.get(instancePoolIndex);
}else {
lightInstancePool.add(dl = new DynamicLightInstance());
}
++instancePoolIndex;
dl.updateLight(posX, posY, posZ, radius);
lightRenderList.add(dl);
}
}
public static final void clearRenderList() {
if(instancePoolIndex > maxListLengthTracker) {
maxListLengthTracker = instancePoolIndex;
}
lightRenderList.clear();
instancePoolIndex = 0;
}
public static final void commitLightSourceBuckets(double renderPosX, double renderPosY, double renderPosZ) {
updateTimers();
lastTotal = lightRenderList.size();
if(bucketLoader != null) {
bucketLoader.clearBuckets();
@ -131,7 +142,8 @@ public class DynamicLightsStateManager {
bucketLoader.setRenderPos(renderPosX, renderPosY, renderPosZ);
bucketLoader.truncateOverflowingBuffers();
}
lightRenderList.clear();
updateTimers();
clearRenderList();
}
public static final void setupInverseViewMatrix() {
@ -141,25 +153,21 @@ public class DynamicLightsStateManager {
private static final void updateTimers() {
long millis = System.currentTimeMillis();
if(millis - lastTick > 1000l) {
if(millis - lastTick > 5000l) {
lastTick = millis;
Iterator<DynamicLightInstance> itr = lightRenderers.values().iterator();
while(itr.hasNext()) {
DynamicLightInstance dl = itr.next();
if(millis - dl.lastCacheHit > renderTimeout) {
dl.destroy();
itr.remove();
if(maxListLengthTracker < (lightInstancePool.size() >> 1)) {
List<DynamicLightInstance> newPool = new ArrayList(Math.max(maxListLengthTracker, 16));
for(int i = 0; i < maxListLengthTracker; ++i) {
newPool.add(lightInstancePool.get(i));
}
lightInstancePool = newPool;
}
maxListLengthTracker = 0;
}
}
public static final void destroyAll() {
Iterator<DynamicLightInstance> itr = lightRenderers.values().iterator();
while(itr.hasNext()) {
itr.next().destroy();
}
lightRenderers.clear();
lightInstancePool = new ArrayList();
}
public static String getF3String() {

View File

@ -1,11 +1,7 @@
package net.lax1dude.eaglercraft.v1_8.opengl.ext.dynamiclights.program;
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.GL_FRAGMENT_SHADER;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.GL_VERTEX_SHADER;
import java.util.ArrayList;
import java.util.List;
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;