Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all
Unified · Split
| @@ -259,7 +259,7 @@ void ScriptEngine::errorInLoadingScript(const QUrl& url) { · 258 unmodified lines | ||
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of |
| 262 | −// invokeAnimationCallback requires that the type be registered. | |
| 262 | +// callAnimationStateHandler requires that the type be registered. | |
| 263 | 263 | static QScriptValue animVarMapToScriptValue(QScriptEngine* engine, const AnimVariantMap& parameters) { |
| 264 | 264 | return parameters.animVariantMapToScriptValue(engine); |
| 265 | 265 | } |
| @@ -340,7 +340,7 @@ void ScriptEngine::init() { · 74 unmodified lines | ||
| 340 | 340 | void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) { |
| 341 | 341 | if (QThread::currentThread() != thread()) { |
| 342 | 342 | #ifdef THREAD_DEBUGGING |
| 343 | − qDebug() << "*** WARNING *** ScriptEngine::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name; | |
| 343 | + qDebug() << "*** WARNING *** ScriptEngine::registerValue() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]"; | |
| 344 | 344 | #endif |
| 345 | 345 | QMetaObject::invokeMethod(this, "registerValue", |
| 346 | 346 | Q_ARG(const QString&, valueName), |
| @@ -729,8 +729,16 @@ void ScriptEngine::stop() { · 382 unmodified lines | ||
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | // Other threads can invoke this through invokeMethod, which causes the callback to be asynchronously executed in this script's thread. |
| 732 | −void ScriptEngine::invokeAnimationCallback(QScriptValue callback, AnimVariantMap parameters) { | |
| 733 | − checkThread(); | |
| 732 | +void ScriptEngine::callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters) { | |
| 733 | + if (QThread::currentThread() != thread()) { | |
| 734 | +#ifdef THREAD_DEBUGGING | |
| 735 | + qDebug() << "*** WARNING *** ScriptEngine::callAnimationStateHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name; | |
| 736 | +#endif | |
| 737 | + QMetaObject::invokeMethod(this, "callAnimationStateHandler", | |
| 738 | + Q_ARG(QScriptValue, callback), | |
| 739 | + Q_ARG(AnimVariantMap, parameters)); | |
| 740 | + return; | |
| 741 | + } | |
| 734 | 742 | QScriptValue javascriptParametgers = parameters.animVariantMapToScriptValue(this); |
| 735 | 743 | QScriptValueList callingArguments; |
| 736 | 744 | callingArguments << javascriptParametgers; |
| @@ -923,19 +931,12 @@ void ScriptEngine::load(const QString& loadFile) { · 186 unmodified lines | ||
| 923 | 931 | } |
| 924 | 932 | } |
| 925 | 933 | |
| 926 | −bool ScriptEngine::checkThread() const { | |
| 934 | +// Look up the handler associated with eventName and entityID. If found, evalute the argGenerator thunk and call the handler with those args | |
| 935 | +void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& eventName, std::function<QScriptValueList()> argGenerator) { | |
| 927 | 936 | if (QThread::currentThread() != thread()) { |
| 928 | 937 | qDebug() << "*** ERROR *** ScriptEngine::generalHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]"; |
| 929 | 938 | assert(false); |
| 930 | − return true; | |
| 931 | − } | |
| 932 | − return false; | |
| 933 | −} | |
| 934 | − | |
| 935 | −// Look up the handler associated with eventName and entityID. If found, evalute the argGenerator thunk and call the handler with those args | |
| 936 | −void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& eventName, std::function<QScriptValueList()> argGenerator) { | |
| 937 | − if (checkThread()) { | |
| 938 | − return; | |
| 939 | + return ; | |
| 939 | 940 | } |
| 940 | 941 | if (!_registeredHandlers.contains(entityID)) { |
| 941 | 942 | return; |