History

Create ScriptManagerScriptingInterface to move off the scripting API into its own class

Add a lot of documentation

Dale Glass committed 3 years ago

Commit 4d701551 parent 9e217923 files · +1598 −536Browse files

Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 3 files). Show all

Unified · Split

libraries/script-engine/src/ScriptManager.cpp+5−28
@@ -56,6 +56,7 @@ · 55 unmodified lines
5656 #include "ScriptProgram.h"
5757 #include "ScriptValueIterator.h"
5858 #include "ScriptValueUtils.h"
59+#include "ScriptManagerScriptingInterface.h"
5960
6061 #include <Profile.h>
6162
@@ -270,6 +271,8 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con · 208 unmodified lines
270271 break;
271272 }
272273
274+ _scriptingInterface = std::make_shared<ScriptManagerScriptingInterface>(this);
275+
273276 if (isEntityServerScript()) {
274277 qCDebug(scriptengine) << "isEntityServerScript() -- limiting maxRetries to 1";
275278 processLevelMaxRetries = 1;
@@ -683,7 +686,7 @@ void ScriptManager::init() { · 407 unmodified lines
683686 // NOTE: You do not want to end up creating new instances of singletons here. They will be on the ScriptManager thread
684687 // and are likely to be unusable if we "reset" the ScriptManager by creating a new one (on a whole new thread).
685688
686− scriptEngine->registerGlobalObject("Script", this);
689+ scriptEngine->registerGlobalObject("Script", _scriptingInterface.get());
687690
688691 {
689692 // set up Script.require.resolve and Script.require.cache
@@ -827,7 +830,7 @@ void ScriptManager::run() { · 137 unmodified lines
827830 // (because we're a client script)
828831 hifi::scripting::setLocalAccessSafeThread(true);
829832 }
830−
833+
831834
832835 //_engine->enterIsolateOnThisThread();
833836
@@ -1878,32 +1881,6 @@ void ScriptManager::loadEntityScript(const EntityItemID& entityID, const QString · 1044 unmodified lines
18781881 }, forceRedownload);
18791882 }
18801883
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 &bull; 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− */
19071884 // The JSDoc is for the callEntityScriptMethod() call in this method.
19081885 // since all of these operations can be asynch we will always do the actual work in the response handler
19091886 // for the download