Skip to content

Commit

Permalink
Add do_not_block_main_thread option to platform=web
Browse files Browse the repository at this point in the history
  • Loading branch information
adamscott committed Jul 23, 2023
1 parent 6588a4a commit b165a84
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 29 deletions.
20 changes: 20 additions & 0 deletions modules/webrtc/library_godot_webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const GodotRTCDataChannel = {
},
},

godot_js_rtc_datachannel_ready_state_get__proxy: 'sync',
godot_js_rtc_datachannel_ready_state_get__sig: 'ii',
godot_js_rtc_datachannel_ready_state_get: function (p_id) {
const ref = IDHandler.get(p_id);
Expand All @@ -110,6 +111,7 @@ const GodotRTCDataChannel = {
}
},

godot_js_rtc_datachannel_send__proxy: 'sync',
godot_js_rtc_datachannel_send__sig: 'iiiii',
godot_js_rtc_datachannel_send: function (p_id, p_buffer, p_length, p_raw) {
const ref = IDHandler.get(p_id);
Expand All @@ -131,16 +133,19 @@ const GodotRTCDataChannel = {
return 0;
},

godot_js_rtc_datachannel_is_ordered__proxy: 'sync',
godot_js_rtc_datachannel_is_ordered__sig: 'ii',
godot_js_rtc_datachannel_is_ordered: function (p_id) {
return GodotRTCDataChannel.get_prop(p_id, 'ordered', true);
},

godot_js_rtc_datachannel_id_get__proxy: 'sync',
godot_js_rtc_datachannel_id_get__sig: 'ii',
godot_js_rtc_datachannel_id_get: function (p_id) {
return GodotRTCDataChannel.get_prop(p_id, 'id', 65535);
},

godot_js_rtc_datachannel_max_packet_lifetime_get__proxy: 'sync',
godot_js_rtc_datachannel_max_packet_lifetime_get__sig: 'ii',
godot_js_rtc_datachannel_max_packet_lifetime_get: function (p_id) {
const ref = IDHandler.get(p_id);
Expand All @@ -156,21 +161,25 @@ const GodotRTCDataChannel = {
return 65535;
},

godot_js_rtc_datachannel_max_retransmits_get__proxy: 'sync',
godot_js_rtc_datachannel_max_retransmits_get__sig: 'ii',
godot_js_rtc_datachannel_max_retransmits_get: function (p_id) {
return GodotRTCDataChannel.get_prop(p_id, 'maxRetransmits', 65535);
},

godot_js_rtc_datachannel_is_negotiated__proxy: 'sync',
godot_js_rtc_datachannel_is_negotiated__sig: 'ii',
godot_js_rtc_datachannel_is_negotiated: function (p_id) {
return GodotRTCDataChannel.get_prop(p_id, 'negotiated', 65535);
},

godot_js_rtc_datachannel_get_buffered_amount__proxy: 'sync',
godot_js_rtc_datachannel_get_buffered_amount__sig: 'ii',
godot_js_rtc_datachannel_get_buffered_amount: function (p_id) {
return GodotRTCDataChannel.get_prop(p_id, 'bufferedAmount', 0);
},

godot_js_rtc_datachannel_label_get__proxy: 'sync',
godot_js_rtc_datachannel_label_get__sig: 'ii',
godot_js_rtc_datachannel_label_get: function (p_id) {
const ref = IDHandler.get(p_id);
Expand All @@ -189,12 +198,14 @@ const GodotRTCDataChannel = {
return GodotRuntime.allocString(ref.protocol);
},

godot_js_rtc_datachannel_destroy__proxy: 'sync',
godot_js_rtc_datachannel_destroy__sig: 'vi',
godot_js_rtc_datachannel_destroy: function (p_id) {
GodotRTCDataChannel.close(p_id);
IDHandler.remove(p_id);
},

godot_js_rtc_datachannel_connect__proxy: 'sync',
godot_js_rtc_datachannel_connect__sig: 'viiiiii',
godot_js_rtc_datachannel_connect: function (p_id, p_ref, p_on_open, p_on_message, p_on_error, p_on_close) {
const onopen = GodotRuntime.get_func(p_on_open).bind(null, p_ref);
Expand All @@ -204,6 +215,7 @@ const GodotRTCDataChannel = {
GodotRTCDataChannel.connect(p_id, onopen, onmessage, onerror, onclose);
},

godot_js_rtc_datachannel_close__proxy: 'sync',
godot_js_rtc_datachannel_close__sig: 'vi',
godot_js_rtc_datachannel_close: function (p_id) {
const ref = IDHandler.get(p_id);
Expand Down Expand Up @@ -356,6 +368,7 @@ const GodotRTCPeerConnection = {
},
},

godot_js_rtc_pc_create__proxy: 'sync',
godot_js_rtc_pc_create__sig: 'iiiiiiii',
godot_js_rtc_pc_create: function (p_config, p_ref, p_on_connection_state_change, p_on_ice_gathering_state_change, p_on_signaling_state_change, p_on_ice_candidate, p_on_datachannel) {
const wrap = function (p_func) {
Expand All @@ -371,6 +384,7 @@ const GodotRTCPeerConnection = {
);
},

godot_js_rtc_pc_close__proxy: 'sync',
godot_js_rtc_pc_close__sig: 'vi',
godot_js_rtc_pc_close: function (p_id) {
const ref = IDHandler.get(p_id);
Expand All @@ -380,11 +394,13 @@ const GodotRTCPeerConnection = {
ref.close();
},

godot_js_rtc_pc_destroy__proxy: 'sync',
godot_js_rtc_pc_destroy__sig: 'vi',
godot_js_rtc_pc_destroy: function (p_id) {
GodotRTCPeerConnection.destroy(p_id);
},

godot_js_rtc_pc_offer_create__proxy: 'sync',
godot_js_rtc_pc_offer_create__sig: 'viiii',
godot_js_rtc_pc_offer_create: function (p_id, p_obj, p_on_session, p_on_error) {
const ref = IDHandler.get(p_id);
Expand All @@ -400,6 +416,7 @@ const GodotRTCPeerConnection = {
});
},

godot_js_rtc_pc_local_description_set__proxy: 'sync',
godot_js_rtc_pc_local_description_set__sig: 'viiiii',
godot_js_rtc_pc_local_description_set: function (p_id, p_type, p_sdp, p_obj, p_on_error) {
const ref = IDHandler.get(p_id);
Expand All @@ -417,6 +434,7 @@ const GodotRTCPeerConnection = {
});
},

godot_js_rtc_pc_remote_description_set__proxy: 'sync',
godot_js_rtc_pc_remote_description_set__sig: 'viiiiii',
godot_js_rtc_pc_remote_description_set: function (p_id, p_type, p_sdp, p_obj, p_session_created, p_on_error) {
const ref = IDHandler.get(p_id);
Expand All @@ -442,6 +460,7 @@ const GodotRTCPeerConnection = {
});
},

godot_js_rtc_pc_ice_candidate_add__proxy: 'sync',
godot_js_rtc_pc_ice_candidate_add__sig: 'viiii',
godot_js_rtc_pc_ice_candidate_add: function (p_id, p_mid_name, p_mline_idx, p_sdp) {
const ref = IDHandler.get(p_id);
Expand All @@ -458,6 +477,7 @@ const GodotRTCPeerConnection = {
},

godot_js_rtc_pc_datachannel_create__deps: ['$GodotRTCDataChannel'],
godot_js_rtc_pc_datachannel_create__proxy: 'sync',
godot_js_rtc_pc_datachannel_create__sig: 'iiii',
godot_js_rtc_pc_datachannel_create: function (p_id, p_label, p_config) {
try {
Expand Down
5 changes: 5 additions & 0 deletions modules/websocket/library_godot_websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const GodotWebSocket = {
},
},

godot_js_websocket_create__proxy: 'sync',
godot_js_websocket_create__sig: 'iiiiiiii',
godot_js_websocket_create: function (p_ref, p_url, p_proto, p_on_open, p_on_message, p_on_error, p_on_close) {
const on_open = GodotRuntime.get_func(p_on_open).bind(null, p_ref);
Expand All @@ -166,6 +167,7 @@ const GodotWebSocket = {
return GodotWebSocket.create(socket, on_open, on_message, on_error, on_close);
},

godot_js_websocket_send__proxy: 'sync',
godot_js_websocket_send__sig: 'iiiii',
godot_js_websocket_send: function (p_id, p_buf, p_buf_len, p_raw) {
const bytes_array = new Uint8Array(p_buf_len);
Expand All @@ -180,18 +182,21 @@ const GodotWebSocket = {
return GodotWebSocket.send(p_id, out);
},

godot_js_websocket_buffered_amount__proxy: 'sync',
godot_js_websocket_buffered_amount__sig: 'ii',
godot_js_websocket_buffered_amount: function (p_id) {
return GodotWebSocket.bufferedAmount(p_id);
},

godot_js_websocket_close__proxy: 'sync',
godot_js_websocket_close__sig: 'viii',
godot_js_websocket_close: function (p_id, p_code, p_reason) {
const code = p_code;
const reason = GodotRuntime.parseString(p_reason);
GodotWebSocket.close(p_id, code, reason);
},

godot_js_websocket_destroy__proxy: 'sync',
godot_js_websocket_destroy__sig: 'vi',
godot_js_websocket_destroy: function (p_id) {
GodotWebSocket.destroy(p_id);
Expand Down
12 changes: 12 additions & 0 deletions platform/web/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def get_opts():
"dlink_enabled", "Enable WebAssembly dynamic linking (GDExtension support). Produces bigger binaries", False
),
BoolVariable("use_closure_compiler", "Use closure compiler to minimize JavaScript code", False),
BoolVariable(
"do_not_block_main_thread",
"Use Emscripten PROXY_TO_PTHREAD option to run the main application code to a separate thread",
False,
),
]


Expand Down Expand Up @@ -213,6 +218,13 @@ def configure(env: "Environment"):
env.Append(LINKFLAGS=["-s", "SIDE_MODULE=2"])
env.extra_suffix = ".dlink" + env.extra_suffix

# Run the main application in a web worker
if env["do_not_block_main_thread"]:
env.Append(LINKFLAGS=["-s", "PROXY_TO_PTHREAD=1"])
env.Append(CPPDEFINES=["PROXY_TO_PTHREAD_ENABLED"])
# https://github.com/emscripten-core/emscripten/issues/18034#issuecomment-1277561925
env.Append(LINKFLAGS=["-s", "TEXTDECODER=0"])

# Reduce code size by generating less support code (e.g. skip NodeJS support).
env.Append(LINKFLAGS=["-s", "ENVIRONMENT=web,worker"])

Expand Down
Loading

0 comments on commit b165a84

Please sign in to comment.