Tried to integrate Promises + web workers into Netscript code. Doesn't work at all right now

This commit is contained in:
Daniel Xie
2016-11-28 16:02:06 -06:00
parent 320526ebb3
commit 4687b80256
5 changed files with 987 additions and 8 deletions
+23 -1
View File
@@ -147,13 +147,16 @@ var Engine = {
},
/* Main Event Loop */
_scriptUpdateStatusCounter: 0,
idleTimer: function() {
//Get time difference
var _thisUpdate = new Date().getTime();
var diff = _thisUpdate - Engine._lastUpdate;
//Divide this by cycle time to determine how many cycles have elapsed since last update
diff = Math.round(diff / Engine._idleSpeed);
Engine._scriptUpdateStatusCounter += diff;
if (diff > 0) {
//Update the game engine by the calculated number of cycles
@@ -161,6 +164,12 @@ var Engine = {
Engine._lastUpdate = _thisUpdate;
}
if (Engine._scriptUpdateStatusCounter >= 50) {
console.log("Updating Script Status");
Engine._scriptUpdateStatusCounter = 0;
Engine.updateScriptStatus();
}
window.requestAnimationFrame(Engine.idleTimer);
},
@@ -217,6 +226,16 @@ var Engine = {
}
},
/* NetScript Web Worker Stuff */
_scriptWebWorker: null,
updateScriptStatus: function() {
Engine._scriptWebWorker.postMessage(
{'type': "Status Update",
'buf1': JSON.stringify(ForeignServers),
'buf2': JSON.stringify(Player)}
)
},
/* Initialization */
init: function() {
//Initialization functions
@@ -233,6 +252,9 @@ var Engine = {
CompanyPositions.init();
}
if (window.Worker) {
Engine._scriptWebWorker = new Worker("netscript/NetscriptWorker.js");
}
//Load, save, and delete buttons
//Engine.Clickables.saveButton = document.getElementById("save");