mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 23:36:41 +02:00
adjusting for interval and interval spread
This commit is contained in:
parent
a65c869239
commit
609ddda74e
2 changed files with 24 additions and 9 deletions
|
@ -19,7 +19,7 @@ var DEFAULT_SOUND_DATA = {
|
||||||
};
|
};
|
||||||
var MIN_PLAY_INTERVAL = 0.2;
|
var MIN_PLAY_INTERVAL = 0.2;
|
||||||
|
|
||||||
var UPDATE_TIME = 2000;
|
var UPDATE_TIME = 100;
|
||||||
var EXPIRATION_TIME = 7000;
|
var EXPIRATION_TIME = 7000;
|
||||||
|
|
||||||
var soundEntityMap = {};
|
var soundEntityMap = {};
|
||||||
|
@ -27,7 +27,7 @@ var soundUrls = {};
|
||||||
|
|
||||||
print("EBL STARTING SCRIPT");
|
print("EBL STARTING SCRIPT");
|
||||||
|
|
||||||
function slowUpdate() {
|
function update() {
|
||||||
var avatars = AvatarList.getAvatarIdentifiers();
|
var avatars = AvatarList.getAvatarIdentifiers();
|
||||||
for (var i = 0; i < avatars.length; i++) {
|
for (var i = 0; i < avatars.length; i++) {
|
||||||
var avatar = AvatarList.getAvatar(avatars[i]);
|
var avatar = AvatarList.getAvatar(avatars[i]);
|
||||||
|
@ -60,7 +60,7 @@ function handleActiveSoundEntities() {
|
||||||
// An avatar hasn't been within range of this sound entity recently, so remove it from map
|
// An avatar hasn't been within range of this sound entity recently, so remove it from map
|
||||||
soundProperties.soundInjector.stop();
|
soundProperties.soundInjector.stop();
|
||||||
delete soundEntityMap[soundEntity];
|
delete soundEntityMap[soundEntity];
|
||||||
} else if(soundProperties.isDownloaded) {
|
} else if (soundProperties.isDownloaded) {
|
||||||
// If this sound hasn't expired yet, we want to potentially play it!
|
// If this sound hasn't expired yet, we want to potentially play it!
|
||||||
if (soundProperties.readyToPlay) {
|
if (soundProperties.readyToPlay) {
|
||||||
var newPosition = Entities.getEntityProperties(soundEntity, "position").position;
|
var newPosition = Entities.getEntityProperties(soundEntity, "position").position;
|
||||||
|
@ -71,6 +71,7 @@ function handleActiveSoundEntities() {
|
||||||
loop: soundProperties.loop
|
loop: soundProperties.loop
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
print("PLAY!!")
|
||||||
soundProperties.soundInjector.restart();
|
soundProperties.soundInjector.restart();
|
||||||
}
|
}
|
||||||
soundProperties.readyToPlay = false;
|
soundProperties.readyToPlay = false;
|
||||||
|
@ -84,6 +85,7 @@ function handleActiveSoundEntities() {
|
||||||
// Now let's get our new current interval
|
// Now let's get our new current interval
|
||||||
soundProperties.currentInterval = soundProperties.interval + randFloat(-soundProperties.intervalSpread, soundProperties.intervalSpread);
|
soundProperties.currentInterval = soundProperties.interval + randFloat(-soundProperties.intervalSpread, soundProperties.intervalSpread);
|
||||||
soundProperties.currentInterval = Math.max(MIN_PLAY_INTERVAL, soundProperties.currentInterval);
|
soundProperties.currentInterval = Math.max(MIN_PLAY_INTERVAL, soundProperties.currentInterval);
|
||||||
|
print("CURRENT INTERVAL " + soundProperties.currentInterval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,10 +146,23 @@ function handleFoundSoundEntities(entities) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkForSoundPropertyChanges(currentProps, newProps) {
|
function checkForSoundPropertyChanges(currentProps, newProps) {
|
||||||
var needsUpdate = false;
|
var needsNewInjector = false;
|
||||||
|
|
||||||
|
if (currentProps.interval !== newProps.interval && !currentProps.loop) {
|
||||||
|
// interval only applies to non looping sounds
|
||||||
|
currentProps.interval = newProps.interval;
|
||||||
|
currentProps.currentInterval = currentProps.interval + randFloat(-currentProps.intervalSpread, currentProps.intervalSpread);
|
||||||
|
currentProps.currentInterval = Math.max(MIN_PLAY_INTERVAL, currentProps.currentInterval);
|
||||||
|
currentProps.readyToPlay = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentProps.intervalSpread !== currentProps.intervalSpread) {
|
||||||
|
currentProps.currentInterval = currentProps.interval + randFloat(-currentProps.intervalSpread, currentProps.intervalSpread);
|
||||||
|
currentProps.currentInterval = Math.max(MIN_PLAY_INTERVAL, currentProps.currentInterval);
|
||||||
|
}
|
||||||
if (currentProps.volume !== newProps.volume) {
|
if (currentProps.volume !== newProps.volume) {
|
||||||
currentProps.volume = newProps.volume;
|
currentProps.volume = newProps.volume;
|
||||||
needsUpdate = true;
|
needsNewInjector = true;
|
||||||
}
|
}
|
||||||
if (currentProps.url !== newProps.url) {
|
if (currentProps.url !== newProps.url) {
|
||||||
currentProps.url = newProps.url;
|
currentProps.url = newProps.url;
|
||||||
|
@ -162,9 +177,9 @@ function checkForSoundPropertyChanges(currentProps, newProps) {
|
||||||
} else {
|
} else {
|
||||||
currentProps.sound = sound;
|
currentProps.sound = sound;
|
||||||
}
|
}
|
||||||
needsUpdate = true;
|
needsNewInjector = true;
|
||||||
}
|
}
|
||||||
if (needsUpdate) {
|
if (needsNewInjector) {
|
||||||
// If we were looping we need to stop that so new changes are applied
|
// If we were looping we need to stop that so new changes are applied
|
||||||
currentProps.soundInjector.stop();
|
currentProps.soundInjector.stop();
|
||||||
currentProps.soundInjector = null;
|
currentProps.soundInjector = null;
|
||||||
|
@ -173,4 +188,4 @@ function checkForSoundPropertyChanges(currentProps, newProps) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.setInterval(slowUpdate, UPDATE_TIME);
|
Script.setInterval(update, UPDATE_TIME);
|
|
@ -20,7 +20,7 @@ var userData = {
|
||||||
soundKey: {
|
soundKey: {
|
||||||
url: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove2.wav",
|
url: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove2.wav",
|
||||||
volume: 0.3,
|
volume: 0.3,
|
||||||
loop: true,
|
loop: false,
|
||||||
interval: 2000,
|
interval: 2000,
|
||||||
intervalSpread: 1000
|
intervalSpread: 1000
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue