Clean up progress.js

This commit is contained in:
Ryan Huffman 2016-08-02 16:19:38 -07:00
parent 5d50389e29
commit 79a243b171

View file

@ -13,6 +13,11 @@
(function() { (function() {
function debug() {
return;
print.apply(null, arguments);
}
var rawProgress = 100, // % raw value. var rawProgress = 100, // % raw value.
displayProgress = 100, // % smoothed value to display. displayProgress = 100, // % smoothed value to display.
DISPLAY_PROGRESS_MINOR_MAXIMUM = 8, // % displayed progress bar goes up to while 0% raw progress. DISPLAY_PROGRESS_MINOR_MAXIMUM = 8, // % displayed progress bar goes up to while 0% raw progress.
@ -39,7 +44,6 @@
background2D = {}, background2D = {},
bar2D = {}, bar2D = {},
SCALE_2D = 0.35, // Scale the SVGs for 2D display. SCALE_2D = 0.35, // Scale the SVGs for 2D display.
//SCALE_2D = 1.0, // Scale the SVGs for 2D display.
background3D = {}, background3D = {},
bar3D = {}, bar3D = {},
PROGRESS_3D_DIRECTION = 0.0, // Degrees from avatar orientation. PROGRESS_3D_DIRECTION = 0.0, // Degrees from avatar orientation.
@ -96,44 +100,58 @@
}); });
} }
function resetProgress() { function resetProgress() {
wasActive = true; isDownloading = true;
bestRawProgress = 0; bestRawProgress = 0;
rawProgress = 0; rawProgress = 0;
cooldown = 1000; initialDelayCooldown = INITIAL_DELAY_COOLDOWN_TIME;
displayProgress = 0; displayProgress = 0;
} }
Window.domainChanged.connect(function() { Window.domainChanged.connect(function() {
hasShownOnThisDomain = false;
resetProgress(); resetProgress();
}); });
var hasShownOnThisDomain = false; // Max seen since downloads started. This is reset when all downloads have completed.
var maxSeen = 0; var maxSeen = 0;
// Progress is defined as: (pending_downloads + active_downloads) / max_seen
// We keep track of both the current progress (rawProgress) and the
// best progress we've seen (bestRawProgress). As you are downloading, you may
// encounter new assets that require downloads, increasing the number of
// pending downloads and thus decreasing your overall progress.
var bestRawProgress = 0; var bestRawProgress = 0;
var wasActive = false;
var cooldown = 1000; // True if we have known active downloads
var isDownloading = false;
// Entities are streamed to users, so you don't receive them all at once; instead, you
// receive them over a period of time. In many cases we end up in a situation where
//
// The initial delay cooldown keeps us from tracking progress before the allotted time
// has passed.
var INITIAL_DELAY_COOLDOWN_TIME = 1000;
var initialDelayCooldown = 0;
function onDownloadInfoChanged(info) { function onDownloadInfoChanged(info) {
var i; var i;
print("PROGRESS: Download info changed ", info.downloading.length, info.pending, maxSeen); debug("PROGRESS: Download info changed ", info.downloading.length, info.pending, maxSeen);
// Update raw progress value // Update raw progress value
if (info.downloading.length + info.pending === 0) { if (info.downloading.length + info.pending === 0) {
wasActive = false; isDownloading = false;
rawProgress = 100; rawProgress = 100;
bestRawProgress = 100; bestRawProgress = 100;
cooldown = 0; initialDelayCooldown = INITIAL_DELAY_COOLDOWN_TIME;
} else { } else {
var count = info.downloading.length + info.pending; var count = info.downloading.length + info.pending;
if (!wasActive) { if (!isDownloading) {
resetProgress(); resetProgress();
maxSeen = count; maxSeen = count;
} }
if (count > maxSeen) { if (count > maxSeen) {
maxSeen = count; maxSeen = count;
} }
if (cooldown <= 0) { if (initialDelayCooldown <= 0) {
rawProgress = ((maxSeen - count) / maxSeen) * 100; rawProgress = ((maxSeen - count) / maxSeen) * 100;
if (rawProgress > bestRawProgress) { if (rawProgress > bestRawProgress) {
@ -141,7 +159,7 @@
} }
} }
} }
print("PROGRESS:", rawProgress, bestRawProgress, maxSeen); debug("PROGRESS:", rawProgress, bestRawProgress, maxSeen);
} }
function createOverlays() { function createOverlays() {
@ -214,7 +232,7 @@
var worldOverlayOn = false; var worldOverlayOn = false;
var currentOrientation = null; var currentOrientation = null;
function update() { function update() {
cooldown -= 30; initialDelayCooldown -= 30;
var viewport, var viewport,
eyePosition, eyePosition,
avatarOrientation; avatarOrientation;
@ -231,7 +249,6 @@
displayProgress += diff * 0.05; displayProgress += diff * 0.05;
} }
} }
//print('PROGRESS:', displayProgress);
// Update state // Update state
if (!visible) { // Not visible because no recent downloads if (!visible) { // Not visible because no recent downloads
@ -328,16 +345,7 @@
windowHeight = viewport.y; windowHeight = viewport.y;
var yOffset = HMD.active ? -300 : -10; var yOffset = HMD.active ? -300 : -10;
yOffset += yAdjust;
// if (hmdActive) {
// if (true) { //hasShownOnThisDomain) {
// yOffset = -100;
// SCALE_2D = 1.0/3;
// } else {
// yOffset = -300;
// SCALE_2D = 2.0/3;
// }
// }
background2D.width = SCALE_2D * BACKGROUND_WIDTH; background2D.width = SCALE_2D * BACKGROUND_WIDTH;
background2D.height = SCALE_2D * BACKGROUND_HEIGHT; background2D.height = SCALE_2D * BACKGROUND_HEIGHT;
bar2D.width = SCALE_2D * BAR_WIDTH; bar2D.width = SCALE_2D * BAR_WIDTH;
@ -354,9 +362,6 @@
}); });
} }
function setProgressBar(progress) {
}
function setUp() { function setUp() {
background2D.width = SCALE_2D * BACKGROUND_WIDTH; background2D.width = SCALE_2D * BACKGROUND_WIDTH;
background2D.height = SCALE_2D * BACKGROUND_HEIGHT; background2D.height = SCALE_2D * BACKGROUND_HEIGHT;
@ -384,25 +389,9 @@
deleteOverlays(); deleteOverlays();
} }
var yAdjust = 0;
function keyPress(event) {
print("Key event: ", event.text);
if (event.text == '.') {
yAdjust -= 10;
updateProgressBarLocation();
} else if (event.text == ',') {
yAdjust += 10;
updateProgressBarLocation();
} else if (event.text == 'SPACE') {
worldOverlayOn = !worldOverlayOn;
}
}
setUp(); setUp();
GlobalServices.downloadInfoChanged.connect(onDownloadInfoChanged); GlobalServices.downloadInfoChanged.connect(onDownloadInfoChanged);
GlobalServices.updateDownloadInfo(); GlobalServices.updateDownloadInfo();
//Script.update.connect(update);
Script.setInterval(update, 1000/60); Script.setInterval(update, 1000/60);
Script.scriptEnding.connect(tearDown); Script.scriptEnding.connect(tearDown);
Controller.keyPressEvent.connect(keyPress);
}()); }());