Update #45 - Fixed various issues with the client

This commit is contained in:
lax1dude
2024-12-14 20:54:34 -08:00
parent 12535d429f
commit 346047cf24
39 changed files with 571 additions and 208 deletions

View File

@ -464,6 +464,9 @@ public class PlatformRuntime {
@Import(module = "platformRuntime", name = "immediateContinue")
private static native void immediateContinue0();
@Import(module = "platformRuntime", name = "immediateContinueSupported")
public static native boolean immediateContinueSupported();
public static void postCreate() {
}

View File

@ -32,7 +32,7 @@ public class WASMGCBufferAllocator {
public static Address malloc(int size) {
if(size == 0) {
throw new IllegalArgumentException("Tried to allocate 0 bytes!");
return Address.fromInt(0);
}
Address addr;
if(enableBufferOverflowCheck) {
@ -55,11 +55,11 @@ public class WASMGCBufferAllocator {
}
public static Address calloc(int size) {
if(size == 0) {
return Address.fromInt(0);
}
Address addr;
if(enableBufferOverflowCheck) {
if(size == 0) {
throw new OutOfMemoryError("Tried to allocate 0 bytes!");
}
addr = DirectMalloc.calloc(size + 12);
if(addr.toInt() == 0) {
throw new OutOfMemoryError("DirectMalloc returned null pointer!");
@ -87,33 +87,55 @@ public class WASMGCBufferAllocator {
if(tag != ptr.add(size + 8).getInt()) {
throw new RuntimeException("Detected a buffer write overflow");
}
DirectMalloc.free(ptr);
}else {
DirectMalloc.free(ptr);
}
DirectMalloc.free(ptr);
}
}
private static final ByteBuffer ZERO_LENGTH_BYTE_BUFFER = new DirectMallocByteBuffer(Address.fromInt(0), 0, true);
public static ByteBuffer allocateByteBuffer(int size) {
return new DirectMallocByteBuffer(malloc(size), size, true);
if(size != 0) {
return new DirectMallocByteBuffer(malloc(size), size, true);
}else {
return ZERO_LENGTH_BYTE_BUFFER;
}
}
private static final ShortBuffer ZERO_LENGTH_SHORT_BUFFER = new DirectMallocShortBuffer(Address.fromInt(0), 0, true);
public static ShortBuffer allocateShortBuffer(int size) {
return new DirectMallocShortBuffer(malloc(size << 1), size, true);
if(size != 0) {
return new DirectMallocShortBuffer(malloc(size << 1), size, true);
}else {
return ZERO_LENGTH_SHORT_BUFFER;
}
}
private static final IntBuffer ZERO_LENGTH_INT_BUFFER = new DirectMallocIntBuffer(Address.fromInt(0), 0, true);
public static IntBuffer allocateIntBuffer(int size) {
return new DirectMallocIntBuffer(malloc(size << 2), size, true);
if(size != 0) {
return new DirectMallocIntBuffer(malloc(size << 2), size, true);
}else {
return ZERO_LENGTH_INT_BUFFER;
}
}
private static final FloatBuffer ZERO_LENGTH_FLOAT_BUFFER = new DirectMallocFloatBuffer(Address.fromInt(0), 0, true);
public static FloatBuffer allocateFloatBuffer(int size) {
return new DirectMallocFloatBuffer(malloc(size << 2), size, true);
if(size != 0) {
return new DirectMallocFloatBuffer(malloc(size << 2), size, true);
}else {
return ZERO_LENGTH_FLOAT_BUFFER;
}
}
public static void freeByteBuffer(ByteBuffer buffer) {
DirectMallocByteBuffer buf = (DirectMallocByteBuffer)buffer;
if(buf.original) {
WASMGCBufferAllocator.free(buf.address);
free(buf.address);
}else {
throwNotOriginal(buf);
}
@ -122,7 +144,7 @@ public class WASMGCBufferAllocator {
public static void freeShortBuffer(ShortBuffer buffer) {
DirectMallocShortBuffer buf = (DirectMallocShortBuffer)buffer;
if(buf.original) {
WASMGCBufferAllocator.free(buf.address);
free(buf.address);
}else {
throwNotOriginal(buf);
}
@ -131,7 +153,7 @@ public class WASMGCBufferAllocator {
public static void freeIntBuffer(IntBuffer buffer) {
DirectMallocIntBuffer buf = (DirectMallocIntBuffer)buffer;
if(buf.original) {
WASMGCBufferAllocator.free(buf.address);
free(buf.address);
}else {
throwNotOriginal(buf);
}
@ -140,7 +162,7 @@ public class WASMGCBufferAllocator {
public static void freeFloatBuffer(FloatBuffer buffer) {
DirectMallocFloatBuffer buf = (DirectMallocFloatBuffer)buffer;
if(buf.original) {
WASMGCBufferAllocator.free(buf.address);
free(buf.address);
}else {
throwNotOriginal(buf);
}

View File

@ -1,7 +1,6 @@
package net.lax1dude.eaglercraft.v1_8.internal.buffer;
import org.teavm.interop.Address;
import org.teavm.interop.DirectMalloc;
import org.teavm.jso.typedarrays.Float32Array;
import org.teavm.jso.typedarrays.Int16Array;
import org.teavm.jso.typedarrays.Int32Array;

View File

@ -28,6 +28,7 @@ async function entryPoint() {
crashURL = self.__eaglercraftXLoaderContext.getImageURL(2);
faviconURL = self.__eaglercraftXLoaderContext.getImageURL(3);
const args = self.__eaglercraftXLoaderContext.getMainArgs();
delete self.__eaglercraftXLoaderContext;
const isWorker = args[0] === "_worker_process_";
if(!isWorker) {

View File

@ -561,21 +561,39 @@ async function initPlatformInput(inputImports) {
* @return {Promise}
*/
function syncDelay(fpsLimit) {
if(fpsLimit > 0 && fpsLimit < 1000) {
if(fpsLimit > 0 && fpsLimit <= 1000) {
const frameMillis = (1000 / fpsLimit);
if(manualSyncTimer === 0) {
manualSyncTimer = performance.now();
manualSyncTimer = performance.now() + frameMillis;
}else {
const millis = performance.now();
const frameMillis = (1000 / fpsLimit);
var frameTime = millis - manualSyncTimer;
if(frameTime > 2000 || frameTime < 0) {
frameTime = frameMillis;
var millis = performance.now();
var remaining = (manualSyncTimer - millis) | 0;
if(remaining > 0) {
if(!runtimeOpts.useDelayOnSwap && allowImmediateContinue) {
return immediateContinueImpl().then(function() {
var millis0 = performance.now();
var remaining0 = (manualSyncTimer - millis0) | 0;
if(remaining0 > 0) {
return sleepPromise(remaining0).then(function() {
var millis1 = performance.now();
if((manualSyncTimer += frameMillis) < millis1) {
manualSyncTimer = millis1;
}
});
}else if((manualSyncTimer += frameMillis) < millis0) {
manualSyncTimer = millis0;
}
});
}else {
return sleepPromise(remaining).then(function() {
var millis0 = performance.now();
if((manualSyncTimer += frameMillis) < millis0) {
manualSyncTimer = millis0;
}
});
}
}else if((manualSyncTimer += frameMillis) < millis) {
manualSyncTimer = millis;
}else {
manualSyncTimer += frameMillis;
}
if(frameTime >= 0 && frameTime < frameMillis) {
return sleepPromise(frameMillis - frameTime);
}
}
}else {

View File

@ -199,6 +199,13 @@ function swapDelayImpl() {
eagruntimeImpl.platformRuntime["immediateContinue"] = new WebAssembly.Suspending(immediateContinueImpl);
/**
* @return {boolean}
*/
eagruntimeImpl.platformRuntime["immediateContinueSupported"] = function() {
return allowImmediateContinue;
};
/**
* @param {number} id
* @param {string} str