diff --git a/examples/entityScripts/tribble.js b/examples/entityScripts/tribble.js index 3afdcc43e4..22990af1d1 100644 --- a/examples/entityScripts/tribble.js +++ b/examples/entityScripts/tribble.js @@ -29,13 +29,19 @@ accumulated = 0; } } - function randomCentered() { return Math.random() - 0.5; } - function randomVector() { return {x: randomCentered() * dimensions.x, y: randomCentered() * dimensions.y, z: randomCentered() * dimensions.z}; } + function randomCentered() { + return Math.random() - 0.5; + } + function randomVector() { + return {x: randomCentered() * dimensions.x, y: randomCentered() * dimensions.y, z: randomCentered() * dimensions.z}; + } function move() { var newData = {velocity: Vec3.sum({x: 0, y: 1, z: 0}, randomVector()), angularVelocity: Vec3.multiply(Math.PI, randomVector())}; var nextChange = Math.ceil(Math.random() * 2000 / moveRate); Entities.editEntity(entityID, newData); - if (!shutdown) { Script.setTimeout(move, nextChange); } + if (!shutdown) { + Script.setTimeout(move, nextChange); + } } function startUpdate() { print('startUpdate', entityID); @@ -44,7 +50,9 @@ } function stopUpdate() { print('stopUpdate', entityID, hasUpdate); - if (!hasUpdate) { return; } + if (!hasUpdate) { + return; + } hasUpdate = false; Script.update.disconnect(update); } @@ -79,7 +87,9 @@ if (moveTimeout) { Script.setTimeout(move, 1000); if (moveTimeout > 0) { - Script.setTimeout(function () { shutdown = true; }, moveTimeout * 1000); + Script.setTimeout(function () { + shutdown = true; + }, moveTimeout * 1000); } } }; diff --git a/examples/libraries/virtualBaton.js b/examples/libraries/virtualBaton.js index b1f813f764..dad31a7b1e 100644 --- a/examples/libraries/virtualBaton.js +++ b/examples/libraries/virtualBaton.js @@ -60,7 +60,9 @@ function virtualBatonf(options) { // order) of both.) connectionTest = options.connectionTest || function connectionTest(id) { var idLength = 38; - if (id.length === idLength) { return exports.validId(id); } + if (id.length === idLength) { + return exports.validId(id); + } return (id.length === 2 * idLength) && exports.validId(id.slice(0, idLength)) && exports.validId(id.slice(idLength)); }; @@ -70,7 +72,9 @@ function virtualBatonf(options) { // Truthy if id exists as either a connected avatar or valid entity. exports.validId = function validId(id) { var avatar = avatarList.getAvatar(id); - if (avatar && (avatar.sessionUUID === id)) { return true; } + if (avatar && (avatar.sessionUUID === id)) { + return true; + } var properties = entities.getEntityProperties(id, ['type']); return properties && properties.type; }; @@ -80,13 +84,19 @@ function virtualBatonf(options) { log.apply(null, [].map.call(arguments, JSON.stringify)); } function debugFlow() { - if (options.debugFlow) { debug.apply(null, arguments); } + if (options.debugFlow) { + debug.apply(null, arguments); + } } function debugSend(destination, operation, data) { - if (options.debugSend) { debug('baton:', batonName, instanceId, 's=>', destination, operation, data); } + if (options.debugSend) { + debug('baton:', batonName, instanceId, 's=>', destination, operation, data); + } } function debugReceive(senderID, operation, data) { // senderID is client sessionUUID -- not necessarily instanceID! - if (options.debugReceive) { debug('baton:', batonName, senderID, '=>r', instanceId, operation, data); } + if (options.debugReceive) { + debug('baton:', batonName, senderID, '=>r', instanceId, operation, data); + } } // Messages: Just synactic sugar for hooking things up to Messages system. @@ -95,7 +105,9 @@ function virtualBatonf(options) { var channelKey = "io.highfidelity.virtualBaton:" + batonName, subchannelHandlers = {}, // Message channel string => {receiver, op} subchannelKeys = {}; // operation => Message channel string - function subchannelKey(operation) { return channelKey + ':' + operation; } + function subchannelKey(operation) { + return channelKey + ':' + operation; + } function receive(operation, handler) { // Record a handler for an operation on our channelKey var subKey = subchannelKey(operation); subchannelHandlers[subKey] = {receiver: handler, op: operation}; @@ -116,7 +128,9 @@ function virtualBatonf(options) { } function messageHandler(channel, messageString, senderID) { var handler = subchannelHandlers[channel]; - if (!handler) { return; } + if (!handler) { + return; + } var data = JSON.parse(messageString); debugReceive(senderID, handler.op, data); handler.receiver(data); @@ -215,7 +229,9 @@ function virtualBatonf(options) { }); // Paxos Acceptor behavior var bestProposal = {number: 0}, accepted = {}; - function acceptedId() { return accepted && accepted.winner; } + function acceptedId() { + return accepted && accepted.winner; + } receive('prepare!', function (data) { var response = {proposalNumber: data.number, proposerId: data.proposerId}; if (betterNumber(data, bestProposal)) { @@ -256,7 +272,9 @@ function virtualBatonf(options) { function localRelease() { var callback = releaseCallback; debugFlow('baton:', batonName, 'localRelease', 'callback:', !!releaseCallback); - if (!releaseCallback) { return; } // Already released, but we might still receive a stale message. That's ok. + if (!releaseCallback) { + return; + } // Already released, but we might still receive a stale message. That's ok. releaseCallback = undefined; callback(batonName); // Pass batonName so that clients may use the same handler for different batons. } @@ -340,7 +358,9 @@ function virtualBatonf(options) { exports.unload = function unload() { // Disconnect from everything. messages.messageReceived.disconnect(messageHandler); timers.clearInterval(exports.recheckWatchdog); - if (electionWatchdog) { timers.clearTimeout(electionWatchdog); } + if (electionWatchdog) { + timers.clearTimeout(electionWatchdog); + } electionWatchdog = claimCallback = releaseCallback = null; Object.keys(subchannelHandlers).forEach(messages.unsubscribe); debugFlow('baton:', batonName, instanceId, 'unload'); diff --git a/tests/mocha/test/testVirtualBaton.js b/tests/mocha/test/testVirtualBaton.js index c661bfeffc..2a4edb4d5d 100644 --- a/tests/mocha/test/testVirtualBaton.js +++ b/tests/mocha/test/testVirtualBaton.js @@ -7,11 +7,16 @@ var virtualBaton = require('../../../examples/libraries/virtualBaton.js'); describe('temp', function () { var messageCount = 0, testStart = Date.now(); function makeMessager(nodes, me, mode) { // shim for High Fidelity Message system - function noopSend(channel, string, source) { } - function hasChannel(node, channel) { return -1 !== node.subscribed.indexOf(channel); } + function noopSend(channel, string, source) { + } + function hasChannel(node, channel) { + return -1 !== node.subscribed.indexOf(channel); + } function sendSync(channel, message, nodes, skip) { nodes.forEach(function (node) { - if (!hasChannel(node, channel) || (node === skip)) { return; } + if (!hasChannel(node, channel) || (node === skip)) { + return; + } node.sender(channel, message, me.name); }); } @@ -22,7 +27,11 @@ describe('temp', function () { return { subscriberCount: function () { var c = 0; - nodes.forEach(function (n) { if (n.subscribed.length) { c++; } }); + nodes.forEach(function (n) { + if (n.subscribed.length) { + c++; + } + }); return c; }, subscribe: function (channel) { @@ -32,7 +41,9 @@ describe('temp', function () { me.subscribed.splice(me.subscribed.indexOf(channel), 1); }, sendMessage: function (channel, message) { - if ((mode === 'immediate2Me') && hasChannel(me, channel)) { me.sender(channel, message, me.name); } + if ((mode === 'immediate2Me') && hasChannel(me, channel)) { + me.sender(channel, message, me.name); + } if (mode === 'immediate') { sendSync(channel, message, nodes, null); } else { @@ -43,7 +54,9 @@ describe('temp', function () { }, messageReceived: { connect: function (f) { - me.sender = function (c, m, i) { messageCount++; f(c, m, i); }; + me.sender = function (c, m, i) { + messageCount++; f(c, m, i); + }; }, disconnect: function () { me.sender = noopSend; @@ -60,7 +73,9 @@ describe('temp', function () { debugReceive: debug.receive, debugFlow: debug.flow, useOptimizations: optimize, - connectionTest: function (id) { return baton.validId(id); }, + connectionTest: function (id) { + return baton.validId(id); + }, globals: { Messages: makeMessager(nodes, node, mode), MyAvatar: {sessionUUID: node.name}, @@ -71,17 +86,24 @@ describe('temp', function () { clearInterval: clearInterval }, AvatarList: { - getAvatar: function (id) { return {sessionUUID: id}; } + getAvatar: function (id) { + return {sessionUUID: id}; + } }, - Entities: {getEntityProperties: function () { }}, + Entities: {getEntityProperties: function () { + }}, print: console.log } }); return baton; } - function noRelease(batonName) { assert.ok(!batonName, "should not release"); } + function noRelease(batonName) { + assert.ok(!batonName, "should not release"); + } function defineABunch(mode, optimize) { - function makeKey(prefix) { return prefix + mode + (optimize ? '-opt' : ''); } + function makeKey(prefix) { + return prefix + mode + (optimize ? '-opt' : ''); + } var testKeys = makeKey('single-'); it(testKeys, function (done) { var nodes = [{name: 'a'}]; @@ -137,17 +159,23 @@ describe('temp', function () { console.log('claimed al', key); assert.ok(!gotB, "should not get A after B"); gotA = true; - if (!gotB) { done(); } + if (!gotB) { + done(); + } }, function () { assert.ok(gotA, "Should claim it first"); releaseA = true; - if (gotB) { done(); } + if (gotB) { + done(); + } }); setTimeout(function () { makeBaton(testKeydsl, nodes, nodes[1], debug, mode, optimize).claim(function (key) { console.log('claimed bl', key); gotB = true; - if (releaseA) { done(); } + if (releaseA) { + done(); + } }, noRelease); }, 3000); });