mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-29 20:37:05 +02:00
Merge pull request #1594 from danielyxie/dev
Fix ram miscalc and ls with tiemstamps
This commit is contained in:
Vendored
+11
-11
File diff suppressed because one or more lines are too long
+2
-2
File diff suppressed because one or more lines are too long
+1
-1
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)}
|
||||
|
||||
@@ -131,11 +132,6 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
* Using map access to do the same
|
||||
const myScan = ns['scan'];
|
||||
|
||||
* Saving script in the improper order.
|
||||
Increase the cost of an imported script, save it, then run the
|
||||
parent. To fix this just re-open & save every script in order
|
||||
from most imported to least imported (parent script).
|
||||
|
||||
Sorry :(`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -22,6 +22,12 @@ export class Output {
|
||||
export class RawOutput {
|
||||
raw: React.ReactNode;
|
||||
constructor(node: React.ReactNode) {
|
||||
if (Settings.EnableTimestamps)
|
||||
node = (
|
||||
<>
|
||||
[{getTimestamp()}] {node}
|
||||
</>
|
||||
);
|
||||
this.raw = node;
|
||||
}
|
||||
}
|
||||
@@ -143,10 +143,6 @@ export function ls(
|
||||
{ segments: allScripts, style: { color: "yellow", fontStyle: "bold" } },
|
||||
].filter((g) => g.segments.length > 0);
|
||||
for (let i = 0; i < groups.length; i++) {
|
||||
if (i !== 0) {
|
||||
terminal.print("");
|
||||
terminal.print("");
|
||||
}
|
||||
postSegments(groups[i].segments, groups[i].style);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user