* </tbody> * </table> * @typedef {object} Script.MemoryUsageData */ /*@jsdoc * Returns memory usage statistics data. * @function Script.getMemoryUsageStatistics * @Returns {Script.MemoryUsageData} Object containing statistics about memory usage. */ Q_INVOKABLE QVariantMap getMemoryUsageStatistics(); /*@jsdoc * Start collecting object statistics that can later be reported with Script.dumpHeapObjectStatistics(). * @function Script.startCollectingObjectStatistics */ Q_INVOKABLE void startCollectingObjectStatistics(); /*@jsdoc * Prints heap statistics to a file. Collecting needs to first be started with Script.dumpHeapObjectStatistics(). * @function Script.dumpHeapObjectStatistics */ Q_INVOKABLE void dumpHeapObjectStatistics(); /*@jsdoc * Create test object for garbage collector debugging. * @function Script.createGarbageCollectorDebuggingObject() * @Returns Test object. */ Q_INVOKABLE ScriptValue createGarbageCollectorDebuggingObject(); /*@jsdoc * Starts collecting profiling data * @function Script.startProfiling */ Q_INVOKABLE void startProfiling(); /*@jsdoc * Stops collecting profiling data and writes them to a timestamped CSV file in Logs directory. * @function Script.stopProfilingAndSave * @example <caption>Collect profiling data from a script.</caption> * Script.startProfiling(); * workFunc1(); * Script.stopProfilingAndSave(); * * function workFunc1() { * for (var i=0; i<100000; i++) { * var vec1 = {x: i, y: i+1, z: i+2}; * var vec2 = {x: i+3, y: i+4, z: i+5}; * workFunc2(vec1, vec2); * } * }; * function workFunc2(vec1, vec2) { * var cross = Vec3.cross(vec1, vec2); * var dot = Vec3.dot(vec1, vec2); * }; */ Q_INVOKABLE void stopProfilingAndSave(); /*@jsdoc * After calling this function current script engine will start receiving server-side entity script messages * through signals such as errorEntityMessage. This function can be invoked both from client-side entity scripts * and from interface scripts. * @function Script.subscribeToServerEntityScriptMessages * @param {Uuid=} entityID - The ID of the entity that requests entity server script messages. Only needs to be specified * for entity scripts, and must not be specified for other types of scripts. */ Q_INVOKABLE void requestServerEntityScriptMessages(); Q_INVOKABLE void requestServerEntityScriptMessages(const QUuid& entityID); /*@jsdoc * Calling this function signalizes that current script doesn't require stop receiving server-side entity script messages * through signals such as errorEntityMessage. This function can be invoked both from client-side entity scripts * and from interface scripts. * @function Script.unsubscribeFromServerEntityScriptMessages * @param {Uuid=} entityID - The ID of the entity that requests entity server script messages. Only needs to be specified * for entity scripts, and must not be specified for other types of scripts. */ Q_INVOKABLE void removeServerEntityScriptMessagesRequest(); Q_INVOKABLE void removeServerEntityScriptMessagesRequest(const QUuid& entityID); /*@jsdoc * This decodes Base64 string and returns contents as ArrayBuffer. * @function Script.atob * @param {String} base64 - String with Base64-encoded binary data. * @returns {ArrayBuffer} Decoded binary data. */ Q_INVOKABLE QByteArray atob(const QString &base64); /*@jsdoc * This encodes ArrayBuffer and returns Base64-encoded string. * @function Script.btoa * @param {ArrayBuffer} binary - Data to be encoded. * @returns {String} String with Base64-encoded binary data. */ Q_INVOKABLE QString btoa(const QByteArray &binary); signals: /*@jsdoc * @function Script.scriptLoaded * @param {string} filename - File name. * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void scriptLoaded(const QString& scriptFilename); /*@jsdoc * @function Script.errorLoadingScript * @param {string} filename - File name. * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void errorLoadingScript(const QString& scriptFilename); /*@jsdoc * Triggered frequently at a system-determined interval. * @function Script.update * @param {number} deltaTime - The time since the last update, in s. * @returns {Signal} * @example <caption>Report script update intervals.</caption> * Script.update.connect(function (deltaTime) { * print("Update: " + deltaTime); * }); */ void update(float deltaTime); /*@jsdoc * Triggered when the script is stopping. * @function Script.scriptEnding * @returns {Signal} * @example <caption>Report when a script is stopping.</caption> * print("Script started"); * * Script.scriptEnding.connect(function () { * print("Script ending"); * }); * * Script.setTimeout(function () { * print("Stopping script"); * Script.stop(); * }, 1000); */ void scriptEnding(); /*@jsdoc * Triggered when the script prints a message to the program log via {@link print}, {@link Script.print}, * {@link console.log}, {@link console.debug}, {@link console.group}, {@link console.groupEnd}, {@link console.time}, or * {@link console.timeEnd}. * @function Script.printedMessage * @param {string} message - The message. * @param {string} scriptName - The name of the script that generated the message. * @returns {Signal} */ void printedMessage(const QString& message, const QString& scriptName); /*@jsdoc * Triggered when the script generates an error, {@link console.error} or {@link console.exception} is called, or * {@link console.assert} is called and fails. * @function Script.errorMessage * @param {string} message - The error message. * @param {string} scriptName - The name of the script that generated the error message. * @returns {Signal} */ void errorMessage(const QString& message, const QString& scriptName); /*@jsdoc * Triggered when the script generates a warning or {@link console.warn} is called. * @function Script.warningMessage * @param {string} message - The warning message. * @param {string} scriptName - The name of the script that generated the warning message. * @returns {Signal} */ void warningMessage(const QString& message, const QString& scriptName); /*@jsdoc * Triggered when the script generates an information message or {@link console.info} is called. * @function Script.infoMessage * @param {string} message - The information message. * @param {string} scriptName - The name of the script that generated the information message. * @returns {Signal} */ void infoMessage(const QString& message, const QString& scriptName); /*@jsdoc * Triggered when the running state of the script changes, e.g., from running to stopping. * @function Script.runningStateChanged * @returns {Signal} */ void runningStateChanged(); /*@jsdoc * @function Script.clearDebugWindow * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void clearDebugWindow(); /*@jsdoc * @function Script.loadScript * @param {string} scriptName - Script name. * @param {boolean} isUserLoaded - Is user loaded. * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void loadScript(const QString& scriptName, bool isUserLoaded); /*@jsdoc * @function Script.reloadScript * @param {string} scriptName - Script name. * @param {boolean} isUserLoaded - Is user loaded. * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void reloadScript(const QString& scriptName, bool isUserLoaded); /*@jsdoc * Triggered when the script has stopped. * @function Script.doneRunning * @returns {Signal} */ void doneRunning(); /*@jsdoc * @function Script.entityScriptDetailsUpdated * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ // Emitted when an entity script is added or removed, or when the status of an entity // script is updated (goes from RUNNING to ERROR_RUNNING_SCRIPT, for example) void entityScriptDetailsUpdated(); /*@jsdoc * Triggered when the script starts for the user. See also, {@link Entities.preload}. * <p class="availableIn"><strong>Supported Script Types:</strong> Client Entity Scripts • Server Entity Scripts</p> * @function Script.entityScriptPreloadFinished * @param {Uuid} entityID - The ID of the entity that the script is running in. * @returns {Signal} * @example <caption>Get the ID of the entity that a client entity script is running in.</caption> * var entityScript = function () { * this.entityID = Uuid.NULL; * }; * * Script.entityScriptPreloadFinished.connect(function (entityID) { * this.entityID = entityID; * print("Entity ID: " + this.entityID); * }); * * var entityID = Entities.addEntity({ * type: "Box", * position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5 })), * dimensions: { x: 0.5, y: 0.5, z: 0.5 }, * color: { red: 255, green: 0, blue: 0 }, * script: "(" + entityScript + ")", // Could host the script on a Web server instead. * lifetime: 300 // Delete after 5 minutes. * }); */ // Emitted when an entity script has finished running preload void entityScriptPreloadFinished(const EntityItemID& entityID); /*@jsdoc * Triggered when a script generates an unhandled exception. * @function Script.unhandledException * @param {object} exception - The details of the exception. * @returns {Signal} * @example <caption>Report the details of an unhandled exception.</caption> * Script.unhandledException.connect(function (exception) { * print("Unhandled exception: " + JSON.stringify(exception)); * }); * var properties = JSON.parse("{ x: 1"); // Invalid JSON string. */ void unhandledException(const ScriptValue& exception); protected: /*@jsdoc * @function Script.executeOnScriptThread * @param {function} function - Function. * @param {ConnectionType} [type=2] - Connection type. * @deprecated This function is deprecated and will be removed. */ // V8TODO: Nothing seems to be using this, and it generates: // hifi.scriptengine: Parameter 1 in method ScriptManagerScriptingInterface :: "executeOnScriptThread" is of type QMetaType::UnknownType // so removing for now. // // Q_INVOKABLE void executeOnScriptThread(std::function<void()> function, const Qt::ConnectionType& type = Qt::QueuedConnection ) { _manager->executeOnScriptThread(function, type);} /*@jsdoc * @function Script._requireResolve * @param {string} module - Module. * @param {string} [relativeTo=""] - Relative to. * @returns {string} Result. * @deprecated This function is deprecated and will be removed. */ // note: this is not meant to be called directly, but just to have QMetaObject take care of wiring it up in general; // then inside of init() we just have to do "Script.require.resolve = Script._requireResolve;" Q_INVOKABLE QString _requireResolve(const QString& moduleId, const QString& relativeTo = QString()) { return _manager->_requireResolve(moduleId, relativeTo); } /*@jsdoc * @function Script.entityScriptContentAvailable * @param {Uuid} entityID - Entity ID. * @param {string} scriptOrURL - Path. * @param {string} contents - Contents. * @param {boolean} isURL - Is a URL. * @param {boolean} success - Success. * @param {string} status - Status. * @deprecated This function is deprecated and will be removed. */ Q_INVOKABLE void entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success, const QString& status) { _manager->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success, status); } private slots: void scriptManagerException(std::shared_ptr<ScriptException> exception); private: ScriptManager *_manager;};Lines 501–820 of 820. Previous lines
* </tbody> * </table> * @typedef {object} Script.MemoryUsageData */ /*@jsdoc * Returns memory usage statistics data. * @function Script.getMemoryUsageStatistics * @Returns {Script.MemoryUsageData} Object containing statistics about memory usage. */ Q_INVOKABLE QVariantMap getMemoryUsageStatistics(); /*@jsdoc * Start collecting object statistics that can later be reported with Script.dumpHeapObjectStatistics(). * @function Script.startCollectingObjectStatistics */ Q_INVOKABLE void startCollectingObjectStatistics(); /*@jsdoc * Prints heap statistics to a file. Collecting needs to first be started with Script.dumpHeapObjectStatistics(). * @function Script.dumpHeapObjectStatistics */ Q_INVOKABLE void dumpHeapObjectStatistics(); /*@jsdoc * Create test object for garbage collector debugging. * @function Script.createGarbageCollectorDebuggingObject() * @Returns Test object. */ Q_INVOKABLE ScriptValue createGarbageCollectorDebuggingObject(); /*@jsdoc * Starts collecting profiling data * @function Script.startProfiling */ Q_INVOKABLE void startProfiling(); /*@jsdoc * Stops collecting profiling data and writes them to a timestamped CSV file in Logs directory. * @function Script.stopProfilingAndSave * @example <caption>Collect profiling data from a script.</caption> * Script.startProfiling(); * workFunc1(); * Script.stopProfilingAndSave(); * * function workFunc1() { * for (var i=0; i<100000; i++) { * var vec1 = {x: i, y: i+1, z: i+2}; * var vec2 = {x: i+3, y: i+4, z: i+5}; * workFunc2(vec1, vec2); * } * }; * function workFunc2(vec1, vec2) { * var cross = Vec3.cross(vec1, vec2); * var dot = Vec3.dot(vec1, vec2); * }; */ Q_INVOKABLE void stopProfilingAndSave(); /*@jsdoc * After calling this function current script engine will start receiving server-side entity script messages * through signals such as errorEntityMessage. This function can be invoked both from client-side entity scripts * and from interface scripts. * @function Script.subscribeToServerEntityScriptMessages * @param {Uuid=} entityID - The ID of the entity that requests entity server script messages. Only needs to be specified * for entity scripts, and must not be specified for other types of scripts. */ Q_INVOKABLE void requestServerEntityScriptMessages(); Q_INVOKABLE void requestServerEntityScriptMessages(const QUuid& entityID); /*@jsdoc * Calling this function signalizes that current script doesn't require stop receiving server-side entity script messages * through signals such as errorEntityMessage. This function can be invoked both from client-side entity scripts * and from interface scripts. * @function Script.unsubscribeFromServerEntityScriptMessages * @param {Uuid=} entityID - The ID of the entity that requests entity server script messages. Only needs to be specified * for entity scripts, and must not be specified for other types of scripts. */ Q_INVOKABLE void removeServerEntityScriptMessagesRequest(); Q_INVOKABLE void removeServerEntityScriptMessagesRequest(const QUuid& entityID); /*@jsdoc * This decodes Base64 string and returns contents as ArrayBuffer. * @function Script.atob * @param {String} base64 - String with Base64-encoded binary data. * @returns {ArrayBuffer} Decoded binary data. */ Q_INVOKABLE QByteArray atob(const QString &base64); /*@jsdoc * This encodes ArrayBuffer and returns Base64-encoded string. * @function Script.btoa * @param {ArrayBuffer} binary - Data to be encoded. * @returns {String} String with Base64-encoded binary data. */ Q_INVOKABLE QString btoa(const QByteArray &binary); signals: /*@jsdoc * @function Script.scriptLoaded * @param {string} filename - File name. * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void scriptLoaded(const QString& scriptFilename); /*@jsdoc * @function Script.errorLoadingScript * @param {string} filename - File name. * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void errorLoadingScript(const QString& scriptFilename); /*@jsdoc * Triggered frequently at a system-determined interval. * @function Script.update * @param {number} deltaTime - The time since the last update, in s. * @returns {Signal} * @example <caption>Report script update intervals.</caption> * Script.update.connect(function (deltaTime) { * print("Update: " + deltaTime); * }); */ void update(float deltaTime); /*@jsdoc * Triggered when the script is stopping. * @function Script.scriptEnding * @returns {Signal} * @example <caption>Report when a script is stopping.</caption> * print("Script started"); * * Script.scriptEnding.connect(function () { * print("Script ending"); * }); * * Script.setTimeout(function () { * print("Stopping script"); * Script.stop(); * }, 1000); */ void scriptEnding(); /*@jsdoc * Triggered when the script prints a message to the program log via {@link print}, {@link Script.print}, * {@link console.log}, {@link console.debug}, {@link console.group}, {@link console.groupEnd}, {@link console.time}, or * {@link console.timeEnd}. * @function Script.printedMessage * @param {string} message - The message. * @param {string} scriptName - The name of the script that generated the message. * @returns {Signal} */ void printedMessage(const QString& message, const QString& scriptName); /*@jsdoc * Triggered when the script generates an error, {@link console.error} or {@link console.exception} is called, or * {@link console.assert} is called and fails. * @function Script.errorMessage * @param {string} message - The error message. * @param {string} scriptName - The name of the script that generated the error message. * @returns {Signal} */ void errorMessage(const QString& message, const QString& scriptName); /*@jsdoc * Triggered when the script generates a warning or {@link console.warn} is called. * @function Script.warningMessage * @param {string} message - The warning message. * @param {string} scriptName - The name of the script that generated the warning message. * @returns {Signal} */ void warningMessage(const QString& message, const QString& scriptName); /*@jsdoc * Triggered when the script generates an information message or {@link console.info} is called. * @function Script.infoMessage * @param {string} message - The information message. * @param {string} scriptName - The name of the script that generated the information message. * @returns {Signal} */ void infoMessage(const QString& message, const QString& scriptName); /*@jsdoc * Triggered when the running state of the script changes, e.g., from running to stopping. * @function Script.runningStateChanged * @returns {Signal} */ void runningStateChanged(); /*@jsdoc * @function Script.clearDebugWindow * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void clearDebugWindow(); /*@jsdoc * @function Script.loadScript * @param {string} scriptName - Script name. * @param {boolean} isUserLoaded - Is user loaded. * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void loadScript(const QString& scriptName, bool isUserLoaded); /*@jsdoc * @function Script.reloadScript * @param {string} scriptName - Script name. * @param {boolean} isUserLoaded - Is user loaded. * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ void reloadScript(const QString& scriptName, bool isUserLoaded); /*@jsdoc * Triggered when the script has stopped. * @function Script.doneRunning * @returns {Signal} */ void doneRunning(); /*@jsdoc * @function Script.entityScriptDetailsUpdated * @returns {Signal} * @deprecated This signal is deprecated and will be removed. */ // Emitted when an entity script is added or removed, or when the status of an entity // script is updated (goes from RUNNING to ERROR_RUNNING_SCRIPT, for example) void entityScriptDetailsUpdated(); /*@jsdoc * Triggered when the script starts for the user. See also, {@link Entities.preload}. * <p class="availableIn"><strong>Supported Script Types:</strong> Client Entity Scripts • Server Entity Scripts</p> * @function Script.entityScriptPreloadFinished * @param {Uuid} entityID - The ID of the entity that the script is running in. * @returns {Signal} * @example <caption>Get the ID of the entity that a client entity script is running in.</caption> * var entityScript = function () { * this.entityID = Uuid.NULL; * }; * * Script.entityScriptPreloadFinished.connect(function (entityID) { * this.entityID = entityID; * print("Entity ID: " + this.entityID); * }); * * var entityID = Entities.addEntity({ * type: "Box", * position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5 })), * dimensions: { x: 0.5, y: 0.5, z: 0.5 }, * color: { red: 255, green: 0, blue: 0 }, * script: "(" + entityScript + ")", // Could host the script on a Web server instead. * lifetime: 300 // Delete after 5 minutes. * }); */ // Emitted when an entity script has finished running preload void entityScriptPreloadFinished(const EntityItemID& entityID); /*@jsdoc * Triggered when a script generates an unhandled exception. * @function Script.unhandledException * @param {object} exception - The details of the exception. * @returns {Signal} * @example <caption>Report the details of an unhandled exception.</caption> * Script.unhandledException.connect(function (exception) { * print("Unhandled exception: " + JSON.stringify(exception)); * }); * var properties = JSON.parse("{ x: 1"); // Invalid JSON string. */ void unhandledException(const ScriptValue& exception); protected: /*@jsdoc * @function Script.executeOnScriptThread * @param {function} function - Function. * @param {ConnectionType} [type=2] - Connection type. * @deprecated This function is deprecated and will be removed. */ // V8TODO: Nothing seems to be using this, and it generates: // hifi.scriptengine: Parameter 1 in method ScriptManagerScriptingInterface :: "executeOnScriptThread" is of type QMetaType::UnknownType // so removing for now. // // Q_INVOKABLE void executeOnScriptThread(std::function<void()> function, const Qt::ConnectionType& type = Qt::QueuedConnection ) { _manager->executeOnScriptThread(function, type);} /*@jsdoc * @function Script._requireResolve * @param {string} module - Module. * @param {string} [relativeTo=""] - Relative to. * @returns {string} Result. * @deprecated This function is deprecated and will be removed. */ // note: this is not meant to be called directly, but just to have QMetaObject take care of wiring it up in general; // then inside of init() we just have to do "Script.require.resolve = Script._requireResolve;" Q_INVOKABLE QString _requireResolve(const QString& moduleId, const QString& relativeTo = QString()) { return _manager->_requireResolve(moduleId, relativeTo); } /*@jsdoc * @function Script.entityScriptContentAvailable * @param {Uuid} entityID - Entity ID. * @param {string} scriptOrURL - Path. * @param {string} contents - Contents. * @param {boolean} isURL - Is a URL. * @param {boolean} success - Success. * @param {string} status - Status. * @deprecated This function is deprecated and will be removed. */ Q_INVOKABLE void entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success, const QString& status) { _manager->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success, status); } private slots: void scriptManagerException(std::shared_ptr<ScriptException> exception); private: ScriptManager *_manager; };