mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-27 18:38:14 -05:00
Update #46 - Fix pointer lock issue (sorta)
This commit is contained in:
@ -143,4 +143,7 @@ public class ServerPlatformSingleplayer {
|
||||
@Import(module = "serverPlatformSingleplayer", name = "setCrashCallback")
|
||||
private static native JSWASMCrashCallbackInterface setCrashCallbackWASM0();
|
||||
|
||||
@Import(module = "serverPlatformSingleplayer", name = "isTabAboutToClose")
|
||||
public static native boolean isTabAboutToCloseWASM();
|
||||
|
||||
}
|
||||
|
@ -196,6 +196,13 @@ function initializeClientPlatfSP(spImports) {
|
||||
}
|
||||
};
|
||||
|
||||
window.__curEaglerX188UnloadListenerCB = function() {
|
||||
if(workerObj) {
|
||||
workerObj.postMessage({
|
||||
"ch": "~!WASM_AUTOSAVE"
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function initializeNoClientPlatfSP(spImports) {
|
||||
|
@ -133,9 +133,6 @@ async function initializeContext() {
|
||||
|
||||
currentRedirectorFunc = addLogMessageImpl;
|
||||
|
||||
window.__curEaglerX188UnloadListenerCB = function() {
|
||||
//TODO: Autosave somehow?
|
||||
};
|
||||
if(window.__isEaglerX188UnloadListenerSet !== "yes") {
|
||||
window.onbeforeunload = function(evt) {
|
||||
if(window.__curEaglerX188UnloadListenerCB) {
|
||||
|
@ -80,6 +80,7 @@ async function initPlatformInput(inputImports) {
|
||||
|
||||
var pointerLockSupported = false;
|
||||
var pointerLockFlag = false;
|
||||
var pointerLockWaiting = false;
|
||||
var mouseUngrabTimer = 0;
|
||||
var mouseGrabTimer = 0;
|
||||
var mouseUngrabTimeout = -1;
|
||||
@ -116,6 +117,7 @@ async function initPlatformInput(inputImports) {
|
||||
focus: null,
|
||||
blur: null,
|
||||
pointerlock: null,
|
||||
pointerlockerr: null,
|
||||
fullscreenChange: null
|
||||
};
|
||||
|
||||
@ -412,6 +414,10 @@ async function initPlatformInput(inputImports) {
|
||||
}
|
||||
pointerLockFlag = grab;
|
||||
}, 60);
|
||||
pointerLockWaiting = false;
|
||||
}));
|
||||
document.addEventListener("pointerlockerror", /** @type {function(Event)} */ (currentEventListeners.pointerlockerr = function(evt) {
|
||||
pointerLockWaiting = false;
|
||||
}));
|
||||
}else {
|
||||
eagError("Pointer lock is not supported on this browser");
|
||||
@ -646,6 +652,7 @@ async function initPlatformInput(inputImports) {
|
||||
const t = performance.now() | 0;
|
||||
mouseGrabTimer = t;
|
||||
if(grab) {
|
||||
pointerLockWaiting = true;
|
||||
try {
|
||||
canvasElement.requestPointerLock();
|
||||
}catch(ex) {
|
||||
@ -663,9 +670,11 @@ async function initPlatformInput(inputImports) {
|
||||
}else {
|
||||
if(mouseUngrabTimeout !== -1) window.clearTimeout(mouseUngrabTimeout);
|
||||
mouseUngrabTimeout = -1;
|
||||
try {
|
||||
document.exitPointerLock();
|
||||
}catch(ex) {
|
||||
if(!pointerLockWaiting) {
|
||||
try {
|
||||
document.exitPointerLock();
|
||||
}catch(ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -690,7 +699,7 @@ async function initPlatformInput(inputImports) {
|
||||
* @return {boolean}
|
||||
*/
|
||||
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));
|
||||
currentEventListeners.pointerlock = null;
|
||||
}
|
||||
if(currentEventListeners.pointerlockerr) {
|
||||
document.removeEventListener("pointerlockerror", /** @type {function(Event)} */ (currentEventListeners.pointerlockerr));
|
||||
currentEventListeners.pointerlockerr = null;
|
||||
}
|
||||
if(currentEventListeners.fullscreenChange) {
|
||||
fullscreenQuery.removeEventListener("change", /** @type {function(Event)} */ (currentEventListeners.fullscreenChange));
|
||||
currentEventListeners.fullscreenChange = null;
|
||||
|
@ -19,6 +19,9 @@ const serverPlatfSPName = "serverPlatformSingleplayer";
|
||||
/** @type {function(string, boolean)|null} */
|
||||
var sendIntegratedServerCrash = null;
|
||||
|
||||
/** @type {boolean} */
|
||||
var isTabClosingFlag = false;
|
||||
|
||||
function initializeServerPlatfSP(spImports) {
|
||||
|
||||
const serverMessageQueue = new EaglerLinkedQueue();
|
||||
@ -35,6 +38,11 @@ function initializeServerPlatfSP(spImports) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(channel === "~!WASM_AUTOSAVE") {
|
||||
isTabClosingFlag = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(!buf) {
|
||||
eagError("Recieved IPC packet with null buffer");
|
||||
return;
|
||||
@ -72,6 +80,14 @@ function initializeServerPlatfSP(spImports) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean}
|
||||
*/
|
||||
spImports["isTabAboutToClose"] = function() {
|
||||
const ret = isTabClosingFlag;
|
||||
isTabClosingFlag = false;
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
function initializeNoServerPlatfSP(spImports) {
|
||||
@ -79,4 +95,5 @@ function initializeNoServerPlatfSP(spImports) {
|
||||
setUnsupportedFunc(spImports, serverPlatfSPName, "getAvailablePackets");
|
||||
setUnsupportedFunc(spImports, serverPlatfSPName, "getNextPacket");
|
||||
setUnsupportedFunc(spImports, serverPlatfSPName, "setCrashCallback");
|
||||
setUnsupportedFunc(spImports, serverPlatfSPName, "isTabAboutToClose");
|
||||
}
|
||||
|
Reference in New Issue
Block a user