Update #46 - Fix pointer lock issue (sorta)

This commit is contained in:
lax1dude 2024-12-24 18:13:15 -08:00
parent 346047cf24
commit 3288d05a9a
19 changed files with 102 additions and 27 deletions

View File

@ -1 +1 @@
u45 u46

View File

@ -336,7 +336,7 @@
+ } + }
+ +
> INSERT 27 : 243 @ 27 > INSERT 27 : 247 @ 27
+ +
+ private int hotbarAreaX = -1; + private int hotbarAreaX = -1;
@ -369,12 +369,16 @@
+ && touchVPosX < interactButtonX + interactButtonW && touchVPosY < interactButtonY + interactButtonH; + && touchVPosX < interactButtonX + interactButtonW && touchVPosY < interactButtonY + interactButtonH;
+ float f = MathHelper.clamp_float(mc.gameSettings.touchControlOpacity, 0.0f, 1.0f); + float f = MathHelper.clamp_float(mc.gameSettings.touchControlOpacity, 0.0f, 1.0f);
+ if (f > 0.0f) { + if (f > 0.0f) {
+ if (f < 1.0f)
+ GlStateManager.enableBlend();
+ GlStateManager.color(1.0f, 1.0f, 1.0f, f); + GlStateManager.color(1.0f, 1.0f, 1.0f, f);
+ drawTexturedModalRect(xx, yy, 0, hover ? 216 : 236, 118, 20); + drawTexturedModalRect(xx, yy, 0, hover ? 216 : 236, 118, 20);
+ GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
+ drawCenteredString(mc.fontRendererObj, I18n.format("touch.interact.entity"), + drawCenteredString(mc.fontRendererObj, I18n.format("touch.interact.entity"),
+ parScaledResolution.getScaledWidth() / 2, yy + 6, + parScaledResolution.getScaledWidth() / 2, yy + 6,
+ (hover ? 16777120 : 14737632) | ((int) (f * 255.0f) << 24)); + (hover ? 16777120 : 14737632) | ((int) (f * 255.0f) << 24));
+ if (f < 1.0f)
+ GlStateManager.disableBlend();
+ } + }
+ } else { + } else {
+ interactButtonX = -1; + interactButtonX = -1;

View File

@ -96,4 +96,8 @@ public class ServerPlatformSingleplayer {
} }
public static boolean isTabAboutToCloseWASM() {
return false;
}
} }

View File

