mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 03:25:44 +02:00
Pid resets to 1 when installing or destroying a BitNode.
This commit is contained in:
+1
-36
@@ -6,6 +6,7 @@ import { killWorkerScript } from "./Netscript/killWorkerScript";
|
||||
import { WorkerScript } from "./Netscript/WorkerScript";
|
||||
import { workerScripts } from "./Netscript/WorkerScripts";
|
||||
import { WorkerScriptStartStopEventEmitter } from "./Netscript/WorkerScriptStartStopEventEmitter";
|
||||
import { generateNextPid } from "./Netscript/Pid";
|
||||
|
||||
import { CONSTANTS } from "./Constants";
|
||||
import { Engine } from "./engine";
|
||||
@@ -412,42 +413,6 @@ function processNetscript1Imports(code, workerScript) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and return the next availble PID for a script
|
||||
*/
|
||||
let pidCounter = 1;
|
||||
function generateNextPid() {
|
||||
let tempCounter = pidCounter;
|
||||
|
||||
// Cap the number of search iterations at some arbitrary value to avoid
|
||||
// infinite loops. We'll assume that players wont have 1mil+ running scripts
|
||||
let found = false;
|
||||
for (let i = 0; i < 1e6;) {
|
||||
if (!workerScripts.has(tempCounter + i)) {
|
||||
found = true;
|
||||
tempCounter = tempCounter + i;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i === Number.MAX_SAFE_INTEGER - 1) {
|
||||
i = 1;
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
pidCounter = tempCounter + 1;
|
||||
if (pidCounter >= Number.MAX_SAFE_INTEGER) {
|
||||
pidCounter = 1;
|
||||
}
|
||||
|
||||
return tempCounter;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to start a RunningScript (by creating and starting its
|
||||
* corresponding WorkerScript), and add the RunningScript to the server on which
|
||||
|
||||
Reference in New Issue
Block a user