From e5c6fcaa70ef1754e5fee5b3927e21a14f553d90 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Sat, 15 Oct 2016 17:01:19 -0700 Subject: [PATCH] Get Cells and vesicles just once, 20 seconds after we start querying (and shut down queries). --- .../DomainContent/CellScience/moveCellsAC.js | 15 ++++++++++----- .../DomainContent/CellScience/moveVesiclesAC.js | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js b/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js index d696d464bf..7b0669c616 100644 --- a/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js +++ b/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js @@ -39,11 +39,13 @@ var THROTTLE = true; var THROTTLE_RATE = 5000; var sinceLastUpdate = 0; +var entitiesToMove = []; //print('cells script') function findCells() { var results = Entities.findEntities(basePosition, 60000); + Script.clearInterval(octreeQueryInterval); // we don't need it any more if (results.length === 0) { // print('no entities found') @@ -55,9 +57,7 @@ function findCells() { // print('name is:: ' + name) if (name === 'Cell') { // print('found a cell!!' + v) - Script.setTimeout(function() { - moveCell(v); - }, Math.random() * THROTTLE_RATE); + entitiesToMove.push(v); } }); } @@ -93,6 +93,7 @@ function update(deltaTime) { Entities.setPacketsPerSecond(6000); print("PPS:" + Entities.getPacketsPerSecond()); initialized = true; + Script.setTimeout(findCells, 20 * 1000); // After 20 seconds of getting entities, look for cells. } return; } @@ -102,7 +103,11 @@ function update(deltaTime) { if (sinceLastUpdate > THROTTLE_RATE) { // print('SHOULD FIND CELLS!!!') sinceLastUpdate = 0; - findCells(); + entitiesToMove.forEach(function (v) { + Script.setTimeout(function() { + moveCell(v); + }, Math.random() * THROTTLE_RATE); // don't move all of them every five seconds, but at random times over interval + }); } else { // print('returning in update ' + sinceLastUpdate) return; @@ -116,4 +121,4 @@ function unload() { } Script.update.connect(update); -Script.scriptEnding.connect(unload); \ No newline at end of file +Script.scriptEnding.connect(unload); diff --git a/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js b/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js index 4d4ce76d74..114abd4984 100644 --- a/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js +++ b/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js @@ -39,11 +39,13 @@ var THROTTLE = true; var THROTTLE_RATE = 5000; var sinceLastUpdate = 0; +var entitiesToMove = []; //print('vesicle script') function findVesicles() { var results = Entities.findEntities(basePosition, 60000); + Script.clearInterval(octreeQueryInterval); // we don't need it any more if (results.length === 0) { // print('no entities found'); @@ -54,9 +56,7 @@ function findVesicles() { var name = Entities.getEntityProperties(v, 'name').name; if (name === 'vesicle') { //print('found a vesicle!!' + v) - Script.setTimeout(function() { - moveVesicle(v); - }, Math.random() * THROTTLE_RATE); + entitiesToMove.push(v); } }); } @@ -100,6 +100,7 @@ function update(deltaTime) { Entities.setPacketsPerSecond(6000); print("PPS:" + Entities.getPacketsPerSecond()); initialized = true; + Script.setTimeout(findVesicles, 20 * 1000); // After 20 seconds of getting entities, look for cells. } return; } @@ -108,7 +109,11 @@ function update(deltaTime) { sinceLastUpdate = sinceLastUpdate + deltaTime * 1000; if (sinceLastUpdate > THROTTLE_RATE) { sinceLastUpdate = 0; - findVesicles(); + entitiesToMove.forEach(function (v) { + Script.setTimeout(function() { + moveVesicle(v); + }, Math.random() * THROTTLE_RATE); // don't move all of them every five seconds, but at random times over interval + }); } else { return; } @@ -121,4 +126,4 @@ function unload() { } Script.update.connect(update); -Script.scriptEnding.connect(unload); \ No newline at end of file +Script.scriptEnding.connect(unload);