History

Get rid of globalObject().property("MyAvatar").property("animationStateHandlerResult").

Howard Stearns committed 11 years ago

Commit 2b7ceff1 parent 913842a4 files · +22 −9Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+14−7
@@ -260,12 +260,23 @@ void ScriptEngine::errorInLoadingScript(const QUrl& url) { · 259 unmodified lines
260260
261261 // Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of
262262 // callAnimationStateHandler requires that the type be registered.
263+// These two are meaningful, if we ever do want to use them...
263264 static QScriptValue animVarMapToScriptValue(QScriptEngine* engine, const AnimVariantMap& parameters) {
264265 return parameters.animVariantMapToScriptValue(engine);
265266 }
266267 static void animVarMapFromScriptValue(const QScriptValue& value, AnimVariantMap& parameters) {
267268 parameters.animVariantMapFromScriptValue(value);
268269 }
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+}
269280
270281 void ScriptEngine::init() {
271282 if (_isInitialized) {
@@ -326,6 +337,7 @@ void ScriptEngine::init() { · 54 unmodified lines
326337 registerGlobalObject("Uuid", &_uuidLibrary);
327338 registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
328339 qScriptRegisterMetaType(this, animVarMapToScriptValue, animVarMapFromScriptValue);
340+ qScriptRegisterMetaType(this, resultHandlerToScriptValue, resultHandlerFromScriptValue);
329341
330342 // constants
331343 globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE)));
@@ -729,7 +741,7 @@ void ScriptEngine::stop() { · 397 unmodified lines
729741 }
730742
731743 // 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) {
733745 if (QThread::currentThread() != thread()) {
734746 #ifdef THREAD_DEBUGGING
735747 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
743755 QScriptValueList callingArguments;
744756 callingArguments << javascriptParametgers;
745757 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);
752759 }
753760
754761 void ScriptEngine::timerFired() {