mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Optimize memory usage
This commit is contained in:
parent
f4ec26f06b
commit
49e18094c0
3 changed files with 68 additions and 29 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
**/node_modules/
|
**/node_modules/
|
||||||
data/minify/package-lock.json
|
data/minify/package-lock.json
|
||||||
*.db
|
*.db
|
||||||
|
roms/
|
||||||
|
|
|
@ -55,7 +55,7 @@ class EJS_GameManager {
|
||||||
}
|
}
|
||||||
getRetroArchCfg() {
|
getRetroArchCfg() {
|
||||||
return "autosave_interval = 60\n" +
|
return "autosave_interval = 60\n" +
|
||||||
"screenshot_directory = /\n" +
|
"screenshot_directory = \"/\"\n" +
|
||||||
"block_sram_overwrite = false\n" +
|
"block_sram_overwrite = false\n" +
|
||||||
"video_gpu_screenshot = false\n" +
|
"video_gpu_screenshot = false\n" +
|
||||||
"audio_latency = 64\n" +
|
"audio_latency = 64\n" +
|
||||||
|
@ -169,7 +169,7 @@ class EJS_GameManager {
|
||||||
try {
|
try {
|
||||||
if (fileNames.length > 1) {
|
if (fileNames.length > 1) {
|
||||||
fileNames = fileNames.filter((item) => {
|
fileNames = fileNames.filter((item) => {
|
||||||
return ["toc", "ccd", "exe", "pbp", "chd", "img", "bin"].includes(item.split(".").pop().toLowerCase());
|
return ["toc", "ccd", "exe", "pbp", "chd", "img", "bin", "iso"].includes(item.split(".").pop().toLowerCase());
|
||||||
})
|
})
|
||||||
fileNames = fileNames.sort((a, b) => {
|
fileNames = fileNames.sort((a, b) => {
|
||||||
if (isNaN(a.charAt()) || isNaN(b.charAt())) throw new Error("Incorrect file name format");
|
if (isNaN(a.charAt()) || isNaN(b.charAt())) throw new Error("Incorrect file name format");
|
||||||
|
|
110
data/emulator.js
110
data/emulator.js
|
@ -359,7 +359,7 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
checkCompression(data, msg) {
|
checkCompression(data, msg, fileCbFunc) {
|
||||||
if (msg) {
|
if (msg) {
|
||||||
this.textElem.innerText = msg;
|
this.textElem.innerText = msg;
|
||||||
}
|
}
|
||||||
|
@ -404,8 +404,13 @@ class EmulatorJS {
|
||||||
this.textElem.innerText = msg + progress;
|
this.textElem.innerText = msg + progress;
|
||||||
}
|
}
|
||||||
if (data.data.t === 2) {
|
if (data.data.t === 2) {
|
||||||
|
if (typeof fileCbFunc === "function") {
|
||||||
|
fileCbFunc(data.data.file, data.data.data);
|
||||||
|
files[data.data.file] = true;
|
||||||
|
} else {
|
||||||
files[data.data.file] = data.data.data;
|
files[data.data.file] = data.data.data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (data.data.t === 1) {
|
if (data.data.t === 1) {
|
||||||
resolve(files);
|
resolve(files);
|
||||||
}
|
}
|
||||||
|
@ -432,8 +437,13 @@ class EmulatorJS {
|
||||||
this.textElem.innerText = msg + progress;
|
this.textElem.innerText = msg + progress;
|
||||||
}
|
}
|
||||||
if (data.data.t === 2) {
|
if (data.data.t === 2) {
|
||||||
|
if (typeof fileCbFunc === "function") {
|
||||||
|
fileCbFunc(data.data.file, data.data.data);
|
||||||
|
files[data.data.file] = true;
|
||||||
|
} else {
|
||||||
files[data.data.file] = data.data.data;
|
files[data.data.file] = data.data.data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (data.data.t === 1) {
|
if (data.data.t === 1) {
|
||||||
resolve(files);
|
resolve(files);
|
||||||
}
|
}
|
||||||
|
@ -475,8 +485,13 @@ class EmulatorJS {
|
||||||
this.textElem.innerText = msg + progress;
|
this.textElem.innerText = msg + progress;
|
||||||
}
|
}
|
||||||
if (data.data.t === 2) {
|
if (data.data.t === 2) {
|
||||||
|
if (typeof fileCbFunc === "function") {
|
||||||
|
fileCbFunc(data.data.file, data.data.data);
|
||||||
|
files[data.data.file] = true;
|
||||||
|
} else {
|
||||||
files[data.data.file] = data.data.data;
|
files[data.data.file] = data.data.data;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (data.data.t === 1) {
|
if (data.data.t === 1) {
|
||||||
resolve(files);
|
resolve(files);
|
||||||
}
|
}
|
||||||
|
@ -498,9 +513,14 @@ class EmulatorJS {
|
||||||
} else if (compression === "rar") {
|
} else if (compression === "rar") {
|
||||||
return decompressRar(data);
|
return decompressRar(data);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (typeof fileCbFunc === "function") {
|
||||||
|
fileCbFunc("!!notCompressedData", data);
|
||||||
|
return new Promise(resolve => resolve({"!!notCompressedData": true}));
|
||||||
} else {
|
} else {
|
||||||
return new Promise(resolve => resolve({"!!notCompressedData": data}));
|
return new Promise(resolve => resolve({"!!notCompressedData": data}));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
downloadGameCore() {
|
downloadGameCore() {
|
||||||
|
@ -757,40 +777,13 @@ class EmulatorJS {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Data")).then((data) => {
|
|
||||||
const altName = this.config.gameUrl.startsWith("blob:") ? this.config.gameName || "game" : this.config.gameUrl.split('/').pop().split("#")[0].split("?")[0];
|
|
||||||
const fileNames = (() => {
|
|
||||||
let rv = [];
|
|
||||||
for (const k in data) rv.push(k);
|
|
||||||
return rv;
|
|
||||||
})();
|
|
||||||
if (fileNames.length === 1) fileNames[0] = altName;
|
|
||||||
let execFile = null;
|
|
||||||
if (this.getCore(true) === "psx") {
|
|
||||||
execFile = this.gameManager.createCueFile(fileNames);
|
|
||||||
}
|
|
||||||
for (const k in data) {
|
|
||||||
if (k === "!!notCompressedData") {
|
|
||||||
|
|
||||||
if (this.getCore(true) === "psx" && execFile !== null) {
|
let resData = {};
|
||||||
this.fileName = execFile;
|
const altName = this.config.gameUrl.startsWith("blob:") ? this.config.gameName || "game" : this.config.gameUrl.split('/').pop().split("#")[0].split("?")[0];
|
||||||
} else {
|
this.checkCompression(new Uint8Array(data), this.localization("Decompress Game Data"), (fileName, fileData) => {
|
||||||
this.fileName = altName;
|
console.log(fileName);
|
||||||
}
|
if (fileName.includes("/")) {
|
||||||
FS.writeFile(altName, data[k]);
|
const paths = fileName.split("/");
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (k.endsWith('/')) {
|
|
||||||
FS.mkdir(k);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!this.fileName || ((this.extensions[this.getCore()] || []).includes(k.split(".").pop()) &&
|
|
||||||
//always prefer m3u files for psx cores
|
|
||||||
!(this.getCore(true) === "psx" && ["m3u", "ccd"].includes(this.fileName.split(".").pop())))) {
|
|
||||||
this.fileName = k;
|
|
||||||
}
|
|
||||||
if (k.includes("/")) {
|
|
||||||
const paths = k.split("/");
|
|
||||||
let cp = "";
|
let cp = "";
|
||||||
for (let i=0; i<paths.length-1; i++) {
|
for (let i=0; i<paths.length-1; i++) {
|
||||||
if (paths[i] === "") continue;
|
if (paths[i] === "") continue;
|
||||||
|
@ -800,8 +793,51 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.getCore(true) === "psx" && execFile !== null && ["m3u", "cue"].includes(k.split(".").pop().toLowerCase())) continue;
|
if (fileName.endsWith('/')) {
|
||||||
FS.writeFile("/"+k, data[k]);
|
FS.mkdir(fileName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.getCore(true) === "psx" && ["m3u", "cue"].includes(fileName.split(".").pop().toLowerCase())) {
|
||||||
|
resData[fileName] = fileData;
|
||||||
|
} else if (this.getCore(true) === "psx" && fileName !== "!!notCompressedData") {
|
||||||
|
resData[fileName] = true;
|
||||||
|
}
|
||||||
|
if (fileName === "!!notCompressedData") {
|
||||||
|
FS.writeFile(altName, fileData);
|
||||||
|
resData[altName] = true;
|
||||||
|
} else {
|
||||||
|
FS.writeFile("/"+fileName, fileData);
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
const fileNames = (() => {
|
||||||
|
let rv = [];
|
||||||
|
for (const k in resData) rv.push(k);
|
||||||
|
return rv;
|
||||||
|
})();
|
||||||
|
if (fileNames.length === 1) fileNames[0] = altName;
|
||||||
|
let execFile = null;
|
||||||
|
if (this.getCore(true) === "psx") {
|
||||||
|
execFile = this.gameManager.createCueFile(fileNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const k in resData) {
|
||||||
|
if (k === "!!notCompressedData") {
|
||||||
|
if (this.getCore(true) === "psx" && execFile !== null) {
|
||||||
|
this.fileName = execFile;
|
||||||
|
} else {
|
||||||
|
this.fileName = altName;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!this.fileName || ((this.extensions[this.getCore()] || []).includes(k.split(".").pop()) &&
|
||||||
|
//always prefer m3u files for psx cores
|
||||||
|
!(this.getCore(true) === "psx" && ["m3u", "ccd"].includes(this.fileName.split(".").pop())))) {
|
||||||
|
this.fileName = k;
|
||||||
|
}
|
||||||
|
if (this.getCore(true) === "psx" && execFile === null && ["m3u", "cue"].includes(k.split(".").pop().toLowerCase())) {
|
||||||
|
console.log(k, resData[k]);
|
||||||
|
FS.writeFile("/"+k, resData[k]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.getCore(true) === "psx" && execFile !== null) {
|
if (this.getCore(true) === "psx" && execFile !== null) {
|
||||||
this.fileName = execFile;
|
this.fileName = execFile;
|
||||||
|
@ -809,6 +845,8 @@ class EmulatorJS {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.downloadFile(this.config.gameUrl, (res) => {
|
this.downloadFile(this.config.gameUrl, (res) => {
|
||||||
if (res === -1) {
|
if (res === -1) {
|
||||||
this.textElem.innerText = this.localization('Network Error');
|
this.textElem.innerText = this.localization('Network Error');
|
||||||
|
|
Loading…
Reference in a new issue