Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all
Unified · Split
| @@ -260,12 +260,23 @@ void ScriptEngine::errorInLoadingScript(const QUrl& url) { · 259 unmodified lines | |||
| 260 | 260 | ||
| 261 | // Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of | 261 | // Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of |
| 262 | // callAnimationStateHandler requires that the type be registered. | 262 | // callAnimationStateHandler requires that the type be registered. |
| 263 | // These two are meaningful, if we ever do want to use them... | ||
| 263 | static QScriptValue animVarMapToScriptValue(QScriptEngine* engine, const AnimVariantMap& parameters) { | 264 | static QScriptValue animVarMapToScriptValue(QScriptEngine* engine, const AnimVariantMap& parameters) { |
| 264 | return parameters.animVariantMapToScriptValue(engine); | 265 | return parameters.animVariantMapToScriptValue(engine); |
| 265 | } | 266 | } |
| 266 | static void animVarMapFromScriptValue(const QScriptValue& value, AnimVariantMap& parameters) { | 267 | static void animVarMapFromScriptValue(const QScriptValue& value, AnimVariantMap& parameters) { |
| 267 | parameters.animVariantMapFromScriptValue(value); | 268 | parameters.animVariantMapFromScriptValue(value); |
| 268 | } | 269 | } |
| 270 | // ... while these two are not. But none of the four are ever used. | ||
| 271 | static QScriptValue resultHandlerToScriptValue(QScriptEngine* engine, const AnimVariantResultHandler& resultHandler) { | ||
| 272 | qCCritical(scriptengine) << "Attempt to marshall result handler to javascript"; | ||
| 273 | assert(false); | ||
| 274 | return QScriptValue(); | ||
| 275 | } | ||
| 276 | static void resultHandlerFromScriptValue(const QScriptValue& value, AnimVariantResultHandler& resultHandler) { | ||
| 277 | qCCritical(scriptengine) << "Attempt to marshall result handler from javascript"; | ||
| 278 | assert(false); | ||
| 279 | } | ||
| 269 | 280 | ||
| 270 | void ScriptEngine::init() { | 281 | void ScriptEngine::init() { |
| 271 | if (_isInitialized) { | 282 | if (_isInitialized) { |
| @@ -326,6 +337,7 @@ void ScriptEngine::init() { · 54 unmodified lines | |||
| 326 | registerGlobalObject("Uuid", &_uuidLibrary); | 337 | registerGlobalObject("Uuid", &_uuidLibrary); |
| 327 | registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data()); | 338 | registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data()); |
| 328 | qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue); | 339 | qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue); |
| 340 | qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue); | ||
| 329 | 341 | ||
| 330 | // constants | 342 | // constants |
| 331 | globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); | 343 | globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); |
| @@ -729,7 +741,7 @@ void ScriptEngine::stop() { · 397 unmodified lines | |||
| 729 | } | 741 | } |
| 730 | 742 | ||
| 731 | // Other threads can invoke this through invokeMethod, which causes the callback to be asynchronously executed in this script's thread. | 743 | // Other threads can invoke this through invokeMethod, which causes the callback to be asynchronously executed in this script's thread. |
| 732 | void ScriptEngine::callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters) { | 744 | void ScriptEngine::callAnimationStateHandler(QScriptValue callback, AnimVariantMap parameters, AnimVariantResultHandler resultHandler) { |
| 733 | if (QThread::currentThread() != thread()) { | 745 | if (QThread::currentThread() != thread()) { |
| 734 | #ifdef THREAD_DEBUGGING | 746 | #ifdef THREAD_DEBUGGING |
| 735 | qDebug() << "*** WARNING *** ScriptEngine::callAnimationStateHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name; | 747 | qDebug() << "*** WARNING *** ScriptEngine::callAnimationStateHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name; |
| @@ -743,12 +755,7 @@ void ScriptEngine::callAnimationStateHandler(QScriptValue callback, AnimVariantM · 7 unmodified lines | |||
| 743 | QScriptValueList callingArguments; | 755 | QScriptValueList callingArguments; |
| 744 | callingArguments << javascriptParametgers; | 756 | callingArguments << javascriptParametgers; |
| 745 | QScriptValue result = callback.call(QScriptValue(), callingArguments); | 757 | QScriptValue result = callback.call(QScriptValue(), callingArguments); |
| 746 | // We want to give the result back to the rig, but we don't have the rig or the avatar. But the global does. | 758 | resultHandler(callback, result); |
| 747 | // This is sort of like going through DependencyManager.get. | ||
| 748 | QScriptValue resultHandler = globalObject().property("MyAvatar").property("animationStateHandlerResult"); | ||
| 749 | QScriptValueList resultArguments; | ||
| 750 | resultArguments << callback << result; | ||
| 751 | resultHandler.call(QScriptValue(), resultArguments); // Call it synchronously, on our own time and thread. | ||
| 752 | } | 759 | } |
| 753 | 760 | ||
| 754 | void ScriptEngine::timerFired() { | 761 | void ScriptEngine::timerFired() { |