Add a lot of documentation
Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 3 files). Show all
Unified · Split
| @@ -56,6 +56,7 @@ · 55 unmodified lines | ||
| 56 | 56 | #include "ScriptProgram.h" |
| 57 | 57 | #include "ScriptValueIterator.h" |
| 58 | 58 | #include "ScriptValueUtils.h" |
| 59 | +#include "ScriptManagerScriptingInterface.h" | |
| 59 | 60 | |
| 60 | 61 | #include <Profile.h> |
| 61 | 62 | |
| @@ -270,6 +271,8 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con · 208 unmodified lines | ||
| 270 | 271 | break; |
| 271 | 272 | } |
| 272 | 273 | |
| 274 | + _scriptingInterface = std::make_shared<ScriptManagerScriptingInterface>(this); | |
| 275 | + | |
| 273 | 276 | if (isEntityServerScript()) { |
| 274 | 277 | qCDebug(scriptengine) << "isEntityServerScript() -- limiting maxRetries to 1"; |
| 275 | 278 | processLevelMaxRetries = 1; |
| @@ -683,7 +686,7 @@ void ScriptManager::init() { · 407 unmodified lines | ||
| 683 | 686 | // NOTE: You do not want to end up creating new instances of singletons here. They will be on the ScriptManager thread |
| 684 | 687 | // and are likely to be unusable if we "reset" the ScriptManager by creating a new one (on a whole new thread). |
| 685 | 688 | |
| 686 | − scriptEngine->registerGlobalObject("Script", this); | |
| 689 | + scriptEngine->registerGlobalObject("Script", _scriptingInterface.get()); | |
| 687 | 690 | |
| 688 | 691 | { |
| 689 | 692 | // set up Script.require.resolve and Script.require.cache |
| @@ -827,7 +830,7 @@ void ScriptManager::run() { · 137 unmodified lines | ||
| 827 | 830 | // (because we're a client script) |
| 828 | 831 | hifi::scripting::setLocalAccessSafeThread(true); |
| 829 | 832 | } |
| 830 | − | |
| 833 | + | |
| 831 | 834 | |
| 832 | 835 | //_engine->enterIsolateOnThisThread(); |
| 833 | 836 | |
| @@ -1878,32 +1881,6 @@ void ScriptManager::loadEntityScript(const EntityItemID& entityID, const QString · 1044 unmodified lines | ||
| 1878 | 1881 | }, forceRedownload); |
| 1879 | 1882 | } |
| 1880 | 1883 | |
| 1881 | −/*@jsdoc | |
| 1882 | − * Triggered when the script starts for a user. See also, {@link Script.entityScriptPreloadFinished}. | |
| 1883 | − * <p>Note: Can only be connected to via <code>this.preload = function (...) { ... }</code> in the entity script.</p> | |
| 1884 | − * <p class="availableIn"><strong>Supported Script Types:</strong> Client Entity Scripts • Server Entity Scripts</p> | |
| 1885 | − * @function Entities.preload | |
| 1886 | − * @param {Uuid} entityID - The ID of the entity that the script is running in. | |
| 1887 | − * @returns {Signal} | |
| 1888 | − * @example <caption>Get the ID of the entity that a client entity script is running in.</caption> | |
| 1889 | − * var entityScript = (function () { | |
| 1890 | − * this.entityID = Uuid.NULL; | |
| 1891 | − * | |
| 1892 | − * this.preload = function (entityID) { | |
| 1893 | − * this.entityID = entityID; | |
| 1894 | − * print("Entity ID: " + this.entityID); | |
| 1895 | − * }; | |
| 1896 | − * }); | |
| 1897 | − * | |
| 1898 | − * var entityID = Entities.addEntity({ | |
| 1899 | − * type: "Box", | |
| 1900 | − * position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5 })), | |
| 1901 | − * dimensions: { x: 0.5, y: 0.5, z: 0.5 }, | |
| 1902 | − * color: { red: 255, green: 0, blue: 0 }, | |
| 1903 | − * script: "(" + entityScript + ")", // Could host the script on a Web server instead. | |
| 1904 | − * lifetime: 300 // Delete after 5 minutes. | |
| 1905 | − * }); | |
| 1906 | − */ | |
| 1907 | 1884 | // The JSDoc is for the callEntityScriptMethod() call in this method. |
| 1908 | 1885 | // since all of these operations can be asynch we will always do the actual work in the response handler |
| 1909 | 1886 | // for the download |