Exposing the REsource Caches through a bit of ui, adding MaterialCache to the family

This commit is contained in:
Sam Gateau 2019-09-17 18:06:08 -07:00
parent 3d199ff444
commit c0660329a3
16 changed files with 571 additions and 1 deletions

View file

@ -105,8 +105,8 @@
#include <MessagesClient.h>
#include <hfm/ModelFormatRegistry.h>
#include <model-networking/ModelCacheScriptingInterface.h>
#include <material-networking/MaterialCacheScriptingInterface.h>
#include <material-networking/TextureCacheScriptingInterface.h>
#include <material-networking/MaterialCache.h>
#include <ModelEntityItem.h>
#include <NetworkAccessManager.h>
#include <NetworkingConstants.h>
@ -885,6 +885,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<TextureCache>();
DependencyManager::set<MaterialCache>();
DependencyManager::set<TextureCacheScriptingInterface>();
DependencyManager::set<MaterialCacheScriptingInterface>();
DependencyManager::set<FramebufferCache>();
DependencyManager::set<AnimationCache>();
DependencyManager::set<AnimationCacheScriptingInterface>();
@ -2908,6 +2909,7 @@ Application::~Application() {
DependencyManager::destroy<AnimationCacheScriptingInterface>();
DependencyManager::destroy<AnimationCache>();
DependencyManager::destroy<FramebufferCache>();
DependencyManager::destroy<MaterialCacheScriptingInterface>();
DependencyManager::destroy<MaterialCache>();
DependencyManager::destroy<TextureCacheScriptingInterface>();
DependencyManager::destroy<TextureCache>();
@ -3433,6 +3435,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) {
// Caches
surfaceContext->setContextProperty("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
surfaceContext->setContextProperty("TextureCache", DependencyManager::get<TextureCacheScriptingInterface>().data());
surfaceContext->setContextProperty("MaterialCache", DependencyManager::get<MaterialCacheScriptingInterface>().data());
surfaceContext->setContextProperty("ModelCache", DependencyManager::get<ModelCacheScriptingInterface>().data());
surfaceContext->setContextProperty("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
@ -7563,6 +7566,7 @@ void Application::registerScriptEngineWithApplicationServices(const ScriptEngine
// Caches
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("TextureCache", DependencyManager::get<TextureCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("MaterialCache", DependencyManager::get<MaterialCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("ModelCache", DependencyManager::get<ModelCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());

View file

@ -41,6 +41,7 @@ void ModelEntityWrapper::setModel(const ModelPointer& model) {
if (_model) {
_needsInitialSimulation = true;
}
}
});
}

View file

@ -0,0 +1,17 @@
//
// MaterialCacheScriptingInterface.cpp
// libraries/mmodel-networking/src/model-networking
//
// Created by Sam Gateau on 17 September 2019.
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "MaterialCacheScriptingInterface.h"
MaterialCacheScriptingInterface::MaterialCacheScriptingInterface() :
ScriptableResourceCache::ScriptableResourceCache(DependencyManager::get<MaterialCache>())
{ }

View file

@ -0,0 +1,51 @@
//
// MaterialCacheScriptingInterface.h
// libraries/material-networking/src/material-networking
//
// Created by Sam Gateau on 17 September 2019.
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
#ifndef hifi_MaterialCacheScriptingInterface_h
#define hifi_MaterialCacheScriptingInterface_h
#include <QObject>
#include <ResourceCache.h>
#include "MaterialCache.h"
class MaterialCacheScriptingInterface : public ScriptableResourceCache, public Dependency {
Q_OBJECT
// Properties are copied over from ResourceCache (see ResourceCache.h for reason).
/**jsdoc
* The <code>TextureCache</code> API manages texture cache resources.
*
* @namespace TextureCache
*
* @hifi-interface
* @hifi-client-entity
* @hifi-avatar
*
* @property {number} numTotal - Total number of total resources. <em>Read-only.</em>
* @property {number} numCached - Total number of cached resource. <em>Read-only.</em>
* @property {number} sizeTotal - Size in bytes of all resources. <em>Read-only.</em>
* @property {number} sizeCached - Size in bytes of all cached resources. <em>Read-only.</em>
*
* @borrows ResourceCache.getResourceList as getResourceList
* @borrows ResourceCache.updateTotalSize as updateTotalSize
* @borrows ResourceCache.prefetch as prefetch
* @borrows ResourceCache.dirty as dirty
*/
public:
MaterialCacheScriptingInterface();
};
#endif // hifi_MaterialCacheScriptingInterface_h

View file

@ -0,0 +1,66 @@
"use strict";
var Page = Script.require('./cash/Page.js');
function openView() {
//window.closed.connect(function() { Script.stop(); });
var pages = new Pages();
function fromQml(message) {
console.log(JSON.stringify(message))
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);
var onMouseReleaseEvent = function () {
};
Controller.mouseReleaseEvent.connect(onMouseReleaseEvent);
var onMouseMoveEvent = function (e) {
};
Controller.mouseMoveEvent.connect(onMouseMoveEvent);
}
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, 420, 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('openAnimationCacheInspector', 'Animation Cache Inspector', "./AnimationCacheInspector.qml", 300, 500);
pages.addPage('openSoundCacheInspector', 'Sound Cache Inspector', "./SoundCacheInspector.qml", 300, 500);
pages.open('Cash');
return pages;
}
openView();

View file

@ -0,0 +1,80 @@
//
// cash.qml
//
// Created by Sam Gateau on 17/9/2019
// 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.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import controlsUit 1.0 as HifiControls
import "../lib/prop" as Prop
import "cash"
Rectangle {
anchors.fill: parent
id: root;
Prop.Global { id: global;}
color: global.color
ScrollView {
id: scrollView
anchors.fill: parent
contentWidth: parent.width
clip: true
Column {
id: column
width: parent.width
Prop.PropFolderPanel {
label: "Cache Inspectors"
isUnfold: true
panelFrameData: Component {
Column {
Prop.PropButton {
text: "Model"
onClicked: {
sendToScript({method: "openModelCacheInspector"});
}
width:column.width
}
Prop.PropButton {
text: "Material"
onClicked: {
sendToScript({method: "openMaterialCacheInspector"});
}
width:column.width
}
Prop.PropButton {
text: "Texture"
onClicked: {
sendToScript({method: "openTextureCacheInspector"});
}
width:column.width
}
Prop.PropButton {
text: "Animation"
onClicked: {
sendToScript({method: "openAnimationCacheInspector"});
}
width:column.width
}
Prop.PropButton {
text: "Sound"
onClicked: {
sendToScript({method: "openSoundCacheInspector"});
}
width:column.width
}
}
}
}
}
}
}

View file

@ -0,0 +1,20 @@
//
// AnimationCacheInspector.qml
//
// Created by Sam Gateau on 2019-09-17
// 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.7
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import "../../lib/prop" as Prop
ResourceCacheInspector {
id: root;
anchors.fill: parent.fill
cache: AnimationCache
}

View file

@ -0,0 +1,20 @@
//
// MaterialCacheInspector.qml
//
// Created by Sam Gateau on 2019-09-17
// 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.7
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import "../../lib/prop" as Prop
ResourceCacheInspector {
id: root;
anchors.fill: parent.fill
cache: MaterialCache
}

View file

@ -0,0 +1,20 @@
//
// ModelCacheInspector.qml
//
// Created by Sam Gateau on 2019-09-17
// 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.7
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import "../../lib/prop" as Prop
ResourceCacheInspector {
id: root;
anchors.fill: parent.fill
cache: ModelCache
}

View file

@ -0,0 +1,90 @@
//
// Page.js
//
// Sam Gateau, created on 4/19/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
"use strict";
(function() {
function Page(title, qmlurl, width, height, onViewCreated, onViewClosed) {
this.title = title;
this.qml = qmlurl;
this.width = width;
this.height = height;
this.onViewCreated = onViewCreated;
this.onViewClosed = onViewClosed;
this.window;
print("Page: New Page:" + JSON.stringify(this));
}
Page.prototype.killView = function () {
print("Page: Kill window for page:" + JSON.stringify(this));
if (this.window) {
print("Page: Kill window for page:" + this.title);
//this.window.closed.disconnect(function () {
// this.killView();
//});
this.window.close();
this.window = false;
}
};
Page.prototype.createView = function () {
var that = this;
if (!this.window) {
print("Page: New window for page:" + this.title);
this.window = Desktop.createWindow(Script.resolvePath(this.qml), {
title: this.title,
presentationMode: Desktop.PresentationMode.NATIVE,
size: {x: this.width, y: this.height}
});
this.onViewCreated(this.window);
this.window.closed.connect(function () {
that.killView();
that.onViewClosed();
});
}
};
Pages = function () {
this._pages = {};
};
Pages.prototype.addPage = function (command, title, qmlurl, width, height, onViewCreated, onViewClosed) {
if (onViewCreated === undefined) {
// Workaround for bad linter
onViewCreated = function(window) {};
}
if (onViewClosed === undefined) {
// Workaround for bad linter
onViewClosed = function() {};
}
this._pages[command] = new Page(title, qmlurl, width, height, onViewCreated, onViewClosed);
};
Pages.prototype.open = function (command) {
print("Pages: command = " + command);
if (!this._pages[command]) {
print("Pages: unknown command = " + command);
return;
}
this._pages[command].createView();
};
Pages.prototype.clear = function () {
for (var p in this._pages) {
print("Pages: kill page: " + p);
this._pages[p].killView();
delete this._pages[p];
}
this._pages = {};
};
}());

View file

@ -0,0 +1,122 @@
//
// ResourceCacheInspector.qml
//
// Created by Sam Gateau on 2019-09-17
// 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.7
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import "../../lib/prop" as Prop
Item {
id: root;
anchors.fill: parent.fill
property var cache: {}
function fromScript(message) {
switch (message.method) {
case "setJSON":
// jsonText.items = message.params.items;
break;
case "setItemList":
//console.log(message.params.items)
resouceItemsModel.resetItemList(message.params.items)
break;
case "resetItemList":
resetItemList()
break;
}
}
Component.onCompleted: {
// if (cache !== undefined) {
resetItemList();
// }
}
function resetItemList() {
var theList = cache.getResourceList();
resouceItemsModel.resetItemList(theList)
}
ListModel {
id: resouceItemsModel
function resetItemList(itemList) {
resouceItemsModel.clear()
for (var i in itemList) {
//resouceItemsModel.append({ "name": itemList[i]})
resouceItemsModel.append({ "name": itemList[i].toString()})
}
}
}
Component {
id: resouceItemDelegate
Row {
id: itemRow
Prop.PropLabel {
text: model.name
}
}
}
Item {
id: header
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
Prop.PropButton {
anchors.left: parent.left
id: refresh
text: "Refresh"
onClicked: {
resetItemList()
}
}
Prop.PropScalar {
id: totalCount
anchors.right: parent.right
label: "Count"
sourceValueVar: resouceItemsModel.count
integral: true
readOnly: true
}
Prop.PropScalar {
id: totalCount
anchors.right: parent.right
label: "Count"
sourceValueVar: resouceItemsModel.count
integral: true
readOnly: true
}
height: refresh.height
}
ScrollView {
anchors.top: header.bottom
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
clip: true
ListView {
id: listView
model: resouceItemsModel
delegate: resouceItemDelegate
}
}
}

View file

@ -0,0 +1,20 @@
//
// SoundCacheInspector.qml
//
// Created by Sam Gateau on 2019-09-17
// 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.7
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import "../../lib/prop" as Prop
ResourceCacheInspector {
id: root;
anchors.fill: parent.fill
cache: SoundCache
}

View file

@ -0,0 +1,20 @@
//
// TextureCacheInspector.qml
//
// Created by Sam Gateau on 2019-09-17
// 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.7
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import "../../lib/prop" as Prop
ResourceCacheInspector {
id: root;
anchors.fill: parent.fill
cache: TextureCache
}

View file

@ -0,0 +1,6 @@
ResourceCacheInspector 1.0 ResourceCacheInspector.qml
TextureCacheInspector 1.0 TextureCacheInspector.qml
MaterialCacheInspector 1.0 MaterialCacheInspector.qml
ModelCacheInspector 1.0 ModelCacheInspector.qml
AnimationCacheInspector 1.0 AnimationCacheInspector.qml
SoundCacheInspector 1.0 SoundCacheInspector.qml

View file

@ -3,6 +3,7 @@ Global 1.0 style/Global.qml
PropText 1.0 style/PiText.qml
PropLabel 1.0 style/PiLabel.qml
PropSplitter 1.0 style/PiSplitter.qml
PropButton 1.0 style/PiButton.qml
PropComboBox 1.0 style/PiComboBox.qml
PropCanvasIcon 1.0 style/PiCanvasIcon.qml
PropCheckBox 1.0 style/PiCheckBox.qml

View file

@ -0,0 +1,32 @@
//
// Prop/style/PiButton.qml
//
// Created by Sam Gateau on 17/09/2019
// 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.6
import QtQuick.Controls 2.1
Button {
Global { id: global }
id: control
text: ""
spacing: 0
contentItem: PiText {
text: control.text
horizontalAlignment: Text.AlignHCenter
}
background: Rectangle {
color: control.down ? global.colorBackHighlight : global.colorBackShadow
opacity: enabled ? 1 : 0.3
border.color: control.down ? global.colorBorderHighight : (control.hovered ? global.colorBorderHighight : global.colorBorderLight)
border.width: global.valueBorderWidth
radius: global.valueBorderRadius
}
}