diff --git a/scripts/system/places/places.js b/scripts/system/places/places.js index aeb5aba07f..5aa8d282b1 100644 --- a/scripts/system/places/places.js +++ b/scripts/system/places/places.js @@ -38,8 +38,10 @@ var channel = "com.overte.places"; var portalChannelName = "com.overte.places.portalRezzer"; - var MAX_DISTANCE_TO_CONSIDER_PORTAL = 50.0; //in meters + var MAX_DISTANCE_TO_CONSIDER_PORTAL = 100.0; //in meters var PORTAL_DURATION_MILLISEC = 45000; //45 sec + var rezzerPortalCount = 0; + var MAX_REZZED_PORTAL = 15; var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); @@ -587,37 +589,44 @@ } function generatePortal(position, url, name, placeID) { - var TOLERANCE_FACTOR = 1.1; - if (Vec3.distance(MyAvatar.position, position) < MAX_DISTANCE_TO_CONSIDER_PORTAL) { - var height = MyAvatar.userHeight * MyAvatar.scale * TOLERANCE_FACTOR; - - var portalPosition = Vec3.sum(position, {"x": 0.0, "y": height/2, "z": 0.0}); - var dimensions = {"x": height * 0.618, "y": height, "z": height * 0.618}; - var userdata = { - "url": url, - "name": name, - "placeID": placeID - }; - - var portalID = Entities.addEntity({ - "position": portalPosition, - "dimensions": dimensions, - "type": "Shape", - "shape": "Sphere", - "name": "Portal to " + name, - "canCastShadow": false, - "collisionless": true, - "userData": JSON.stringify(userdata), - "script": ROOT + "portal.js", - "visible": "false", - "grab": { - "grabbable": false - } - }, "local"); - - Script.setTimeout(function () { - Entities.deleteEntity(portalID); - }, PORTAL_DURATION_MILLISEC); + if (rezzerPortalCount <= MAX_REZZED_PORTAL) { + var TOLERANCE_FACTOR = 1.1; + if (Vec3.distance(MyAvatar.position, position) < MAX_DISTANCE_TO_CONSIDER_PORTAL) { + var height = MyAvatar.userHeight * MyAvatar.scale * TOLERANCE_FACTOR; + + var portalPosition = Vec3.sum(position, {"x": 0.0, "y": height/2, "z": 0.0}); + var dimensions = {"x": height * 0.618, "y": height, "z": height * 0.618}; + var userdata = { + "url": url, + "name": name, + "placeID": placeID + }; + + var portalID = Entities.addEntity({ + "position": portalPosition, + "dimensions": dimensions, + "type": "Shape", + "shape": "Sphere", + "name": "Portal to " + name, + "canCastShadow": false, + "collisionless": true, + "userData": JSON.stringify(userdata), + "script": ROOT + "portal.js", + "visible": "false", + "grab": { + "grabbable": false + } + }, "local"); + rezzerPortalCount = rezzerPortalCount + 1; + + Script.setTimeout(function () { + Entities.deleteEntity(portalID); + rezzerPortalCount = rezzerPortalCount - 1; + if (rezzerPortalCount < 0) { + rezzerPortalCount = 0; + } + }, PORTAL_DURATION_MILLISEC); + } } } diff --git a/scripts/system/places/portal.js b/scripts/system/places/portal.js index 2cf4c0bc14..5c16cd93c0 100644 --- a/scripts/system/places/portal.js +++ b/scripts/system/places/portal.js @@ -15,13 +15,17 @@ var portalURL = ""; var portalName = ""; var TP_SOUND = SoundCache.getSound(ROOT + "sounds/teleportSound.mp3"); + var PORTAL_SOUND = SoundCache.getSound(ROOT + "sounds/portalSound.mp3"); + var portalInjector = Uuid.NONE; + var portalPosition; this.preload = function(entityID) { - var properties = Entities.getEntityProperties(entityID, ["userData", "dimensions"]); + var properties = Entities.getEntityProperties(entityID, ["userData", "dimensions", "position"]); var userDataObj = JSON.parse(properties.userData); portalURL = userDataObj.url; portalName = userDataObj.name; + portalPosition = properties.position; var portalColor = getColorFromPlaceID(userDataObj.placeID); @@ -116,6 +120,26 @@ "spinFinish": 0 },"local"); + if (PORTAL_SOUND.downloaded) { + playLoopSound(); + } else { + PORTAL_SOUND.ready.connect(onSoundReady); + } + } + + function onSoundReady() { + PORTAL_SOUND.ready.disconnect(onSoundReady); + playLoopSound(); + } + + function playLoopSound() { + var injectorOptions = { + "position": portalPosition, + "volume": 0.15, + "loop": true, + "localOnly": true + }; + portalInjector = Audio.playSound(PORTAL_SOUND, injectorOptions); } this.enterEntity = function(entityID) { @@ -129,11 +153,16 @@ var timer = Script.setTimeout(function () { Window.location = portalURL; + portalInjector.stop(); Entities.deleteEntity(entityID); }, 1000); - }; + }; + this.unload = function(entityID) { + portalInjector.stop(); + }; + function getColorFromPlaceID(placeID) { var idIntegerConstant = getStringScore(placeID); var hue = (idIntegerConstant%360)/360; diff --git a/scripts/system/places/sounds/portalSound.mp3 b/scripts/system/places/sounds/portalSound.mp3 new file mode 100644 index 0000000000..5e7f5a9bd0 Binary files /dev/null and b/scripts/system/places/sounds/portalSound.mp3 differ