@ -10,7 +10,7 @@ public class EaglercraftVersion {
/// Customize these to fit your fork: /// Customize these to fit your fork:
public static final String projectForkName = "EaglercraftX"; public static final String projectForkName = "EaglercraftX";
public static final String projectForkVersion = "u45"; public static final String projectForkVersion = "u46";
public static final String projectForkVendor = "lax1dude"; public static final String projectForkVendor = "lax1dude";
public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8";
@ -20,20 +20,20 @@ public class EaglercraftVersion {
public static final String projectOriginName = "EaglercraftX"; public static final String projectOriginName = "EaglercraftX";
public static final String projectOriginAuthor = "lax1dude"; public static final String projectOriginAuthor = "lax1dude";
public static final String projectOriginRevision = "1.8"; public static final String projectOriginRevision = "1.8";
public static final String projectOriginVersion = "u45"; public static final String projectOriginVersion = "u46";
public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace
// EPK Version Identifier // EPK Version Identifier
public static final String EPKVersionIdentifier = "u45"; // Set to null to disable EPK version check public static final String EPKVersionIdentifier = "u46"; // Set to null to disable EPK version check
// Updating configuration // Updating configuration
public static final boolean enableUpdateService = true; public static final boolean enableUpdateService = true;
public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client"; public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client";
public static final int updateBundlePackageVersionInt = 45; public static final int updateBundlePackageVersionInt = 46;
public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName; public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName;

View File

@ -86,6 +86,11 @@ public class EaglerIntegratedServerWorker {
} }
} }
} }
if(ServerPlatformSingleplayer.isTabAboutToCloseWASM() && !isServerStopped()) {
logger.info("Autosaving worlds because the tab is about to close!");
currentProcess.getConfigurationManager().saveAllPlayerData();
currentProcess.saveAllWorlds(false);
}
} }
public static void tick() { public static void tick() {

View File

@ -1 +1 @@
u45 u46

View File

@ -162,7 +162,7 @@ void main() {
#ifdef COMPILE_ENABLE_MC_LIGHTING #ifdef COMPILE_ENABLE_MC_LIGHTING
#ifdef COMPILE_NORMAL_ATTRIB #ifdef COMPILE_NORMAL_ATTRIB
vec3 normal = normalize(v_normal3f); vec3 normal = v_normal3f;
#else #else
vec3 normal = u_uniformNormal3f; vec3 normal = u_uniformNormal3f;
#endif #endif

View File

@ -104,7 +104,7 @@ void main() {
vec3 normal; vec3 normal;
#ifdef COMPILE_NORMAL_ATTRIB #ifdef COMPILE_NORMAL_ATTRIB
normal = normalize(v_normal3f); normal = v_normal3f;
#else #else
normal = u_uniformNormal3f; normal = u_uniformNormal3f;
#endif #endif

View File

@ -206,8 +206,8 @@ void main() {
#endif #endif
#ifdef COMPILE_NORMAL_ATTRIB #ifdef COMPILE_NORMAL_ATTRIB
normalVector3f = normalize(v_normal3f); normalVector3f = v_normal3f;
block1f = v_block1f; block1f = round(v_block1f);
#else #else
normalVector3f = u_uniformNormal3f; normalVector3f = u_uniformNormal3f;
block1f = u_blockConstant1f; block1f = u_blockConstant1f;

View File

@ -199,7 +199,7 @@ void main() {
#endif #endif
#ifdef COMPILE_NORMAL_ATTRIB #ifdef COMPILE_NORMAL_ATTRIB
normalVector3f = normalize(v_normal3f); normalVector3f = v_normal3f;
block1f = round(v_block1f); block1f = round(v_block1f);
#else #else
normalVector3f = u_uniformNormal3f; normalVector3f = u_uniformNormal3f;

View File

@ -146,7 +146,7 @@ void main() {
#endif #endif
#ifdef COMPILE_NORMAL_ATTRIB #ifdef COMPILE_NORMAL_ATTRIB
vec3 normal = normalize(v_normal3f); vec3 normal = v_normal3f;
#else #else
vec3 normal = u_uniformNormal3f; vec3 normal = u_uniformNormal3f;
#endif #endif

View File

@ -1,8 +1,8 @@
client-version-integer=45 client-version-integer=46
client-package-name=net.lax1dude.eaglercraft.v1_8.client client-package-name=net.lax1dude.eaglercraft.v1_8.client
client-origin-name=EaglercraftX client-origin-name=EaglercraftX
client-origin-version=u45 client-origin-version=u46
client-origin-vendor=lax1dude client-origin-vendor=lax1dude
client-fork-name=EaglercraftX client-fork-name=EaglercraftX
client-fork-version=u45 client-fork-version=u46
client-fork-vendor=lax1dude client-fork-vendor=lax1dude

View File

@ -99,6 +99,7 @@ public class PlatformInput {
private static EventListener<?> focus = null; private static EventListener<?> focus = null;
private static EventListener<?> blur = null; private static EventListener<?> blur = null;
private static EventListener<?> pointerlock = null; private static EventListener<?> pointerlock = null;
private static EventListener<?> pointerlockerr = null;
private static EventListener<?> fullscreen = null; private static EventListener<?> fullscreen = null;
private static Map<String,LegacyKeycodeTranslator.LegacyKeycode> keyCodeTranslatorMap = null; private static Map<String,LegacyKeycodeTranslator.LegacyKeycode> keyCodeTranslatorMap = null;
@ -224,6 +225,7 @@ public class PlatformInput {
private static long mouseGrabTimer = 0l; private static long mouseGrabTimer = 0l;
private static int mouseUngrabTimeout = -1; private static int mouseUngrabTimeout = -1;
private static boolean pointerLockFlag = false; private static boolean pointerLockFlag = false;
private static boolean pointerLockWaiting = false;
private static final int FULLSCREEN_NONE = 0; private static final int FULLSCREEN_NONE = 0;
private static final int FULLSCREEN_CORE = 1; private static final int FULLSCREEN_CORE = 1;
@ -643,7 +645,7 @@ public class PlatformInput {
Window.setTimeout(new TimerHandler() { Window.setTimeout(new TimerHandler() {
@Override @Override
public void onTimer() { public void onTimer() {
boolean grab = isPointerLocked(); boolean grab = isPointerLockedImpl();
if(!grab) { if(!grab) {
if(pointerLockFlag) { if(pointerLockFlag) {
mouseUngrabTimer = PlatformRuntime.steadyTimeMillis(); mouseUngrabTimer = PlatformRuntime.steadyTimeMillis();
@ -654,6 +656,13 @@ public class PlatformInput {
}, 60); }, 60);
mouseDX = 0.0D; mouseDX = 0.0D;
mouseDY = 0.0D; mouseDY = 0.0D;
pointerLockWaiting = false;
}
});
win.getDocument().addEventListener(pointerLockSupported == POINTER_LOCK_MOZ ? "mozpointerlockerror" : "pointerlockerror", pointerlockerr = new EventListener<Event>() {
@Override
public void handleEvent(Event evt) {
pointerLockWaiting = false;
} }
}); });
if(pointerLockSupported == POINTER_LOCK_MOZ) { if(pointerLockSupported == POINTER_LOCK_MOZ) {
@ -693,9 +702,9 @@ public class PlatformInput {
} }
}); });
} }
if(pointerLockSupported == FULLSCREEN_WEBKIT) { if(fullscreenSupported == FULLSCREEN_WEBKIT) {
PlatformRuntime.logger.info("Using webkit- vendor prefix for fullscreen"); PlatformRuntime.logger.info("Using webkit- vendor prefix for fullscreen");
}else if(pointerLockSupported == FULLSCREEN_MOZ) { }else if(fullscreenSupported == FULLSCREEN_MOZ) {
PlatformRuntime.logger.info("Using moz- vendor prefix for fullscreen"); PlatformRuntime.logger.info("Using moz- vendor prefix for fullscreen");
} }
}else { }else {
@ -1322,6 +1331,7 @@ public class PlatformInput {
pointerLockFlag = grab; pointerLockFlag = grab;
mouseGrabTimer = t; mouseGrabTimer = t;
if(grab) { if(grab) {
pointerLockWaiting = true;
callRequestPointerLock(canvas); callRequestPointerLock(canvas);
if(mouseUngrabTimeout != -1) Window.clearTimeout(mouseUngrabTimeout); if(mouseUngrabTimeout != -1) Window.clearTimeout(mouseUngrabTimeout);
mouseUngrabTimeout = -1; mouseUngrabTimeout = -1;
@ -1336,8 +1346,10 @@ public class PlatformInput {
}else { }else {
if(mouseUngrabTimeout != -1) Window.clearTimeout(mouseUngrabTimeout); if(mouseUngrabTimeout != -1) Window.clearTimeout(mouseUngrabTimeout);
mouseUngrabTimeout = -1; mouseUngrabTimeout = -1;
if(!pointerLockWaiting) {
callExitPointerLock(win.getDocument()); callExitPointerLock(win.getDocument());
} }
}
mouseDX = 0.0D; mouseDX = 0.0D;
mouseDY = 0.0D; mouseDY = 0.0D;
} }
@ -1408,6 +1420,11 @@ public class PlatformInput {
} }
public static boolean isPointerLocked() { public static boolean isPointerLocked() {
if(pointerLockWaiting) return true; // workaround for chrome bug
return isPointerLockedImpl();
}
private static boolean isPointerLockedImpl() {
switch(pointerLockSupported) { switch(pointerLockSupported) {
case POINTER_LOCK_CORE: case POINTER_LOCK_CORE:
return isPointerLocked0(win.getDocument(), canvas); return isPointerLocked0(win.getDocument(), canvas);
@ -1534,6 +1551,10 @@ public class PlatformInput {
win.getDocument().removeEventListener("pointerlockchange", pointerlock); win.getDocument().removeEventListener("pointerlockchange", pointerlock);
pointerlock = null; pointerlock = null;
} }
if(pointerlockerr != null) {
win.getDocument().removeEventListener("pointerlockerror", pointerlockerr);
pointerlockerr = null;
}
if(fullscreen != null) { if(fullscreen != null) {
TeaVMUtils.removeEventListener(fullscreenQuery, "change", fullscreen); TeaVMUtils.removeEventListener(fullscreenQuery, "change", fullscreen);
fullscreen = null; fullscreen = null;

View File

@ -296,4 +296,8 @@ public class ServerPlatformSingleplayer {
} }
public static boolean isTabAboutToCloseWASM() {
return false;
}
} }

View File

@ -143,4 +143,7 @@ public class ServerPlatformSingleplayer {
@Import(module = "serverPlatformSingleplayer", name = "setCrashCallback") @Import(module = "serverPlatformSingleplayer", name = "setCrashCallback")
private static native JSWASMCrashCallbackInterface setCrashCallbackWASM0(); private static native JSWASMCrashCallbackInterface setCrashCallbackWASM0();
@Import(module = "serverPlatformSingleplayer", name = "isTabAboutToClose")
public static native boolean isTabAboutToCloseWASM();
} }

View File

@ -196,6 +196,13 @@ function initializeClientPlatfSP(spImports) {
} }
}; };
window.__curEaglerX188UnloadListenerCB = function() {
if(workerObj) {
workerObj.postMessage({
"ch": "~!WASM_AUTOSAVE"
});
}
};
} }
function initializeNoClientPlatfSP(spImports) { function initializeNoClientPlatfSP(spImports) {

View File

@ -133,9 +133,6 @@ async function initializeContext() {
currentRedirectorFunc = addLogMessageImpl; currentRedirectorFunc = addLogMessageImpl;
window.__curEaglerX188UnloadListenerCB = function() {
//TODO: Autosave somehow?
};
if(window.__isEaglerX188UnloadListenerSet !== "yes") { if(window.__isEaglerX188UnloadListenerSet !== "yes") {
window.onbeforeunload = function(evt) { window.onbeforeunload = function(evt) {
if(window.__curEaglerX188UnloadListenerCB) { if(window.__curEaglerX188UnloadListenerCB) {

View File

@ -80,6 +80,7 @@ async function initPlatformInput(inputImports) {
var pointerLockSupported = false; var pointerLockSupported = false;
var pointerLockFlag = false; var pointerLockFlag = false;
var pointerLockWaiting = false;
var mouseUngrabTimer = 0; var mouseUngrabTimer = 0;
var mouseGrabTimer = 0; var mouseGrabTimer = 0;
var mouseUngrabTimeout = -1; var mouseUngrabTimeout = -1;
@ -116,6 +117,7 @@ async function initPlatformInput(inputImports) {
focus: null, focus: null,
blur: null, blur: null,
pointerlock: null, pointerlock: null,
pointerlockerr: null,
fullscreenChange: null fullscreenChange: null
}; };
@ -412,6 +414,10 @@ async function initPlatformInput(inputImports) {
} }
pointerLockFlag = grab; pointerLockFlag = grab;
}, 60); }, 60);
pointerLockWaiting = false;
}));
document.addEventListener("pointerlockerror", /** @type {function(Event)} */ (currentEventListeners.pointerlockerr = function(evt) {
pointerLockWaiting = false;
})); }));
}else { }else {
eagError("Pointer lock is not supported on this browser"); eagError("Pointer lock is not supported on this browser");
@ -646,6 +652,7 @@ async function initPlatformInput(inputImports) {
const t = performance.now() | 0; const t = performance.now() | 0;
mouseGrabTimer = t; mouseGrabTimer = t;
if(grab) { if(grab) {
pointerLockWaiting = true;
try { try {
canvasElement.requestPointerLock(); canvasElement.requestPointerLock();
}catch(ex) { }catch(ex) {
@ -663,11 +670,13 @@ async function initPlatformInput(inputImports) {
}else { }else {
if(mouseUngrabTimeout !== -1) window.clearTimeout(mouseUngrabTimeout); if(mouseUngrabTimeout !== -1) window.clearTimeout(mouseUngrabTimeout);
mouseUngrabTimeout = -1; mouseUngrabTimeout = -1;
if(!pointerLockWaiting) {
try { try {
document.exitPointerLock(); document.exitPointerLock();
}catch(ex) { }catch(ex) {
} }
} }
}
}; };
inputImports["mouseSetGrabbed"] = mouseSetGrabbed; inputImports["mouseSetGrabbed"] = mouseSetGrabbed;
@ -690,7 +699,7 @@ async function initPlatformInput(inputImports) {
* @return {boolean} * @return {boolean}
*/ */
inputImports["isPointerLocked"] = function() { inputImports["isPointerLocked"] = function() {
return pointerLockSupported && document.pointerLockElement === canvasElement; return pointerLockSupported && (pointerLockWaiting || document.pointerLockElement === canvasElement);
}; };
/** /**
@ -1124,6 +1133,10 @@ async function initPlatformInput(inputImports) {
document.removeEventListener("pointerlockchange", /** @type {function(Event)} */ (currentEventListeners.pointerlock)); document.removeEventListener("pointerlockchange", /** @type {function(Event)} */ (currentEventListeners.pointerlock));
currentEventListeners.pointerlock = null; currentEventListeners.pointerlock = null;
} }
if(currentEventListeners.pointerlockerr) {
document.removeEventListener("pointerlockerror", /** @type {function(Event)} */ (currentEventListeners.pointerlockerr));
currentEventListeners.pointerlockerr = null;
}
if(currentEventListeners.fullscreenChange) { if(currentEventListeners.fullscreenChange) {
fullscreenQuery.removeEventListener("change", /** @type {function(Event)} */ (currentEventListeners.fullscreenChange)); fullscreenQuery.removeEventListener("change", /** @type {function(Event)} */ (currentEventListeners.fullscreenChange));
currentEventListeners.fullscreenChange = null; currentEventListeners.fullscreenChange = null;

View File

@ -19,6 +19,9 @@ const serverPlatfSPName = "serverPlatformSingleplayer";
/** @type {function(string, boolean)|null} */ /** @type {function(string, boolean)|null} */
var sendIntegratedServerCrash = null; var sendIntegratedServerCrash = null;
/** @type {boolean} */
var isTabClosingFlag = false;
function initializeServerPlatfSP(spImports) { function initializeServerPlatfSP(spImports) {
const serverMessageQueue = new EaglerLinkedQueue(); const serverMessageQueue = new EaglerLinkedQueue();
@ -35,6 +38,11 @@ function initializeServerPlatfSP(spImports) {
return; return;
} }
if(channel === "~!WASM_AUTOSAVE") {
isTabClosingFlag = true;
return;
}
if(!buf) { if(!buf) {
eagError("Recieved IPC packet with null buffer"); eagError("Recieved IPC packet with null buffer");
return; return;
@ -72,6 +80,14 @@ function initializeServerPlatfSP(spImports) {
}; };
}; };
/**
* @return {boolean}
*/
spImports["isTabAboutToClose"] = function() {
const ret = isTabClosingFlag;
isTabClosingFlag = false;
return ret;
};
} }
function initializeNoServerPlatfSP(spImports) { function initializeNoServerPlatfSP(spImports) {
@ -79,4 +95,5 @@ function initializeNoServerPlatfSP(spImports) {
setUnsupportedFunc(spImports, serverPlatfSPName, "getAvailablePackets"); setUnsupportedFunc(spImports, serverPlatfSPName, "getAvailablePackets");
setUnsupportedFunc(spImports, serverPlatfSPName, "getNextPacket"); setUnsupportedFunc(spImports, serverPlatfSPName, "getNextPacket");
setUnsupportedFunc(spImports, serverPlatfSPName, "setCrashCallback"); setUnsupportedFunc(spImports, serverPlatfSPName, "setCrashCallback");
setUnsupportedFunc(spImports, serverPlatfSPName, "isTabAboutToClose");
} }