mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 23:53:48 +01:00
commit
82d1560f52
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -114,13 +114,14 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
threads = 1;
|
||||
}
|
||||
|
||||
workerScript.dynamicRamUsage += ramCost * threads;
|
||||
workerScript.dynamicRamUsage += ramCost;
|
||||
if (workerScript.dynamicRamUsage > 1.01 * workerScript.ramUsage) {
|
||||
throw makeRuntimeRejectMsg(
|
||||
workerScript,
|
||||
`Dynamic RAM usage calculated to be greater than initial RAM usage on fn: ${fnName}.
|
||||
This is probably because you somehow circumvented the static RAM calculation.
|
||||
|
||||
Threads: ${threads}
|
||||
Dynamic RAM Usage: ${numeralWrapper.formatRAM(workerScript.dynamicRamUsage)}
|
||||
Static RAM Usage: ${numeralWrapper.formatRAM(workerScript.ramUsage)}
|
||||
|
||||
|
@ -8,7 +8,7 @@ function makeScriptBlob(code: string): Blob {
|
||||
return new Blob([code], { type: "text/javascript" });
|
||||
}
|
||||
|
||||
export function compile(script: Script, scripts: Script[]): void {
|
||||
export async function compile(script: Script, scripts: Script[]): Promise<void> {
|
||||
if (!shouldCompile(script, scripts)) return;
|
||||
// The URL at the top is the one we want to import. It will
|
||||
// recursively import all the other modules in the urlStack.
|
||||
@ -17,7 +17,7 @@ export function compile(script: Script, scripts: Script[]): void {
|
||||
// but not really behaves like import. Particularly, it cannot
|
||||
// load fully dynamic content. So we hide the import from webpack
|
||||
// by placing it inside an eval call.
|
||||
script.markUpdated();
|
||||
await script.updateRamUsage(scripts);
|
||||
const uurls = _getScriptUrls(script, scripts, []);
|
||||
if (script.url) URL.revokeObjectURL(script.url); // remove the old reference.
|
||||
if (script.dependencies.length > 0) script.dependencies.forEach((dep) => URL.revokeObjectURL(dep.url));
|
||||
@ -37,7 +37,8 @@ export function compile(script: Script, scripts: Script[]): void {
|
||||
export async function executeJSScript(scripts: Script[] = [], workerScript: WorkerScript): Promise<void> {
|
||||
const script = workerScript.getScript();
|
||||
if (script === null) throw new Error("script is null");
|
||||
compile(script, scripts);
|
||||
await compile(script, scripts);
|
||||
workerScript.ramUsage = script.ramUsage;
|
||||
const loadedModule = await script.module;
|
||||
|
||||
const ns = workerScript.env.vars;
|
||||
|
@ -477,7 +477,8 @@ function createAndAddWorkerScript(runningScriptObj: RunningScript, server: BaseS
|
||||
} else {
|
||||
runningScriptObj.threads = 1;
|
||||
}
|
||||
const ramUsage = roundToTwo(getRamUsageFromRunningScript(runningScriptObj) * threads);
|
||||
const oneRamUsage = getRamUsageFromRunningScript(runningScriptObj);
|
||||
const ramUsage = roundToTwo(oneRamUsage * threads);
|
||||
const ramAvailable = server.maxRam - server.ramUsed;
|
||||
if (ramUsage > ramAvailable) {
|
||||
dialogBoxCreate(
|
||||
@ -502,7 +503,7 @@ function createAndAddWorkerScript(runningScriptObj: RunningScript, server: BaseS
|
||||
// Create the WorkerScript. NOTE: WorkerScript ctor will set the underlying
|
||||
// RunningScript's PID as well
|
||||
const s = new WorkerScript(runningScriptObj, pid, NetscriptFunctions);
|
||||
s.ramUsage = ramUsage;
|
||||
s.ramUsage = oneRamUsage;
|
||||
|
||||
// Add the WorkerScript to the global pool
|
||||
workerScripts.set(pid, s);
|
||||
|
Loading…
Reference in New Issue
Block a user