diff --git a/src/Netscript/NetscriptWorker.js b/src/Netscript/NetscriptWorker.js index 95110ad8a..f1e4da0d3 100644 --- a/src/Netscript/NetscriptWorker.js +++ b/src/Netscript/NetscriptWorker.js @@ -9,10 +9,10 @@ function WorkerScript() { this.name = ""; this.running = false; - this.serverHostname = null; + this.serverIp = null; this.code = ""; this.env = new Environment(); - this.timeout = null; + this.output = ""; } //Array containing all scripts that are running across all servers, to easily run them all diff --git a/src/Terminal.js b/src/Terminal.js index ff1aba5d9..d8a0a5334 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -385,6 +385,8 @@ var Terminal = { case "scp": //TODO break; + case "tail": + break; case "top": //TODO List each's script RAM usage break; @@ -481,7 +483,7 @@ var Terminal = { var s = new WorkerScript(); s.name = filename; s.code = Player.getCurrentServer().scripts[i].code; - s.hostname = Player.getCurrentServer().hostname; + s.serverIp = Player.getCurrentServer().ip; workerScripts.push(s); console.log("Pushed script onto workerScripts"); return; diff --git a/src/engine.js b/src/engine.js index 3da8ad29a..648dc5421 100644 --- a/src/engine.js +++ b/src/engine.js @@ -150,6 +150,7 @@ var Engine = { //Get time difference var _thisUpdate = new Date().getTime(); var diff = _thisUpdate - Engine._lastUpdate; + var offset = diff % Engine._idleSpeed; //Divide this by cycle time to determine how many cycles have elapsed since last update diff = Math.floor(diff / Engine._idleSpeed); @@ -157,12 +158,35 @@ var Engine = { if (diff > 0) { //Update the game engine by the calculated number of cycles Engine.updateGame(diff); - Engine._lastUpdate = _thisUpdate; + Engine._lastUpdate = _thisUpdate - offset; } window.requestAnimationFrame(Engine.idleTimer); }, + //Counters for the main event loop. Represent the number of game cycles are required + //for something to happen. + Counters: { + autoSaveCounter: 300, + }, + + decrementAllCounters: function(numCycles = 1) { + for (var counter in Engine.Counters) { + if (Engine.Counters.hasOwnProperty(counter)) { + Engine.Counters[counter] = Engine.Counters[counter] - numCycles; + } + } + }, + + //Checks if any counters are 0 and if they are, executes whatever + //is necessary and then resets the counter + checkCounters: function() { + if (Engine.Counters.autoSaveCounter <= 0) { + Engine.saveGame(); + Engine.Counters.autoSaveCounter = 300; + } + }, + //TODO Account for numCycles in Code, hasn't been done yet updateGame: function(numCycles = 1) { //Manual hack @@ -175,8 +199,10 @@ var Engine = { Engine._actionTimeStr = "Time left: "; Player.startAction = false; } - - Engine.updateHackProgress(); + Engine.decrementAllCounters(numCycles); + Engine.checkCounters(); + + Engine.updateHackProgress(numCycles); }, /* Calculates the hack progress for a manual (non-scripted) hack and updates the progress bar/time accordingly */ @@ -186,10 +212,11 @@ var Engine = { _actionProgressStr: "[ ]", _actionProgressBarCount: 1, _actionInProgress: false, - updateHackProgress: function() { + updateHackProgress: function(numCycles = 1) { if (Engine._actionInProgress == true) { //TODO Do this calculation based on numCycles rather than idle speed - Engine._actionTimeLeft -= (Engine._idleSpeed/ 1000); //Substract idle speed (ms) + var timeElapsedMilli = numCycles * Engine._idleSpeed; + Engine._actionTimeLeft -= (timeElapsedMilli/ 1000); //Substract idle speed (ms) //Calculate percent filled var percent = Math.round((1 - Engine._actionTimeLeft / Engine._totalActionTime) * 100);