diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index a744236099..d6a2fa7dba 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -138,17 +138,17 @@ void ScriptableResource::setInScript(bool isInScript) { } void ScriptableResource::loadingChanged() { - emit stateChanged(LOADING); + setState(LOADING); } void ScriptableResource::loadedChanged() { - emit stateChanged(LOADED); + setState(LOADED); } void ScriptableResource::finished(bool success) { disconnectHelper(); - emit stateChanged(success ? FINISHED : FAILED); + setState(success ? FINISHED : FAILED); } void ScriptableResource::disconnectHelper() { diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 0f2d191567..64e3f4dc34 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -114,6 +114,9 @@ signals: void progressChanged(uint64_t bytesReceived, uint64_t bytesTotal); void stateChanged(int state); +protected: + void setState(State state) { _state = state; emit stateChanged(_state); } + private slots: void loadingChanged(); void loadedChanged(); diff --git a/scripts/developer/tests/scriptableResource/lib.js b/scripts/developer/tests/scriptableResource/lib.js index 5241d0968e..255b3bd036 100644 --- a/scripts/developer/tests/scriptableResource/lib.js +++ b/scripts/developer/tests/scriptableResource/lib.js @@ -26,8 +26,8 @@ function getFrame(callback) { } function makeFrame(state) { - if (state == Resource.State.FAILED) { throw "Failed to load frame"; } - if (state != Resource.State.FINISHED) { return; } + if (state === Resource.State.FAILED) { throw "Failed to load frame"; } + if (state !== Resource.State.FINISHED) { return; } var pictureFrameProperties = { name: 'scriptableResourceTest Picture Frame', @@ -50,7 +50,6 @@ function getFrame(callback) { position.x += - 5 * Math.sin(rads); position.z += - 5 * Math.cos(rads); - print(JSON.stringify(position)); return position; } } @@ -67,10 +66,10 @@ function prefetch(callback) { var filepath = MOVIE_URL + padded + '.jpg'; var texture = TextureCache.prefetch(filepath); frames.push(texture); - if (!texture.state == Resource.State.FINISHED) { + if (texture.state !== Resource.State.FINISHED) { numLoading++; texture.stateChanged.connect(function(state) { - if (state == Resource.State.FAILED || state == Resource.State.FINISHED) { + if (state === Resource.State.FAILED || state === Resource.State.FINISHED) { --numLoading; if (!numLoading) { callback(frames); } } diff --git a/scripts/developer/tests/scriptableResource/loadPerfTest.js b/scripts/developer/tests/scriptableResource/loadPerfTest.js new file mode 100644 index 0000000000..17feef264d --- /dev/null +++ b/scripts/developer/tests/scriptableResource/loadPerfTest.js @@ -0,0 +1,34 @@ +// +// loadPerfTest.js +// scripts/developer/tests/scriptableResource +// +// Created by Zach Pomerantz on 4/27/16. +// Copyright 2016 High Fidelity, Inc. +// +// Preloads 158 textures 50 times for performance profiling. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var TIMES = 50; + +Script.include([ + '../../../developer/utilities/cache/cacheStats.js', + 'lib.js', +], function() { + var fetch = function() { + prefetch(function(frames) { + while (frames.length) { frames.pop(); } + Script.requestGarbageCollection(); + + if (--TIMES > 0) { + // Pause a bit to avoid a deadlock + var DEADLOCK_AVOIDANCE_TIMEOUT = 100; + Script.setTimeout(fetch, DEADLOCK_AVOIDANCE_TIMEOUT); + } + }); + }; + + fetch(); +}); diff --git a/scripts/developer/tests/scriptableResource/movieTest.js b/scripts/developer/tests/scriptableResource/movieTest.js index 61b2bf7942..557c53af6a 100644 --- a/scripts/developer/tests/scriptableResource/movieTest.js +++ b/scripts/developer/tests/scriptableResource/movieTest.js @@ -1,5 +1,5 @@ // -// testMovie.js +// movieTest.js // scripts/developer/tests/scriptableResource // // Created by Zach Pomerantz on 4/27/16. diff --git a/scripts/developer/tests/scriptableResource/prefetchTest.js b/scripts/developer/tests/scriptableResource/prefetchTest.js index cda805967e..07acb462cb 100644 --- a/scripts/developer/tests/scriptableResource/prefetchTest.js +++ b/scripts/developer/tests/scriptableResource/prefetchTest.js @@ -1,5 +1,5 @@ // -// testPrefetch.js +// prefetchTest.js // scripts/developer/tests/scriptableResource // // Created by Zach Pomerantz on 4/27/16.