Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future-proof dynCalls #233

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var SystemThreadingTimerLib = {
setTimeout(function()
{
if (id === vars.currentCallbackId)
Runtime.dynCall('v', vars.callback);
{{{ makeDynCall("v", "vars.callback") }}}();
},
interval);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var LibraryWebSocket = {
console.log("[JSLIB WebSocket] Connected.");

if (webSocketState.onOpen)
Module.dynCall_vi(webSocketState.onOpen, instanceId);
{{{ makeDynCall("vi", "webSocketState.onOpen") }}}(instanceId);

};

Expand All @@ -170,7 +170,7 @@ var LibraryWebSocket = {
HEAPU8.set(dataBuffer, buffer);

try {
Module.dynCall_viii(webSocketState.onMessage, instanceId, buffer, dataBuffer.length);
{{{ makeDynCall("viii", "webSocketState.onMessage") }}}(instanceId, buffer, dataBuffer.length);
} finally {
_free(buffer);
}
Expand All @@ -182,7 +182,7 @@ var LibraryWebSocket = {
HEAPU8.set(dataBuffer, buffer);

try {
Module.dynCall_viii(webSocketState.onMessage, instanceId, buffer, dataBuffer.length);
{{{ makeDynCall("viii", "webSocketState.onMessage") }}}(instanceId, buffer, dataBuffer.length);
} finally {
_free(buffer);
}
Expand All @@ -204,7 +204,7 @@ var LibraryWebSocket = {
stringToUTF8(msg, buffer, length);

try {
Module.dynCall_vii(webSocketState.onError, instanceId, buffer);
{{{ makeDynCall("vii", "webSocketState.onError") }}}(instanceId, buffer);
} finally {
_free(buffer);
}
Expand All @@ -219,7 +219,7 @@ var LibraryWebSocket = {
console.log("[JSLIB WebSocket] Closed.");

if (webSocketState.onClose)
Module.dynCall_vii(webSocketState.onClose, instanceId, ev.code);
{{{ makeDynCall("vii", "webSocketState.onClose") }}}(instanceId, ev.code);

delete instance.ws;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ var WebGLInputMobile = {

document.body.addEventListener("touchend", function () {
document.body.removeEventListener("touchend", arguments.callee);
Runtime.dynCall("vi", touchend, [id]);
{{{ makeDynCall("vi", "touchend") }}}(id);
});

return id;
},
WebGLInputMobileOnFocusOut: function (id, focusout) {
document.body.addEventListener("focusout", function () {
document.body.removeEventListener("focusout", arguments.callee);
Runtime.dynCall("vi", focusout, [id]);
{{{ makeDynCall("vi", "focusout") }}}(id);
});
},
}
Expand Down
25 changes: 6 additions & 19 deletions Assets/Thirdweb/Plugins/WebGLInputCopy/WebGLInput/WebGLInput.jslib
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
var WebGLInput = {
$instances: [],
WebGLInputInit : function() {
// use WebAssembly.Table : makeDynCall
// when enable. dynCall is undefined
if(typeof dynCall === "undefined")
{
// make Runtime.dynCall to undefined
Runtime = { dynCall : undefined }
}
else
{
// Remove the `Runtime` object from "v1.37.27: 12/24/2017"
// if Runtime not defined. create and add functon!!
if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall }
}
},
WebGLInputCreate: function (canvasId, x, y, width, height, fontsize, text, placeholder, isMultiLine, isPassword, isHidden, isMobile) {

Expand Down Expand Up @@ -112,7 +99,7 @@ var WebGLInput = {
input.setSelectionRange(start + 1, start + 1);
input.oninput(); // call oninput to exe ValueChange function!!
} else {
(!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, e.shiftKey ? -1 : 1]) : {{{ makeDynCall("vii", "cb") }}}(id, e.shiftKey ? -1 : 1);
{{{ makeDynCall("vii", "cb") }}}(id, e.shiftKey ? -1 : 1);
}
}
});
Expand All @@ -124,13 +111,13 @@ var WebGLInput = {
WebGLInputOnFocus: function (id, cb) {
var input = instances[id];
input.onfocus = function () {
(!!Runtime.dynCall) ? Runtime.dynCall("vi", cb, [id]) : {{{ makeDynCall("vi", "cb") }}}(id);
{{{ makeDynCall("vi", "cb") }}}(id);
};
},
WebGLInputOnBlur: function (id, cb) {
var input = instances[id];
input.onblur = function () {
(!!Runtime.dynCall) ? Runtime.dynCall("vi", cb, [id]) : {{{ makeDynCall("vi", "cb") }}}(id);
{{{ makeDynCall("vi", "cb") }}}(id);
};
},
WebGLInputIsFocus: function (id) {
Expand All @@ -143,7 +130,7 @@ var WebGLInput = {
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
(!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, buffer]) : {{{ makeDynCall("vii", "cb") }}}(id, buffer);
{{{ makeDynCall("vii", "cb") }}}(id, buffer);
};
},
WebGLInputOnEditEnd:function(id, cb){
Expand All @@ -153,7 +140,7 @@ var WebGLInput = {
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
(!!Runtime.dynCall) ? Runtime.dynCall("vii", cb, [id, buffer]) : {{{ makeDynCall("vii", "cb") }}}(id, buffer);
{{{ makeDynCall("vii", "cb") }}}(id, buffer);
};
},
WebGLInputOnKeyboardEvent:function(id, cb){
Expand All @@ -167,7 +154,7 @@ var WebGLInput = {
var shift = e.shiftKey ? 1 : 0;
var ctrl = e.ctrlKey ? 1 : 0;
var alt = e.altKey ? 1 : 0;
(!!Runtime.dynCall) ? Runtime.dynCall("viiiiiii", cb, [id, mode, key, code, shift, ctrl, alt]) : {{{ makeDynCall("viiiiiii", "cb") }}}(id, mode, key, code, shift, ctrl, alt);
{{{ makeDynCall("viiiiiii", "cb") }}}(id, mode, key, code, shift, ctrl, alt);
}
}
input.addEventListener('keydown', function(e) { func(1, e); });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
#if parseInt(EMSCRIPTEN_VERSION.split('.')[0]) < 2 || (parseInt(EMSCRIPTEN_VERSION.split('.')[0]) == 2 && parseInt(EMSCRIPTEN_VERSION.split('.')[1]) < 0) || (parseInt(EMSCRIPTEN_VERSION.split('.')[0]) == 2 && parseInt(EMSCRIPTEN_VERSION.split('.')[1]) == 0 && parseInt(EMSCRIPTEN_VERSION.split('.')[2]) < 3)
#error "ThirdWeb plugin requires building with Emscripten 2.0.3 and Unity 2021.2 or newer. Please update"
#endif

var WebGLWindow = {
WebGLWindowInit : function() {
// use WebAssembly.Table : makeDynCall
// when enable. dynCall is undefined
if(typeof dynCall === "undefined")
{
// make Runtime.dynCall to undefined
Runtime = { dynCall : undefined }
}
else
{
// Remove the `Runtime` object from "v1.37.27: 12/24/2017"
// if Runtime not defined. create and add functon!!
if(typeof Runtime === "undefined") Runtime = { dynCall : dynCall }
}
},
WebGLWindowGetCanvasName: function() {
var elements = document.getElementsByTagName('canvas');
Expand All @@ -33,17 +24,17 @@ var WebGLWindow = {
},
WebGLWindowOnFocus: function (cb) {
window.addEventListener('focus', function () {
(!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}();
{{{ makeDynCall("v", "cb") }}}();
});
},
WebGLWindowOnBlur: function (cb) {
window.addEventListener('blur', function () {
(!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}();
{{{ makeDynCall("v", "cb") }}}();
});
},
WebGLWindowOnResize: function(cb) {
window.addEventListener('resize', function () {
(!!Runtime.dynCall) ? Runtime.dynCall("v", cb, []) : {{{ makeDynCall("v", "cb") }}}();
{{{ makeDynCall("v", "cb") }}}();
});
},
WebGLWindowInjectFullscreen : function () {
Expand Down