mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 09:13:07 +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:
@@ -17,6 +17,8 @@ import { Settings } from "../../Settings/Settings";
|
||||
import { TablePaginationActionsAll } from "../React/TablePaginationActionsAll";
|
||||
import SearchIcon from "@mui/icons-material/Search";
|
||||
import { useRerender } from "../React/hooks";
|
||||
import { matchScriptPathUnanchored } from "../../utils/helpers/scriptKey";
|
||||
import lodash from "lodash";
|
||||
|
||||
// Map of server hostname -> all workerscripts on that server for all active scripts
|
||||
interface IServerData {
|
||||
@@ -36,7 +38,13 @@ export function ServerAccordions(props: IProps): React.ReactElement {
|
||||
const [filter, setFilter] = useState("");
|
||||
const [page, setPage] = useState(0);
|
||||
const [rowsPerPage, setRowsPerPage] = useState(Settings.ActiveScriptsServerPageSize);
|
||||
const rerender = useRerender();
|
||||
const rerenderHook = useRerender();
|
||||
let scheduledRerender = false;
|
||||
const rerender = () => {
|
||||
if (scheduledRerender) return;
|
||||
scheduledRerender = true;
|
||||
requestAnimationFrame(rerenderHook);
|
||||
};
|
||||
|
||||
const handleChangePage = (event: unknown, newPage: number): void => {
|
||||
setPage(newPage);
|
||||
@@ -73,11 +81,16 @@ export function ServerAccordions(props: IProps): React.ReactElement {
|
||||
if (data !== undefined) data.workerScripts.push(ws);
|
||||
}
|
||||
|
||||
const filtered = Object.values(serverToScriptMap).filter(
|
||||
(data) =>
|
||||
data &&
|
||||
(data.server.hostname.includes(filter) || data.server.runningScripts.find((s) => s.filename.includes(filter))),
|
||||
);
|
||||
// Match filter in the scriptname part of the key
|
||||
const pattern = matchScriptPathUnanchored(lodash.escapeRegExp(filter));
|
||||
const filtered = Object.values(serverToScriptMap).filter((data) => {
|
||||
if (!data) return false;
|
||||
if (data.server.hostname.includes(filter)) return true;
|
||||
for (const k of data.server.runningScriptMap.keys()) {
|
||||
if (pattern.test(k)) return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
useEffect(() => WorkerScriptStartStopEventEmitter.subscribe(rerender));
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import Collapse from "@mui/material/Collapse";
|
||||
import ExpandLess from "@mui/icons-material/ExpandLess";
|
||||
import ExpandMore from "@mui/icons-material/ExpandMore";
|
||||
|
||||
import { killWorkerScript } from "../../Netscript/killWorkerScript";
|
||||
import { killWorkerScriptByPid } from "../../Netscript/killWorkerScript";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
|
||||
import { dialogBoxCreate } from "../React/DialogBox";
|
||||
@@ -53,7 +53,7 @@ export function WorkerScriptAccordion(props: IProps): React.ReactElement {
|
||||
function logClickHandler(): void {
|
||||
LogBoxEvents.emit(scriptRef);
|
||||
}
|
||||
const killScript = killWorkerScript.bind(null, { runningScript: scriptRef, hostname: scriptRef.server });
|
||||
const killScript = killWorkerScriptByPid.bind(null, scriptRef.pid);
|
||||
|
||||
function killScriptClickHandler(): void {
|
||||
if (killScript()) dialogBoxCreate("Killing script");
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ export function GameRoot(): React.ReactElement {
|
||||
|
||||
function killAllScripts(): void {
|
||||
for (const server of GetAllServers()) {
|
||||
server.runningScripts = [];
|
||||
server.runningScriptMap.clear();
|
||||
}
|
||||
saveObject.saveGame();
|
||||
setTimeout(() => htmlLocation.reload(), 2000);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import { EventEmitter } from "../../utils/EventEmitter";
|
||||
import { RunningScript } from "../../Script/RunningScript";
|
||||
import { killWorkerScript } from "../../Netscript/killWorkerScript";
|
||||
import { killWorkerScriptByPid } from "../../Netscript/killWorkerScript";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Box from "@mui/material/Box";
|
||||
import Button from "@mui/material/Button";
|
||||
@@ -14,7 +14,7 @@ import ArrowForwardIosIcon from "@mui/icons-material/ArrowForwardIos";
|
||||
import { workerScripts } from "../../Netscript/WorkerScripts";
|
||||
import { startWorkerScript } from "../../NetscriptWorker";
|
||||
import { GetServer } from "../../Server/AllServers";
|
||||
import { findRunningScript } from "../../Script/ScriptHelpers";
|
||||
import { findRunningScriptByPid } from "../../Script/ScriptHelpers";
|
||||
import { debounce } from "lodash";
|
||||
import { Settings } from "../../Settings/Settings";
|
||||
import { ANSIITypography } from "./ANSIITypography";
|
||||
@@ -160,23 +160,6 @@ function LogWindow(props: IProps): React.ReactElement {
|
||||
setSize([size.width, size.height]);
|
||||
};
|
||||
|
||||
// useEffect(
|
||||
// () =>
|
||||
// WorkerScriptStartStopEventEmitter.subscribe(() => {
|
||||
// setTimeout(() => {
|
||||
// const server = GetServer(script.server);
|
||||
// if (server === null) return;
|
||||
// const existingScript = findRunningScript(script.filename, script.args, server);
|
||||
// if (existingScript) {
|
||||
// existingScript.logs = script.logs.concat(existingScript.logs)
|
||||
// setScript(existingScript)
|
||||
// }
|
||||
// rerender();
|
||||
// }, 100)
|
||||
// }),
|
||||
// [],
|
||||
// );
|
||||
|
||||
const setPosition = ({ x, y }: LogBoxPositionData) => {
|
||||
const node = rootRef?.current;
|
||||
if (!node) return;
|
||||
@@ -213,13 +196,13 @@ function LogWindow(props: IProps): React.ReactElement {
|
||||
}, []);
|
||||
|
||||
function kill(): void {
|
||||
killWorkerScript({ runningScript: script, hostname: script.server });
|
||||
killWorkerScriptByPid(script.pid);
|
||||
}
|
||||
|
||||
function run(): void {
|
||||
const server = GetServer(script.server);
|
||||
if (server === null) return;
|
||||
const s = findRunningScript(script.filename, script.args, server);
|
||||
const s = findRunningScriptByPid(script.pid, server);
|
||||
if (s === null) {
|
||||
const baseScript = server.scripts.get(script.filename);
|
||||
if (!baseScript) {
|
||||
|
||||
Reference in New Issue
Block a user