mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-28 10:58:15 -05:00
Update #43 - Fix invisible block entities and other issues
This commit is contained in:
@ -100,7 +100,7 @@ public class PlatformAudio {
|
||||
this.gain = gain;
|
||||
this.pitch = pitch;
|
||||
this.repeat = repeat;
|
||||
source.setOnEnded(this);
|
||||
TeaVMUtils.addEventListener(source, "ended", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -249,12 +249,11 @@ public class PlatformAudio {
|
||||
private static native boolean detectLoadViaAudioBufferSupport(AudioContext ctx);
|
||||
|
||||
private static void detectOGGSupport() {
|
||||
byte[] fileData = EagRuntime.getRequiredResourceBytes("/assets/eagler/audioctx_test_ogg.dat");
|
||||
|
||||
if(((TeaVMClientConfigAdapter)PlatformRuntime.getClientConfigAdapter()).isUseJOrbisAudioDecoderTeaVM()) {
|
||||
logger.info("Note: Using embedded JOrbis OGG decoder");
|
||||
oggSupport = false;
|
||||
}else {
|
||||
byte[] fileData = EagRuntime.getRequiredResourceBytes("/assets/eagler/audioctx_test_ogg.dat");
|
||||
try {
|
||||
Int8Array arr = Int8Array.create(fileData.length);
|
||||
arr.set(TeaVMUtils.unwrapByteArray(fileData), 0);
|
||||
|
@ -8,7 +8,6 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMUtils;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.teavm.Touch;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.teavm.TouchEvent;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.teavm.VisualViewport;
|
||||
|
||||
@ -102,6 +101,7 @@ public class PlatformInput {
|
||||
private static EventListener<?> focus = null;
|
||||
private static EventListener<?> blur = null;
|
||||
private static EventListener<?> pointerlock = null;
|
||||
private static EventListener<?> fullscreen = null;
|
||||
|
||||
private static Map<String,LegacyKeycodeTranslator.LegacyKeycode> keyCodeTranslatorMap = null;
|
||||
|
||||
@ -685,7 +685,7 @@ public class PlatformInput {
|
||||
if(fullscreenSupported != FULLSCREEN_NONE) {
|
||||
fullscreenQuery = fullscreenMediaQuery();
|
||||
if(fullscreenSupported == FULLSCREEN_CORE && (keyboardLockSupported = checkKeyboardLockSupported())) {
|
||||
TeaVMUtils.addEventListener(fullscreenQuery, "change", new EventListener<Event>() {
|
||||
TeaVMUtils.addEventListener(fullscreenQuery, "change", fullscreen = new EventListener<Event>() {
|
||||
@Override
|
||||
public void handleEvent(Event evt) {
|
||||
if (!mediaQueryMatches(evt)) {
|
||||
@ -840,7 +840,7 @@ public class PlatformInput {
|
||||
@JSBody(params = { "e" }, script = "return (typeof e.location === \"number\") ? e.location : 0;")
|
||||
private static native int getLocationSafe(KeyboardEvent e);
|
||||
|
||||
@JSBody(params = { "el", "i", "j" }, script = "el.setSelectionRange(el, i, j)")
|
||||
@JSBody(params = { "el", "i", "j" }, script = "el.setSelectionRange(i, j)")
|
||||
private static native boolean setSelectionRange(HTMLElement el, int i, int j);
|
||||
|
||||
public static int getWindowWidth() {
|
||||
@ -1513,6 +1513,10 @@ public class PlatformInput {
|
||||
win.getDocument().removeEventListener("pointerlockchange", pointerlock);
|
||||
pointerlock = null;
|
||||
}
|
||||
if(fullscreen != null) {
|
||||
TeaVMUtils.removeEventListener(fullscreenQuery, "change", fullscreen);
|
||||
fullscreen = null;
|
||||
}
|
||||
if(mouseUngrabTimeout != -1) {
|
||||
Window.clearTimeout(mouseUngrabTimeout);
|
||||
mouseUngrabTimeout = -1;
|
||||
@ -1786,19 +1790,9 @@ public class PlatformInput {
|
||||
return currentTouchEvent != null ? currentTouchEvent.getEventTouches().get(pointId).posY : 0;
|
||||
}
|
||||
|
||||
public static float touchGetEventTouchRadiusX(int pointId) {
|
||||
return currentTouchEvent != null ? (float)currentTouchEvent.getEventTouches().get(pointId).touch.getRadiusXSafe(5.0 * windowDPI) : 1.0f;
|
||||
}
|
||||
|
||||
public static float touchGetEventTouchRadiusY(int pointId) {
|
||||
return currentTouchEvent != null ? (float)currentTouchEvent.getEventTouches().get(pointId).touch.getRadiusYSafe(5.0 * windowDPI) : 1.0f;
|
||||
}
|
||||
|
||||
public static float touchGetEventTouchRadiusMixed(int pointId) {
|
||||
if(currentTouchEvent != null) {
|
||||
Touch t = currentTouchEvent.getEventTouches().get(pointId).touch;
|
||||
double d = 5.0 * windowDPI;
|
||||
return (float)(t.getRadiusXSafe(d) * 0.5 + t.getRadiusYSafe(d) * 0.5);
|
||||
return currentTouchEvent.getEventTouches().get(pointId).radius;
|
||||
}else {
|
||||
return 1.0f;
|
||||
}
|
||||
@ -1834,8 +1828,7 @@ public class PlatformInput {
|
||||
|
||||
public static float touchRadiusMixed(int pointId) {
|
||||
if(currentTouchState != null) {
|
||||
Touch t = currentTouchState.getTargetTouches().get(pointId).touch;
|
||||
return (float)(t.getRadiusX() * 0.5 + t.getRadiusY() * 0.5);
|
||||
return currentTouchState.getTargetTouches().get(pointId).radius;
|
||||
}else {
|
||||
return 1.0f;
|
||||
}
|
||||
@ -1907,7 +1900,7 @@ public class PlatformInput {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
JSObject obj = evt.getTimeStamp();
|
||||
if(TeaVMUtils.isTruthy(obj)) {
|
||||
if(obj != null && TeaVMUtils.isTruthy(obj)) {
|
||||
double d = ((JSNumber)obj).doubleValue();
|
||||
if(lastTouchKeyboardEvtA != 0.0 && (d - lastTouchKeyboardEvtA) < 10.0) {
|
||||
return;
|
||||
@ -1953,7 +1946,7 @@ public class PlatformInput {
|
||||
shownTouchKeyboardEventWarning = true;
|
||||
}
|
||||
JSObject obj = evt.getTimeStamp();
|
||||
if(TeaVMUtils.isTruthy(obj)) {
|
||||
if(obj != null && TeaVMUtils.isTruthy(obj)) {
|
||||
double d = ((JSNumber)obj).doubleValue();
|
||||
if(lastTouchKeyboardEvtA != 0.0 && (d - lastTouchKeyboardEvtA) < 10.0) {
|
||||
return;
|
||||
@ -2013,7 +2006,7 @@ public class PlatformInput {
|
||||
case "deleteByCut":
|
||||
break;
|
||||
default:
|
||||
PlatformRuntime.logger.info("Ingoring InputEvent.inputType \"{}\" from on-screen keyboard", evt.getInputType());
|
||||
PlatformRuntime.logger.info("Ignoring InputEvent.inputType \"{}\" from on-screen keyboard", evt.getInputType());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2027,7 +2020,7 @@ public class PlatformInput {
|
||||
PlatformRuntime.logger.info("Note: Caught legacy input events from on-screen keyboard, browser could be outdated and doesn't support beforeinput event, or does not respond to cancelling beforeinput");
|
||||
shownLegacyTouchKeyboardWarning = true;
|
||||
}
|
||||
if(TeaVMUtils.isTruthy(obj)) {
|
||||
if(obj != null && TeaVMUtils.isTruthy(obj)) {
|
||||
double d = ((JSNumber)obj).doubleValue();
|
||||
if(lastTouchKeyboardEvtA != 0.0 && (d - lastTouchKeyboardEvtA) < 10.0) {
|
||||
return;
|
||||
|
@ -252,19 +252,21 @@ public class PlatformRuntime {
|
||||
}
|
||||
|
||||
useVisualViewport = false;
|
||||
if(isVisualViewportSupported()) {
|
||||
if(isEmbeddedInBody) {
|
||||
useVisualViewport = true;
|
||||
}else {
|
||||
HTMLElement bodyTag = doc.getBody();
|
||||
if (Math.abs(bodyTag.getClientWidth() - parent.getClientWidth()) <= 10
|
||||
&& Math.abs(bodyTag.getClientHeight() - parent.getClientHeight()) <= 10) {
|
||||
if(teavmCfg.isUseVisualViewportTeaVM()) {
|
||||
if(isVisualViewportSupported()) {
|
||||
if(isEmbeddedInBody) {
|
||||
useVisualViewport = true;
|
||||
}else {
|
||||
HTMLElement bodyTag = doc.getBody();
|
||||
if (Math.abs(bodyTag.getClientWidth() - parent.getClientWidth()) <= 10
|
||||
&& Math.abs(bodyTag.getClientHeight() - parent.getClientHeight()) <= 10) {
|
||||
useVisualViewport = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(useVisualViewport) {
|
||||
logger.info("Note: Detected game is embedded in body, some screens may be resized to window.visualViewport instead for a better mobile experience");
|
||||
if(useVisualViewport) {
|
||||
logger.info("Note: Detected game is embedded in body, some screens may be resized to window.visualViewport instead for a better mobile experience");
|
||||
}
|
||||
}
|
||||
|
||||
ByteBuffer endiannessTestBytes = allocateByteBuffer(4);
|
||||
|
@ -149,6 +149,7 @@ public class PlatformVoiceClient {
|
||||
private GainNode gain = null;
|
||||
private PannerNode panner = null;
|
||||
private AudioNode recNode = null;
|
||||
private HTMLAudioElement mediaElement = null;
|
||||
|
||||
public VoicePeer(EaglercraftUUID peerId, JSObject peerConnection, boolean offer) {
|
||||
this.peerId = peerId;
|
||||
@ -164,10 +165,10 @@ public class PlatformVoiceClient {
|
||||
});
|
||||
TeaVMUtils.addEventListener(peerConnection, "track", (EventListener<Event>) evt -> {
|
||||
rawStream = getFirstStream(evt);
|
||||
HTMLAudioElement aud = (HTMLAudioElement) PlatformRuntime.doc.createElement("audio");
|
||||
aud.setAutoplay(true);
|
||||
aud.setMuted(true);
|
||||
setSrcObject(aud, rawStream);
|
||||
mediaElement = (HTMLAudioElement) PlatformRuntime.doc.createElement("audio");
|
||||
mediaElement.setAutoplay(true);
|
||||
mediaElement.setMuted(true);
|
||||
setSrcObject(mediaElement, rawStream);
|
||||
handlePeerTrack(this, rawStream);
|
||||
});
|
||||
|
||||
|
@ -496,10 +496,6 @@ public class PlatformWebRTC {
|
||||
}
|
||||
}
|
||||
|
||||
public static final byte PEERSTATE_FAILED = 0;
|
||||
public static final byte PEERSTATE_SUCCESS = 1;
|
||||
public static final byte PEERSTATE_LOADING = 2;
|
||||
|
||||
public static class LANPeer {
|
||||
public LANServer client;
|
||||
public String peerId;
|
||||
@ -575,12 +571,7 @@ public class PlatformWebRTC {
|
||||
|
||||
TeaVMUtils.addEventListener(peerConnection, "connectionstatechange", (EventListener<Event>) evt -> {
|
||||
String connectionState = getConnectionState(peerConnection);
|
||||
if ("disconnected".equals(connectionState)) {
|
||||
client.signalRemoteDisconnect(peerId);
|
||||
} else if ("connected".equals(connectionState)) {
|
||||
if (client.peerState != PEERSTATE_SUCCESS) client.peerState = PEERSTATE_SUCCESS;
|
||||
} else if ("failed".equals(connectionState)) {
|
||||
if (client.peerState == PEERSTATE_LOADING) client.peerState = PEERSTATE_FAILED;
|
||||
if ("disconnected".equals(connectionState) || "failed".equals(connectionState)) {
|
||||
client.signalRemoteDisconnect(peerId);
|
||||
}
|
||||
});
|
||||
@ -604,27 +595,22 @@ public class PlatformWebRTC {
|
||||
synchronized(serverLANEventBuffer) {
|
||||
serverLANEventBuffer.put(peerId, e);
|
||||
}
|
||||
if (client.peerStateDesc != PEERSTATE_SUCCESS) client.peerStateDesc = PEERSTATE_SUCCESS;
|
||||
}, err -> {
|
||||
logger.error("Failed to set local description for \"{}\"! {}", peerId, TeaVMUtils.safeErrorMsgToString(err));
|
||||
if (client.peerStateDesc == PEERSTATE_LOADING) client.peerStateDesc = PEERSTATE_FAILED;
|
||||
client.signalRemoteDisconnect(peerId);
|
||||
});
|
||||
}, err -> {
|
||||
logger.error("Failed to create answer for \"{}\"! {}", peerId, TeaVMUtils.safeErrorMsgToString(err));
|
||||
if (client.peerStateDesc == PEERSTATE_LOADING) client.peerStateDesc = PEERSTATE_FAILED;
|
||||
client.signalRemoteDisconnect(peerId);
|
||||
});
|
||||
}
|
||||
}, err -> {
|
||||
logger.error("Failed to set remote description for \"{}\"! {}", peerId, TeaVMUtils.safeErrorMsgToString(err));
|
||||
if (client.peerStateDesc == PEERSTATE_LOADING) client.peerStateDesc = PEERSTATE_FAILED;
|
||||
client.signalRemoteDisconnect(peerId);
|
||||
});
|
||||
} catch (Throwable err) {
|
||||
logger.error("Failed to parse remote description for \"{}\"! {}", peerId, err.getMessage());
|
||||
logger.error(err);
|
||||
if (client.peerStateDesc == PEERSTATE_LOADING) client.peerStateDesc = PEERSTATE_FAILED;
|
||||
client.signalRemoteDisconnect(peerId);
|
||||
}
|
||||
}
|
||||
@ -632,10 +618,8 @@ public class PlatformWebRTC {
|
||||
public void addICECandidate(String candidates) {
|
||||
try {
|
||||
addIceCandidates(peerConnection, candidates);
|
||||
if (client.peerStateIce != PEERSTATE_SUCCESS) client.peerStateIce = PEERSTATE_SUCCESS;
|
||||
} catch (Throwable err) {
|
||||
logger.error("Failed to parse ice candidate for \"{}\"! {}", peerId, err.getMessage());
|
||||
if (client.peerStateIce == PEERSTATE_LOADING) client.peerStateIce = PEERSTATE_FAILED;
|
||||
client.signalRemoteDisconnect(peerId);
|
||||
}
|
||||
}
|
||||
@ -659,11 +643,6 @@ public class PlatformWebRTC {
|
||||
public Set<Map<String, String>> iceServers = new HashSet<>();
|
||||
public Map<String, LANPeer> peerList = new HashMap<>();
|
||||
public Map<String, LANPeer> ipcMapList = new HashMap<>();
|
||||
public byte peerState = PEERSTATE_LOADING;
|
||||
public byte peerStateConnect = PEERSTATE_LOADING;
|
||||
public byte peerStateInitial = PEERSTATE_LOADING;
|
||||
public byte peerStateDesc = PEERSTATE_LOADING;
|
||||
public byte peerStateIce = PEERSTATE_LOADING;
|
||||
|
||||
public void setIceServers(String[] urls) {
|
||||
iceServers.clear();
|
||||
@ -706,18 +685,15 @@ public class PlatformWebRTC {
|
||||
}
|
||||
}
|
||||
|
||||
public void resetPeerStates() {
|
||||
peerState = peerStateConnect = peerStateInitial = peerStateDesc = peerStateIce = PEERSTATE_LOADING;
|
||||
}
|
||||
|
||||
public void signalRemoteConnect(String peerId) {
|
||||
try {
|
||||
JSObject peerConnection = createRTCPeerConnection(JSONWriter.valueToString(iceServers));
|
||||
LANPeer peerInstance = new LANPeer(this, peerId, peerConnection);
|
||||
peerList.put(peerId, peerInstance);
|
||||
if (peerStateConnect != PEERSTATE_SUCCESS) peerStateConnect = PEERSTATE_SUCCESS;
|
||||
} catch (Throwable e) {
|
||||
if (peerStateConnect == PEERSTATE_LOADING) peerStateConnect = PEERSTATE_FAILED;
|
||||
logger.error("Failed to create peer for \"{}\"", peerId);
|
||||
logger.error(e);
|
||||
signalRemoteDisconnect(peerId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -907,7 +883,6 @@ public class PlatformWebRTC {
|
||||
synchronized(serverLANEventBuffer) {
|
||||
serverLANEventBuffer.clear();
|
||||
}
|
||||
rtcLANServer.resetPeerStates();
|
||||
rtcLANServer.setIceServers(servers);
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ public class IndexedDBFilesystem implements IEaglerFilesystem {
|
||||
TeaVMUtils.addEventListener(f, "blocked", new EventHandler() {
|
||||
@Override
|
||||
public void handleEvent() {
|
||||
cb.complete(new DatabaseOpen(false, true, null, null));
|
||||
cb.complete(new DatabaseOpen(false, true, "database locked", null));
|
||||
}
|
||||
});
|
||||
TeaVMUtils.addEventListener(f, "success", new EventHandler() {
|
||||
|
@ -24,19 +24,23 @@ public class OffsetTouch {
|
||||
public final int eventUID;
|
||||
public final int posX;
|
||||
public final int posY;
|
||||
public final float radius;
|
||||
|
||||
public OffsetTouch(Touch touch, int eventUID, int posX, int posY) {
|
||||
public OffsetTouch(Touch touch, int eventUID, int posX, int posY, float radius) {
|
||||
this.touch = touch;
|
||||
this.eventUID = eventUID;
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public static OffsetTouch create(Touch touch, ITouchUIDMapper mapper, int originX, int originY) {
|
||||
double contentScale = PlatformInput.getDPI();
|
||||
double d = 5.0 * contentScale;
|
||||
OffsetTouch ot = new OffsetTouch(touch, mapper.call(touch.getIdentifier()),
|
||||
(int) ((touch.getPageX() - originX) * contentScale),
|
||||
PlatformInput.getWindowHeight() - (int) ((touch.getPageY() - originY) * contentScale) - 1);
|
||||
PlatformInput.getWindowHeight() - (int) ((touch.getPageY() - originY) * contentScale) - 1,
|
||||
(float)(touch.getRadiusXSafe(d) * 0.5 + touch.getRadiusYSafe(d) * 0.5));
|
||||
return ot;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,9 @@ public class TeaVMUtils {
|
||||
@JSBody(params = { "obj", "name", "handler" }, script = "obj.addEventListener(name, handler);")
|
||||
public static native void addEventListener(JSObject obj, String name, JSObject handler);
|
||||
|
||||
@JSBody(params = { "obj", "name", "handler" }, script = "obj.removeEventListener(name, handler);")
|
||||
public static native void removeEventListener(JSObject obj, String name, JSObject handler);
|
||||
|
||||
@JSBody(params = {}, script = "return (new Error()).stack;")
|
||||
public static native String dumpJSStackTrace();
|
||||
|
||||
|
Reference in New Issue
Block a user