From c69d064cc3b136782204319fd3c6cd4846170344 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 25 Apr 2017 22:14:03 -0700 Subject: [PATCH] code review fixes --- scripts/tutorials/createSwords.js | 4 +- .../tutorials/entity_scripts/springHold.js | 6 +- scripts/tutorials/entity_scripts/touch.js | 3 +- scripts/tutorials/nBody.js | 55 ++++++++++--------- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/scripts/tutorials/createSwords.js b/scripts/tutorials/createSwords.js index 89597353a9..749df3c5ed 100644 --- a/scripts/tutorials/createSwords.js +++ b/scripts/tutorials/createSwords.js @@ -34,7 +34,7 @@ var sword1 = Entities.addEntity({ grabbable:true } }) - }) + }); var sword2 = Entities.addEntity({ type: "Box", @@ -50,7 +50,7 @@ var sword2 = Entities.addEntity({ grabbable:true } }) - }) + }); Script.scriptEnding.connect(function scriptEnding() { Entities.deleteEntity(sword1); diff --git a/scripts/tutorials/entity_scripts/springHold.js b/scripts/tutorials/entity_scripts/springHold.js index 12aeac387c..12b34381a6 100644 --- a/scripts/tutorials/entity_scripts/springHold.js +++ b/scripts/tutorials/entity_scripts/springHold.js @@ -31,8 +31,7 @@ angularTimeScale: timescale, ttl: ACTION_TTL }; - var success = Entities.updateAction(_this.copy, _this.actionID, props); - return; + Entities.updateAction(_this.copy, _this.actionID, props); } function createSpringAction(timescale) { @@ -46,7 +45,6 @@ ttl: ACTION_TTL }; _this.actionID = Entities.addAction("spring", _this.copy, props); - return; } function createCopy() { @@ -69,7 +67,7 @@ grabbable:false } }) - } + }; _this.copy = Entities.addEntity(props); } diff --git a/scripts/tutorials/entity_scripts/touch.js b/scripts/tutorials/entity_scripts/touch.js index 08681a7d3c..d6a59aa167 100644 --- a/scripts/tutorials/entity_scripts/touch.js +++ b/scripts/tutorials/entity_scripts/touch.js @@ -111,7 +111,6 @@ ttl: ACTION_TTL }; var success = Entities.updateAction(_this.copy, _this.actionID, props); - return; } function createSpringAction(timescale) { @@ -148,7 +147,7 @@ grabbable:false } }) - } + }; _this.copy = Entities.addEntity(props); } diff --git a/scripts/tutorials/nBody.js b/scripts/tutorials/nBody.js index 58fc89d553..01797201b2 100644 --- a/scripts/tutorials/nBody.js +++ b/scripts/tutorials/nBody.js @@ -28,39 +28,40 @@ var COLOR3 = { red: 51, green: 51, blue: 255 }; var inFront = Vec3.sum(Camera.getPosition(), Vec3.multiply(radius * 20, Quat.getFront(Camera.getOrientation()))); for (var i = 0; i < n; i++) { - bodies.push(Entities.addEntity({ - type: "Model", - modelURL: (i == 0) ? EARTH : MOON, - shapeType: "sphere", - dimensions: { x: radius * 2, y: radius * 2, z: radius * 2}, - position: Vec3.sum(inFront, { x: 0, y: i * 2 * radius, z: 0 }), - gravity: { x: 0, y: 0, z: 0 }, - damping: 0.0, - angularDamping: 0.0, - dynamic: true + bodies.push(Entities.addEntity({ + type: "Model", + modelURL: (i == 0) ? EARTH : MOON, + shapeType: "sphere", + dimensions: { x: radius * 2, y: radius * 2, z: radius * 2}, + position: Vec3.sum(inFront, { x: 0, y: i * 2 * radius, z: 0 }), + gravity: { x: 0, y: 0, z: 0 }, + damping: 0.0, + angularDamping: 0.0, + dynamic: true })); } Script.update.connect(function(dt) { - var props = []; - for (var i = 0; i < n; i++) { - props.push(Entities.getEntityProperties(bodies[i])); - } - for (var i = 0; i < n; i++) { - if (props[i].dynamic) { - var dv = { x: 0, y: 0, z: 0}; - for (var j = 0; j < n; j++) { - if (i != j) { - dv = Vec3.sum(dv, Vec3.multiply(G * dt / Vec3.distance(props[i].position, props[j].position), Vec3.normalize(Vec3.subtract(props[j].position, props[i].position)))); - } - } - Entities.editEntity(bodies[i], { velocity: Vec3.sum(props[i].velocity, dv)}); + var props = []; + for (var i = 0; i < n; i++) { + props.push(Entities.getEntityProperties(bodies[i])); } - } + for (var i = 0; i < n; i++) { + if (props[i].dynamic) { + var dv = { x: 0, y: 0, z: 0}; + for (var j = 0; j < n; j++) { + if (i != j) { + dv = Vec3.sum(dv, Vec3.multiply(G * dt / Vec3.distance(props[i].position, props[j].position), + Vec3.normalize(Vec3.subtract(props[j].position, props[i].position)))); + } + } + Entities.editEntity(bodies[i], { velocity: Vec3.sum(props[i].velocity, dv)}); + } + } }); Script.scriptEnding.connect(function scriptEnding() { - for (var i = 0; i < n; i++) { - Entities.deleteEntity(bodies[i]); - } + for (var i = 0; i < n; i++) { + Entities.deleteEntity(bodies[i]); + } }); \ No newline at end of file