correct existing uses of the isPlaying property

This commit is contained in:
Stephen Birarda 2016-05-25 11:11:06 -07:00
parent ba77aaf7ef
commit 64720444cf
10 changed files with 155 additions and 157 deletions

View file

@ -3,8 +3,8 @@
// examples // examples
// //
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// Creates a flock of birds that fly around and chirp, staying inside the corners of the box defined // Creates a flock of birds that fly around and chirp, staying inside the corners of the box defined
// at the start of the script. // at the start of the script.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -13,12 +13,12 @@
// The rectangular area in the domain where the flock will fly // The rectangular area in the domain where the flock will fly
var lowerCorner = { x: 0, y: 0, z: 0 }; var lowerCorner = { x: 0, y: 0, z: 0 };
var upperCorner = { x: 30, y: 10, z: 30 }; var upperCorner = { x: 30, y: 10, z: 30 };
var STARTING_FRACTION = 0.25; var STARTING_FRACTION = 0.25;
var NUM_BIRDS = 50; var NUM_BIRDS = 50;
var UPDATE_INTERVAL = 0.016; var UPDATE_INTERVAL = 0.016;
var playSounds = true; var playSounds = true;
var SOUND_PROBABILITY = 0.001; var SOUND_PROBABILITY = 0.001;
var STARTING_LIFETIME = (1.0 / SOUND_PROBABILITY) * UPDATE_INTERVAL * 10; var STARTING_LIFETIME = (1.0 / SOUND_PROBABILITY) * UPDATE_INTERVAL * 10;
var numPlaying = 0; var numPlaying = 0;
var BIRD_SIZE = 0.08; var BIRD_SIZE = 0.08;
@ -36,17 +36,17 @@ var ALIGNMENT_FORCE = 1.5;
var COHESION_FORCE = 1.0; var COHESION_FORCE = 1.0;
var MAX_COHESION_VELOCITY = 0.5; var MAX_COHESION_VELOCITY = 0.5;
var followBirds = false; var followBirds = false;
var AVATAR_FOLLOW_RATE = 0.001; var AVATAR_FOLLOW_RATE = 0.001;
var AVATAR_FOLLOW_VELOCITY_TIMESCALE = 2.0; var AVATAR_FOLLOW_VELOCITY_TIMESCALE = 2.0;
var AVATAR_FOLLOW_ORIENTATION_RATE = 0.005; var AVATAR_FOLLOW_ORIENTATION_RATE = 0.005;
var floor = false; var floor = false;
var MAKE_FLOOR = false; var MAKE_FLOOR = false;
var averageVelocity = { x: 0, y: 0, z: 0 }; var averageVelocity = { x: 0, y: 0, z: 0 };
var averagePosition = { x: 0, y: 0, z: 0 }; var averagePosition = { x: 0, y: 0, z: 0 };
var birdsLoaded = false; var birdsLoaded = false;
var oldAvatarOrientation; var oldAvatarOrientation;
var oldAvatarPosition; var oldAvatarPosition;
@ -79,10 +79,10 @@ function updateBirds(deltaTime) {
birds[i].entityId = false; birds[i].entityId = false;
return; return;
} }
// Sum up average position and velocity // Sum up average position and velocity
if (Vec3.length(properties.velocity) > MIN_ALIGNMENT_VELOCITY) { if (Vec3.length(properties.velocity) > MIN_ALIGNMENT_VELOCITY) {
sumVelocity = Vec3.sum(sumVelocity, properties.velocity); sumVelocity = Vec3.sum(sumVelocity, properties.velocity);
birdVelocitiesCounted += 1; birdVelocitiesCounted += 1;
} }
sumPosition = Vec3.sum(sumPosition, properties.position); sumPosition = Vec3.sum(sumPosition, properties.position);
birdPositionsCounted += 1; birdPositionsCounted += 1;
@ -93,10 +93,10 @@ function updateBirds(deltaTime) {
var randomVelocity = randomVector(RANDOM_FLAP_VELOCITY); var randomVelocity = randomVector(RANDOM_FLAP_VELOCITY);
randomVelocity.y = FLAP_UP + Math.random() * FLAP_UP; randomVelocity.y = FLAP_UP + Math.random() * FLAP_UP;
// Alignment Velocity // Alignment Velocity
var alignmentVelocityMagnitude = Math.min(MAX_ALIGNMENT_VELOCITY, Vec3.length(Vec3.multiply(ALIGNMENT_FORCE, averageVelocity))); var alignmentVelocityMagnitude = Math.min(MAX_ALIGNMENT_VELOCITY, Vec3.length(Vec3.multiply(ALIGNMENT_FORCE, averageVelocity)));
var alignmentVelocity = Vec3.multiply(alignmentVelocityMagnitude, Vec3.normalize(averageVelocity)); var alignmentVelocity = Vec3.multiply(alignmentVelocityMagnitude, Vec3.normalize(averageVelocity));
alignmentVelocity.y *= VERTICAL_ALIGNMENT_COUPLING; alignmentVelocity.y *= VERTICAL_ALIGNMENT_COUPLING;
// Cohesion // Cohesion
var distanceFromCenter = Vec3.length(Vec3.subtract(averagePosition, properties.position)); var distanceFromCenter = Vec3.length(Vec3.subtract(averagePosition, properties.position));
@ -107,10 +107,10 @@ function updateBirds(deltaTime) {
Entities.editEntity(birds[i].entityId, { velocity: Vec3.sum(properties.velocity, newVelocity) }); Entities.editEntity(birds[i].entityId, { velocity: Vec3.sum(properties.velocity, newVelocity) });
} }
// Check whether to play a chirp // Check whether to play a chirp
if (playSounds && (!birds[i].audioId || !birds[i].audioId.isPlaying) && (Math.random() < ((numPlaying > 0) ? SOUND_PROBABILITY / numPlaying : SOUND_PROBABILITY))) { if (playSounds && (!birds[i].audioId || !birds[i].audioId.playing) && (Math.random() < ((numPlaying > 0) ? SOUND_PROBABILITY / numPlaying : SOUND_PROBABILITY))) {
var options = { var options = {
position: properties.position, position: properties.position,
volume: BIRD_MASTER_VOLUME volume: BIRD_MASTER_VOLUME
@ -126,43 +126,43 @@ function updateBirds(deltaTime) {
// Change size, and update lifetime to keep bird alive // Change size, and update lifetime to keep bird alive
Entities.editEntity(birds[i].entityId, { dimensions: Vec3.multiply(1.5, properties.dimensions), Entities.editEntity(birds[i].entityId, { dimensions: Vec3.multiply(1.5, properties.dimensions),
lifetime: properties.ageInSeconds + STARTING_LIFETIME}); lifetime: properties.ageInSeconds + STARTING_LIFETIME});
} else if (birds[i].audioId) { } else if (birds[i].audioId) {
// If bird is playing a chirp // If bird is playing a chirp
if (!birds[i].audioId.isPlaying) { if (!birds[i].audioId.playing) {
Entities.editEntity(birds[i].entityId, { dimensions: { x: BIRD_SIZE, y: BIRD_SIZE, z: BIRD_SIZE }}); Entities.editEntity(birds[i].entityId, { dimensions: { x: BIRD_SIZE, y: BIRD_SIZE, z: BIRD_SIZE }});
numPlaying--; numPlaying--;
} }
} }
// Keep birds in their 'cage' // Keep birds in their 'cage'
var bounce = false; var bounce = false;
var newVelocity = properties.velocity; var newVelocity = properties.velocity;
var newPosition = properties.position; var newPosition = properties.position;
if (properties.position.x < lowerCorner.x) { if (properties.position.x < lowerCorner.x) {
newPosition.x = lowerCorner.x; newPosition.x = lowerCorner.x;
newVelocity.x *= -1.0; newVelocity.x *= -1.0;
bounce = true; bounce = true;
} else if (properties.position.x > upperCorner.x) { } else if (properties.position.x > upperCorner.x) {
newPosition.x = upperCorner.x; newPosition.x = upperCorner.x;
newVelocity.x *= -1.0; newVelocity.x *= -1.0;
bounce = true; bounce = true;
} }
if (properties.position.y < lowerCorner.y) { if (properties.position.y < lowerCorner.y) {
newPosition.y = lowerCorner.y; newPosition.y = lowerCorner.y;
newVelocity.y *= -1.0; newVelocity.y *= -1.0;
bounce = true; bounce = true;
} else if (properties.position.y > upperCorner.y) { } else if (properties.position.y > upperCorner.y) {
newPosition.y = upperCorner.y; newPosition.y = upperCorner.y;
newVelocity.y *= -1.0; newVelocity.y *= -1.0;
bounce = true; bounce = true;
} }
if (properties.position.z < lowerCorner.z) { if (properties.position.z < lowerCorner.z) {
newPosition.z = lowerCorner.z; newPosition.z = lowerCorner.z;
newVelocity.z *= -1.0; newVelocity.z *= -1.0;
bounce = true; bounce = true;
} else if (properties.position.z > upperCorner.z) { } else if (properties.position.z > upperCorner.z) {
newPosition.z = upperCorner.z; newPosition.z = upperCorner.z;
newVelocity.z *= -1.0; newVelocity.z *= -1.0;
bounce = true; bounce = true;
} }
@ -171,7 +171,7 @@ function updateBirds(deltaTime) {
} }
} }
} }
// Update average velocity and position of flock // Update average velocity and position of flock
if (birdVelocitiesCounted > 0) { if (birdVelocitiesCounted > 0) {
averageVelocity = Vec3.multiply(1.0 / birdVelocitiesCounted, sumVelocity); averageVelocity = Vec3.multiply(1.0 / birdVelocitiesCounted, sumVelocity);
//print(Vec3.length(averageVelocity)); //print(Vec3.length(averageVelocity));
@ -184,10 +184,10 @@ function updateBirds(deltaTime) {
MyAvatar.orientation = Quat.mix(MyAvatar.orientation, birdDirection, AVATAR_FOLLOW_ORIENTATION_RATE); MyAvatar.orientation = Quat.mix(MyAvatar.orientation, birdDirection, AVATAR_FOLLOW_ORIENTATION_RATE);
} }
} }
} }
if (birdPositionsCounted > 0) { if (birdPositionsCounted > 0) {
averagePosition = Vec3.multiply(1.0 / birdPositionsCounted, sumPosition); averagePosition = Vec3.multiply(1.0 / birdPositionsCounted, sumPosition);
// If Following birds, update position // If Following birds, update position
if (followBirds) { if (followBirds) {
MyAvatar.position = Vec3.sum(Vec3.multiply(AVATAR_FOLLOW_RATE, MyAvatar.position), Vec3.multiply(1.0 - AVATAR_FOLLOW_RATE, averagePosition)); MyAvatar.position = Vec3.sum(Vec3.multiply(AVATAR_FOLLOW_RATE, MyAvatar.position), Vec3.multiply(1.0 - AVATAR_FOLLOW_RATE, averagePosition));
} }
@ -211,12 +211,12 @@ Script.scriptEnding.connect(function() {
}); });
function loadBirds(howMany) { function loadBirds(howMany) {
oldAvatarOrientation = MyAvatar.orientation; oldAvatarOrientation = MyAvatar.orientation;
oldAvatarPosition = MyAvatar.position; oldAvatarPosition = MyAvatar.position;
var sound_filenames = ["bushtit_1.raw", "bushtit_2.raw", "bushtit_3.raw"]; var sound_filenames = ["bushtit_1.raw", "bushtit_2.raw", "bushtit_3.raw"];
/* Here are more sounds/species you can use /* Here are more sounds/species you can use
, "mexicanWhipoorwill.raw", , "mexicanWhipoorwill.raw",
"rosyfacedlovebird.raw", "saysphoebe.raw", "westernscreechowl.raw", "bandtailedpigeon.wav", "bridledtitmouse.wav", "rosyfacedlovebird.raw", "saysphoebe.raw", "westernscreechowl.raw", "bandtailedpigeon.wav", "bridledtitmouse.wav",
"browncrestedflycatcher.wav", "commonnighthawk.wav", "commonpoorwill.wav", "doublecrestedcormorant.wav", "browncrestedflycatcher.wav", "commonnighthawk.wav", "commonpoorwill.wav", "doublecrestedcormorant.wav",
"gambelsquail.wav", "goldcrownedkinglet.wav", "greaterroadrunner.wav","groovebilledani.wav","hairywoodpecker.wav", "gambelsquail.wav", "goldcrownedkinglet.wav", "greaterroadrunner.wav","groovebilledani.wav","hairywoodpecker.wav",
@ -252,19 +252,19 @@ function loadBirds(howMany) {
{ red: 216, green: 153, blue: 99 }, { red: 216, green: 153, blue: 99 },
{ red: 242, green: 226, blue: 64 } { red: 242, green: 226, blue: 64 }
]; ];
var SOUND_BASE_URL = "http://public.highfidelity.io/sounds/Animals/"; var SOUND_BASE_URL = "http://public.highfidelity.io/sounds/Animals/";
for (var i = 0; i < howMany; i++) { for (var i = 0; i < howMany; i++) {
var whichBird = Math.floor(Math.random() * sound_filenames.length); var whichBird = Math.floor(Math.random() * sound_filenames.length);
var position = { var position = {
x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.x - lowerCorner.x) * STARTING_FRACTION, x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.x - lowerCorner.x) * STARTING_FRACTION,
y: lowerCorner.y + (upperCorner.y - lowerCorner.y) / 2.0 + (Math.random() - 0.5) * (upperCorner.y - lowerCorner.y) * STARTING_FRACTION, y: lowerCorner.y + (upperCorner.y - lowerCorner.y) / 2.0 + (Math.random() - 0.5) * (upperCorner.y - lowerCorner.y) * STARTING_FRACTION,
z: lowerCorner.z + (upperCorner.z - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.z - lowerCorner.z) * STARTING_FRACTION z: lowerCorner.z + (upperCorner.z - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.z - lowerCorner.z) * STARTING_FRACTION
}; };
birds.push({ birds.push({
sound: SoundCache.getSound(SOUND_BASE_URL + sound_filenames[whichBird]), sound: SoundCache.getSound(SOUND_BASE_URL + sound_filenames[whichBird]),
entityId: Entities.addEntity({ entityId: Entities.addEntity({
type: "Sphere", type: "Sphere",
position: position, position: position,
@ -282,8 +282,8 @@ function loadBirds(howMany) {
} }
if (MAKE_FLOOR) { if (MAKE_FLOOR) {
var FLOOR_THICKNESS = 0.05; var FLOOR_THICKNESS = 0.05;
floor = Entities.addEntity({ type: "Box", position: { x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0, floor = Entities.addEntity({ type: "Box", position: { x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0,
y: lowerCorner.y, y: lowerCorner.y,
z: lowerCorner.z + (upperCorner.z - lowerCorner.z) / 2.0 }, z: lowerCorner.z + (upperCorner.z - lowerCorner.z) / 2.0 },
dimensions: { x: (upperCorner.x - lowerCorner.x), y: FLOOR_THICKNESS, z: (upperCorner.z - lowerCorner.z)}, dimensions: { x: (upperCorner.x - lowerCorner.x), y: FLOOR_THICKNESS, z: (upperCorner.z - lowerCorner.z)},
color: {red: 100, green: 100, blue: 100} color: {red: 100, green: 100, blue: 100}

View file

@ -49,7 +49,7 @@ function debug() { // Display the arguments not just [Object object].
EntityViewer.setCenterRadius(QUERY_RADIUS); EntityViewer.setCenterRadius(QUERY_RADIUS);
// ENTITY DATA CACHE // ENTITY DATA CACHE
// //
var entityCache = {}; // A dictionary of unexpired EntityData objects. var entityCache = {}; // A dictionary of unexpired EntityData objects.
var examinationCount = 0; var examinationCount = 0;
function EntityDatum(entityIdentifier) { // Just the data of an entity that we need to know about. function EntityDatum(entityIdentifier) { // Just the data of an entity that we need to know about.
@ -146,7 +146,7 @@ function EntityDatum(entityIdentifier) { // Just the data of an entity that we n
return; return;
} }
that.injector.setOptions(options); // PLAYING => UPDATE POSITION ETC that.injector.setOptions(options); // PLAYING => UPDATE POSITION ETC
if (!that.injector.isPlaying) { // Subtle: a looping sound will not check playbackGap. if (!that.injector.playing) { // Subtle: a looping sound will not check playbackGap.
if (repeat()) { // WAITING => PLAYING if (repeat()) { // WAITING => PLAYING
// Setup next play just once, now. Changes won't be looked at while we wait. // Setup next play just once, now. Changes won't be looked at while we wait.
that.playAfter = randomizedNextPlay(); that.playAfter = randomizedNextPlay();
@ -208,7 +208,7 @@ function updateAllEntityData() { // A fast update of all entities we know about.
stats.entities++; stats.entities++;
if (datum.url) { if (datum.url) {
stats.sounds++; stats.sounds++;
if (datum.injector && datum.injector.isPlaying) { if (datum.injector && datum.injector.playing) {
stats.playing++; stats.playing++;
} }
} }

View file

@ -283,7 +283,7 @@ function actionStartEvent(event) {
if (avatarIndex < avatars.length) { if (avatarIndex < avatars.length) {
var actionPlace = avatars[avatarIndex]; var actionPlace = avatars[avatarIndex];
print("Changing avatar to " + actionPlace.name print("Changing avatar to " + actionPlace.name
+ " after click on panel " + panelIndex + " with avatar index " + avatarIndex); + " after click on panel " + panelIndex + " with avatar index " + avatarIndex);
MyAvatar.useFullAvatarURL(actionPlace.content_url); MyAvatar.useFullAvatarURL(actionPlace.content_url);
@ -395,7 +395,7 @@ function update(deltaTime) {
Overlays.editOverlay(descriptionText, { position: textOverlayPosition() }); Overlays.editOverlay(descriptionText, { position: textOverlayPosition() });
// if the reticle is up then we may need to play the next muzak // if the reticle is up then we may need to play the next muzak
if (currentMuzakInjector && !currentMuzakInjector.isPlaying) { if (currentMuzakInjector && !currentMuzakInjector.playing) {
playNextMuzak(); playNextMuzak();
} }
} }

View file

@ -21,7 +21,7 @@ var CHATTER_VOLUME = 0.20
var EXTRA_VOLUME = 0.25 var EXTRA_VOLUME = 0.25
function playChatter() { function playChatter() {
if (chatter.downloaded && !chatter.isPlaying) { if (chatter.downloaded && !chatter.playing) {
Audio.playSound(chatter, { loop: true, volume: CHATTER_VOLUME }); Audio.playSound(chatter, { loop: true, volume: CHATTER_VOLUME });
} }
} }
@ -31,7 +31,7 @@ chatter.ready.connect(playChatter);
var currentInjector = null; var currentInjector = null;
function playRandomExtras() { function playRandomExtras() {
if ((!currentInjector || !currentInjector.isPlaying) && (Math.random() < (1.0 / 1800.0))) { if ((!currentInjector || !currentInjector.playing) && (Math.random() < (1.0 / 1800.0))) {
// play a random extra sound about every 30s // play a random extra sound about every 30s
currentInjector = Audio.playSound( currentInjector = Audio.playSound(
extras[Math.floor(Math.random() * extras.length)], extras[Math.floor(Math.random() * extras.length)],

View file

@ -22,12 +22,12 @@ function printVector(v) {
return; return;
} }
function vMinus(a, b) { function vMinus(a, b) {
var rval = { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z }; var rval = { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
return rval; return rval;
} }
// The model file to be used for the guitar // The model file to be used for the guitar
var guitarModel = HIFI_PUBLIC_BUCKET + "models/attachments/guitar.fst"; var guitarModel = HIFI_PUBLIC_BUCKET + "models/attachments/guitar.fst";
// Load sounds that will be played // Load sounds that will be played
@ -47,7 +47,7 @@ chords[6] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Me
chords[7] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+E+short.raw"); chords[7] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+E+short.raw");
chords[8] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+G+short.raw"); chords[8] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Metal+G+short.raw");
// Steel Guitar // Steel Guitar
chords[9] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+A.raw"); chords[9] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+A.raw");
chords[10] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+B.raw"); chords[10] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+B.raw");
chords[11] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+E.raw"); chords[11] = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Guitars/Guitar+-+Steel+E.raw");
@ -83,8 +83,8 @@ if (leftHanded) {
} }
var lastPosition = { x: 0.0, var lastPosition = { x: 0.0,
y: 0.0, y: 0.0,
z: 0.0 }; z: 0.0 };
var audioInjector = null; var audioInjector = null;
var selectorPressed = false; var selectorPressed = false;
@ -106,7 +106,7 @@ function checkHands(deltaTime) {
var chord = Controller.getValue(chordTrigger); var chord = Controller.getValue(chordTrigger);
if (volume > 1.0) volume = 1.0; if (volume > 1.0) volume = 1.0;
if ((chord > 0.1) && audioInjector && audioInjector.isPlaying) { if ((chord > 0.1) && audioInjector && audioInjector.playing) {
// If chord finger trigger pulled, stop current chord // If chord finger trigger pulled, stop current chord
print("stopping chord because cord trigger pulled"); print("stopping chord because cord trigger pulled");
audioInjector.stop(); audioInjector.stop();
@ -119,7 +119,7 @@ function checkHands(deltaTime) {
guitarSelector += NUM_CHORDS; guitarSelector += NUM_CHORDS;
if (guitarSelector >= NUM_CHORDS * NUM_GUITARS) { if (guitarSelector >= NUM_CHORDS * NUM_GUITARS) {
guitarSelector = 0; guitarSelector = 0;
} }
print("new guitarBase: " + guitarSelector); print("new guitarBase: " + guitarSelector);
stopAudio(true); stopAudio(true);
selectorPressed = true; selectorPressed = true;
@ -160,7 +160,7 @@ function checkHands(deltaTime) {
} }
function stopAudio(killInjector) { function stopAudio(killInjector) {
if (audioInjector && audioInjector.isPlaying) { if (audioInjector && audioInjector.playing) {
print("stopped sound"); print("stopped sound");
audioInjector.stop(); audioInjector.stop();
} }
@ -212,4 +212,3 @@ function scriptEnding() {
Script.update.connect(checkHands); Script.update.connect(checkHands);
Script.scriptEnding.connect(scriptEnding); Script.scriptEnding.connect(scriptEnding);
Controller.keyPressEvent.connect(keyPressEvent); Controller.keyPressEvent.connect(keyPressEvent);

View file

@ -340,7 +340,7 @@ function moveRats() {
var metaRat = getMetaRatByRat(rat); var metaRat = getMetaRatByRat(rat);
if (metaRat !== undefined) { if (metaRat !== undefined) {
if (metaRat.injector !== undefined) { if (metaRat.injector !== undefined) {
if (metaRat.injector.isPlaying === true) { if (metaRat.injector.playing === true) {
metaRat.injector.options = { metaRat.injector.options = {
loop: true, loop: true,
position: ratPosition position: ratPosition

View file

@ -8,7 +8,7 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
(function(){ (function(){
this.entityID = null; this.entityID = null;
this.properties = null; this.properties = null;
@ -30,13 +30,13 @@
"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav",
"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav"
]; ];
this.turnSoundURLS = [ this.turnSoundURLS = [
"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav", "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove1.wav",
"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav", "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove2.wav",
"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav" "http://public.highfidelity.io/sounds/MovingFurniture/FurnitureMove3.wav"
// TODO: determine if these or other turn sounds work better than move sounds. // TODO: determine if these or other turn sounds work better than move sounds.
//"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn1.wav", //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn1.wav",
//"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn2.wav", //"http://public.highfidelity.io/sounds/MovingFurniture/FurnitureTurn2.wav",
@ -50,7 +50,7 @@
this.turnSound = null; this.turnSound = null;
this.moveInjector = null; this.moveInjector = null;
this.turnInjector = null; this.turnInjector = null;
var debug = false; var debug = false;
var displayRotateTargets = true; // change to false if you don't want the rotate targets var displayRotateTargets = true; // change to false if you don't want the rotate targets
var rotateOverlayTargetSize = 10000; // really big target var rotateOverlayTargetSize = 10000; // really big target
@ -61,12 +61,12 @@
var yawZero; var yawZero;
var rotationNormal; var rotationNormal;
var yawNormal; var yawNormal;
var stopSoundDelay = 100; // number of msecs of not moving to have sound stop var stopSoundDelay = 100; // number of msecs of not moving to have sound stop
this.getRandomInt = function(min, max) { this.getRandomInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min; return Math.floor(Math.random() * (max - min + 1)) + min;
} }
this.downloadSounds = function() { this.downloadSounds = function() {
for (var i = 0; i < this.moveSoundURLS.length; i++) { for (var i = 0; i < this.moveSoundURLS.length; i++) {
this.moveSounds[i] = SoundCache.getSound(this.moveSoundURLS[i]); this.moveSounds[i] = SoundCache.getSound(this.moveSoundURLS[i]);
@ -95,7 +95,7 @@
if (debug) { if (debug) {
print("playMoveSound() --- calling this.moveInjector = Audio.playSound(this.moveSound...)"); print("playMoveSound() --- calling this.moveInjector = Audio.playSound(this.moveSound...)");
} }
if (!this.moveInjector) { if (!this.moveInjector) {
this.moveInjector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 }); this.moveInjector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 });
} else { } else {
@ -148,7 +148,7 @@
var upVector = { x: 0, y: 1, z: 0 }; var upVector = { x: 0, y: 1, z: 0 };
var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction,
this.properties.position, upVector); this.properties.position, upVector);
var newPosition = Vec3.sum(intersection, this.graboffset); var newPosition = Vec3.sum(intersection, this.graboffset);
Entities.editEntity(this.entityID, { position: newPosition }); Entities.editEntity(this.entityID, { position: newPosition });
}; };
@ -158,7 +158,7 @@
var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y)
var upVector = { x: 0, y: 1, z: 0 }; var upVector = { x: 0, y: 1, z: 0 };
var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction, var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction,
this.properties.position, upVector); this.properties.position, upVector);
this.graboffset = Vec3.subtract(this.properties.position, intersection); this.graboffset = Vec3.subtract(this.properties.position, intersection);
}; };
@ -183,18 +183,18 @@
this.lastMovedPosition.y = mouseEvent.y; this.lastMovedPosition.y = mouseEvent.y;
} }
} }
this.move = function(mouseEvent) { this.move = function(mouseEvent) {
this.updatePosition(mouseEvent); this.updatePosition(mouseEvent);
if (this.moveInjector === null || !this.moveInjector.isPlaying) { if (this.moveInjector === null || !this.moveInjector.playing) {
this.playMoveSound(); this.playMoveSound();
} }
}; };
this.release = function(mouseEvent) { this.release = function(mouseEvent) {
this.updatePosition(mouseEvent); this.updatePosition(mouseEvent);
}; };
this.rotate = function(mouseEvent) { this.rotate = function(mouseEvent) {
var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y)
var result = Overlays.findRayIntersection(pickRay); var result = Overlays.findRayIntersection(pickRay);
@ -205,7 +205,7 @@
var centerToZero = Vec3.subtract(center, zero); var centerToZero = Vec3.subtract(center, zero);
var centerToIntersect = Vec3.subtract(center, result.intersection); var centerToIntersect = Vec3.subtract(center, result.intersection);
var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal); var angleFromZero = Vec3.orientedAngle(centerToZero, centerToIntersect, rotationNormal);
var distanceFromCenter = Vec3.distance(center, result.intersection); var distanceFromCenter = Vec3.distance(center, result.intersection);
var snapToInner = false; var snapToInner = false;
// var innerRadius = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1; // var innerRadius = (Vec3.length(selectionManager.worldDimensions) / 2) * 1.1;
@ -213,10 +213,10 @@
angleFromZero = Math.floor(angleFromZero/innerSnapAngle) * innerSnapAngle; angleFromZero = Math.floor(angleFromZero/innerSnapAngle) * innerSnapAngle;
snapToInner = true; snapToInner = true;
} }
var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 }); var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 });
Entities.editEntity(this.entityID, { rotation: Quat.multiply(yawChange, this.originalRotation) }); Entities.editEntity(this.entityID, { rotation: Quat.multiply(yawChange, this.originalRotation) });
// update the rotation display accordingly... // update the rotation display accordingly...
var startAtCurrent = 360-angleFromZero; var startAtCurrent = 360-angleFromZero;
@ -245,7 +245,7 @@
} }
} }
if (this.turnInjector === null || !this.turnInjector.isPlaying) { if (this.turnInjector === null || !this.turnInjector.playing) {
this.playTurnSound(); this.playTurnSound();
} }
}; };
@ -267,7 +267,7 @@
this.rotateOverlayOuter = null; this.rotateOverlayOuter = null;
this.rotateOverlayCurrent = null; this.rotateOverlayCurrent = null;
} }
this.displayRotateOverlay = function(mouseEvent) { this.displayRotateOverlay = function(mouseEvent) {
var yawOverlayAngles = { x: 90, y: 0, z: 0 }; var yawOverlayAngles = { x: 90, y: 0, z: 0 };
var yawOverlayRotation = Quat.fromVec3Degrees(yawOverlayAngles); var yawOverlayRotation = Quat.fromVec3Degrees(yawOverlayAngles);
@ -356,14 +356,14 @@
var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y) var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y)
var result = Overlays.findRayIntersection(pickRay); var result = Overlays.findRayIntersection(pickRay);
yawZero = result.intersection; yawZero = result.intersection;
}; };
this.preload = function(entityID) { this.preload = function(entityID) {
this.updateProperties(entityID); // All callbacks start by updating the properties this.updateProperties(entityID); // All callbacks start by updating the properties
this.downloadSounds(); this.downloadSounds();
}; };
this.clickDownOnEntity = function(entityID, mouseEvent) { this.clickDownOnEntity = function(entityID, mouseEvent) {
this.updateProperties(entityID); // All callbacks start by updating the properties this.updateProperties(entityID); // All callbacks start by updating the properties
this.grab(mouseEvent); this.grab(mouseEvent);
@ -372,13 +372,13 @@
var nowMSecs = nowDate.getTime(); var nowMSecs = nowDate.getTime();
this.clickedAt = nowMSecs; this.clickedAt = nowMSecs;
this.firstHolding = true; this.firstHolding = true;
this.clicked.x = mouseEvent.x; this.clicked.x = mouseEvent.x;
this.clicked.y = mouseEvent.y; this.clicked.y = mouseEvent.y;
this.lastMovedPosition.x = mouseEvent.x; this.lastMovedPosition.x = mouseEvent.x;
this.lastMovedPosition.y = mouseEvent.y; this.lastMovedPosition.y = mouseEvent.y;
this.lastMovedMSecs = nowMSecs; this.lastMovedMSecs = nowMSecs;
this.pickRandomSounds(); this.pickRandomSounds();
}; };
@ -391,7 +391,7 @@
if (this.clicked.x == mouseEvent.x && this.clicked.y == mouseEvent.y) { if (this.clicked.x == mouseEvent.x && this.clicked.y == mouseEvent.y) {
var d = new Date(); var d = new Date();
var now = d.getTime(); var now = d.getTime();
if (now - this.clickedAt > 500) { if (now - this.clickedAt > 500) {
this.displayRotateOverlay(mouseEvent); this.displayRotateOverlay(mouseEvent);
this.firstHolding = false; this.firstHolding = false;
@ -402,13 +402,13 @@
this.firstHolding = false; this.firstHolding = false;
} }
} }
if (this.rotateMode) { if (this.rotateMode) {
this.rotate(mouseEvent); this.rotate(mouseEvent);
} else { } else {
this.move(mouseEvent); this.move(mouseEvent);
} }
this.stopSoundIfNotMoving(mouseEvent); this.stopSoundIfNotMoving(mouseEvent);
}; };
this.clickReleaseOnEntity = function(entityID, mouseEvent) { this.clickReleaseOnEntity = function(entityID, mouseEvent) {
@ -418,7 +418,7 @@
} else { } else {
this.release(mouseEvent); this.release(mouseEvent);
} }
if (this.rotateOverlayTarget != null) { if (this.rotateOverlayTarget != null) {
this.cleanupRotateOverlay(); this.cleanupRotateOverlay();
this.rotateMode = false; this.rotateMode = false;

View file

@ -22,7 +22,7 @@ var BIRD_VELOCITY = 2.0;
var LIGHT_RADIUS = 10.0; var LIGHT_RADIUS = 10.0;
var BIRD_MASTER_VOLUME = 0.5; var BIRD_MASTER_VOLUME = 0.5;
var useLights = true; var useLights = true;
function randomVector(scale) { function randomVector(scale) {
return { x: Math.random() * scale - scale / 2.0, y: Math.random() * scale - scale / 2.0, z: Math.random() * scale - scale / 2.0 }; return { x: Math.random() * scale - scale / 2.0, y: Math.random() * scale - scale / 2.0, z: Math.random() * scale - scale / 2.0 };
@ -33,11 +33,11 @@ function maybePlaySound(deltaTime) {
// Set the location and other info for the sound to play // Set the location and other info for the sound to play
var whichBird = Math.floor(Math.random() * birds.length); var whichBird = Math.floor(Math.random() * birds.length);
//print("playing sound # " + whichBird); //print("playing sound # " + whichBird);
var position = { var position = {
x: lowerCorner.x + Math.random() * (upperCorner.x - lowerCorner.x), x: lowerCorner.x + Math.random() * (upperCorner.x - lowerCorner.x),
y: lowerCorner.y + Math.random() * (upperCorner.y - lowerCorner.y), y: lowerCorner.y + Math.random() * (upperCorner.y - lowerCorner.y),
z: lowerCorner.z + Math.random() * (upperCorner.z - lowerCorner.z) z: lowerCorner.z + Math.random() * (upperCorner.z - lowerCorner.z)
}; };
var options = { var options = {
position: position, position: position,
volume: BIRD_MASTER_VOLUME volume: BIRD_MASTER_VOLUME
@ -63,31 +63,31 @@ function maybePlaySound(deltaTime) {
constantAttenuation: 0, constantAttenuation: 0,
linearAttenuation: 4.0, linearAttenuation: 4.0,
quadraticAttenuation: 2.0, quadraticAttenuation: 2.0,
lifetime: 10 lifetime: 10
}); });
} }
playing.push({ audioId: Audio.playSound(birds[whichBird].sound, options), entityId: entityId, lightId: lightId, color: birds[whichBird].color }); playing.push({ audioId: Audio.playSound(birds[whichBird].sound, options), entityId: entityId, lightId: lightId, color: birds[whichBird].color });
} }
if (playing.length != numPlaying) { if (playing.length != numPlaying) {
numPlaying = playing.length; numPlaying = playing.length;
//print("number playing = " + numPlaying); //print("number playing = " + numPlaying);
} }
for (var i = 0; i < playing.length; i++) { for (var i = 0; i < playing.length; i++) {
if (!playing[i].audioId.isPlaying) { if (!playing[i].audioId.playing) {
Entities.deleteEntity(playing[i].entityId); Entities.deleteEntity(playing[i].entityId);
if (useLights) { if (useLights) {
Entities.deleteEntity(playing[i].lightId); Entities.deleteEntity(playing[i].lightId);
} }
playing.splice(i, 1); playing.splice(i, 1);
} else { } else {
var loudness = playing[i].audioId.loudness; var loudness = playing[i].audioId.loudness;
var newColor = { red: playing[i].color.red, green: playing[i].color.green, blue: playing[i].color.blue }; var newColor = { red: playing[i].color.red, green: playing[i].color.green, blue: playing[i].color.blue };
if (loudness > 0.05) { if (loudness > 0.05) {
newColor.red *= (1.0 - loudness); newColor.red *= (1.0 - loudness);
newColor.green *= (1.0 - loudness); newColor.green *= (1.0 - loudness);
newColor.blue *= (1.0 - loudness); newColor.blue *= (1.0 - loudness);
} }
var properties = Entities.getEntityProperties(playing[i].entityId); var properties = Entities.getEntityProperties(playing[i].entityId);
var newPosition = Vec3.sum(properties.position, randomVector(BIRD_VELOCITY * deltaTime)); var newPosition = Vec3.sum(properties.position, randomVector(BIRD_VELOCITY * deltaTime));
@ -120,7 +120,7 @@ Script.scriptEnding.connect(function() {
}); });
function loadBirds() { function loadBirds() {
var sound_filenames = ["bushtit_1.raw", "bushtit_2.raw", "bushtit_3.raw", "mexicanWhipoorwill.raw", var sound_filenames = ["bushtit_1.raw", "bushtit_2.raw", "bushtit_3.raw", "mexicanWhipoorwill.raw",
"rosyfacedlovebird.raw", "saysphoebe.raw", "westernscreechowl.raw", "bandtailedpigeon.wav", "bridledtitmouse.wav", "rosyfacedlovebird.raw", "saysphoebe.raw", "westernscreechowl.raw", "bandtailedpigeon.wav", "bridledtitmouse.wav",
"browncrestedflycatcher.wav", "commonnighthawk.wav", "commonpoorwill.wav", "doublecrestedcormorant.wav", "browncrestedflycatcher.wav", "commonnighthawk.wav", "commonpoorwill.wav", "doublecrestedcormorant.wav",
"gambelsquail.wav", "goldcrownedkinglet.wav", "greaterroadrunner.wav","groovebilledani.wav","hairywoodpecker.wav", "gambelsquail.wav", "goldcrownedkinglet.wav", "greaterroadrunner.wav","groovebilledani.wav","hairywoodpecker.wav",
@ -155,13 +155,13 @@ function loadBirds() {
{ red: 216, green: 153, blue: 99 }, { red: 216, green: 153, blue: 99 },
{ red: 242, green: 226, blue: 64 } { red: 242, green: 226, blue: 64 }
]; ];
var SOUND_BASE_URL = "http://public.highfidelity.io/sounds/Animals/"; var SOUND_BASE_URL = "http://public.highfidelity.io/sounds/Animals/";
for (var i = 0; i < sound_filenames.length; i++) { for (var i = 0; i < sound_filenames.length; i++) {
birds.push({ birds.push({
sound: SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i]), sound: SoundCache.getSound(SOUND_BASE_URL + sound_filenames[i]),
color: colors[i] color: colors[i]
}); });
} }
} }

View file

@ -88,19 +88,19 @@ var DRONE_VOLUME = 0.3;
function drawLobby() { function drawLobby() {
if (!panelWall) { if (!panelWall) {
print("Adding overlays for the lobby panel wall and orb shell."); print("Adding overlays for the lobby panel wall and orb shell.");
var cameraEuler = Quat.safeEulerAngles(Camera.orientation); var cameraEuler = Quat.safeEulerAngles(Camera.orientation);
var towardsMe = Quat.angleAxis(cameraEuler.y + 180, { x: 0, y: 1, z: 0}); var towardsMe = Quat.angleAxis(cameraEuler.y + 180, { x: 0, y: 1, z: 0});
var orbPosition = Vec3.sum(Camera.position, Vec3.multiplyQbyV(towardsMe, ORB_SHIFT)); var orbPosition = Vec3.sum(Camera.position, Vec3.multiplyQbyV(towardsMe, ORB_SHIFT));
var panelWallProps = { var panelWallProps = {
url: LOBBY_PANEL_WALL_URL, url: LOBBY_PANEL_WALL_URL,
position: Vec3.sum(orbPosition, Vec3.multiplyQbyV(towardsMe, panelsCenterShift)), position: Vec3.sum(orbPosition, Vec3.multiplyQbyV(towardsMe, panelsCenterShift)),
rotation: towardsMe, rotation: towardsMe,
dimensions: panelsDimensions dimensions: panelsDimensions
}; };
var orbShellProps = { var orbShellProps = {
url: LOBBY_SHELL_URL, url: LOBBY_SHELL_URL,
position: orbPosition, position: orbPosition,
@ -128,13 +128,13 @@ function drawLobby() {
visible: false, visible: false,
isFacingAvatar: true isFacingAvatar: true
}; };
avatarStickPosition = MyAvatar.position; avatarStickPosition = MyAvatar.position;
panelWall = Overlays.addOverlay("model", panelWallProps); panelWall = Overlays.addOverlay("model", panelWallProps);
orbShell = Overlays.addOverlay("model", orbShellProps); orbShell = Overlays.addOverlay("model", orbShellProps);
descriptionText = Overlays.addOverlay("text3d", descriptionTextProps); descriptionText = Overlays.addOverlay("text3d", descriptionTextProps);
if (droneSound.downloaded) { if (droneSound.downloaded) {
// start the drone sound // start the drone sound
if (!currentDrone) { if (!currentDrone) {
@ -143,7 +143,7 @@ function drawLobby() {
currentDrone.restart(); currentDrone.restart();
} }
} }
// start one of our muzak sounds // start one of our muzak sounds
playRandomMuzak(); playRandomMuzak();
} }
@ -157,31 +157,31 @@ function changeLobbyTextures() {
req.send(); req.send();
places = JSON.parse(req.responseText).data.places; places = JSON.parse(req.responseText).data.places;
var NUM_PANELS = places.length; var NUM_PANELS = places.length;
var textureProp = { var textureProp = {
textures: {} textures: {}
}; };
for (var j = 0; j < NUM_PANELS; j++) { for (var j = 0; j < NUM_PANELS; j++) {
var panelIndex = placeIndexToPanelIndex(j); var panelIndex = placeIndexToPanelIndex(j);
textureProp["textures"]["file" + panelIndex] = places[j].previews.lobby; textureProp["textures"]["file" + panelIndex] = places[j].previews.lobby;
}; };
Overlays.editOverlay(panelWall, textureProp); Overlays.editOverlay(panelWall, textureProp);
} }
var MUZAK_VOLUME = 0.1; var MUZAK_VOLUME = 0.1;
function playCurrentSound(secondOffset) { function playCurrentSound(secondOffset) {
if (currentSound == latinSound) { if (currentSound == latinSound) {
if (!latinInjector) { if (!latinInjector) {
latinInjector = Audio.playSound(latinSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME }); latinInjector = Audio.playSound(latinSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME });
} else { } else {
latinInjector.restart(); latinInjector.restart();
} }
currentMuzakInjector = latinInjector; currentMuzakInjector = latinInjector;
} else if (currentSound == elevatorSound) { } else if (currentSound == elevatorSound) {
if (!elevatorInjector) { if (!elevatorInjector) {
@ -189,7 +189,7 @@ function playCurrentSound(secondOffset) {
} else { } else {
elevatorInjector.restart(); elevatorInjector.restart();
} }
currentMuzakInjector = elevatorInjector; currentMuzakInjector = elevatorInjector;
} }
} }
@ -205,14 +205,14 @@ function playNextMuzak() {
currentSound = latinSound; currentSound = latinSound;
} }
} }
playCurrentSound(0); playCurrentSound(0);
} }
} }
function playRandomMuzak() { function playRandomMuzak() {
currentSound = null; currentSound = null;
if (latinSound.downloaded && elevatorSound.downloaded) { if (latinSound.downloaded && elevatorSound.downloaded) {
currentSound = Math.random() < 0.5 ? latinSound : elevatorSound; currentSound = Math.random() < 0.5 ? latinSound : elevatorSound;
} else if (latinSound.downloaded) { } else if (latinSound.downloaded) {
@ -220,11 +220,11 @@ function playRandomMuzak() {
} else if (elevatorSound.downloaded) { } else if (elevatorSound.downloaded) {
currentSound = elevatorSound; currentSound = elevatorSound;
} }
if (currentSound) { if (currentSound) {
// pick a random number of seconds from 0-10 to offset the muzak // pick a random number of seconds from 0-10 to offset the muzak
var secondOffset = Math.random() * 10; var secondOffset = Math.random() * 10;
playCurrentSound(secondOffset); playCurrentSound(secondOffset);
} else { } else {
currentMuzakInjector = null; currentMuzakInjector = null;
@ -233,36 +233,36 @@ function playRandomMuzak() {
function cleanupLobby() { function cleanupLobby() {
toggleEnvironmentRendering(true); toggleEnvironmentRendering(true);
// for each of the 21 placeholder textures, set them back to default so the cached model doesn't have changed textures // for each of the 21 placeholder textures, set them back to default so the cached model doesn't have changed textures
var panelTexturesReset = {}; var panelTexturesReset = {};
panelTexturesReset["textures"] = {}; panelTexturesReset["textures"] = {};
for (var j = 0; j < MAX_NUM_PANELS; j++) { for (var j = 0; j < MAX_NUM_PANELS; j++) {
panelTexturesReset["textures"]["file" + (j + 1)] = LOBBY_BLANK_PANEL_TEXTURE_URL; panelTexturesReset["textures"]["file" + (j + 1)] = LOBBY_BLANK_PANEL_TEXTURE_URL;
}; };
Overlays.editOverlay(panelWall, panelTexturesReset); Overlays.editOverlay(panelWall, panelTexturesReset);
Overlays.deleteOverlay(panelWall); Overlays.deleteOverlay(panelWall);
Overlays.deleteOverlay(orbShell); Overlays.deleteOverlay(orbShell);
Overlays.deleteOverlay(descriptionText); Overlays.deleteOverlay(descriptionText);
panelWall = false; panelWall = false;
orbShell = false; orbShell = false;
if (currentDrone) { if (currentDrone) {
currentDrone.stop(); currentDrone.stop();
currentDrone = null currentDrone = null
} }
if (currentMuzakInjector) { if (currentMuzakInjector) {
currentMuzakInjector.stop(); currentMuzakInjector.stop();
currentMuzakInjector = null; currentMuzakInjector = null;
} }
places = {}; places = {};
} }
function actionStartEvent(event) { function actionStartEvent(event) {
@ -271,19 +271,19 @@ function actionStartEvent(event) {
// check if we hit a panel and if we should jump there // check if we hit a panel and if we should jump there
var result = Overlays.findRayIntersection(event.actionRay); var result = Overlays.findRayIntersection(event.actionRay);
if (result.intersects && result.overlayID == panelWall) { if (result.intersects && result.overlayID == panelWall) {
var panelName = result.extraInfo; var panelName = result.extraInfo;
var panelStringIndex = panelName.indexOf("Panel"); var panelStringIndex = panelName.indexOf("Panel");
if (panelStringIndex != -1) { if (panelStringIndex != -1) {
var panelIndex = parseInt(panelName.slice(5)); var panelIndex = parseInt(panelName.slice(5));
var placeIndex = panelIndexToPlaceIndex(panelIndex); var placeIndex = panelIndexToPlaceIndex(panelIndex);
if (placeIndex < places.length) { if (placeIndex < places.length) {
var actionPlace = places[placeIndex]; var actionPlace = places[placeIndex];
print("Jumping to " + actionPlace.name + " at " + actionPlace.address print("Jumping to " + actionPlace.name + " at " + actionPlace.address
+ " after click on panel " + panelIndex + " with place index " + placeIndex); + " after click on panel " + panelIndex + " with place index " + placeIndex);
Window.location = actionPlace.address; Window.location = actionPlace.address;
maybeCleanupLobby(); maybeCleanupLobby();
} }
@ -328,7 +328,7 @@ function handleLookAt(pickRay) {
var placeIndex = panelIndexToPlaceIndex(panelIndex); var placeIndex = panelIndexToPlaceIndex(panelIndex);
if (placeIndex < places.length) { if (placeIndex < places.length) {
var actionPlace = places[placeIndex]; var actionPlace = places[placeIndex];
if (actionPlace.description == "") { if (actionPlace.description == "") {
Overlays.editOverlay(descriptionText, { text: actionPlace.name, visible: showText }); Overlays.editOverlay(descriptionText, { text: actionPlace.name, visible: showText });
} else { } else {
@ -378,7 +378,7 @@ function update(deltaTime) {
Overlays.editOverlay(descriptionText, { position: textOverlayPosition() }); Overlays.editOverlay(descriptionText, { position: textOverlayPosition() });
// if the reticle is up then we may need to play the next muzak // if the reticle is up then we may need to play the next muzak
if (currentMuzakInjector && !currentMuzakInjector.isPlaying) { if (currentMuzakInjector && !currentMuzakInjector.playing) {
playNextMuzak(); playNextMuzak();
} }
} }

View file

@ -2,12 +2,12 @@
// playTestSound.js // playTestSound.js
// examples // examples
// //
// Created by Philip Rosedale // Created by Philip Rosedale
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// Creates an object in front of you that changes color and plays a light // Creates an object in front of you that changes color and plays a light
// at the start of a drum clip that loops. As you move away it will tell you in the // at the start of a drum clip that loops. As you move away it will tell you in the
// log how many meters you are from the source. // log how many meters you are from the source.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -17,7 +17,7 @@ var sound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Dru
var position = Vec3.sum(Vec3.sum(MyAvatar.position, { x: 0, y: 0.5, z: 0 }), Quat.getFront(MyAvatar.orientation)); var position = Vec3.sum(Vec3.sum(MyAvatar.position, { x: 0, y: 0.5, z: 0 }), Quat.getFront(MyAvatar.orientation));
var time; var time;
var soundPlaying = null; var soundPlaying = null;
var baseColor = { red: 100, green: 100, blue: 100 }; var baseColor = { red: 100, green: 100, blue: 100 };
@ -38,8 +38,8 @@ var box = Entities.addEntity({
function checkSound(deltaTime) { function checkSound(deltaTime) {
var started = false; var started = false;
if (!sound.downloaded) { if (!sound.downloaded) {
return; return;
} }
if (soundPlaying == null) { if (soundPlaying == null) {
soundPlaying = Audio.playSound(sound, { soundPlaying = Audio.playSound(sound, {
@ -47,9 +47,9 @@ function checkSound(deltaTime) {
volume: 1.0, volume: 1.0,
loop: false } ); loop: false } );
started = true; started = true;
} else if (!soundPlaying.isPlaying) { } else if (!soundPlaying.playing) {
soundPlaying.restart(); soundPlaying.restart();
started = true; started = true;
} }
if (started) { if (started) {
Entities.editEntity(box, { color: litColor }); Entities.editEntity(box, { color: litColor });
@ -67,19 +67,19 @@ function checkSound(deltaTime) {
lifetime: lightTime / 1000 lifetime: lightTime / 1000
}); });
Script.setTimeout(resetColor, lightTime); Script.setTimeout(resetColor, lightTime);
} }
var currentDistance = Vec3.distance(MyAvatar.position, position); var currentDistance = Vec3.distance(MyAvatar.position, position);
if (Math.abs(currentDistance - distance) > 1.0) { if (Math.abs(currentDistance - distance) > 1.0) {
print("Distance from source: " + currentDistance); print("Distance from source: " + currentDistance);
distance = currentDistance; distance = currentDistance;
} }
} }
function resetColor() { function resetColor() {
Entities.editEntity(box, { color: baseColor }); Entities.editEntity(box, { color: baseColor });
} }
function scriptEnding() { function scriptEnding() {
Entities.deleteEntity(box); Entities.deleteEntity(box);
if (soundPlaying) { if (soundPlaying) {
@ -93,4 +93,3 @@ function scriptEnding() {
// Connect a call back that happens every frame // Connect a call back that happens every frame
Script.scriptEnding.connect(scriptEnding); Script.scriptEnding.connect(scriptEnding);
Script.update.connect(checkSound); Script.update.connect(checkSound);