Update #49 - Fix unclosable pause menu glitch

This commit is contained in:
lax1dude
2025-01-26 15:23:47 -08:00
parent ed97c1ac00
commit ad900211dd
47 changed files with 1051 additions and 274 deletions

View File

@ -23,6 +23,7 @@ import org.teavm.jso.typedarrays.Uint8ClampedArray;
import net.lax1dude.eaglercraft.v1_8.Base64;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCDirectArrayConverter;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.BetterJSStringConverter;
@ -242,11 +243,11 @@ public class PlatformApplication {
}
public static void downloadFileWithName(String str, byte[] dat) {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(dat);
MemoryStack.push();
try {
downloadFileWithNameTeaVM(BetterJSStringConverter.stringToJS(str), WASMGCBufferAllocator.getUnsignedByteBufferView(buf));
downloadFileWithNameTeaVM(BetterJSStringConverter.stringToJS(str), WASMGCDirectArrayConverter.byteArrayToStackU8Array(dat));
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
}

View File

@ -16,6 +16,7 @@ import org.teavm.jso.typedarrays.Uint8ClampedArray;
import net.lax1dude.eaglercraft.v1_8.EaglerInputStream;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCDirectArrayConverter;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.BetterJSStringConverter;
@ -163,12 +164,13 @@ public class PlatformAssets {
}
public static ImageData loadImageFile(byte[] data, String mime) {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(data);
JSImageLoadResult asyncResult;
MemoryStack.push();
try {
asyncResult = loadImageFile0(WASMGCBufferAllocator.getUnsignedByteBufferView(buf), BetterJSStringConverter.stringToJS(mime));
asyncResult = loadImageFile0(WASMGCDirectArrayConverter.byteArrayToStackU8Array(data),
BetterJSStringConverter.stringToJS(mime));
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
if(asyncResult == null) {
@ -178,15 +180,17 @@ public class PlatformAssets {
int w = asyncResult.getWidth();
int h = asyncResult.getHeight();
int len = w * h;
int len2 = len << 2;
ByteBuffer dataDest = PlatformRuntime.allocateByteBuffer(len << 2);
MemoryStack.push();
try {
loadImageFile1(asyncResult, WASMGCBufferAllocator.getUnsignedClampedByteBufferView(dataDest));
Address dataDest = MemoryStack.malloc(len2);
loadImageFile1(asyncResult, WASMGCBufferAllocator.getUnsignedClampedByteBufferView0(dataDest, len2));
int[] pixelsArray = new int[len];
copyPixelArrayFast(pixelsArray, WASMGCBufferAllocator.getByteBufferAddress(dataDest), len);
copyPixelArrayFast(pixelsArray, dataDest, len2);
return new ImageData(w, h, pixelsArray, true);
}finally {
PlatformRuntime.freeByteBuffer(dataDest);
MemoryStack.pop();
}
}
@ -208,7 +212,7 @@ public class PlatformAssets {
@Unmanaged
private static void copyPixelArrayFast(int[] pixelsArray, Address addr, int count) {
Address addrEnd = addr.add(count << 2);
Address addrEnd = addr.add(count);
int dstOffset = 0;
while(addr.isLessThan(addrEnd)) {
pixelsArray[dstOffset] = addr.getInt();

View File

@ -23,8 +23,7 @@ import org.teavm.jso.webaudio.MediaStreamAudioDestinationNode;
import org.teavm.jso.webaudio.PannerNode;
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCDirectArrayConverter;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.BetterJSStringConverter;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.JOrbisAudioBufferDecoder;
@ -79,16 +78,16 @@ public class PlatformAudio {
logger.info("Note: Using embedded JOrbis OGG decoder");
}else {
byte[] fileData = EagRuntime.getRequiredResourceBytes("/assets/eagler/audioctx_test_ogg.dat");
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(fileData);
MemoryStack.push();
try {
AudioBuffer audioBuffer = decodeAudioBrowserAsync(WASMGCBufferAllocator.getUnsignedByteBufferView(buf),
AudioBuffer audioBuffer = decodeAudioBrowserAsync(WASMGCDirectArrayConverter.byteArrayToStackU8Array(fileData),
BetterJSStringConverter.stringToJS("audioctx_test_ogg.dat"));
if(audioBuffer != null && audioBuffer.getLength() > 0) {
oggSupport = true;
}
}catch(Throwable t) {
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
if(!oggSupport) {
logger.error("OGG file support detected as false! Using embedded JOrbis OGG decoder");
@ -294,27 +293,17 @@ public class PlatformAudio {
if(data == null) {
return null;
}
if(oggSupport) {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(data);
if(oggSupport || !(data.length > 4 && data[0] == (byte) 0x4F && data[1] == (byte) 0x67 && data[2] == (byte) 0x67
&& data[3] == (byte) 0x53)) {
MemoryStack.push();
try {
return decodeAudioBrowserAsync(WASMGCBufferAllocator.getUnsignedByteBufferView(buf),
return decodeAudioBrowserAsync(WASMGCDirectArrayConverter.byteArrayToStackU8Array(data),
BetterJSStringConverter.stringToJS(errorFileName));
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
}else {
if (data.length > 4 && data[0] == (byte) 0x4F && data[1] == (byte) 0x67 && data[2] == (byte) 0x67
&& data[3] == (byte) 0x53) {
return JOrbisAudioBufferDecoder.decodeAudioJOrbis(data, errorFileName);
}else {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(data);
try {
return decodeAudioBrowserAsync(WASMGCBufferAllocator.getUnsignedByteBufferView(buf),
BetterJSStringConverter.stringToJS(errorFileName));
}finally {
PlatformRuntime.freeByteBuffer(buf);
}
}
return JOrbisAudioBufferDecoder.decodeAudioJOrbis(data, errorFileName);
}
}

View File

@ -382,6 +382,7 @@ public class PlatformInput {
int posY = windowHeight - (int)(obj.getPosY() * windowDPI) - 1;
switch(type) {
case EVENT_MOUSE_DOWN: {
handleWindowFocus();
int button = obj.getButton();
button = button == 1 ? 2 : (button == 2 ? 1 : button);
if(button >= 0 && button < buttonStates.length) {
@ -466,6 +467,7 @@ public class PlatformInput {
JSTouchEvent obj = evt.getEventObj();
switch(obj.getEventType()) {
case EVENT_TOUCH_START:
handleWindowFocus();
touchEvents.add(currentTouchState = SortedTouchEvent.createTouchEvent(EnumTouchEvent.TOUCHSTART, obj.getChangedTouches(),
obj.getTargetTouches(), touchUIDMapperCreate, windowHeight, windowDPI));
break;
@ -598,6 +600,14 @@ public class PlatformInput {
}
}
private static void handleWindowFocus() {
if(!isWindowFocused) {
PlatformRuntime.logger.warn("Detected mouse input while the window was not focused, setting the window focused so the client doesn't pause");
isWindowFocused = true;
}
isMouseOverWindow = true;
}
public static int getWindowWidth() {
return windowWidth;
}

View File

@ -12,8 +12,7 @@ import org.teavm.jso.core.JSArray;
import org.teavm.jso.core.JSString;
import org.teavm.jso.typedarrays.Uint8Array;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCDirectArrayConverter;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.BetterJSStringConverter;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
@ -67,11 +66,11 @@ public class PlatformWebRTC {
public static native void clientLANCloseConnection();
public static void clientLANSendPacket(byte[] pkt) {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(pkt);
MemoryStack.push();
try {
clientLANSendPacket0(WASMGCBufferAllocator.getUnsignedByteBufferView(buf));
clientLANSendPacket0(WASMGCDirectArrayConverter.byteArrayToStackU8Array(pkt));
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
}
@ -254,11 +253,11 @@ public class PlatformWebRTC {
private void writePacket(byte[] pkt) {
if(dead) return;
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(pkt);
MemoryStack.push();
try {
handle.writePacket(WASMGCBufferAllocator.getUnsignedByteBufferView(buf));
handle.writePacket(WASMGCDirectArrayConverter.byteArrayToStackU8Array(pkt));
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
}

View File

@ -14,8 +14,7 @@ import org.teavm.jso.typedarrays.ArrayBuffer;
import org.teavm.jso.typedarrays.Uint8Array;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime.JSEagRuntimeEvent;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCDirectArrayConverter;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.BetterJSStringConverter;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
@ -224,12 +223,12 @@ public class PlatformWebView {
sendStringMessage(BetterJSStringConverter.stringToJS(currentMessageChannelName),
BetterJSStringConverter.stringToJS(new String(packet.data, StandardCharsets.UTF_8)));
}else if(packet.type == SPacketWebViewMessageV4EAG.TYPE_BINARY) {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(packet.data);
MemoryStack.push();
try {
sendBinaryMessage(BetterJSStringConverter.stringToJS(currentMessageChannelName),
WASMGCBufferAllocator.getUnsignedByteBufferView(buf));
WASMGCDirectArrayConverter.byteArrayToStackU8Array(packet.data));
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
}
}else {
@ -342,12 +341,12 @@ public class PlatformWebView {
JSWebViewOptions opts = makeOptions(isBlob ? 1 : 0, BetterJSStringConverter.stringToJS(options.fallbackTitle),
options.scriptEnabled, options.strictCSPEnable, options.serverMessageAPIEnabled);
if(isBlob) {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(options.blob);
MemoryStack.push();
try {
opts.setBlob(WASMGCBufferAllocator.getUnsignedByteBufferView(buf));
opts.setBlob(WASMGCDirectArrayConverter.byteArrayToStackU8Array(options.blob));
beginShowing0(state, opts, x, y, w, h);
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
}else {
opts.setURI(BetterJSStringConverter.stringToJS(options.url.toString()));

View File

@ -0,0 +1,131 @@
package net.lax1dude.eaglercraft.v1_8.internal.buffer;
import org.teavm.interop.Address;
import org.teavm.interop.DirectMalloc;
/**
* Copyright (c) 2025 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
public class MemoryStack {
public static final int STACK_SIZE = 2 * 1024 * 1024;
public static final int MALLOC_THRESHOLD = 512 * 1024;
public static final int RESERVE_SIZE = 64 * 1024;
public static final Address stackBase;
public static final Address stackMax;
private static Address stackBottomPointer;
private static Address stackTopPointer;
static {
stackBase = DirectMalloc.malloc(STACK_SIZE + 16);
if(stackBase.toInt() == 0) {
throw new IllegalStateException("Could not allocate MemoryStack of size " + STACK_SIZE);
}
stackMax = stackBase.add(STACK_SIZE);
stackBottomPointer = stackBase;
stackBottomPointer.putInt(0);
stackBottomPointer.add(4).putInt(0);
stackTopPointer = stackBottomPointer.add(8);
}
public static void push() {
stackTopPointer.putAddress(stackBottomPointer);
stackTopPointer.add(4).putInt(0);
stackBottomPointer = stackTopPointer;
stackTopPointer = stackBottomPointer.add(8);
if(stackTopPointer.toInt() > stackMax.toInt()) {
throw new StackOverflowError();
}
}
public static void pop() {
stackTopPointer = stackBottomPointer;
stackBottomPointer = stackTopPointer.getAddress();
Address cleanup = stackTopPointer.add(4).getAddress();
while(cleanup.toInt() != 0) {
WASMGCBufferAllocator.free(cleanup.getAddress());
cleanup = cleanup.add(4).getAddress();
}
if(stackBottomPointer.toInt() == 0) {
throw new IllegalStateException("MemoryStack underflow");
}
}
public static Address malloc(int length) {
if(length > MALLOC_THRESHOLD || (stackMax.toInt() - stackTopPointer.toInt()) < RESERVE_SIZE) {
if(stackTopPointer.toInt() + 8 > stackMax.toInt()) {
throw new StackOverflowError();
}
Address malloced = WASMGCBufferAllocator.malloc(length);
Address cleanup = stackBottomPointer.add(4).getAddress();
stackTopPointer.putAddress(malloced);
stackTopPointer.add(4).putAddress(cleanup);
stackBottomPointer.add(4).putAddress(stackTopPointer);
stackTopPointer = stackTopPointer.add(8);
return malloced;
}else {
Address ret = stackTopPointer;
stackTopPointer = stackTopPointer.add((length + 3) & 0xFFFFFFFC);
return ret;
}
}
public static ByteBuffer mallocByteBuffer(int length) {
return new DirectMallocByteBuffer(malloc(length), length, false);
}
public static IntBuffer mallocIntBuffer(int length) {
return new DirectMallocIntBuffer(malloc(length << 2), length, false);
}
public static FloatBuffer mallocFloatBuffer(int length) {
return new DirectMallocFloatBuffer(malloc(length << 2), length, false);
}
public static Address calloc(int length) {
if(length > MALLOC_THRESHOLD || (stackMax.toInt() - stackTopPointer.toInt()) < RESERVE_SIZE) {
if(stackTopPointer.toInt() + 8 > stackMax.toInt()) {
throw new StackOverflowError();
}
Address malloced = WASMGCBufferAllocator.calloc(length);
Address cleanup = stackBottomPointer.add(4).getAddress();
stackTopPointer.putAddress(malloced);
stackTopPointer.add(4).putAddress(cleanup);
stackBottomPointer.add(4).putAddress(stackTopPointer);
stackTopPointer = stackTopPointer.add(8);
return malloced;
}else {
DirectMalloc.zmemset(stackTopPointer, length);
Address ret = stackTopPointer;
stackTopPointer = stackTopPointer.add((length + 3) & 0xFFFFFFFC);
return ret;
}
}
public static ByteBuffer callocByteBuffer(int length) {
return new DirectMallocByteBuffer(calloc(length), length, false);
}
public static IntBuffer callocIntBuffer(int length) {
return new DirectMallocIntBuffer(calloc(length << 2), length, false);
}
public static FloatBuffer callocFloatBuffer(int length) {
return new DirectMallocFloatBuffer(calloc(length << 2), length, false);
}
}

View File

@ -10,7 +10,7 @@ import org.teavm.jso.typedarrays.Uint8Array;
import org.teavm.jso.typedarrays.Uint8ClampedArray;
/**
* Copyright (c) 2024 lax1dude. All Rights Reserved.
* Copyright (c) 2024-2025 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -33,6 +33,13 @@ public class WASMGCDirectArrayConverter {
return new DirectMallocByteBuffer(ret, len, true);
}
public static ByteBuffer byteArrayToStackBuffer(byte[] byteArray) {
int len = byteArray.length;
Address ret = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(ret, byteArray, 0, len);
return new DirectMallocByteBuffer(ret, len, true);
}
public static ByteBuffer byteArrayToBuffer(byte[] byteArray, int offset, int length) {
if(offset < 0) throw Buffer.makeIOOBE(offset);
if(offset + length > byteArray.length) throw Buffer.makeIOOBE(offset + length - 1);
@ -41,6 +48,14 @@ public class WASMGCDirectArrayConverter {
return new DirectMallocByteBuffer(ret, length, true);
}
public static ByteBuffer byteArrayToStackBuffer(byte[] byteArray, int offset, int length) {
if(offset < 0) throw Buffer.makeIOOBE(offset);
if(offset + length > byteArray.length) throw Buffer.makeIOOBE(offset + length - 1);
Address ret = MemoryStack.malloc(length);
WASMGCDirectArrayCopy.memcpy(ret, byteArray, offset, length);
return new DirectMallocByteBuffer(ret, length, true);
}
public static ShortBuffer shortArrayToBuffer(short[] shortArray) {
int len = shortArray.length;
Address ret = WASMGCBufferAllocator.malloc(len << 1);
@ -48,6 +63,13 @@ public class WASMGCDirectArrayConverter {
return new DirectMallocShortBuffer(ret, len, true);
}
public static ShortBuffer shortArrayToStackBuffer(short[] shortArray) {
int len = shortArray.length;
Address ret = MemoryStack.malloc(len << 1);
WASMGCDirectArrayCopy.memcpy(ret, shortArray, 0, len);
return new DirectMallocShortBuffer(ret, len, true);
}
public static ShortBuffer shortArrayToBuffer(short[] shortArray, int offset, int length) {
if(offset < 0) throw Buffer.makeIOOBE(offset);
if(offset + length > shortArray.length) throw Buffer.makeIOOBE(offset + length - 1);
@ -56,6 +78,14 @@ public class WASMGCDirectArrayConverter {
return new DirectMallocShortBuffer(ret, length, true);
}
public static ShortBuffer shortArrayToStackBuffer(short[] shortArray, int offset, int length) {
if(offset < 0) throw Buffer.makeIOOBE(offset);
if(offset + length > shortArray.length) throw Buffer.makeIOOBE(offset + length - 1);
Address ret = MemoryStack.malloc(length << 1);
WASMGCDirectArrayCopy.memcpy(ret, shortArray, offset, length);
return new DirectMallocShortBuffer(ret, length, true);
}
public static IntBuffer intArrayToBuffer(int[] intArray) {
int len = intArray.length;
Address ret = WASMGCBufferAllocator.malloc(len << 2);
@ -63,6 +93,13 @@ public class WASMGCDirectArrayConverter {
return new DirectMallocIntBuffer(ret, len, true);
}
public static IntBuffer intArrayToStackBuffer(int[] intArray) {
int len = intArray.length;
Address ret = MemoryStack.malloc(len << 2);
WASMGCDirectArrayCopy.memcpy(ret, intArray, 0, len);
return new DirectMallocIntBuffer(ret, len, true);
}
public static IntBuffer intArrayToBuffer(int[] intArray, int offset, int length) {
if(offset < 0) throw Buffer.makeIOOBE(offset);
if(offset + length > intArray.length) throw Buffer.makeIOOBE(offset + length - 1);
@ -71,6 +108,14 @@ public class WASMGCDirectArrayConverter {
return new DirectMallocIntBuffer(ret, length, true);
}
public static IntBuffer intArrayToStackBuffer(int[] intArray, int offset, int length) {
if(offset < 0) throw Buffer.makeIOOBE(offset);
if(offset + length > intArray.length) throw Buffer.makeIOOBE(offset + length - 1);
Address ret = MemoryStack.malloc(length << 2);
WASMGCDirectArrayCopy.memcpy(ret, intArray, offset, length);
return new DirectMallocIntBuffer(ret, length, true);
}
public static FloatBuffer floatArrayToBuffer(float[] floatArray) {
int len = floatArray.length;
Address ret = WASMGCBufferAllocator.malloc(len << 2);
@ -78,6 +123,13 @@ public class WASMGCDirectArrayConverter {
return new DirectMallocFloatBuffer(ret, len, true);
}
public static FloatBuffer floatArrayToStackBuffer(float[] floatArray) {
int len = floatArray.length;
Address ret = MemoryStack.malloc(len << 2);
WASMGCDirectArrayCopy.memcpy(ret, floatArray, 0, len);
return new DirectMallocFloatBuffer(ret, len, true);
}
public static FloatBuffer floatArrayToBuffer(float[] floatArray, int offset, int length) {
if(offset < 0) throw Buffer.makeIOOBE(offset);
if(offset + length > floatArray.length) throw Buffer.makeIOOBE(offset + length - 1);
@ -86,6 +138,14 @@ public class WASMGCDirectArrayConverter {
return new DirectMallocFloatBuffer(ret, length, true);
}
public static FloatBuffer floatArrayToStackBuffer(float[] floatArray, int offset, int length) {
if(offset < 0) throw Buffer.makeIOOBE(offset);
if(offset + length > floatArray.length) throw Buffer.makeIOOBE(offset + length - 1);
Address ret = MemoryStack.malloc(length << 2);
WASMGCDirectArrayCopy.memcpy(ret, floatArray, offset, length);
return new DirectMallocFloatBuffer(ret, length, true);
}
private static final Uint8Array UINT8ZeroLength = new Uint8Array(0);
private static final Uint8ClampedArray UINT8CZeroLength = new Uint8ClampedArray(0);
private static final Int8Array INT8ZeroLength = new Int8Array(0);
@ -99,148 +159,269 @@ public class WASMGCDirectArrayConverter {
if(len == 0) {
return UINT8ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
Uint8Array ret = new Uint8Array(len);
ret.set(WASMGCBufferAllocator.getUnsignedByteBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Uint8Array byteArrayToStackU8Array(byte[] byteArray) {
int len = byteArray.length;
if(len == 0) {
return UINT8ZeroLength;
}
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
return WASMGCBufferAllocator.getUnsignedByteBufferView0(addr, len);
}
public static Uint8ClampedArray byteArrayToExternU8CArray(byte[] byteArray) {
int len = byteArray.length;
if(len == 0) {
return UINT8CZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
Uint8ClampedArray ret = new Uint8ClampedArray(len);
ret.set(WASMGCBufferAllocator.getUnsignedClampedByteBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Uint8ClampedArray byteArrayToStackU8CArray(byte[] byteArray) {
int len = byteArray.length;
if(len == 0) {
return UINT8CZeroLength;
}
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
return WASMGCBufferAllocator.getUnsignedClampedByteBufferView0(addr, len);
}
public static Int8Array byteArrayToExternI8Array(byte[] byteArray) {
int len = byteArray.length;
if(len == 0) {
return INT8ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
Int8Array ret = new Int8Array(len);
ret.set(WASMGCBufferAllocator.getByteBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Int8Array byteArrayToStackI8Array(byte[] byteArray) {
int len = byteArray.length;
if(len == 0) {
return INT8ZeroLength;
}
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
return WASMGCBufferAllocator.getByteBufferView0(addr, len);
}
public static Uint16Array byteArrayToExternU16Array(byte[] byteArray) {
int len = byteArray.length & 0xFFFFFFFE;
if(len == 0) {
return UINT16ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
len >>= 1;
Uint16Array ret = new Uint16Array(len);
ret.set(WASMGCBufferAllocator.getUnsignedShortBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Uint16Array byteArrayToStackU16Array(byte[] byteArray) {
int len = byteArray.length & 0xFFFFFFFE;
if(len == 0) {
return UINT16ZeroLength;
}
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
return WASMGCBufferAllocator.getUnsignedShortBufferView0(addr, len >> 1);
}
public static Int16Array byteArrayToExternI16Array(byte[] byteArray) {
int len = byteArray.length & 0xFFFFFFFE;
if(len == 0) {
return INT16ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
len >>= 1;
Int16Array ret = new Int16Array(len);
ret.set(WASMGCBufferAllocator.getShortBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Int16Array byteArrayToStackI16Array(byte[] byteArray) {
int len = byteArray.length & 0xFFFFFFFE;
if(len == 0) {
return INT16ZeroLength;
}
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
return WASMGCBufferAllocator.getShortBufferView0(addr, len >> 1);
}
public static Uint16Array shortArrayToExternU16Array(short[] shortArray) {
int len = shortArray.length;
if(len == 0) {
return UINT16ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len << 1);
MemoryStack.push();
Address addr = MemoryStack.malloc(len << 1);
WASMGCDirectArrayCopy.memcpy(addr, shortArray, 0, len);
Uint16Array ret = new Uint16Array(len);
ret.set(WASMGCBufferAllocator.getUnsignedShortBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Uint16Array shortArrayToStackU16Array(short[] shortArray) {
int len = shortArray.length;
if(len == 0) {
return UINT16ZeroLength;
}
Address addr = MemoryStack.malloc(len << 1);
WASMGCDirectArrayCopy.memcpy(addr, shortArray, 0, len);
return WASMGCBufferAllocator.getUnsignedShortBufferView0(addr, len);
}
public static Int16Array shortArrayToExternI16Array(short[] shortArray) {
int len = shortArray.length;
if(len == 0) {
return INT16ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len << 1);
MemoryStack.push();
Address addr = MemoryStack.malloc(len << 1);
WASMGCDirectArrayCopy.memcpy(addr, shortArray, 0, len);
Int16Array ret = new Int16Array(len);
ret.set(WASMGCBufferAllocator.getShortBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Int16Array shortArrayToStackI16Array(short[] shortArray) {
int len = shortArray.length;
if(len == 0) {
return INT16ZeroLength;
}
Address addr = MemoryStack.malloc(len << 1);
WASMGCDirectArrayCopy.memcpy(addr, shortArray, 0, len);
return WASMGCBufferAllocator.getShortBufferView0(addr, len);
}
public static Int32Array byteArrayToExternI32Array(byte[] byteArray) {
int len = byteArray.length & 0xFFFFFFFC;
if(len == 0) {
return INT32ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
len >>= 2;
Int32Array ret = new Int32Array(len);
ret.set(WASMGCBufferAllocator.getIntBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Int32Array byteArrayToStackI32Array(byte[] byteArray) {
int len = byteArray.length & 0xFFFFFFFC;
if(len == 0) {
return INT32ZeroLength;
}
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
return WASMGCBufferAllocator.getIntBufferView0(addr, len >> 2);
}
public static Int32Array intArrayToExternI32Array(int[] intArray) {
int len = intArray.length;
if(len == 0) {
return INT32ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len << 2);
MemoryStack.push();
Address addr = MemoryStack.malloc(len << 2);
WASMGCDirectArrayCopy.memcpy(addr, intArray, 0, len);
Int32Array ret = new Int32Array(len);
ret.set(WASMGCBufferAllocator.getIntBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Int32Array intArrayToStackI32Array(int[] intArray) {
int len = intArray.length;
if(len == 0) {
return INT32ZeroLength;
}
Address addr = MemoryStack.malloc(len << 2);
WASMGCDirectArrayCopy.memcpy(addr, intArray, 0, len);
return WASMGCBufferAllocator.getIntBufferView0(addr, len);
}
public static Float32Array byteArrayToExternF32Array(byte[] byteArray) {
int len = byteArray.length & 0xFFFFFFFC;
if(len == 0) {
return FLOAT32ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
len >>= 2;
Float32Array ret = new Float32Array(len);
ret.set(WASMGCBufferAllocator.getFloatBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Float32Array byteArrayToStackF32Array(byte[] byteArray) {
int len = byteArray.length & 0xFFFFFFFC;
if(len == 0) {
return FLOAT32ZeroLength;
}
Address addr = MemoryStack.malloc(len);
WASMGCDirectArrayCopy.memcpy(addr, byteArray, 0, len);
return WASMGCBufferAllocator.getFloatBufferView0(addr, len >> 2);
}
public static Float32Array floatArrayToExternF32Array(float[] floatArray) {
int len = floatArray.length;
if(len == 0) {
return FLOAT32ZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len << 2);
MemoryStack.push();
Address addr = MemoryStack.malloc(len << 2);
WASMGCDirectArrayCopy.memcpy(addr, floatArray, 0, len);
Float32Array ret = new Float32Array(len);
ret.set(WASMGCBufferAllocator.getFloatBufferView0(addr, len));
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
public static Float32Array floatArrayToStackF32Array(float[] floatArray) {
int len = floatArray.length;
if(len == 0) {
return FLOAT32ZeroLength;
}
Address addr = MemoryStack.malloc(len << 2);
WASMGCDirectArrayCopy.memcpy(addr, floatArray, 0, len);
return WASMGCBufferAllocator.getFloatBufferView0(addr, len);
}
private static final byte[] byteZeroLength = new byte[0];
private static final short[] shortZeroLength = new short[0];
private static final int[] intZeroLength = new int[0];
@ -251,11 +432,12 @@ public class WASMGCDirectArrayConverter {
if(len == 0) {
return byteZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCBufferAllocator.getUnsignedByteBufferView0(addr, len).set(U8Array);
byte[] ret = new byte[len];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -264,11 +446,12 @@ public class WASMGCDirectArrayConverter {
if(len == 0) {
return byteZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCBufferAllocator.getUnsignedClampedByteBufferView0(addr, len).set(U8CArray);
byte[] ret = new byte[len];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -277,11 +460,12 @@ public class WASMGCDirectArrayConverter {
if(len == 0) {
return byteZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len);
MemoryStack.push();
Address addr = MemoryStack.malloc(len);
WASMGCBufferAllocator.getByteBufferView0(addr, len).set(I8Array);
byte[] ret = new byte[len];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -291,11 +475,12 @@ public class WASMGCDirectArrayConverter {
return byteZeroLength;
}
int len2 = len << 1;
Address addr = WASMGCBufferAllocator.malloc(len2);
MemoryStack.push();
Address addr = MemoryStack.malloc(len2);
WASMGCBufferAllocator.getUnsignedShortBufferView0(addr, len).set(U16Array);
byte[] ret = new byte[len2];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len2);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -305,11 +490,12 @@ public class WASMGCDirectArrayConverter {
return byteZeroLength;
}
int len2 = len << 1;
Address addr = WASMGCBufferAllocator.malloc(len2);
MemoryStack.push();
Address addr = MemoryStack.malloc(len2);
WASMGCBufferAllocator.getShortBufferView0(addr, len).set(I16Array);
byte[] ret = new byte[len2];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len2);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -318,11 +504,12 @@ public class WASMGCDirectArrayConverter {
if(len == 0) {
return shortZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len << 1);
MemoryStack.push();
Address addr = MemoryStack.malloc(len << 1);
WASMGCBufferAllocator.getUnsignedShortBufferView0(addr, len).set(U16Array);
short[] ret = new short[len];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -331,11 +518,12 @@ public class WASMGCDirectArrayConverter {
if(len == 0) {
return shortZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len << 1);
MemoryStack.push();
Address addr = MemoryStack.malloc(len << 1);
WASMGCBufferAllocator.getShortBufferView0(addr, len).set(I16Array);
short[] ret = new short[len];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -345,11 +533,12 @@ public class WASMGCDirectArrayConverter {
return byteZeroLength;
}
int len2 = len << 2;
Address addr = WASMGCBufferAllocator.malloc(len2);
MemoryStack.push();
Address addr = MemoryStack.malloc(len2);
WASMGCBufferAllocator.getIntBufferView0(addr, len).set(I32Array);
byte[] ret = new byte[len2];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len2);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -358,11 +547,12 @@ public class WASMGCDirectArrayConverter {
if(len == 0) {
return intZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len << 2);
MemoryStack.push();
Address addr = MemoryStack.malloc(len << 2);
WASMGCBufferAllocator.getIntBufferView0(addr, len).set(I32Array);
int[] ret = new int[len];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -372,11 +562,12 @@ public class WASMGCDirectArrayConverter {
return byteZeroLength;
}
int len2 = len << 2;
Address addr = WASMGCBufferAllocator.malloc(len2);
MemoryStack.push();
Address addr = MemoryStack.malloc(len2);
WASMGCBufferAllocator.getFloatBufferView0(addr, len).set(F32Array);
byte[] ret = new byte[len2];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len2);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}
@ -385,11 +576,12 @@ public class WASMGCDirectArrayConverter {
if(len == 0) {
return floatZeroLength;
}
Address addr = WASMGCBufferAllocator.malloc(len << 2);
MemoryStack.push();
Address addr = MemoryStack.malloc(len << 2);
WASMGCBufferAllocator.getFloatBufferView0(addr, len).set(F32Array);
float[] ret = new float[len];
WASMGCDirectArrayCopy.memcpy(ret, 0, addr, len);
WASMGCBufferAllocator.free(addr);
MemoryStack.pop();
return ret;
}

View File

@ -6,6 +6,7 @@ import org.teavm.interop.Unmanaged;
import org.teavm.jso.core.JSArray;
import org.teavm.jso.core.JSString;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
/**
@ -31,12 +32,13 @@ public class BetterJSStringConverter {
public static JSString stringToJS(String input) {
if(input == null) return null;
int len = input.length();
Address tmpAddr = WASMGCBufferAllocator.malloc(len << 1);
MemoryStack.push();
Address tmpAddr = MemoryStack.malloc(len << 1);
for(int i = 0; i < len; ++i) {
tmpAddr.add(i << 1).putChar(input.charAt(i));
}
JSString ret = textDecoder.decode(WASMGCBufferAllocator.getUnsignedByteBufferView0(tmpAddr, len << 1));
WASMGCBufferAllocator.free(tmpAddr);
MemoryStack.pop();
return ret;
}

View File

@ -11,10 +11,10 @@ import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
import net.lax1dude.eaglercraft.v1_8.internal.ITextureGL;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformAssets;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformInput;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.IntBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
import net.lax1dude.eaglercraft.v1_8.opengl.ImageData;
@ -56,29 +56,32 @@ public class EarlyLoadScreen {
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
ImageData img = PlatformAssets.loadImageFile(Base64.decodeBase64(loadScreen));
ByteBuffer upload = PlatformRuntime.allocateByteBuffer(192*192*4);
IntBuffer pixelUpload = upload.asIntBuffer();
pixelUpload.put(img.pixels);
pixelUpload.flip();
_wglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 192, 192, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelUpload);
// create vertex buffer:
FloatBuffer vertexUpload = upload.asFloatBuffer();
vertexUpload.clear();
vertexUpload.put(0.0f); vertexUpload.put(0.0f);
vertexUpload.put(0.0f); vertexUpload.put(1.0f);
vertexUpload.put(1.0f); vertexUpload.put(0.0f);
vertexUpload.put(1.0f); vertexUpload.put(0.0f);
vertexUpload.put(0.0f); vertexUpload.put(1.0f);
vertexUpload.put(1.0f); vertexUpload.put(1.0f);
vertexUpload.flip();
vbo = _wglGenBuffers();
_wglBindBuffer(GL_ARRAY_BUFFER, vbo);
_wglBufferData(GL_ARRAY_BUFFER, vertexUpload, GL_STATIC_DRAW);
PlatformRuntime.freeByteBuffer(upload);
MemoryStack.push();
try {
ByteBuffer upload = MemoryStack.mallocByteBuffer(192*192*4);
IntBuffer pixelUpload = upload.asIntBuffer();
pixelUpload.put(img.pixels);
pixelUpload.flip();
_wglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 192, 192, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelUpload);
// create vertex buffer:
FloatBuffer vertexUpload = upload.asFloatBuffer();
vertexUpload.clear();
vertexUpload.put(0.0f); vertexUpload.put(0.0f);
vertexUpload.put(0.0f); vertexUpload.put(1.0f);
vertexUpload.put(1.0f); vertexUpload.put(0.0f);
vertexUpload.put(1.0f); vertexUpload.put(0.0f);
vertexUpload.put(0.0f); vertexUpload.put(1.0f);
vertexUpload.put(1.0f); vertexUpload.put(1.0f);
vertexUpload.flip();
vbo = _wglGenBuffers();
_wglBindBuffer(GL_ARRAY_BUFFER, vbo);
_wglBufferData(GL_ARRAY_BUFFER, vertexUpload, GL_STATIC_DRAW);
}finally {
MemoryStack.pop();
}
// compile the splash shader:
@ -165,11 +168,15 @@ public class EarlyLoadScreen {
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
IntBuffer upload = PlatformRuntime.allocateIntBuffer(img.width * img.height);
upload.put(img.pixels);
upload.flip();
_wglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width, img.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, upload);
PlatformRuntime.freeIntBuffer(upload);
MemoryStack.push();
try {
IntBuffer upload = MemoryStack.mallocIntBuffer(img.width * img.height);
upload.put(img.pixels);
upload.flip();
_wglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width, img.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, upload);
}finally {
MemoryStack.pop();
}
}
public static void paintFinal(boolean softVAOs) {

View File

@ -17,8 +17,8 @@ import com.jcraft.jorbis.Info;
import net.lax1dude.eaglercraft.v1_8.EaglerInputStream;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformAudio;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
@ -88,8 +88,9 @@ public class JOrbisAudioBufferDecoder {
logger.error("[{}]: Empty file", errorString);
return null;
}
FloatBuffer buf = PlatformRuntime.allocateFloatBuffer(ch * len);
MemoryStack.push();
try {
FloatBuffer buf = MemoryStack.mallocFloatBuffer(ch * len);
int len2 = 0;
for(float[][] fl : lst) {
for(int i = 0; i < ch; ++i) {
@ -102,7 +103,7 @@ public class JOrbisAudioBufferDecoder {
return PlatformAudio.decodeAudioBufferPCMBrowser(WASMGCBufferAllocator.getFloatBufferView(buf), ch,
len, dec.jorbisInfo.rate);
}finally {
PlatformRuntime.freeFloatBuffer(buf);
MemoryStack.pop();
}
}
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;
import org.teavm.jso.core.JSString;
import org.teavm.jso.typedarrays.Uint8Array;
import net.lax1dude.eaglercraft.v1_8.EagUtils;
@ -12,8 +13,7 @@ import net.lax1dude.eaglercraft.v1_8.internal.EnumEaglerConnectionState;
import net.lax1dude.eaglercraft.v1_8.internal.IWebSocketClient;
import net.lax1dude.eaglercraft.v1_8.internal.IWebSocketFrame;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCDirectArrayConverter;
/**
@ -40,7 +40,7 @@ public class WASMGCWebSocketClient implements IWebSocketClient {
void closeSocket();
void sendStringFrame(String str);
void sendStringFrame(JSString str);
void sendBinaryFrame(Uint8Array arr);
@ -220,16 +220,16 @@ public class WASMGCWebSocketClient implements IWebSocketClient {
@Override
public void send(String str) {
handle.sendStringFrame(str);
handle.sendStringFrame(BetterJSStringConverter.stringToJS(str));
}
@Override
public void send(byte[] bytes) {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(bytes);
MemoryStack.push();
try {
handle.sendBinaryFrame(WASMGCBufferAllocator.getUnsignedByteBufferView(buf));
handle.sendBinaryFrame(WASMGCDirectArrayConverter.byteArrayToStackU8Array(bytes));
}finally {
PlatformRuntime.freeByteBuffer(buf);
MemoryStack.pop();
}
}

View File

@ -10,8 +10,8 @@ import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
import net.lax1dude.eaglercraft.v1_8.internal.IRenderbufferGL;
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
import net.lax1dude.eaglercraft.v1_8.internal.ITextureGL;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
@ -93,21 +93,24 @@ public class WebGLBackBuffer {
_wglBindRenderbuffer(_GL_RENDERBUFFER, gles2DepthRenderbuffer);
_wglRenderbufferStorage(_GL_RENDERBUFFER, _GL_DEPTH_COMPONENT16, sw, sh);
_wglFramebufferRenderbuffer(_GL_FRAMEBUFFER, _GL_DEPTH_ATTACHMENT, _GL_RENDERBUFFER, gles2DepthRenderbuffer);
ByteBuffer upload = PlatformRuntime.allocateByteBuffer(48);
upload.putFloat(0.0f); upload.putFloat(0.0f);
upload.putFloat(1.0f); upload.putFloat(0.0f);
upload.putFloat(0.0f); upload.putFloat(1.0f);
upload.putFloat(1.0f); upload.putFloat(0.0f);
upload.putFloat(1.0f); upload.putFloat(1.0f);
upload.putFloat(0.0f); upload.putFloat(1.0f);
upload.flip();
gles2BlitVBO = _wglGenBuffers();
EaglercraftGPU.bindVAOGLArrayBufferNow(gles2BlitVBO);
_wglBufferData(GL_ARRAY_BUFFER, upload, GL_STATIC_DRAW);
PlatformRuntime.freeByteBuffer(upload);
MemoryStack.push();
try {
ByteBuffer upload = MemoryStack.mallocByteBuffer(48);
upload.putFloat(0.0f); upload.putFloat(0.0f);
upload.putFloat(1.0f); upload.putFloat(0.0f);
upload.putFloat(0.0f); upload.putFloat(1.0f);
upload.putFloat(1.0f); upload.putFloat(0.0f);
upload.putFloat(1.0f); upload.putFloat(1.0f);
upload.putFloat(0.0f); upload.putFloat(1.0f);
upload.flip();
gles2BlitVBO = _wglGenBuffers();
EaglercraftGPU.bindVAOGLArrayBufferNow(gles2BlitVBO);
_wglBufferData(GL_ARRAY_BUFFER, upload, GL_STATIC_DRAW);
}finally {
MemoryStack.pop();
}
if(isVAOCapable) {
gles2BlitVAO = _wglGenVertexArrays();

View File

@ -11,8 +11,7 @@ import org.teavm.jso.typedarrays.Uint8Array;
import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCDirectArrayConverter;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.BetterJSStringConverter;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.WASMGCClientConfigAdapter;
@ -69,11 +68,12 @@ public class ClientPlatformSingleplayer {
if(isSingleThreadMode) {
SingleThreadWorker.sendPacketToWorker(packet);
}else {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(packet.contents);
MemoryStack.push();
try {
sendPacket0(BetterJSStringConverter.stringToJS(packet.channel), WASMGCBufferAllocator.getUnsignedByteBufferView(buf));
}finally {
PlatformRuntime.freeByteBuffer(buf);
sendPacket0(BetterJSStringConverter.stringToJS(packet.channel),
WASMGCDirectArrayConverter.byteArrayToStackU8Array(packet.contents));
} finally {
MemoryStack.pop();
}
}
}

View File

@ -16,9 +16,7 @@ import net.lax1dude.eaglercraft.v1_8.Filesystem;
import net.lax1dude.eaglercraft.v1_8.internal.IClientConfigAdapter;
import net.lax1dude.eaglercraft.v1_8.internal.IEaglerFilesystem;
import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCBufferAllocator;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.MemoryStack;
import net.lax1dude.eaglercraft.v1_8.internal.buffer.WASMGCDirectArrayConverter;
import net.lax1dude.eaglercraft.v1_8.internal.vfs2.VFile2;
import net.lax1dude.eaglercraft.v1_8.internal.wasm_gc_teavm.BetterJSStringConverter;
@ -71,11 +69,12 @@ public class ServerPlatformSingleplayer {
if(singleThreadMode) {
singleThreadCB.accept(packet);
}else {
ByteBuffer buf = WASMGCDirectArrayConverter.byteArrayToBuffer(packet.contents);
MemoryStack.push();
try {
sendPacket0(BetterJSStringConverter.stringToJS(packet.channel), WASMGCBufferAllocator.getUnsignedByteBufferView(buf));
}finally {
PlatformRuntime.freeByteBuffer(buf);
sendPacket0(BetterJSStringConverter.stringToJS(packet.channel),
WASMGCDirectArrayConverter.byteArrayToStackU8Array(packet.contents));
} finally {
MemoryStack.pop();
}
}
}