From d6eb77e815147b818fe3129fb6ea5cb2f827d98f Mon Sep 17 00:00:00 2001 From: humbletim Date: Fri, 23 Jun 2017 13:09:22 -0400 Subject: [PATCH] changes per feedback to quiet print debugs throughout --- .../app-doppleganger-attachments.js | 14 ++++++-- .../doppleganger-attachments.js | 13 ++++--- .../doppleganger-attachments/doppleganger.js | 34 +++++++++++-------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/unpublishedScripts/marketplace/doppleganger-attachments/app-doppleganger-attachments.js b/unpublishedScripts/marketplace/doppleganger-attachments/app-doppleganger-attachments.js index 4142ff332e..4617cf47b6 100644 --- a/unpublishedScripts/marketplace/doppleganger-attachments/app-doppleganger-attachments.js +++ b/unpublishedScripts/marketplace/doppleganger-attachments/app-doppleganger-attachments.js @@ -12,6 +12,8 @@ var require = Script.require; +var WANT_DEBUG = false; + var DopplegangerClass = require('./doppleganger.js'), DopplegangerAttachments = require('./doppleganger-attachments.js'), modelHelper = require('./model-helper.js').modelHelper; @@ -57,7 +59,7 @@ var doppleganger = new DopplegangerClass({ var currentHash = dopplegangerAttachments.getAttachmentsHash(); if (currentHash !== lastHash) { lastHash = currentHash; - print('app-doppleganger | detect attachment change'); + debugPrint('app-doppleganger | detect attachment change'); dopplegangerAttachments.refreshAttachments(); } } @@ -86,7 +88,7 @@ button.clicked.connect(doppleganger, 'toggle'); doppleganger.activeChanged.connect(function(active, reason) { if (button) { button.editProperties({ isActive: active }); - print('doppleganger.activeChanged', active, reason); + debugPrint('doppleganger.activeChanged', active, reason); } }); @@ -101,9 +103,15 @@ doppleganger.modelLoaded.connect(function(error, result) { // add debug indicators, but only if the user has configured the settings value if (Settings.getValue('debug.doppleganger', false)) { + WANT_DEBUG = true; DopplegangerClass.addDebugControls(doppleganger); } +function debugPrint() { + if (WANT_DEBUG) { + print('app-doppleganger | ' + [].slice.call(arguments).join(' ')); + } +} // ---------------------------------------------------------------------------- UserActivityLogger.logAction('doppleganger_app_load'); @@ -115,7 +123,7 @@ doppleganger.activeChanged.connect(function(active, reason) { // user intentionally toggled the doppleganger UserActivityLogger.logAction('doppleganger_disable'); } else { - print('doppleganger stopped:', reason); + debugPrint('doppleganger stopped:', reason); UserActivityLogger.logAction('doppleganger_autodisable', { reason: reason }); } } diff --git a/unpublishedScripts/marketplace/doppleganger-attachments/doppleganger-attachments.js b/unpublishedScripts/marketplace/doppleganger-attachments/doppleganger-attachments.js index 1d3847cad2..a3b3873c2d 100644 --- a/unpublishedScripts/marketplace/doppleganger-attachments/doppleganger-attachments.js +++ b/unpublishedScripts/marketplace/doppleganger-attachments/doppleganger-attachments.js @@ -5,6 +5,7 @@ module.exports = DopplegangerAttachments; DopplegangerAttachments.version = '0.0.0'; +DopplegangerAttachments.WANT_DEBUG = false; var _modelHelper = require('./model-helper.js'), modelHelper = _modelHelper.modelHelper, @@ -15,6 +16,10 @@ function log() { print('doppleganger-attachments | ' + [].slice.call(arguments).join(' ')); } +function debugPrint() { + DopplegangerAttachments.WANT_DEBUG && log.apply(this, arguments); +} + function DopplegangerAttachments(doppleganger, options) { utils.assign(this, { _options: options, @@ -24,7 +29,7 @@ function DopplegangerAttachments(doppleganger, options) { attachmentsUpdated: utils.signal(function attachmentsUpdated(currentAttachments, previousAttachments){}), }); this._initialize(); - log('DopplegangerAttachments...', JSON.stringify(options)); + debugPrint('DopplegangerAttachments...', JSON.stringify(options)); } DopplegangerAttachments.prototype = { // "hash" the current attachments (so that changes can be detected) @@ -87,7 +92,7 @@ DopplegangerAttachments.prototype = { jointNames = this.doppleganger.jointNames, properties = modelHelper.getProperties(this.doppleganger.objectID); - log('DopplegangerAttachments..._createAttachmentObjects', JSON.stringify({ + debugPrint('DopplegangerAttachments..._createAttachmentObjects', JSON.stringify({ type: properties.type, attachments: attachments.length, parentID: parentID, @@ -96,7 +101,7 @@ DopplegangerAttachments.prototype = { return attachments.map(utils.bind(this, function(attachment, i) { var type = modelHelper.type(attachment.properties && attachment.properties.objectID); if (type === 'overlay') { - log('skipping already-provisioned attachment object', type, attachment.properties && attachment.properties.name); + debugPrint('skipping already-provisioned attachment object', type, attachment.properties && attachment.properties.name); return attachment; } var jointIndex = attachment.$jointIndex, // jointNames.indexOf(attachment.jointName), @@ -133,7 +138,7 @@ DopplegangerAttachments.prototype = { modelHelper.deleteObject(objectID); return objectID = null; } - log('attachment model ('+modelHelper.type(result.objectID)+') is ready; # joints ==', + debugPrint('attachment model ('+modelHelper.type(result.objectID)+') is ready; # joints ==', result.jointNames && result.jointNames.length, result.naturalDimensions, result.objectID); var properties = modelHelper.getProperties(result.objectID), naturalDimensions = attachment.properties.naturalDimensions = properties.naturalDimensions; diff --git a/unpublishedScripts/marketplace/doppleganger-attachments/doppleganger.js b/unpublishedScripts/marketplace/doppleganger-attachments/doppleganger.js index 375105e722..bebd36df45 100644 --- a/unpublishedScripts/marketplace/doppleganger-attachments/doppleganger.js +++ b/unpublishedScripts/marketplace/doppleganger-attachments/doppleganger.js @@ -28,15 +28,15 @@ var _modelHelper = require('./model-helper.js'), modelHelper = _modelHelper.modelHelper, ModelReadyWatcher = _modelHelper.ModelReadyWatcher; +// @property {bool} - toggle verbose debug logging on/off +Doppleganger.WANT_DEBUG = false; + // @property {bool} - when set true, Script.update will be used instead of setInterval for syncing joint data Doppleganger.USE_SCRIPT_UPDATE = false; // @property {int} - the frame rate to target when using setInterval for joint updates Doppleganger.TARGET_FPS = 60; -// @property {int} - the maximum time in seconds to wait for the model overlay to finish loading -Doppleganger.MAX_WAIT_SECS = 10; - // @class Doppleganger - Creates a new instance of a Doppleganger. // @param {Avatar} [options.avatar=MyAvatar] - Avatar used to retrieve position and joint data. // @param {bool} [options.mirrored=true] - Apply "symmetric mirroring" of Left/Right joints. @@ -64,10 +64,10 @@ Doppleganger.prototype = { // @public @method - toggles doppleganger on/off toggle: function() { if (this.active) { - log('toggling off'); + debugPrint('toggling off'); this.stop(); } else { - log('toggling on'); + debugPrint('toggling on'); this.start(); } return this.active; @@ -92,7 +92,7 @@ Doppleganger.prototype = { // note: this mismatch can happen when the avatar's model is actively changing if (size !== translations.length || (this.jointStateCount && size !== this.jointStateCount)) { - log('mismatched joint counts (avatar model likely changed)', size, translations.length, this.jointStateCount); + debugPrint('mismatched joint counts (avatar model likely changed)', size, translations.length, this.jointStateCount); this.stop('avatar_changed_joints'); return; } @@ -168,7 +168,7 @@ Doppleganger.prototype = { Script.scriptEnding.connect(this, function() { modelHelper.deleteObject(this.objectID); }); - log('doppleganger created; objectID =', this.objectID); + debugPrint('doppleganger created; objectID =', this.objectID); // trigger clean up (and stop updates) if the object gets deleted this.onObjectDeleted = function(uuid) { @@ -193,14 +193,14 @@ Doppleganger.prototype = { if (error) { return this.stop(error); } - log('model ('+modelHelper.type(this.objectID)+')' + ' is ready; # joints == ' + result.jointNames.length); + debugPrint('model ('+modelHelper.type(this.objectID)+')' + ' is ready; # joints == ' + result.jointNames.length); var naturalDimensions = modelHelper.getProperties(this.objectID, ['naturalDimensions']).naturalDimensions; - log('naturalDimensions:', JSON.stringify(naturalDimensions)); + debugPrint('naturalDimensions:', JSON.stringify(naturalDimensions)); var props = { visible: true }; if (naturalDimensions) { props.dimensions = Vec3.multiply(this.scale, naturalDimensions); } - log('scaledDimensions:', this.scale, JSON.stringify(props.dimensions)); + debugPrint('scaledDimensions:', this.scale, JSON.stringify(props.dimensions)); modelHelper.editObject(this.objectID, props); if (!options.position) { this.syncVerticalPosition(); @@ -250,7 +250,7 @@ Doppleganger.prototype = { if (this.active) { this.activeChanged(this.active = false, reason); } else if (reason) { - log('already stopped so not triggering another activeChanged; latest reason was:', reason); + debugPrint('already stopped so not triggering another activeChanged; latest reason was:', reason); } }, // @public @method - Reposition the doppleganger so it sees "eye to eye" with the Avatar. @@ -263,7 +263,7 @@ Doppleganger.prototype = { doppleJointIndex = modelHelper.getJointIndex(this.objectID, byJointName),// names.indexOf(byJointName), doppleJointPosition = positions[doppleJointIndex]; - print('........... doppleJointPosition', JSON.stringify({ + debugPrint('........... doppleJointPosition', JSON.stringify({ byJointName: byJointName, dopplePosition: dopplePosition, doppleJointIndex: doppleJointIndex, @@ -276,7 +276,7 @@ Doppleganger.prototype = { avatarJointPosition = this.avatar.getJointPosition(avatarJointIndex); var offset = (avatarJointPosition.y - doppleJointPosition.y); - log('adjusting for offset', offset); + debugPrint('adjusting for offset', offset); if (properties.type === 'model') { dopplePosition.y = avatarPosition.y + offset; } else { @@ -290,11 +290,11 @@ Doppleganger.prototype = { // @private @method - creates the update thread to synchronize joint data _createUpdateThread: function() { if (Doppleganger.USE_SCRIPT_UPDATE) { - log('creating Script.update thread'); + debugPrint('creating Script.update thread'); this.onUpdate = this.update; Script.update.connect(this, 'onUpdate'); } else { - log('creating Script.setInterval thread @ ~', Doppleganger.TARGET_FPS +'fps'); + debugPrint('creating Script.setInterval thread @ ~', Doppleganger.TARGET_FPS +'fps'); var timeout = 1000 / Doppleganger.TARGET_FPS; this._interval = Script.setInterval(bind(this, 'update'), timeout); } @@ -369,6 +369,10 @@ function log() { print('doppleganger | ' + [].slice.call(arguments).join(' ')); } +function debugPrint() { + Doppleganger.WANT_DEBUG && log.apply(this, arguments); +} + // -- ADVANCED DEBUGGING -- // @function - Add debug joint indicators / extra debugging info. // @param {Doppleganger} - existing Doppleganger instance to add controls to