Read state from memory instead of saving to disk

This commit is contained in:
Ethan O'Brien 2024-12-14 14:05:53 -06:00
parent 627fba2f9c
commit 5d54014ce3

View File

@ -5,7 +5,7 @@ class EJS_GameManager {
this.FS = this.Module.FS;
this.functions = {
restart: this.Module.cwrap('system_restart', '', []),
saveStateInfo: this.Module.cwrap('save_state_info', 'null', []),
saveStateInfo: this.Module.cwrap('save_state_info', 'string', []),
loadState: this.Module.cwrap('load_state', 'number', ['string', 'number']),
screenshot: this.Module.cwrap('cmd_take_screenshot', '', []),
simulateInput: this.Module.cwrap('simulate_input', 'null', ['number', 'number', 'number']),
@ -172,8 +172,15 @@ class EJS_GameManager {
this.functions.restart();
}
getState() {
this.functions.saveStateInfo();
return this.FS.readFile("/current.state");
const state = this.functions.saveStateInfo().split("|");
if (state[2] !== "1") {
console.error(state[0]);
return state[0];
}
const size = parseInt(state[0]);
const dataStart = parseInt(state[1]);
const data = this.Module.HEAPU8.subarray(dataStart, dataStart + size);
return new Uint8Array(data);
}
loadState(state) {
try {