Showing the changes to interface/src/Application.cpp (1 of 6 files). Show all
Unified · Split
| @@ -4011,8 +4011,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 4010 unmodified lines | ||
| 4011 | 4011 | AvatarManager::registerMetaTypes(scriptEngine); |
| 4012 | 4012 | |
| 4013 | 4013 | // hook our avatar and avatar hash map object into this script engine |
| 4014 | − scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features | |
| 4015 | − scriptEngine->setAvatarHashMap(DependencyManager::get<AvatarManager>().data(), "AvatarList"); | |
| 4014 | + scriptEngine->registerGlobalObject("MyAvatar", _myAvatar); | |
| 4015 | + scriptEngine->registerGlobalObject("AvatarList", DependencyManager::get<AvatarManager>().data()); | |
| 4016 | 4016 | |
| 4017 | 4017 | scriptEngine->registerGlobalObject("Camera", &_myCamera); |
| 4018 | 4018 | |
| @@ -4036,9 +4036,9 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 17 unmodified lines | ||
| 4036 | 4036 | |
| 4037 | 4037 | scriptEngine->registerGlobalObject("Desktop", DependencyManager::get<DesktopScriptingInterface>().data()); |
| 4038 | 4038 | |
| 4039 | − QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data()); | |
| 4039 | + scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data()); | |
| 4040 | 4040 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, |
| 4041 | − LocationScriptingInterface::locationSetter, windowValue); | |
| 4041 | + LocationScriptingInterface::locationSetter, "Window"); | |
| 4042 | 4042 | // register `location` on the global object. |
| 4043 | 4043 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, |
| 4044 | 4044 | LocationScriptingInterface::locationSetter); |
| @@ -4068,9 +4068,9 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 23 unmodified lines | ||
| 4068 | 4068 | |
| 4069 | 4069 | scriptEngine->registerGlobalObject("Paths", DependencyManager::get<PathUtils>().data()); |
| 4070 | 4070 | |
| 4071 | − QScriptValue hmdInterface = scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance()); | |
| 4072 | − scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0); | |
| 4073 | − scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); | |
| 4071 | + scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance()); | |
| 4072 | + scriptEngine->registerFunction("HMD", "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0); | |
| 4073 | + scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); | |
| 4074 | 4074 | |
| 4075 | 4075 | scriptEngine->registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data()); |
| 4076 | 4076 | |
| @@ -4079,31 +4079,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 2 unmodified lines | ||
| 4079 | 4079 | #ifdef HAVE_RTMIDI |
| 4080 | 4080 | scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance()); |
| 4081 | 4081 | #endif |
| 4082 | − | |
| 4083 | − // TODO: Consider moving some of this functionality into the ScriptEngine class instead. It seems wrong that this | |
| 4084 | − // work is being done in the Application class when really these dependencies are more related to the ScriptEngine's | |
| 4085 | − // implementation | |
| 4086 | − QThread* workerThread = new QThread(this); | |
| 4087 | − QString scriptEngineName = QString("Script Thread:") + scriptEngine->getFilename(); | |
| 4088 | − workerThread->setObjectName(scriptEngineName); | |
| 4089 | − | |
| 4090 | − // when the worker thread is started, call our engine's run.. | |
| 4091 | − connect(workerThread, &QThread::started, scriptEngine, &ScriptEngine::run); | |
| 4092 | − | |
| 4093 | − // when the thread is terminated, add both scriptEngine and thread to the deleteLater queue | |
| 4094 | − connect(scriptEngine, &ScriptEngine::doneRunning, scriptEngine, &ScriptEngine::deleteLater); | |
| 4095 | − connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater); | |
| 4096 | − | |
| 4097 | − // tell the thread to stop when the script engine is done | |
| 4098 | − connect(scriptEngine, &ScriptEngine::destroyed, workerThread, &QThread::quit); | |
| 4099 | − | |
| 4100 | − auto nodeList = DependencyManager::get<NodeList>(); | |
| 4101 | − connect(nodeList.data(), &NodeList::nodeKilled, scriptEngine, &ScriptEngine::nodeKilled); | |
| 4102 | − | |
| 4103 | − scriptEngine->moveToThread(workerThread); | |
| 4104 | − | |
| 4105 | − // Starts an event loop, and emits workerThread->started() | |
| 4106 | − workerThread->start(); | |
| 4107 | 4082 | } |
| 4108 | 4083 | |
| 4109 | 4084 | void Application::initializeAcceptedFiles() { |
| @@ -4249,17 +4224,34 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 139 unmodified lines | ||
| 4249 | 4224 | scriptEngine->setUserLoaded(isUserLoaded); |
| 4250 | 4225 | |
| 4251 | 4226 | if (scriptFilename.isNull()) { |
| 4227 | + // This appears to be the script engine used by the script widget's evaluation window before the file has been saved... | |
| 4228 | + | |
| 4229 | + qDebug() << "############################# HELLO WE ARE HERE!!!! ##################################"; | |
| 4252 | 4230 | // this had better be the script editor (we should de-couple so somebody who thinks they are loading a script |
| 4253 | 4231 | // doesn't just get an empty script engine) |
| 4254 | 4232 | |
| 4255 | 4233 | // we can complete setup now since there isn't a script we have to load |
| 4256 | 4234 | registerScriptEngineWithApplicationServices(scriptEngine); |
| 4235 | + scriptEngine->runInThread(); | |
| 4236 | + | |
| 4237 | + //FIXME - intentionally attempting to test thread safe call to registerGlobalObject() | |
| 4238 | + qDebug() << "about to attempt to call registerGlobalObject on wrong thread!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"; | |
| 4239 | + scriptEngine->registerGlobalObject("LODManager2", DependencyManager::get<LODManager>().data()); | |
| 4240 | + | |
| 4241 | + qDebug() << "about to attempt to call registerFunction on wrong thread!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"; | |
| 4242 | + scriptEngine->registerFunction("WebWindow2", WebWindowClass::constructor, 1); | |
| 4243 | + | |
| 4244 | + qDebug() << "about to attempt to call registerGetterSetter on wrong thread!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"; | |
| 4245 | + scriptEngine->registerGetterSetter("foo_location", LocationScriptingInterface::locationGetter, LocationScriptingInterface::locationSetter); | |
| 4246 | + | |
| 4247 | + | |
| 4257 | 4248 | } else { |
| 4258 | 4249 | // connect to the appropriate signals of this script engine |
| 4259 | 4250 | connect(scriptEngine, &ScriptEngine::scriptLoaded, this, &Application::handleScriptEngineLoaded); |
| 4260 | 4251 | connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &Application::handleScriptLoadError); |
| 4261 | 4252 | |
| 4262 | 4253 | // get the script engine object to load the script at the designated script URL |
| 4254 | + qDebug() << "calling scriptEngine->loadURL(" << scriptUrl << ", " << reload << ");"; | |
| 4263 | 4255 | scriptEngine->loadURL(scriptUrl, reload); |
| 4264 | 4256 | } |
| 4265 | 4257 | |
| @@ -4276,6 +4268,7 @@ void Application::reloadScript(const QString& scriptName, bool isUserLoaded) { · 10 unmodified lines | ||
| 4276 | 4268 | } |
| 4277 | 4269 | |
| 4278 | 4270 | void Application::handleScriptEngineLoaded(const QString& scriptFilename) { |
| 4271 | + qDebug() << "handleScriptEngineLoaded().... scriptFilename:" << scriptFilename; | |
| 4279 | 4272 | ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender()); |
| 4280 | 4273 | |
| 4281 | 4274 | _scriptEnginesHash.insertMulti(scriptFilename, scriptEngine); |
| @@ -4284,6 +4277,17 @@ void Application::handleScriptEngineLoaded(const QString& scriptFilename) { · 2 unmodified lines | ||
| 4284 | 4277 | |
| 4285 | 4278 | // register our application services and set it off on its own thread |
| 4286 | 4279 | registerScriptEngineWithApplicationServices(scriptEngine); |
| 4280 | + scriptEngine->runInThread(); | |
| 4281 | + | |
| 4282 | + //FIXME - intentionally attempting to test thread safe call to registerGlobalObject() | |
| 4283 | + qDebug() << "about to attempt to call registerGlobalObject on wrong thread!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"; | |
| 4284 | + scriptEngine->registerGlobalObject("LODManager2", DependencyManager::get<LODManager>().data()); | |
| 4285 | + | |
| 4286 | + qDebug() << "about to attempt to call registerFunction on wrong thread!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"; | |
| 4287 | + scriptEngine->registerFunction("WebWindow2", WebWindowClass::constructor, 1); | |
| 4288 | + | |
| 4289 | + qDebug() << "about to attempt to call registerGetterSetter on wrong thread!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"; | |
| 4290 | + scriptEngine->registerGetterSetter("foo_location", LocationScriptingInterface::locationGetter, LocationScriptingInterface::locationSetter); | |
| 4287 | 4291 | } |
| 4288 | 4292 | |
| 4289 | 4293 | void Application::handleScriptLoadError(const QString& scriptFilename) { |