mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 15:47:02 +02:00
Decrease CPU usage in tabletUI periodical updates
This commit is contained in:
parent
7cb2bff4c5
commit
ba5a371da1
3 changed files with 34 additions and 41 deletions
|
@ -5435,7 +5435,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
scriptEngine->registerGlobalObject("Test", TestScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("Test", TestScriptingInterface::getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptEngine->registerGlobalObject("Overlays", &_overlays);
|
|
||||||
scriptEngine->registerGlobalObject("Rates", new RatesScriptingInterface(this));
|
scriptEngine->registerGlobalObject("Rates", new RatesScriptingInterface(this));
|
||||||
|
|
||||||
// hook our avatar and avatar hash map object into this script engine
|
// hook our avatar and avatar hash map object into this script engine
|
||||||
|
@ -5534,6 +5533,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
|
|
||||||
auto entityScriptServerLog = DependencyManager::get<EntityScriptServerLogClient>();
|
auto entityScriptServerLog = DependencyManager::get<EntityScriptServerLogClient>();
|
||||||
scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data());
|
scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data());
|
||||||
|
scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance());
|
||||||
|
|
||||||
|
|
||||||
qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue);
|
qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue);
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class AvatarInputs : public QQuickItem {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static AvatarInputs* getInstance();
|
static AvatarInputs* getInstance();
|
||||||
float loudnessToAudioLevel(float loudness);
|
Q_INVOKABLE float loudnessToAudioLevel(float loudness);
|
||||||
AvatarInputs(QQuickItem* parent = nullptr);
|
AvatarInputs(QQuickItem* parent = nullptr);
|
||||||
void update();
|
void update();
|
||||||
bool showAudioTools() const { return _showAudioTools; }
|
bool showAudioTools() const { return _showAudioTools; }
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
/* global Script, HMD, WebTablet, UIWebTablet, UserActivityLogger, Settings, Entities, Messages, Tablet, Overlays,
|
/* global Script, HMD, WebTablet, UIWebTablet, UserActivityLogger, Settings, Entities, Messages, Tablet, Overlays,
|
||||||
MyAvatar, Menu */
|
MyAvatar, Menu, AvatarInputs */
|
||||||
|
|
||||||
(function() { // BEGIN LOCAL_SCOPE
|
(function() { // BEGIN LOCAL_SCOPE
|
||||||
var tabletRezzed = false;
|
var tabletRezzed = false;
|
||||||
|
@ -25,6 +25,9 @@
|
||||||
var debugTablet = false;
|
var debugTablet = false;
|
||||||
var tabletScalePercentage = 100.0;
|
var tabletScalePercentage = 100.0;
|
||||||
UIWebTablet = null;
|
UIWebTablet = null;
|
||||||
|
var MSECS_PER_SEC = 1000.0;
|
||||||
|
var MUTE_MICROPHONE_MENU_ITEM = "Mute Microphone";
|
||||||
|
var gTablet = null;
|
||||||
|
|
||||||
Script.include("../libraries/WebTablet.js");
|
Script.include("../libraries/WebTablet.js");
|
||||||
|
|
||||||
|
@ -49,7 +52,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTabletScalePercentageFromSettings() {
|
function getTabletScalePercentageFromSettings() {
|
||||||
var toolbarMode = Tablet.getTablet("com.highfidelity.interface.tablet.system").toolbarMode;
|
var toolbarMode = gTablet.toolbarMode;
|
||||||
var tabletScalePercentage = DEFAULT_TABLET_SCALE;
|
var tabletScalePercentage = DEFAULT_TABLET_SCALE;
|
||||||
if (!toolbarMode) {
|
if (!toolbarMode) {
|
||||||
if (HMD.active) {
|
if (HMD.active) {
|
||||||
|
@ -77,6 +80,9 @@
|
||||||
if (debugTablet) {
|
if (debugTablet) {
|
||||||
print("TABLET rezzing");
|
print("TABLET rezzing");
|
||||||
}
|
}
|
||||||
|
if (gTablet === null) {
|
||||||
|
gTablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
}
|
||||||
|
|
||||||
tabletScalePercentage = getTabletScalePercentageFromSettings();
|
tabletScalePercentage = getTabletScalePercentageFromSettings();
|
||||||
UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml",
|
UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml",
|
||||||
|
@ -92,7 +98,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function showTabletUI() {
|
function showTabletUI() {
|
||||||
Tablet.getTablet("com.highfidelity.interface.tablet.system").tabletShown = true;
|
gTablet.tabletShown = true;
|
||||||
|
|
||||||
if (!tabletRezzed || !tabletIsValid()) {
|
if (!tabletRezzed || !tabletIsValid()) {
|
||||||
closeTabletUI();
|
closeTabletUI();
|
||||||
|
@ -114,7 +120,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideTabletUI() {
|
function hideTabletUI() {
|
||||||
Tablet.getTablet("com.highfidelity.interface.tablet.system").tabletShown = false;
|
gTablet.tabletShown = false;
|
||||||
if (!UIWebTablet) {
|
if (!UIWebTablet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +136,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeTabletUI() {
|
function closeTabletUI() {
|
||||||
Tablet.getTablet("com.highfidelity.interface.tablet.system").tabletShown = false;
|
gTablet.tabletShown = false;
|
||||||
if (UIWebTablet) {
|
if (UIWebTablet) {
|
||||||
if (UIWebTablet.onClose) {
|
if (UIWebTablet.onClose) {
|
||||||
UIWebTablet.onClose();
|
UIWebTablet.onClose();
|
||||||
|
@ -149,17 +155,21 @@
|
||||||
print("TABLET closeTabletUI, UIWebTablet is null");
|
print("TABLET closeTabletUI, UIWebTablet is null");
|
||||||
}
|
}
|
||||||
tabletRezzed = false;
|
tabletRezzed = false;
|
||||||
|
gTablet = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateShowTablet() {
|
function updateShowTablet() {
|
||||||
var MSECS_PER_SEC = 1000.0;
|
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
|
||||||
|
if (gTablet === null) {
|
||||||
|
gTablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
}
|
||||||
|
|
||||||
// close the WebTablet if it we go into toolbar mode.
|
// close the WebTablet if it we go into toolbar mode.
|
||||||
var tabletShown = Tablet.getTablet("com.highfidelity.interface.tablet.system").tabletShown;
|
var tabletShown = gTablet.tabletShown;
|
||||||
var toolbarMode = Tablet.getTablet("com.highfidelity.interface.tablet.system").toolbarMode;
|
var toolbarMode = gTablet.toolbarMode;
|
||||||
var landscape = Tablet.getTablet("com.highfidelity.interface.tablet.system").landscape;
|
var landscape = gTablet.landscape;
|
||||||
|
|
||||||
if (tabletShown && toolbarMode) {
|
if (tabletShown && toolbarMode) {
|
||||||
closeTabletUI();
|
closeTabletUI();
|
||||||
|
@ -167,18 +177,20 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: move to tablet qml?
|
||||||
if (tabletShown) {
|
if (tabletShown) {
|
||||||
var MUTE_MICROPHONE_MENU_ITEM = "Mute Microphone";
|
|
||||||
var currentMicEnabled = !Menu.isOptionChecked(MUTE_MICROPHONE_MENU_ITEM);
|
var currentMicEnabled = !Menu.isOptionChecked(MUTE_MICROPHONE_MENU_ITEM);
|
||||||
var currentMicLevel = getMicLevel();
|
var currentMicLevel = getMicLevel();
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
gTablet.updateMicEnabled(currentMicEnabled);
|
||||||
tablet.updateMicEnabled(currentMicEnabled);
|
gTablet.updateAudioBar(currentMicLevel);
|
||||||
tablet.updateAudioBar(currentMicLevel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTabletWidthFromSettings();
|
if (validCheckTime - now > MSECS_PER_SEC/4) {
|
||||||
if (UIWebTablet) {
|
//each 250ms should be just fine
|
||||||
UIWebTablet.setLandscape(landscape);
|
updateTabletWidthFromSettings();
|
||||||
|
if (UIWebTablet) {
|
||||||
|
UIWebTablet.setLandscape(landscape);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validCheckTime - now > MSECS_PER_SEC) {
|
if (validCheckTime - now > MSECS_PER_SEC) {
|
||||||
|
@ -228,7 +240,7 @@
|
||||||
}
|
}
|
||||||
if (channel === "home") {
|
if (channel === "home") {
|
||||||
if (UIWebTablet) {
|
if (UIWebTablet) {
|
||||||
Tablet.getTablet("com.highfidelity.interface.tablet.system").landscape = false;
|
gTablet.landscape = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,30 +251,10 @@
|
||||||
|
|
||||||
Script.setInterval(updateShowTablet, 100);
|
Script.setInterval(updateShowTablet, 100);
|
||||||
|
|
||||||
// Initialise variables used to calculate audio level
|
|
||||||
var accumulatedLevel = 0.0;
|
|
||||||
// Note: Might have to tweak the following two based on the rate we're getting the data
|
|
||||||
var AVERAGING_RATIO = 0.05;
|
|
||||||
|
|
||||||
// Calculate microphone level with the same scaling equation (log scale, exponentially averaged) in AvatarInputs and pal.js
|
// Calculate microphone level with the same scaling equation (log scale, exponentially averaged) in AvatarInputs and pal.js
|
||||||
function getMicLevel() {
|
function getMicLevel() {
|
||||||
var LOUDNESS_FLOOR = 11.0;
|
//reuse already existing C++ code
|
||||||
var LOUDNESS_SCALE = 2.8 / 5.0;
|
return AvatarInputs.loudnessToAudioLevel(MyAvatar.audioLoudness)
|
||||||
var LOG2 = Math.log(2.0);
|
|
||||||
var micLevel = 0.0;
|
|
||||||
accumulatedLevel = AVERAGING_RATIO * accumulatedLevel + (1 - AVERAGING_RATIO) * (MyAvatar.audioLoudness);
|
|
||||||
// Convert to log base 2
|
|
||||||
var logLevel = Math.log(accumulatedLevel + 1) / LOG2;
|
|
||||||
|
|
||||||
if (logLevel <= LOUDNESS_FLOOR) {
|
|
||||||
micLevel = logLevel / LOUDNESS_FLOOR * LOUDNESS_SCALE;
|
|
||||||
} else {
|
|
||||||
micLevel = (logLevel - (LOUDNESS_FLOOR - 1.0)) * LOUDNESS_SCALE;
|
|
||||||
}
|
|
||||||
if (micLevel > 1.0) {
|
|
||||||
micLevel = 1.0;
|
|
||||||
}
|
|
||||||
return micLevel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
|
|
Loading…
Reference in a new issue