diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index f8d5ecf28e..25d40ed659 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -320,11 +320,11 @@ void ResourceCache::refreshAll() { QVariantList ResourceCache::getResourceList() { QVariantList list; - if (QThread::currentThread() != thread()) { + /*if (QThread::currentThread() != thread()) { // NOTE: invokeMethod does not allow a const QObject* BLOCKING_INVOKE_METHOD(this, "getResourceList", Q_RETURN_ARG(QVariantList, list)); - } else { + } else {*/ QList resources; { QReadLocker locker(&_resourcesLock); @@ -334,7 +334,7 @@ QVariantList ResourceCache::getResourceList() { for (auto& resource : resources) { list << resource; } - } + /* }*/ return list; } diff --git a/scripts/developer/utilities/cache/cash.js b/scripts/developer/utilities/cache/cash.js index b575b481c7..2181a50c36 100644 --- a/scripts/developer/utilities/cache/cash.js +++ b/scripts/developer/utilities/cache/cash.js @@ -5,25 +5,20 @@ function openView() { //window.closed.connect(function() { Script.stop(); }); - var pages = new Pages(); + var pages = new Pages(); function fromQml(message) { console.log(JSON.stringify(message)) + if (message.method == "inspectResource") { + pages.open("openResourceInspector") + pages.sendTo("openResourceInspector", message) + return; + } if (pages.open(message.method)) { return; } } - var cashWindow function openCashWindow(window) { - if (cashWindow !== undefined) { - activeWindow.fromQml.disconnect(fromQml); - } - if (window !== undefined) { - window.fromQml.connect(fromQml); - } - cashWindow = window; - - var onMousePressEvent = function (e) { }; Controller.mousePressEvent.connect(onMousePressEvent); @@ -38,23 +33,21 @@ function openView() { } function closeCashWindow() { - if (cashWindow !== undefined) { - activeWindow.fromQml.disconnect(fromQml); - } - cashWindow = {}; - Controller.mousePressEvent.disconnect(onMousePressEvent); Controller.mouseReleaseEvent.disconnect(onMouseReleaseEvent); Controller.mouseMoveEvent.disconnect(onMouseMoveEvent); pages.clear(); } + - pages.addPage('Cash', 'Cash', "../cash.qml", 300, 500, openCashWindow, closeCashWindow); - pages.addPage('openModelCacheInspector', 'Model Cache Inspector', "./ModelCacheInspector.qml", 300, 500); - pages.addPage('openMaterialCacheInspector', 'Material Cache Inspector', "./MaterialCacheInspector.qml", 300, 500); - pages.addPage('openTextureCacheInspector', 'Texture Cache Inspector', "./TextureCacheInspector.qml", 300, 500); + pages.addPage('Cash', 'Cash', "../cash.qml", 300, 500, fromQml, openCashWindow, closeCashWindow); + pages.addPage('openModelCacheInspector', 'Model Cache Inspector', "./ModelCacheInspector.qml", 300, 500, fromQml); + pages.addPage('openMaterialCacheInspector', 'Material Cache Inspector', "./MaterialCacheInspector.qml", 300, 500, fromQml); + pages.addPage('openTextureCacheInspector', 'Texture Cache Inspector', "./TextureCacheInspector.qml", 300, 500, fromQml); pages.addPage('openAnimationCacheInspector', 'Animation Cache Inspector', "./AnimationCacheInspector.qml", 300, 500); pages.addPage('openSoundCacheInspector', 'Sound Cache Inspector', "./SoundCacheInspector.qml", 300, 500); + pages.addPage('openResourceInspector', 'Resource Inspector', "./ResourceInspector.qml", 300, 500); + pages.open('Cash'); diff --git a/scripts/developer/utilities/cache/cash/Page.js b/scripts/developer/utilities/cache/cash/Page.js index 06c9704abf..d24af3d1ba 100644 --- a/scripts/developer/utilities/cache/cash/Page.js +++ b/scripts/developer/utilities/cache/cash/Page.js @@ -10,11 +10,12 @@ "use strict"; (function() { -function Page(title, qmlurl, width, height, onViewCreated, onViewClosed) { +function Page(title, qmlurl, width, height, onFromQml, onViewCreated, onViewClosed) { this.title = title; this.qml = qmlurl; this.width = width; this.height = height; + this.onFromQml = onFromQml; this.onViewCreated = onViewCreated; this.onViewClosed = onViewClosed; @@ -30,6 +31,9 @@ Page.prototype.killView = function () { //this.window.closed.disconnect(function () { // this.killView(); //}); + if (this.onFromQml) { + this.window.fromQml.disconnect(this.onFromQml) + } this.window.close(); this.window = false; } @@ -45,6 +49,9 @@ Page.prototype.createView = function () { size: {x: this.width, y: this.height} }); this.onViewCreated(this.window); + if (this.onFromQml) { + this.window.fromQml.connect(this.onFromQml) + } this.window.closed.connect(function () { that.killView(); that.onViewClosed(); @@ -57,7 +64,7 @@ Pages = function () { this._pages = {}; }; -Pages.prototype.addPage = function (command, title, qmlurl, width, height, onViewCreated, onViewClosed) { +Pages.prototype.addPage = function (command, title, qmlurl, width, height, onFromQml, onViewCreated, onViewClosed) { if (onViewCreated === undefined) { // Workaround for bad linter onViewCreated = function(window) {}; @@ -66,7 +73,7 @@ Pages.prototype.addPage = function (command, title, qmlurl, width, height, onVie // Workaround for bad linter onViewClosed = function() {}; } - this._pages[command] = new Page(title, qmlurl, width, height, onViewCreated, onViewClosed); + this._pages[command] = new Page(title, qmlurl, width, height, onFromQml, onViewCreated, onViewClosed); }; Pages.prototype.open = function (command) { @@ -87,4 +94,12 @@ Pages.prototype.clear = function () { this._pages = {}; }; +Pages.prototype.sendTo = function (command, message) { + if (!this._pages[command]) { + print("Pages: unknown command = " + command); + return; + } + this._pages[command].window.sendToQml(message); +}; + }()); diff --git a/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml b/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml index fdf3137caf..733472cb9e 100644 --- a/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml +++ b/scripts/developer/utilities/cache/cash/ResourceCacheInspector.qml @@ -30,6 +30,10 @@ Item { } } + function requestResourceDetails(resourceURL) { + sendToScript({method: "inspectResource", params: {url: resourceURL, semantic: cacheResourceName}}); + } + Component.onCompleted: { resetItemListFromCache(); } @@ -66,7 +70,7 @@ Item { function pullFreshValues() { if (needFreshList) { - console.log("Updating " + cacheResourceName + "cache list") + //console.log("Updating " + cacheResourceName + "cache list") updateItemList(fetchItemsList()) needFreshList = false } @@ -234,12 +238,12 @@ Item { height: item.height onPressed: {held = true} onReleased: {held = false} - + onDoubleClicked: { requestResourceDetails(model.url) } Rectangle { id: item width: parent.width height: global.slimHeight - color: dragArea.held ? global.colorBackHighlight : (model.identifier % 2 ? global.colorBackShadow : global.colorBack) + color: dragArea.held ? global.colorBackHighlight : (index % 2 ? global.colorBackShadow : global.colorBack) Row { id: itemRow anchors.verticalCenter : parent.verticalCenter @@ -324,7 +328,7 @@ Item { ] function refreshFilter() { - console.log("refreshFilter! token = " + textFilter + " field = " + filterField) + //console.log("refreshFilter! token = " + textFilter + " field = " + filterField) acceptItem = acceptItemArray[(textFilter.length != 0) * + (1 + filterField)] } diff --git a/scripts/developer/utilities/cache/cash/ResourceInspector.qml b/scripts/developer/utilities/cache/cash/ResourceInspector.qml new file mode 100644 index 0000000000..099eb735d0 --- /dev/null +++ b/scripts/developer/utilities/cache/cash/ResourceInspector.qml @@ -0,0 +1,58 @@ +// +// ResourceInspector.qml +// +// Created by Sam Gateau on 2019-09-24 +// Copyright 2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.12 +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.3 +import QtQml.Models 2.12 + +import "../../lib/prop" as Prop + +Item { + id: root; + Prop.Global { id: global } + + anchors.fill: parent.fill + property var cache: {} + property string cacheResourceName: "" + + function fromScript(message) { + switch (message.method) { + case "inspectResource": + inspectResource(message.params.url, message.params.semantic) + break; + } + } + + function inspectResource(url, semantic) { + console.log("inspectResource :" + url + " as " + semantic) + info.text = "url: " + url + "\nsemantic: " + semantic + "\n"; + + if (semantic == "Texture") { + var res = TextureCache.prefetch(url, 0) + info.text += JSON.stringify(res); + } else if (semantic == "Model") { + var res = ModelCache.prefetch(url) + info.text += JSON.stringify(res); + } + } + + TextEdit { + id: info + anchors.fill: parent + text: "Click an object to get material JSON" + width: root.width + font.pointSize: 10 + color: "#FFFFFF" + readOnly: true + selectByMouse: true + wrapMode: Text.WordWrap + } +} +