From 0a1a64b7e670dc0572daff4ae2eaabd35558c15f Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Tue, 6 Jan 2015 17:04:42 -0800 Subject: [PATCH] Script updates and fixes to highfidelity-public Script updates and fixes to highfidelity-public --- examples/editEntities.js | 4 +- examples/editModels.js | 4 +- examples/{ => example}/metavoxels.js | 0 .../{ => example}/textInputOverlayExample.js | 4 +- examples/libraries/entitySelectionTool.js | 22 ++-- examples/libraries/unitTest.js | 104 ++++++++++++++++++ examples/playSound.js | 27 ----- .../diagnostics/XMLHttpRequest.js} | 2 +- .../diagnostics}/inWorldTestTone.js | 2 +- .../diagnostics}/playSoundLoop.js | 2 +- .../diagnostics}/playSoundOrbit.js | 6 +- interface/external/rtmidi/readme.txt | 2 +- 12 files changed, 126 insertions(+), 53 deletions(-) rename examples/{ => example}/metavoxels.js (100%) rename examples/{ => example}/textInputOverlayExample.js (97%) create mode 100644 examples/libraries/unitTest.js delete mode 100644 examples/playSound.js rename examples/{testXMLHttpRequest.js => utilities/diagnostics/XMLHttpRequest.js} (99%) rename examples/{ => utilities/diagnostics}/inWorldTestTone.js (95%) rename examples/{ => utilities/diagnostics}/playSoundLoop.js (97%) rename examples/{ => utilities/diagnostics}/playSoundOrbit.js (88%) diff --git a/examples/editEntities.js b/examples/editEntities.js index 632fed088c..709014bdb8 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -77,7 +77,6 @@ var modelURLs = [ HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush6.fbx", - HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed2.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx", @@ -192,8 +191,7 @@ var toolBar = (function () { }); newTextButton = toolBar.addTool({ - //imageURL: toolIconUrl + "add-text.svg", - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily + imageURL: toolIconUrl + "add-text.svg", subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, width: toolWidth, height: toolHeight, diff --git a/examples/editModels.js b/examples/editModels.js index 8ec099650a..7cb911b490 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -56,7 +56,6 @@ var modelURLs = [ HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush6.fbx", - HIFI_PUBLIC_BUCKET + "meshes/newInvader16x16-large-purple.svo", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed2.fbx", HIFI_PUBLIC_BUCKET + "models/entities/3-Buildings-1-Rustic-Shed4.fbx", @@ -1215,8 +1214,7 @@ var toolBar = (function () { }); newTextButton = toolBar.addTool({ - //imageURL: toolIconUrl + "add-text.svg", - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/tools/add-text.svg", // temporarily + imageURL: toolIconUrl + "add-text.svg", subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, width: toolWidth, height: toolHeight, diff --git a/examples/metavoxels.js b/examples/example/metavoxels.js similarity index 100% rename from examples/metavoxels.js rename to examples/example/metavoxels.js diff --git a/examples/textInputOverlayExample.js b/examples/example/textInputOverlayExample.js similarity index 97% rename from examples/textInputOverlayExample.js rename to examples/example/textInputOverlayExample.js index 258e07fcc8..d212a547cf 100644 --- a/examples/textInputOverlayExample.js +++ b/examples/example/textInputOverlayExample.js @@ -58,7 +58,7 @@ var button1 = Overlays.addOverlay("image", { // green button width: 40, height: 35, subImage: { x: 0, y: 0, width: 39, height: 35 }, - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", + imageURL: "https://public.highfidelity.io/images/thumb.png", color: readyColor, visible: true }); @@ -69,7 +69,7 @@ var button2 = Overlays.addOverlay("image", { // red button width: 40, height: 35, subImage: { x: 0, y: 0, width: 39, height: 35 }, - imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png", + imageURL: "https://public.highfidelity.io/images/thumb.png", color: { red: 250, green: 2, blue: 2}, visible: true, }); diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 8aff9c32ed..2b83d7740d 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -590,7 +590,7 @@ SelectionDisplay = (function () { }); var yawHandle = Overlays.addOverlay("billboard", { - url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", + url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png", position: { x:0, y: 0, z: 0}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -603,7 +603,7 @@ SelectionDisplay = (function () { var pitchHandle = Overlays.addOverlay("billboard", { - url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", + url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png", position: { x:0, y: 0, z: 0}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -616,7 +616,7 @@ SelectionDisplay = (function () { var rollHandle = Overlays.addOverlay("billboard", { - url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png", + url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png", position: { x:0, y: 0, z: 0}, color: rotateHandleColor, alpha: rotateHandleAlpha, @@ -835,8 +835,8 @@ SelectionDisplay = (function () { rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far }; - Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-south.png" }); - Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-south.png" }); + Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-south.png" }); + Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-south.png" }); } else { @@ -867,8 +867,8 @@ SelectionDisplay = (function () { pitchCenter = { x: right, y: boundsCenter.y, z: boundsCenter.z }; rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near}; - Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); - Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } } else { @@ -899,8 +899,8 @@ SelectionDisplay = (function () { pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z }; rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far}; - Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); - Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } else { @@ -928,8 +928,8 @@ SelectionDisplay = (function () { rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near }; pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z}; - Overlays.editOverlay(pitchHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); - Overlays.editOverlay(rollHandle, { url: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(pitchHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); + Overlays.editOverlay(rollHandle, { url: "https://public.highfidelity.io/images/rotate-arrow-west-north.png" }); } } diff --git a/examples/libraries/unitTest.js b/examples/libraries/unitTest.js new file mode 100644 index 0000000000..530528e6a3 --- /dev/null +++ b/examples/libraries/unitTest.js @@ -0,0 +1,104 @@ +// +// Unittest.js +// examples +// +// Created by Ryan Huffman on 5/4/14 +// Copyright 2014 High Fidelity, Inc. +// +// This provides very basic unit testing functionality. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +test = function(name, func) { + print("Running test: " + name); + + var unitTest = new UnitTest(name, func); + + try { + unitTest.run(); + print(" Success: " + unitTest.numAssertions + " assertions passed"); + } catch (error) { + print(" Failure: " + error.name + " " + error.message); + } +}; + +AssertionException = function(expected, actual, message) { + print("Creating exception"); + this.message = message + "\n: " + actual + " != " + expected; + this.name = 'AssertionException'; +}; + +UnthrownException = function(message) { + print("Creating exception"); + this.message = message + "\n"; + this.name = 'UnthrownException'; +}; + +UnitTest = function(name, func) { + this.numAssertions = 0; + this.func = func; +}; + +UnitTest.prototype.run = function() { + this.func(); +}; + +UnitTest.prototype.assertNotEquals = function(expected, actual, message) { + this.numAssertions++; + if (expected == actual) { + throw new AssertionException(expected, actual, message); + } +}; + +UnitTest.prototype.assertEquals = function(expected, actual, message) { + this.numAssertions++; + if (expected != actual) { + throw new AssertionException(expected, actual, message); + } +}; + +UnitTest.prototype.assertContains = function (expected, actual, message) { + this.numAssertions++; + if (actual.indexOf(expected) == -1) { + throw new AssertionException(expected, actual, message); + } +}; + +UnitTest.prototype.assertHasProperty = function(property, actual, message) { + this.numAssertions++; + if (actual[property] === undefined) { + throw new AssertionException(property, actual, message); + } +}; + +UnitTest.prototype.assertNull = function(value, message) { + this.numAssertions++; + if (value !== null) { + throw new AssertionException(value, null, message); + } +} + +UnitTest.prototype.arrayEqual = function(array1, array2, message) { + this.numAssertions++; + if (array1.length !== array2.length) { + throw new AssertionException(array1.length , array2.length , message); + } + for (var i = 0; i < array1.length; ++i) { + if (array1[i] !== array2[i]) { + throw new AssertionException(array1[i], array2[i], i + " " + message); + } + } +} + +UnitTest.prototype.raises = function(func, message) { + this.numAssertions++; + try { + func(); + } catch (error) { + return; + } + + throw new UnthrownException(message); +} \ No newline at end of file diff --git a/examples/playSound.js b/examples/playSound.js deleted file mode 100644 index bc21204665..0000000000 --- a/examples/playSound.js +++ /dev/null @@ -1,27 +0,0 @@ -// -// playSound.js -// examples -// -// Copyright 2014 High Fidelity, Inc. -// Plays a sample audio file at the avatar's current location -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - -Script.include("libraries/globals.js"); - -// First, load a sample sound from a URL -var bird = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Animals/bushtit_1.raw"); - -function maybePlaySound(deltaTime) { - if (Math.random() < 0.01) { - // Set the location and other info for the sound to play - Audio.playSound(bird, { - position: MyAvatar.position, - volume: 0.5 - }); - } -} - -// Connect a call back that happens every frame -Script.update.connect(maybePlaySound); \ No newline at end of file diff --git a/examples/testXMLHttpRequest.js b/examples/utilities/diagnostics/XMLHttpRequest.js similarity index 99% rename from examples/testXMLHttpRequest.js rename to examples/utilities/diagnostics/XMLHttpRequest.js index 79d2842464..fb25cb4fad 100644 --- a/examples/testXMLHttpRequest.js +++ b/examples/utilities/diagnostics/XMLHttpRequest.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("Test.js"); +Script.include("../../libraries/unitTest.js"); test("Test default request values", function(finished) { var req = new XMLHttpRequest(); diff --git a/examples/inWorldTestTone.js b/examples/utilities/diagnostics/inWorldTestTone.js similarity index 95% rename from examples/inWorldTestTone.js rename to examples/utilities/diagnostics/inWorldTestTone.js index 660965569c..1fc3cbc2c8 100644 --- a/examples/inWorldTestTone.js +++ b/examples/utilities/diagnostics/inWorldTestTone.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); var sound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/220Sine.wav"); diff --git a/examples/playSoundLoop.js b/examples/utilities/diagnostics/playSoundLoop.js similarity index 97% rename from examples/playSoundLoop.js rename to examples/utilities/diagnostics/playSoundLoop.js index f7116cb615..b9d35141d1 100644 --- a/examples/playSoundLoop.js +++ b/examples/utilities/diagnostics/playSoundLoop.js @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); // A few sample files you may want to try: diff --git a/examples/playSoundOrbit.js b/examples/utilities/diagnostics/playSoundOrbit.js similarity index 88% rename from examples/playSoundOrbit.js rename to examples/utilities/diagnostics/playSoundOrbit.js index 16ba5e52af..d9885b7f34 100644 --- a/examples/playSoundOrbit.js +++ b/examples/utilities/diagnostics/playSoundOrbit.js @@ -9,9 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("libraries/globals.js"); +Script.include("../../libraries/globals.js"); -var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Voxels/voxel create 3.raw"); +var soundClip = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Nylon+A.raw"); var currentTime = 1.570079; // pi/2 var deltaTime = 0.05; @@ -38,6 +38,6 @@ function playSound() { }); } -Script.setInterval(playSound, 250); +Script.setInterval(playSound, 850); diff --git a/interface/external/rtmidi/readme.txt b/interface/external/rtmidi/readme.txt index d0480fce4a..3b9d6603a9 100644 --- a/interface/external/rtmidi/readme.txt +++ b/interface/external/rtmidi/readme.txt @@ -3,7 +3,7 @@ Instructions for adding the RtMidi library to Interface Stephen Birarda, June 30, 2014 1. Download the RtMidi tarball from High Fidelity S3. - http://highfidelity-public.s3.amazonaws.com/dependencies/rtmidi-2.1.0.tar.gz + http://public.highfidelity.io/dependencies/rtmidi-2.1.0.tar.gz 2. Copy RtMidi.h to externals/rtmidi/include.