mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 00:32:51 +02:00
NETSCRIPT: Greatly speed up script launching, and remove the limitation unique args per script (#440)
* Remove the limitation unique args per script * Internal changes to how runningScripts are stored on the server, to make common usage faster.
This commit is contained in:
@@ -15,6 +15,7 @@ import { RamCostConstants } from "../Netscript/RamCostGenerator";
|
||||
import { PositiveInteger } from "../types";
|
||||
import { getKeyList } from "../utils/helpers/getKeyList";
|
||||
import { ScriptFilePath } from "../Paths/ScriptFilePath";
|
||||
import { ScriptKey, scriptKey } from "../utils/helpers/scriptKey";
|
||||
|
||||
export class RunningScript {
|
||||
// Script arguments
|
||||
@@ -61,6 +62,9 @@ export class RunningScript {
|
||||
// hostname of the server on which this script is running
|
||||
server = "";
|
||||
|
||||
// Cached key for ByArgs lookups
|
||||
scriptKey: ScriptKey = "";
|
||||
|
||||
// Number of threads that this script is running with
|
||||
threads = 1 as PositiveInteger;
|
||||
|
||||
@@ -75,6 +79,7 @@ export class RunningScript {
|
||||
if (!ramUsage) throw new Error("Must provide a ramUsage for RunningScript initialization.");
|
||||
this.filename = script.filename;
|
||||
this.args = args;
|
||||
this.scriptKey = scriptKey(this.filename, args);
|
||||
this.server = script.server;
|
||||
this.ramUsage = ramUsage;
|
||||
this.dependencies = script.dependencies;
|
||||
|
||||
@@ -7,7 +7,9 @@ import { processSingleServerGrowth } from "../Server/ServerHelpers";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
import { formatPercent } from "../ui/formatNumber";
|
||||
import { workerScripts } from "../Netscript/WorkerScripts";
|
||||
import { compareArrays } from "../utils/helpers/compareArrays";
|
||||
import { scriptKey } from "../utils/helpers/scriptKey";
|
||||
|
||||
import type { ScriptFilePath } from "../Paths/ScriptFilePath";
|
||||
|
||||
export function scriptCalculateOfflineProduction(runningScript: RunningScript): void {
|
||||
//The Player object stores the last update time from when we were online
|
||||
@@ -80,19 +82,14 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
|
||||
}
|
||||
}
|
||||
|
||||
//Returns a RunningScript object matching the filename and arguments on the
|
||||
//designated server, and false otherwise
|
||||
export function findRunningScript(
|
||||
filename: string,
|
||||
//Returns a RunningScript map containing scripts matching the filename and
|
||||
//arguments on the designated server, or null if none were found
|
||||
export function findRunningScripts(
|
||||
path: ScriptFilePath,
|
||||
args: (string | number | boolean)[],
|
||||
server: BaseServer,
|
||||
): RunningScript | null {
|
||||
for (let i = 0; i < server.runningScripts.length; ++i) {
|
||||
if (server.runningScripts[i].filename === filename && compareArrays(server.runningScripts[i].args, args)) {
|
||||
return server.runningScripts[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
): Map<number, RunningScript> | null {
|
||||
return server.runningScriptMap.get(scriptKey(path, args)) ?? null;
|
||||
}
|
||||
|
||||
//Returns a RunningScript object matching the pid on the
|
||||
|
||||
Reference in New Issue
Block a user