RetroArch/emscripten/library_platform_emscripten.js
Joe Osborn c413bcc626
Threaded emscripten fixes (#17614)
* Actually read CLI args in emscripten

* Fix fetchfs manifest parsing, increase download chunk size

The chunk size should probably be made a parameter in the future.  The
larger chunk size trades longer hitches for fewer hitches.

* Add exec command driver and API functions for emscripten.

Under WASMFS, stdin/stdout can't be customized the way they can with
the JS FS implementation.  Also, this approach frees up stdin/stdout
and simplifies interaction with the command interface for web embedders.

* fixup upload paths, show use of new emscripten cmd interface

* Add JS library function names to EXPORTS as well as EXPORTED_FUNCTIONS for older emsdk versions
2025-02-24 09:25:05 -08:00

68 lines
2.0 KiB
JavaScript

//"use strict";
var LibraryPlatformEmscripten = {
$RPE: {
powerState: {
supported: false,
dischargeTime: 0,
level: 0,
charging: false
},
powerStateChange: function(e) {
RPE.powerState.dischargeTime = Number.isFinite(e.target.dischargingTime) ? e.target.dischargingTime : 0x7FFFFFFF;
RPE.powerState.level = e.target.level;
RPE.powerState.charging = e.target.charging;
},
command_queue:[],
command_reply_queue:[],
},
PlatformEmscriptenPowerStateInit: function() {
if (!navigator.getBattery) return;
navigator.getBattery().then(function(battery) {
battery.addEventListener("chargingchange", RPE.powerStateChange);
battery.addEventListener("levelchange", RPE.powerStateChange);
RPE.powerStateChange({target: battery});
RPE.powerState.supported = true;
});
},
PlatformEmscriptenPowerStateGetSupported: function() {
return RPE.powerState.supported;
},
PlatformEmscriptenPowerStateGetDischargeTime: function() {
return RPE.powerState.dischargeTime;
},
PlatformEmscriptenPowerStateGetLevel: function() {
return RPE.powerState.level;
},
PlatformEmscriptenPowerStateGetCharging: function() {
return RPE.powerState.charging;
},
PlatformEmscriptenGetTotalMem: function() {
if (!performance.memory) return 0;
return performance.memory.jsHeapSizeLimit || 0;
},
PlatformEmscriptenGetFreeMem: function() {
if (!performance.memory) return 0;
return (performance.memory.jsHeapSizeLimit || 0) - (performance.memory.usedJSHeapSize || 0);
},
$EmscriptenSendCommand__deps:["PlatformEmscriptenCommandRaiseFlag"],
$EmscriptenSendCommand: function(str) {
RPE.command_queue.push(str);
_PlatformEmscriptenCommandRaiseFlag();
},
$EmscriptenReceiveCommandReply: function() {
return RPE.command_reply_queue.shift();
}
};
autoAddDeps(LibraryPlatformEmscripten, '$RPE');
mergeInto(LibraryManager.library, LibraryPlatformEmscripten);