Showing the changes to interface/src/Application.cpp (1 of 7 files). Show all
Unified · Split
| @@ -148,7 +148,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 147 unmodified lines | |||
| 148 | _voxelImporter(), | 148 | _voxelImporter(), |
| 149 | _importSucceded(false), | 149 | _importSucceded(false), |
| 150 | _sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard), | 150 | _sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard), |
| 151 | _entityClipboardRenderer(), | 151 | _entities(true), |
| 152 | _entityCollisionSystem(), | ||
| 153 | _entityClipboardRenderer(false), | ||
| 152 | _entityClipboard(), | 154 | _entityClipboard(), |
| 153 | _wantToKillLocalVoxels(false), | 155 | _wantToKillLocalVoxels(false), |
| 154 | _viewFrustum(), | 156 | _viewFrustum(), |
| @@ -3831,35 +3833,7 @@ void joystickFromScriptValue(const QScriptValue &object, Joystick* &out) { · 3676 unmodified lines | |||
| 3831 | out = qobject_cast<Joystick*>(object.toQObject()); | 3833 | out = qobject_cast<Joystick*>(object.toQObject()); |
| 3832 | } | 3834 | } |
| 3833 | 3835 | ||
| 3834 | ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded, | 3836 | void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine) { |
| 3835 | bool loadScriptFromEditor, bool activateMainWindow) { | ||
| 3836 | QUrl scriptUrl(scriptFilename); | ||
| 3837 | const QString& scriptURLString = scriptUrl.toString(); | ||
| 3838 | if (_scriptEnginesHash.contains(scriptURLString) && loadScriptFromEditor | ||
| 3839 | && !_scriptEnginesHash[scriptURLString]->isFinished()) { | ||
| 3840 | |||
| 3841 | return _scriptEnginesHash[scriptURLString]; | ||
| 3842 | } | ||
| 3843 | |||
| 3844 | ScriptEngine* scriptEngine; | ||
| 3845 | if (scriptFilename.isNull()) { | ||
| 3846 | scriptEngine = new ScriptEngine(NO_SCRIPT, "", &_controllerScriptingInterface); | ||
| 3847 | } else { | ||
| 3848 | // start the script on a new thread... | ||
| 3849 | scriptEngine = new ScriptEngine(scriptUrl, &_controllerScriptingInterface); | ||
| 3850 | |||
| 3851 | if (!scriptEngine->hasScript()) { | ||
| 3852 | qDebug() << "Application::loadScript(), script failed to load..."; | ||
| 3853 | QMessageBox::warning(getWindow(), "Error Loading Script", scriptURLString + " failed to load."); | ||
| 3854 | return NULL; | ||
| 3855 | } | ||
| 3856 | |||
| 3857 | _scriptEnginesHash.insertMulti(scriptURLString, scriptEngine); | ||
| 3858 | _runningScriptsWidget->setRunningScripts(getRunningScripts()); | ||
| 3859 | UserActivityLogger::getInstance().loadedScript(scriptURLString); | ||
| 3860 | } | ||
| 3861 | scriptEngine->setUserLoaded(isUserLoaded); | ||
| 3862 | |||
| 3863 | // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so | 3837 | // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so |
| 3864 | // we can use the same ones from the application. | 3838 | // we can use the same ones from the application. |
| 3865 | scriptEngine->getVoxelsScriptingInterface()->setPacketSender(&_voxelEditSender); | 3839 | scriptEngine->getVoxelsScriptingInterface()->setPacketSender(&_voxelEditSender); |
| @@ -3941,6 +3915,38 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 75 unmodified lines | |||
| 3941 | 3915 | ||
| 3942 | // Starts an event loop, and emits workerThread->started() | 3916 | // Starts an event loop, and emits workerThread->started() |
| 3943 | workerThread->start(); | 3917 | workerThread->start(); |
| 3918 | } | ||
| 3919 | |||
| 3920 | ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded, | ||
| 3921 | bool loadScriptFromEditor, bool activateMainWindow) { | ||
| 3922 | QUrl scriptUrl(scriptFilename); | ||
| 3923 | const QString& scriptURLString = scriptUrl.toString(); | ||
| 3924 | if (_scriptEnginesHash.contains(scriptURLString) && loadScriptFromEditor | ||
| 3925 | && !_scriptEnginesHash[scriptURLString]->isFinished()) { | ||
| 3926 | |||
| 3927 | return _scriptEnginesHash[scriptURLString]; | ||
| 3928 | } | ||
| 3929 | |||
| 3930 | ScriptEngine* scriptEngine; | ||
| 3931 | if (scriptFilename.isNull()) { | ||
| 3932 | scriptEngine = new ScriptEngine(NO_SCRIPT, "", &_controllerScriptingInterface); | ||
| 3933 | } else { | ||
| 3934 | // start the script on a new thread... | ||
| 3935 | scriptEngine = new ScriptEngine(scriptUrl, &_controllerScriptingInterface); | ||
| 3936 | |||
| 3937 | if (!scriptEngine->hasScript()) { | ||
| 3938 | qDebug() << "Application::loadScript(), script failed to load..."; | ||
| 3939 | QMessageBox::warning(getWindow(), "Error Loading Script", scriptURLString + " failed to load."); | ||
| 3940 | return NULL; | ||
| 3941 | } | ||
| 3942 | |||
| 3943 | _scriptEnginesHash.insertMulti(scriptURLString, scriptEngine); | ||
| 3944 | _runningScriptsWidget->setRunningScripts(getRunningScripts()); | ||
| 3945 | UserActivityLogger::getInstance().loadedScript(scriptURLString); | ||
| 3946 | } | ||
| 3947 | scriptEngine->setUserLoaded(isUserLoaded); | ||
| 3948 | |||
| 3949 | registerScriptEngineWithApplicationServices(scriptEngine); | ||
| 3944 | 3950 | ||
| 3945 | // restore the main window's active state | 3951 | // restore the main window's active state |
| 3946 | if (activateMainWindow && !loadScriptFromEditor) { | 3952 | if (activateMainWindow && !loadScriptFromEditor) { |