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 | 261 | // Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of |
| 262 | 262 | // callAnimationStateHandler requires that the type be registered. |
| 263 | +// These two are meaningful, if we ever do want to use them... | |
| 263 | 264 | static QScriptValue animVarMapToScriptValue(QScriptEngine* engine, const AnimVariantMap& parameters) { |
| 264 | 265 | return parameters.animVariantMapToScriptValue(engine); |
| 265 | 266 | } |
| 266 | 267 | static void animVarMapFromScriptValue(const QScriptValue& value, AnimVariantMap& parameters) { |
| 267 | 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 | 281 | void ScriptEngine::init() { |
| 271 | 282 | if (_isInitialized) { |
| @@ -326,6 +337,7 @@ void ScriptEngine::init() { · 54 unmodified lines | ||
| 326 | 337 | registerGlobalObject("Uuid", &_uuidLibrary); |
| 327 | 338 | registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data()); |
| 328 | 339 | qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue); |
| 340 | + qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue); | |
| 329 | 341 | |
| 330 | 342 | // constants |
| 331 | 343 | globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE))); |
| @@ -729,7 +741,7 @@ void ScriptEngine::stop() { · 397 unmodified lines | ||
| 729 | 741 | } |
| 730 | 742 | |
| 731 | 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 | 745 | if (QThread::currentThread() != thread()) { |
| 734 | 746 | #ifdef THREAD_DEBUGGING |
| 735 | 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 | 755 | QScriptValueList callingArguments; |
| 744 | 756 | callingArguments << javascriptParametgers; |
| 745 | 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. | |
| 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. | |
| 758 | + resultHandler(callback, result); | |
| 752 | 759 | } |
| 753 | 760 | |
| 754 | 761 | void ScriptEngine::timerFired() { |