mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-14 11:46:34 +02:00
Merge pull request #7833 from zzmp/fix/scriptable-resource
Fix prefetching
This commit is contained in:
commit
22081a8606
6 changed files with 46 additions and 10 deletions
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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); }
|
||||
}
|
||||
|
|
34
scripts/developer/tests/scriptableResource/loadPerfTest.js
Normal file
34
scripts/developer/tests/scriptableResource/loadPerfTest.js
Normal file
|
@ -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();
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// testMovie.js
|
||||
// movieTest.js
|
||||
// scripts/developer/tests/scriptableResource
|
||||
//
|
||||
// Created by Zach Pomerantz on 4/27/16.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// testPrefetch.js
|
||||
// prefetchTest.js
|
||||
// scripts/developer/tests/scriptableResource
|
||||
//
|
||||
// Created by Zach Pomerantz on 4/27/16.
|
||||
|
|
Loading…
Reference in a new issue