mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-10-23 10:13:13 +02:00
aa80cf6451
Reverted ToastVariant back to an enum internally. Still exposed to player as just possible strings. Changed all 1-line documentation comments to actually be 1-line. Moved some because they were not providing documentation for the thing they were trying to.
41 lines
874 B
TypeScript
41 lines
874 B
TypeScript
import { workerScripts } from "./WorkerScripts";
|
|
|
|
let pidCounter = 1;
|
|
|
|
/** Find and return the next availble PID for a script */
|
|
export function generateNextPid(): number {
|
|
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;
|
|
}
|
|
}
|
|
|
|
export function resetPidCounter(): void {
|
|
pidCounter = 1;
|
|
}
|