From 4befab11511fcb7b2b8679768459e72128769892 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 28 Oct 2016 11:34:00 +1300 Subject: [PATCH 1/7] JSLint progress bar code --- scripts/system/progress.js | 117 +++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 62 deletions(-) diff --git a/scripts/system/progress.js b/scripts/system/progress.js index d7f6713c69..b93cdb9218 100644 --- a/scripts/system/progress.js +++ b/scripts/system/progress.js @@ -13,18 +13,14 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -(function() { // BEGIN LOCAL_SCOPE +(function () { // BEGIN LOCAL_SCOPE function debug() { - return; - print.apply(null, arguments); + //print.apply(null, arguments); } 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, alphaDelta = 0.0, // > 0 if fading in; < 0 if fading out. ALPHA_DELTA_IN = 0.15, @@ -46,7 +42,28 @@ windowHeight = 0, background2D = {}, bar2D = {}, - SCALE_2D = 0.35; // Scale the SVGs for 2D display. + SCALE_2D = 0.35, // Scale the SVGs for 2D display. + + // Max seen since downloads started. This is reset when all downloads have completed. + 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. + bestRawProgress = 0, + + // True if we have known active downloads + 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. + INITIAL_DELAY_COOLDOWN_TIME = 1000, + initialDelayCooldown = 0; function fade() { @@ -77,35 +94,14 @@ }); } - Window.domainChanged.connect(function() { + Window.domainChanged.connect(function () { isDownloading = false; bestRawProgress = 100; rawProgress = 100; displayProgress = 100; }); - // Max seen since downloads started. This is reset when all downloads have completed. - 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; - - // 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) { - var i; debug("PROGRESS: Download info changed ", info.downloading.length, info.pending, maxSeen); @@ -167,16 +163,36 @@ Overlays.deleteOverlay(bar2D.overlay); } - var b = 0; - var currentOrientation = null; + function updateProgressBarLocation() { + var viewport = Controller.getViewportDimensions(), + yOffset; + windowWidth = viewport.x; + windowHeight = viewport.y; + + yOffset = HMD.active ? BAR_Y_OFFSET_HMD : BAR_Y_OFFSET_2D; + + background2D.width = SCALE_2D * BACKGROUND_WIDTH; + background2D.height = SCALE_2D * BACKGROUND_HEIGHT; + bar2D.width = SCALE_2D * BAR_WIDTH; + bar2D.height = SCALE_2D * BAR_HEIGHT; + + Overlays.editOverlay(background2D.overlay, { + x: windowWidth / 2 - background2D.width / 2, + y: windowHeight - background2D.height - bar2D.height + yOffset + }); + + Overlays.editOverlay(bar2D.overlay, { + x: windowWidth / 2 - bar2D.width / 2, + y: windowHeight - background2D.height - bar2D.height + (background2D.height - bar2D.height) / 2 + yOffset + }); + } + function update() { initialDelayCooldown -= 30; - var viewport, - eyePosition, - avatarOrientation; + var viewport, diff; if (displayProgress < rawProgress) { - var diff = rawProgress - displayProgress; + diff = rawProgress - displayProgress; if (diff < 0.5) { displayProgress = rawProgress; } else { @@ -204,7 +220,7 @@ } else { // Fully visible because downloading or recently so if (fadeWaitTimer === null) { if (rawProgress === 100) { // Was downloading but have finished so fade out soon - fadeWaitTimer = Script.setTimeout(function() { + fadeWaitTimer = Script.setTimeout(function () { alphaDelta = ALPHA_DELTA_OUT; fadeTimer = Script.setInterval(fade, FADE_INTERVAL); fadeWaitTimer = null; @@ -228,11 +244,11 @@ y: 0, width: BAR_WIDTH, height: BAR_HEIGHT - }, + } }); Overlays.editOverlay(background2D.overlay, { - visible: true, + visible: true }); // Update 2D overlays to maintain positions at bottom middle of window @@ -244,29 +260,6 @@ } } - function updateProgressBarLocation() { - var viewport = Controller.getViewportDimensions(); - windowWidth = viewport.x; - windowHeight = viewport.y; - - var yOffset = HMD.active ? BAR_Y_OFFSET_HMD : BAR_Y_OFFSET_2D; - - background2D.width = SCALE_2D * BACKGROUND_WIDTH; - background2D.height = SCALE_2D * BACKGROUND_HEIGHT; - bar2D.width = SCALE_2D * BAR_WIDTH; - bar2D.height = SCALE_2D * BAR_HEIGHT; - - Overlays.editOverlay(background2D.overlay, { - x: windowWidth / 2 - background2D.width / 2, - y: windowHeight - background2D.height - bar2D.height + yOffset - }); - - Overlays.editOverlay(bar2D.overlay, { - x: windowWidth / 2 - bar2D.width / 2, - y: windowHeight - background2D.height - bar2D.height + (background2D.height - bar2D.height) / 2 + yOffset - }); - } - function setUp() { background2D.width = SCALE_2D * BACKGROUND_WIDTH; background2D.height = SCALE_2D * BACKGROUND_HEIGHT; @@ -283,7 +276,7 @@ setUp(); GlobalServices.downloadInfoChanged.connect(onDownloadInfoChanged); GlobalServices.updateDownloadInfo(); - Script.setInterval(update, 1000/60); + Script.setInterval(update, 1000 / 60); Script.scriptEnding.connect(tearDown); }()); // END LOCAL_SCOPE From 082414298796b9f9a996dbc91f98c1fa8ccda747 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 28 Oct 2016 14:12:24 +1300 Subject: [PATCH 2/7] Add "loading" text --- .../assets/images/progress-bar-text.svg | 103 ++++++++++++++++++ scripts/system/progress.js | 75 +++++++++++-- 2 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 scripts/system/assets/images/progress-bar-text.svg diff --git a/scripts/system/assets/images/progress-bar-text.svg b/scripts/system/assets/images/progress-bar-text.svg new file mode 100644 index 0000000000..05ebb3f637 --- /dev/null +++ b/scripts/system/assets/images/progress-bar-text.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/system/progress.js b/scripts/system/progress.js index b93cdb9218..082ede95c4 100644 --- a/scripts/system/progress.js +++ b/scripts/system/progress.js @@ -35,14 +35,22 @@ BAR_Y_OFFSET_2D = -10, // Offset of progress bar while in desktop mode BAR_Y_OFFSET_HMD = -300, // Offset of progress bar while in HMD BAR_URL = Script.resolvePath("assets/images/progress-bar.svg"), + TEXT_HEIGHT = 32, + TEXT_WIDTH = 256, + TEXT_URL = Script.resolvePath("assets/images/progress-bar-text.svg"), BACKGROUND_WIDTH = 520, BACKGROUND_HEIGHT = 50, BACKGROUND_URL = Script.resolvePath("assets/images/progress-bar-background.svg"), windowWidth = 0, windowHeight = 0, - background2D = {}, bar2D = {}, + background2D = {}, + textDesktop = {}, // Separate desktop and HMD overlays because can't change text size after overlay created. + textHMD = {}, SCALE_2D = 0.35, // Scale the SVGs for 2D display. + SCALE_TEXT_DESKTOP = 0.6, + SCALE_TEXT_HMD = 1.0, + isHMD = false, // Max seen since downloads started. This is reset when all downloads have completed. maxSeen = 0, @@ -92,6 +100,14 @@ alpha: alpha, visible: visible }); + Overlays.editOverlay(textDesktop.overlay, { + alpha: alpha, + visible: visible && !isHMD + }); + Overlays.editOverlay(textHMD.overlay, { + alpha: alpha, + visible: visible && isHMD + }); } Window.domainChanged.connect(function () { @@ -156,6 +172,20 @@ visible: false, alpha: 0.0 }); + textDesktop.overlay = Overlays.addOverlay("image", { + imageURL: TEXT_URL, + width: textDesktop.width, + height: textDesktop.height, + visible: false, + alpha: 0.0 + }); + textHMD.overlay = Overlays.addOverlay("image", { + imageURL: TEXT_URL, + width: textHMD.width, + height: textHMD.height, + visible: false, + alpha: 0.0 + }); } function deleteOverlays() { @@ -166,15 +196,11 @@ function updateProgressBarLocation() { var viewport = Controller.getViewportDimensions(), yOffset; + windowWidth = viewport.x; windowHeight = viewport.y; - - yOffset = HMD.active ? BAR_Y_OFFSET_HMD : BAR_Y_OFFSET_2D; - - background2D.width = SCALE_2D * BACKGROUND_WIDTH; - background2D.height = SCALE_2D * BACKGROUND_HEIGHT; - bar2D.width = SCALE_2D * BAR_WIDTH; - bar2D.height = SCALE_2D * BAR_HEIGHT; + isHMD = HMD.active; + yOffset = isHMD ? BAR_Y_OFFSET_HMD : BAR_Y_OFFSET_2D; Overlays.editOverlay(background2D.overlay, { x: windowWidth / 2 - background2D.width / 2, @@ -185,12 +211,23 @@ x: windowWidth / 2 - bar2D.width / 2, y: windowHeight - background2D.height - bar2D.height + (background2D.height - bar2D.height) / 2 + yOffset }); + + Overlays.editOverlay(textDesktop.overlay, { + x: windowWidth / 2 - textDesktop.width / 2, + y: windowHeight - 2 * textDesktop.height + yOffset + }); + + Overlays.editOverlay(textHMD.overlay, { + x: windowWidth / 2 - textHMD.width / 2, + y: windowHeight - 2 * textHMD.height + yOffset + }); } function update() { - initialDelayCooldown -= 30; var viewport, diff; + initialDelayCooldown -= 30; + if (displayProgress < rawProgress) { diff = rawProgress - displayProgress; if (diff < 0.5) { @@ -235,11 +272,13 @@ } if (visible) { - // Update progress bar Overlays.editOverlay(bar2D.overlay, { visible: true, subImage: { + + // $$$$$$$ + x: BAR_WIDTH * (1 - displayProgress / 100), y: 0, width: BAR_WIDTH, @@ -251,20 +290,34 @@ visible: true }); + Overlays.editOverlay(textDesktop.overlay, { + visible: !isHMD + }); + + Overlays.editOverlay(textHMD.overlay, { + visible: isHMD + }); + // Update 2D overlays to maintain positions at bottom middle of window viewport = Controller.getViewportDimensions(); - if (viewport.x !== windowWidth || viewport.y !== windowHeight) { + if (viewport.x !== windowWidth || viewport.y !== windowHeight || isHMD !== HMD.active) { updateProgressBarLocation(); } } } function setUp() { + isHMD = HMD.active; + background2D.width = SCALE_2D * BACKGROUND_WIDTH; background2D.height = SCALE_2D * BACKGROUND_HEIGHT; bar2D.width = SCALE_2D * BAR_WIDTH; bar2D.height = SCALE_2D * BAR_HEIGHT; + textDesktop.width = SCALE_TEXT_DESKTOP * TEXT_WIDTH; + textDesktop.height = SCALE_TEXT_DESKTOP * TEXT_HEIGHT; + textHMD.width = SCALE_TEXT_HMD * TEXT_WIDTH; + textHMD.height = SCALE_TEXT_HMD * TEXT_HEIGHT; createOverlays(); } From c9e4fddeabe234973135d97cd8e2c31f96ed260c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 28 Oct 2016 14:17:18 +1300 Subject: [PATCH 3/7] Remove background image --- .../assets/images/progress-bar-background.svg | 5 --- scripts/system/progress.js | 34 ++----------------- 2 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 scripts/system/assets/images/progress-bar-background.svg diff --git a/scripts/system/assets/images/progress-bar-background.svg b/scripts/system/assets/images/progress-bar-background.svg deleted file mode 100644 index a8b4e1aab5..0000000000 --- a/scripts/system/assets/images/progress-bar-background.svg +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/scripts/system/progress.js b/scripts/system/progress.js index 082ede95c4..11aabcfc22 100644 --- a/scripts/system/progress.js +++ b/scripts/system/progress.js @@ -38,13 +38,9 @@ TEXT_HEIGHT = 32, TEXT_WIDTH = 256, TEXT_URL = Script.resolvePath("assets/images/progress-bar-text.svg"), - BACKGROUND_WIDTH = 520, - BACKGROUND_HEIGHT = 50, - BACKGROUND_URL = Script.resolvePath("assets/images/progress-bar-background.svg"), windowWidth = 0, windowHeight = 0, bar2D = {}, - background2D = {}, textDesktop = {}, // Separate desktop and HMD overlays because can't change text size after overlay created. textHMD = {}, SCALE_2D = 0.35, // Scale the SVGs for 2D display. @@ -92,10 +88,6 @@ visible = false; } - Overlays.editOverlay(background2D.overlay, { - alpha: alpha, - visible: visible - }); Overlays.editOverlay(bar2D.overlay, { alpha: alpha, visible: visible @@ -152,13 +144,6 @@ } function createOverlays() { - background2D.overlay = Overlays.addOverlay("image", { - imageURL: BACKGROUND_URL, - width: background2D.width, - height: background2D.height, - visible: false, - alpha: 0.0 - }); bar2D.overlay = Overlays.addOverlay("image", { imageURL: BAR_URL, subImage: { @@ -189,8 +174,9 @@ } function deleteOverlays() { - Overlays.deleteOverlay(background2D.overlay); Overlays.deleteOverlay(bar2D.overlay); + Overlays.deleteOverlay(textDesktop.overlay); + Overlays.deleteOverlay(textHMD.overlay); } function updateProgressBarLocation() { @@ -202,14 +188,9 @@ isHMD = HMD.active; yOffset = isHMD ? BAR_Y_OFFSET_HMD : BAR_Y_OFFSET_2D; - Overlays.editOverlay(background2D.overlay, { - x: windowWidth / 2 - background2D.width / 2, - y: windowHeight - background2D.height - bar2D.height + yOffset - }); - Overlays.editOverlay(bar2D.overlay, { x: windowWidth / 2 - bar2D.width / 2, - y: windowHeight - background2D.height - bar2D.height + (background2D.height - bar2D.height) / 2 + yOffset + y: windowHeight - 2 * bar2D.height + yOffset }); Overlays.editOverlay(textDesktop.overlay, { @@ -276,9 +257,6 @@ Overlays.editOverlay(bar2D.overlay, { visible: true, subImage: { - - // $$$$$$$ - x: BAR_WIDTH * (1 - displayProgress / 100), y: 0, width: BAR_WIDTH, @@ -286,10 +264,6 @@ } }); - Overlays.editOverlay(background2D.overlay, { - visible: true - }); - Overlays.editOverlay(textDesktop.overlay, { visible: !isHMD }); @@ -310,8 +284,6 @@ function setUp() { isHMD = HMD.active; - background2D.width = SCALE_2D * BACKGROUND_WIDTH; - background2D.height = SCALE_2D * BACKGROUND_HEIGHT; bar2D.width = SCALE_2D * BAR_WIDTH; bar2D.height = SCALE_2D * BAR_HEIGHT; textDesktop.width = SCALE_TEXT_DESKTOP * TEXT_WIDTH; From edc9b1fa074a8f3fdc9e6aa18f449c7c77310dbe Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 28 Oct 2016 15:50:50 +1300 Subject: [PATCH 4/7] Update bar graph for desktop and HMD displays --- .../system/assets/images/progress-bar-2k.svg | 26 ++++ .../system/assets/images/progress-bar-hmd.svg | 26 ++++ scripts/system/assets/images/progress-bar.svg | 12 -- scripts/system/progress.js | 123 +++++++++++++----- 4 files changed, 139 insertions(+), 48 deletions(-) create mode 100644 scripts/system/assets/images/progress-bar-2k.svg create mode 100644 scripts/system/assets/images/progress-bar-hmd.svg delete mode 100644 scripts/system/assets/images/progress-bar.svg diff --git a/scripts/system/assets/images/progress-bar-2k.svg b/scripts/system/assets/images/progress-bar-2k.svg new file mode 100644 index 0000000000..45758c7c68 --- /dev/null +++ b/scripts/system/assets/images/progress-bar-2k.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/system/assets/images/progress-bar-hmd.svg b/scripts/system/assets/images/progress-bar-hmd.svg new file mode 100644 index 0000000000..a6b555691f --- /dev/null +++ b/scripts/system/assets/images/progress-bar-hmd.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/system/assets/images/progress-bar.svg b/scripts/system/assets/images/progress-bar.svg deleted file mode 100644 index e24a2cbff4..0000000000 --- a/scripts/system/assets/images/progress-bar.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - diff --git a/scripts/system/progress.js b/scripts/system/progress.js index 11aabcfc22..34dbdea7da 100644 --- a/scripts/system/progress.js +++ b/scripts/system/progress.js @@ -30,20 +30,29 @@ fadeWaitTimer = null, FADE_OUT_WAIT = 1000, // Wait before starting to fade out after progress 100%. visible = false, - BAR_WIDTH = 480, // Dimension of SVG in pixels of visible portion (half) of the bar. - BAR_HEIGHT = 10, + + BAR_DESKTOP_WIDTH = 2240, // Width of SVG image in pixels. Sized for 1920 x 1080 display with 6 visible repeats. + BAR_DESKTOP_REPEAT = 320, // Length of repeat in bar = 2240 / 7. + BAR_DESKTOP_HEIGHT = 3, // Display height of SVG + BAR_DESKTOP_URL = Script.resolvePath("assets/images/progress-bar-2k.svg"), + + BAR_HMD_WIDTH = 4430, // Width of SVG image in pixels. Sized for Rift with 6 visible repeats. + BAR_HMD_REPEAT = 585, // Length of repeat in bar = 4430 / 7. + BAR_HMD_HEIGHT = 4, // Display height of SVG + BAR_HMD_URL = Script.resolvePath("assets/images/progress-bar-hmd.svg"), + BAR_Y_OFFSET_2D = -10, // Offset of progress bar while in desktop mode BAR_Y_OFFSET_HMD = -300, // Offset of progress bar while in HMD - BAR_URL = Script.resolvePath("assets/images/progress-bar.svg"), + TEXT_HEIGHT = 32, TEXT_WIDTH = 256, TEXT_URL = Script.resolvePath("assets/images/progress-bar-text.svg"), windowWidth = 0, windowHeight = 0, - bar2D = {}, + barDesktop = {}, + barHMD = {}, textDesktop = {}, // Separate desktop and HMD overlays because can't change text size after overlay created. textHMD = {}, - SCALE_2D = 0.35, // Scale the SVGs for 2D display. SCALE_TEXT_DESKTOP = 0.6, SCALE_TEXT_HMD = 1.0, isHMD = false, @@ -88,9 +97,13 @@ visible = false; } - Overlays.editOverlay(bar2D.overlay, { + Overlays.editOverlay(barDesktop.overlay, { alpha: alpha, - visible: visible + visible: visible && !isHMD + }); + Overlays.editOverlay(barHMD.overlay, { + alpha: alpha, + visible: visible && isHMD }); Overlays.editOverlay(textDesktop.overlay, { alpha: alpha, @@ -144,16 +157,29 @@ } function createOverlays() { - bar2D.overlay = Overlays.addOverlay("image", { - imageURL: BAR_URL, + barDesktop.overlay = Overlays.addOverlay("image", { + imageURL: BAR_DESKTOP_URL, subImage: { x: 0, y: 0, - width: BAR_WIDTH, - height: BAR_HEIGHT + width: BAR_DESKTOP_WIDTH - BAR_DESKTOP_REPEAT, + height: BAR_DESKTOP_HEIGHT }, - width: bar2D.width, - height: bar2D.height, + width: barDesktop.width, + height: barDesktop.height, + visible: false, + alpha: 0.0 + }); + barHMD.overlay = Overlays.addOverlay("image", { + imageURL: BAR_HMD_URL, + subImage: { + x: 0, + y: 0, + width: BAR_HMD_WIDTH - BAR_HMD_REPEAT, + height: BAR_HMD_HEIGHT + }, + width: barHMD.width, + height: barHMD.height, visible: false, alpha: 0.0 }); @@ -174,34 +200,46 @@ } function deleteOverlays() { - Overlays.deleteOverlay(bar2D.overlay); + Overlays.deleteOverlay(barDesktop.overlay); + Overlays.deleteOverlay(barHMD.overlay); Overlays.deleteOverlay(textDesktop.overlay); Overlays.deleteOverlay(textHMD.overlay); } function updateProgressBarLocation() { - var viewport = Controller.getViewportDimensions(), - yOffset; + var viewport = Controller.getViewportDimensions(); windowWidth = viewport.x; windowHeight = viewport.y; isHMD = HMD.active; - yOffset = isHMD ? BAR_Y_OFFSET_HMD : BAR_Y_OFFSET_2D; - Overlays.editOverlay(bar2D.overlay, { - x: windowWidth / 2 - bar2D.width / 2, - y: windowHeight - 2 * bar2D.height + yOffset - }); + if (isHMD) { + barHMD.width = windowWidth; - Overlays.editOverlay(textDesktop.overlay, { - x: windowWidth / 2 - textDesktop.width / 2, - y: windowHeight - 2 * textDesktop.height + yOffset - }); + Overlays.editOverlay(barHMD.overlay, { + x: windowWidth / 2 - barHMD.width / 2, + y: windowHeight - 2 * barHMD.height + BAR_Y_OFFSET_HMD, + width: barHMD.width + }); - Overlays.editOverlay(textHMD.overlay, { - x: windowWidth / 2 - textHMD.width / 2, - y: windowHeight - 2 * textHMD.height + yOffset - }); + Overlays.editOverlay(textHMD.overlay, { + x: windowWidth / 2 - textHMD.width / 2, + y: windowHeight - 2 * textHMD.height + BAR_Y_OFFSET_HMD + }); + } else { + barDesktop.width = windowWidth; + + Overlays.editOverlay(barDesktop.overlay, { + x: windowWidth / 2 - barDesktop.width / 2, + y: windowHeight - 2 * barDesktop.height + BAR_Y_OFFSET_2D, + width: barDesktop.width + }); + + Overlays.editOverlay(textDesktop.overlay, { + x: windowWidth / 2 - textDesktop.width / 2, + y: windowHeight - 2 * textDesktop.height + BAR_Y_OFFSET_2D + }); + } } function update() { @@ -254,13 +292,23 @@ if (visible) { // Update progress bar - Overlays.editOverlay(bar2D.overlay, { - visible: true, + Overlays.editOverlay(barDesktop.overlay, { + visible: !isHMD, subImage: { - x: BAR_WIDTH * (1 - displayProgress / 100), + x: BAR_DESKTOP_REPEAT * (1 - displayProgress / 100), y: 0, - width: BAR_WIDTH, - height: BAR_HEIGHT + width: BAR_DESKTOP_WIDTH - BAR_DESKTOP_REPEAT, + height: BAR_DESKTOP_HEIGHT + } + }); + + Overlays.editOverlay(barHMD.overlay, { + visible: isHMD, + subImage: { + x: BAR_HMD_REPEAT * (1 - displayProgress / 100), + y: 0, + width: BAR_HMD_WIDTH - BAR_HMD_REPEAT, + height: BAR_HMD_HEIGHT } }); @@ -284,8 +332,11 @@ function setUp() { isHMD = HMD.active; - bar2D.width = SCALE_2D * BAR_WIDTH; - bar2D.height = SCALE_2D * BAR_HEIGHT; + barDesktop.width = BAR_DESKTOP_WIDTH; + barDesktop.height = BAR_DESKTOP_HEIGHT; + barHMD.width = BAR_HMD_WIDTH; + barHMD.height = BAR_HMD_HEIGHT; + textDesktop.width = SCALE_TEXT_DESKTOP * TEXT_WIDTH; textDesktop.height = SCALE_TEXT_DESKTOP * TEXT_HEIGHT; textHMD.width = SCALE_TEXT_HMD * TEXT_WIDTH; From 73b2bc433dcaaf745d18846f8033628d6dbd85c8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 28 Oct 2016 18:03:13 +1300 Subject: [PATCH 5/7] Improve bar positions --- .../system/assets/images/progress-bar-hmd.svg | 26 ------------------- scripts/system/progress.js | 24 ++++++++--------- 2 files changed, 11 insertions(+), 39 deletions(-) delete mode 100644 scripts/system/assets/images/progress-bar-hmd.svg diff --git a/scripts/system/assets/images/progress-bar-hmd.svg b/scripts/system/assets/images/progress-bar-hmd.svg deleted file mode 100644 index a6b555691f..0000000000 --- a/scripts/system/assets/images/progress-bar-hmd.svg +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/scripts/system/progress.js b/scripts/system/progress.js index 34dbdea7da..20023b0352 100644 --- a/scripts/system/progress.js +++ b/scripts/system/progress.js @@ -36,13 +36,13 @@ BAR_DESKTOP_HEIGHT = 3, // Display height of SVG BAR_DESKTOP_URL = Script.resolvePath("assets/images/progress-bar-2k.svg"), - BAR_HMD_WIDTH = 4430, // Width of SVG image in pixels. Sized for Rift with 6 visible repeats. - BAR_HMD_REPEAT = 585, // Length of repeat in bar = 4430 / 7. - BAR_HMD_HEIGHT = 4, // Display height of SVG - BAR_HMD_URL = Script.resolvePath("assets/images/progress-bar-hmd.svg"), + BAR_HMD_WIDTH = 2240, // Desktop image works with HMD well. + BAR_HMD_REPEAT = 320, + BAR_HMD_HEIGHT = 3, + BAR_HMD_URL = Script.resolvePath("assets/images/progress-bar-2k.svg"), - BAR_Y_OFFSET_2D = -10, // Offset of progress bar while in desktop mode - BAR_Y_OFFSET_HMD = -300, // Offset of progress bar while in HMD + BAR_Y_OFFSET_DESKTOP = 0, // Offset of progress bar while in desktop mode + BAR_Y_OFFSET_HMD = -100, // Offset of progress bar while in HMD TEXT_HEIGHT = 32, TEXT_WIDTH = 256, @@ -214,30 +214,28 @@ isHMD = HMD.active; if (isHMD) { - barHMD.width = windowWidth; Overlays.editOverlay(barHMD.overlay, { x: windowWidth / 2 - barHMD.width / 2, - y: windowHeight - 2 * barHMD.height + BAR_Y_OFFSET_HMD, - width: barHMD.width + y: windowHeight - 2 * barHMD.height + BAR_Y_OFFSET_HMD }); Overlays.editOverlay(textHMD.overlay, { x: windowWidth / 2 - textHMD.width / 2, - y: windowHeight - 2 * textHMD.height + BAR_Y_OFFSET_HMD + y: windowHeight - 2 * barHMD.height - textHMD.height + BAR_Y_OFFSET_HMD }); + } else { - barDesktop.width = windowWidth; Overlays.editOverlay(barDesktop.overlay, { x: windowWidth / 2 - barDesktop.width / 2, - y: windowHeight - 2 * barDesktop.height + BAR_Y_OFFSET_2D, + y: windowHeight - 2 * barDesktop.height + BAR_Y_OFFSET_DESKTOP, width: barDesktop.width }); Overlays.editOverlay(textDesktop.overlay, { x: windowWidth / 2 - textDesktop.width / 2, - y: windowHeight - 2 * textDesktop.height + BAR_Y_OFFSET_2D + y: windowHeight - 2 * barDesktop.height - textDesktop.height + BAR_Y_OFFSET_DESKTOP }); } } From 610159fcbe44c0079d262ab2999a6de758fb27e8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 28 Oct 2016 18:20:33 +1300 Subject: [PATCH 6/7] Improve bar for 4K displays --- .../system/assets/images/progress-bar-4k.svg | 26 +++++++++++++++ scripts/system/progress.js | 33 ++++++++++++------- 2 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 scripts/system/assets/images/progress-bar-4k.svg diff --git a/scripts/system/assets/images/progress-bar-4k.svg b/scripts/system/assets/images/progress-bar-4k.svg new file mode 100644 index 0000000000..609ab9610b --- /dev/null +++ b/scripts/system/assets/images/progress-bar-4k.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/system/progress.js b/scripts/system/progress.js index 20023b0352..89f64639e7 100644 --- a/scripts/system/progress.js +++ b/scripts/system/progress.js @@ -31,10 +31,15 @@ FADE_OUT_WAIT = 1000, // Wait before starting to fade out after progress 100%. visible = false, - BAR_DESKTOP_WIDTH = 2240, // Width of SVG image in pixels. Sized for 1920 x 1080 display with 6 visible repeats. - BAR_DESKTOP_REPEAT = 320, // Length of repeat in bar = 2240 / 7. - BAR_DESKTOP_HEIGHT = 3, // Display height of SVG - BAR_DESKTOP_URL = Script.resolvePath("assets/images/progress-bar-2k.svg"), + BAR_DESKTOP_2K_WIDTH = 2240, // Width of SVG image in pixels. Sized for 1920 x 1080 display with 6 visible repeats. + BAR_DESKTOP_2K_REPEAT = 320, // Length of repeat in bar = 2240 / 7. + BAR_DESKTOP_2K_HEIGHT = 3, // Display height of SVG + BAR_DESKTOP_2K_URL = Script.resolvePath("assets/images/progress-bar-2k.svg"), + + BAR_DESKTOP_4K_WIDTH = 4480, // Width of SVG image in pixels. Sized for 1920 x 1080 display with 6 visible repeats. + BAR_DESKTOP_4K_REPEAT = 640, // Length of repeat in bar = 2240 / 7. + BAR_DESKTOP_4K_HEIGHT = 6, // Display height of SVG + BAR_DESKTOP_4K_URL = Script.resolvePath("assets/images/progress-bar-4k.svg"), BAR_HMD_WIDTH = 2240, // Desktop image works with HMD well. BAR_HMD_REPEAT = 320, @@ -158,12 +163,12 @@ function createOverlays() { barDesktop.overlay = Overlays.addOverlay("image", { - imageURL: BAR_DESKTOP_URL, + imageURL: barDesktop.url, subImage: { x: 0, y: 0, - width: BAR_DESKTOP_WIDTH - BAR_DESKTOP_REPEAT, - height: BAR_DESKTOP_HEIGHT + width: barDesktop.width - barDesktop.repeat, + height: barDesktop.height }, width: barDesktop.width, height: barDesktop.height, @@ -293,10 +298,10 @@ Overlays.editOverlay(barDesktop.overlay, { visible: !isHMD, subImage: { - x: BAR_DESKTOP_REPEAT * (1 - displayProgress / 100), + x: barDesktop.repeat * (1 - displayProgress / 100), y: 0, - width: BAR_DESKTOP_WIDTH - BAR_DESKTOP_REPEAT, - height: BAR_DESKTOP_HEIGHT + width: barDesktop.width - barDesktop.repeat, + height: barDesktop.height } }); @@ -328,10 +333,14 @@ } function setUp() { + var is4k = Window.innerWidth > 3000; + isHMD = HMD.active; - barDesktop.width = BAR_DESKTOP_WIDTH; - barDesktop.height = BAR_DESKTOP_HEIGHT; + barDesktop.width = is4k ? BAR_DESKTOP_4K_WIDTH : BAR_DESKTOP_2K_WIDTH; + barDesktop.height = is4k ? BAR_DESKTOP_4K_HEIGHT : BAR_DESKTOP_2K_HEIGHT; + barDesktop.repeat = is4k ? BAR_DESKTOP_4K_REPEAT : BAR_DESKTOP_2K_REPEAT; + barDesktop.url = is4k ? BAR_DESKTOP_4K_URL : BAR_DESKTOP_2K_URL; barHMD.width = BAR_HMD_WIDTH; barHMD.height = BAR_HMD_HEIGHT; From b548e6441c5a15961bdb14628e35de049e51986c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 28 Oct 2016 18:57:54 +1300 Subject: [PATCH 7/7] Animate progress bar without regard for amount of content left to load --- scripts/system/progress.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/system/progress.js b/scripts/system/progress.js index 89f64639e7..c0b7143a11 100644 --- a/scripts/system/progress.js +++ b/scripts/system/progress.js @@ -49,6 +49,8 @@ BAR_Y_OFFSET_DESKTOP = 0, // Offset of progress bar while in desktop mode BAR_Y_OFFSET_HMD = -100, // Offset of progress bar while in HMD + ANIMATION_SECONDS_PER_REPEAT = 4, // Speed of bar animation + TEXT_HEIGHT = 32, TEXT_WIDTH = 256, TEXT_URL = Script.resolvePath("assets/images/progress-bar-text.svg"), @@ -246,7 +248,7 @@ } function update() { - var viewport, diff; + var viewport, diff, x; initialDelayCooldown -= 30; @@ -294,11 +296,18 @@ } if (visible) { + x = ((Date.now() / 1000) % ANIMATION_SECONDS_PER_REPEAT) / ANIMATION_SECONDS_PER_REPEAT; + if (isHMD) { + x = x * barDesktop.repeat; + } else { + x = x * BAR_HMD_REPEAT; + } + // Update progress bar Overlays.editOverlay(barDesktop.overlay, { visible: !isHMD, subImage: { - x: barDesktop.repeat * (1 - displayProgress / 100), + x: barDesktop.repeat - x, y: 0, width: barDesktop.width - barDesktop.repeat, height: barDesktop.height @@ -308,7 +317,7 @@ Overlays.editOverlay(barHMD.overlay, { visible: isHMD, subImage: { - x: BAR_HMD_REPEAT * (1 - displayProgress / 100), + x: BAR_HMD_REPEAT - x, y: 0, width: BAR_HMD_WIDTH - BAR_HMD_REPEAT, height: BAR_HMD_HEIGHT @@ -337,11 +346,11 @@ isHMD = HMD.active; - barDesktop.width = is4k ? BAR_DESKTOP_4K_WIDTH : BAR_DESKTOP_2K_WIDTH; + barDesktop.width = is4k ? BAR_DESKTOP_4K_WIDTH - BAR_DESKTOP_4K_REPEAT : BAR_DESKTOP_2K_WIDTH - BAR_DESKTOP_2K_REPEAT; barDesktop.height = is4k ? BAR_DESKTOP_4K_HEIGHT : BAR_DESKTOP_2K_HEIGHT; barDesktop.repeat = is4k ? BAR_DESKTOP_4K_REPEAT : BAR_DESKTOP_2K_REPEAT; barDesktop.url = is4k ? BAR_DESKTOP_4K_URL : BAR_DESKTOP_2K_URL; - barHMD.width = BAR_HMD_WIDTH; + barHMD.width = BAR_HMD_WIDTH - BAR_HMD_REPEAT; barHMD.height = BAR_HMD_HEIGHT; textDesktop.width = SCALE_TEXT_DESKTOP * TEXT_WIDTH;