mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:09:24 +02:00
Display some progress while waiting at 0% and limit speed of advance
This commit is contained in:
parent
4cd1d54f15
commit
334f26c84f
1 changed files with 62 additions and 48 deletions
|
@ -13,9 +13,13 @@
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
var progress = 100, // %
|
var rawProgress = 100, // % raw value.
|
||||||
|
displayProgress = 100, // % smoothed value to display.
|
||||||
|
DISPLAY_PROGRESS_MINOR_MAXIMUM = 8, // % displayed progress bar goes up to while 0% raw progress.
|
||||||
|
DISPLAY_PROGRESS_MINOR_INCREMENT = 0.1, // % amount to increment display value each update when 0% raw progress.
|
||||||
|
DISPLAY_PROGRESS_MAJOR_INCREMENT = 5, // % maximum amount to increment display value when >0% raw progress.
|
||||||
alpha = 0.0,
|
alpha = 0.0,
|
||||||
alphaDelta = 0.0, // > 0 if fading in; < 0 if fading out/
|
alphaDelta = 0.0, // > 0 if fading in; < 0 if fading out.
|
||||||
ALPHA_DELTA_IN = 0.15,
|
ALPHA_DELTA_IN = 0.15,
|
||||||
ALPHA_DELTA_OUT = -0.02,
|
ALPHA_DELTA_OUT = -0.02,
|
||||||
fadeTimer = null,
|
fadeTimer = null,
|
||||||
|
@ -90,56 +94,15 @@
|
||||||
function onDownloadInfoChanged(info) {
|
function onDownloadInfoChanged(info) {
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
// Calculate progress
|
// Update raw progress value
|
||||||
if (info.downloading.length + info.pending === 0) {
|
if (info.downloading.length + info.pending === 0) {
|
||||||
progress = 100;
|
rawProgress = 100;
|
||||||
} else {
|
} else {
|
||||||
progress = 0;
|
rawProgress = 0;
|
||||||
for (i = 0; i < info.downloading.length; i += 1) {
|
for (i = 0; i < info.downloading.length; i += 1) {
|
||||||
progress += info.downloading[i];
|
rawProgress += info.downloading[i];
|
||||||
}
|
}
|
||||||
progress = progress / (info.downloading.length + info.pending);
|
rawProgress = rawProgress / (info.downloading.length + info.pending);
|
||||||
}
|
|
||||||
|
|
||||||
// Update state
|
|
||||||
if (!visible) { // Not visible because no recent downloads
|
|
||||||
if (progress < 100) { // Have started downloading so fade in
|
|
||||||
visible = true;
|
|
||||||
alphaDelta = ALPHA_DELTA_IN;
|
|
||||||
fadeTimer = Script.setInterval(fade, FADE_INTERVAL);
|
|
||||||
}
|
|
||||||
} else if (alphaDelta !== 0.0) { // Fading in or out
|
|
||||||
if (alphaDelta > 0) {
|
|
||||||
if (progress === 100) { // Was donloading but now have finished so fade out
|
|
||||||
alphaDelta = ALPHA_DELTA_OUT;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (progress < 100) { // Was finished downloading but have resumed so fade in
|
|
||||||
alphaDelta = ALPHA_DELTA_IN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { // Fully visible because downloading or recently so
|
|
||||||
if (fadeWaitTimer === null) {
|
|
||||||
if (progress === 100) { // Was downloading but have finished so fade out soon
|
|
||||||
fadeWaitTimer = Script.setTimeout(function () {
|
|
||||||
alphaDelta = ALPHA_DELTA_OUT;
|
|
||||||
fadeTimer = Script.setInterval(fade, FADE_INTERVAL);
|
|
||||||
fadeWaitTimer = null;
|
|
||||||
}, FADE_OUT_WAIT);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (progress < 100) { // Was finished and waiting to fade out but have resumed downloading so don't fade out
|
|
||||||
Script.clearInterval(fadeWaitTimer);
|
|
||||||
fadeWaitTimer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update progress bar
|
|
||||||
if (visible) {
|
|
||||||
Overlays.editOverlay(isOnHMD ? bar3D.overlay : bar2D.overlay, {
|
|
||||||
subImage: { x: BAR_WIDTH * (1 - progress / 100), y: 0, width: BAR_WIDTH, height: BAR_HEIGHT }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +164,58 @@
|
||||||
createOverlays();
|
createOverlays();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate progress value to display
|
||||||
|
if (rawProgress === 0 && displayProgress <= DISPLAY_PROGRESS_MINOR_MAXIMUM) {
|
||||||
|
displayProgress = Math.min(displayProgress + DISPLAY_PROGRESS_MINOR_INCREMENT, DISPLAY_PROGRESS_MINOR_MAXIMUM);
|
||||||
|
} else if (rawProgress < displayProgress) {
|
||||||
|
displayProgress = rawProgress;
|
||||||
|
} else if (rawProgress > displayProgress) {
|
||||||
|
displayProgress = Math.min(rawProgress, displayProgress + DISPLAY_PROGRESS_MAJOR_INCREMENT);
|
||||||
|
} // else (rawProgress === displayProgress); do nothing.
|
||||||
|
|
||||||
|
// Update state
|
||||||
|
if (!visible) { // Not visible because no recent downloads
|
||||||
|
if (displayProgress < 100) { // Have started downloading so fade in
|
||||||
|
visible = true;
|
||||||
|
alphaDelta = ALPHA_DELTA_IN;
|
||||||
|
fadeTimer = Script.setInterval(fade, FADE_INTERVAL);
|
||||||
|
}
|
||||||
|
} else if (alphaDelta !== 0.0) { // Fading in or out
|
||||||
|
if (alphaDelta > 0) {
|
||||||
|
if (displayProgress === 100) { // Was downloading but now have finished so fade out
|
||||||
|
alphaDelta = ALPHA_DELTA_OUT;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (displayProgress < 100) { // Was finished downloading but have resumed so fade in
|
||||||
|
alphaDelta = ALPHA_DELTA_IN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { // Fully visible because downloading or recently so
|
||||||
|
if (fadeWaitTimer === null) {
|
||||||
|
if (displayProgress === 100) { // Was downloading but have finished so fade out soon
|
||||||
|
fadeWaitTimer = Script.setTimeout(function () {
|
||||||
|
alphaDelta = ALPHA_DELTA_OUT;
|
||||||
|
fadeTimer = Script.setInterval(fade, FADE_INTERVAL);
|
||||||
|
fadeWaitTimer = null;
|
||||||
|
}, FADE_OUT_WAIT);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (displayProgress < 100) { // Was finished and waiting to fade out but have resumed so don't fade out
|
||||||
|
Script.clearInterval(fadeWaitTimer);
|
||||||
|
fadeWaitTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
|
|
||||||
|
// Update progress bar
|
||||||
|
Overlays.editOverlay(isOnHMD ? bar3D.overlay : bar2D.overlay, {
|
||||||
|
visible: visible,
|
||||||
|
subImage: { x: BAR_WIDTH * (1 - displayProgress / 100), y: 0, width: BAR_WIDTH, height: BAR_HEIGHT }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update position
|
||||||
if (isOnHMD) {
|
if (isOnHMD) {
|
||||||
// Update 3D overlays to maintain positions relative to avatar
|
// Update 3D overlays to maintain positions relative to avatar
|
||||||
eyePosition = MyAvatar.getDefaultEyePosition();
|
eyePosition = MyAvatar.getDefaultEyePosition();
|
||||||
|
|
Loading…
Reference in a new issue