Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 6 files). Show all
Unified · Split
| @@ -222,7 +222,7 @@ QString ScriptEngine::getFilename() const { · 221 unmodified lines | ||
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | |
| 225 | −// FIXME - remove the file/url scheme code here and let the script cache handle things | |
| 225 | +// FIXME - switch this to the new model of ScriptCache callbacks | |
| 226 | 226 | void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { |
| 227 | 227 | if (_isRunning) { |
| 228 | 228 | return; |
| @@ -238,6 +238,7 @@ void ScriptEngine::loadURL(const QUrl& scriptURL, bool reload) { · 9 unmodified lines | ||
| 238 | 238 | scriptCache->getScript(url, this, isPending, reload); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | +// FIXME - switch this to the new model of ScriptCache callbacks | |
| 241 | 242 | void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scriptContents) { |
| 242 | 243 | _scriptContents = scriptContents; |
| 243 | 244 | if (_wantSignals) { |
| @@ -245,6 +246,7 @@ void ScriptEngine::scriptContentsAvailable(const QUrl& url, const QString& scrip · 1 unmodified line | ||
| 245 | 246 | } |
| 246 | 247 | } |
| 247 | 248 | |
| 249 | +// FIXME - switch this to the new model of ScriptCache callbacks | |
| 248 | 250 | void ScriptEngine::errorInLoadingScript(const QUrl& url) { |
| 249 | 251 | qCDebug(scriptengine) << "ERROR Loading file:" << url.toString() << "line:" << __LINE__; |
| 250 | 252 | if (_wantSignals) { |
| @@ -320,13 +322,17 @@ void ScriptEngine::init() { · 69 unmodified lines | ||
| 320 | 322 | |
| 321 | 323 | void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { |
| 322 | 324 | if (QThread::currentThread() != thread()) { |
| 325 | + #ifdef THREAD_DEBUGGING | |
| 323 | 326 | qDebug() << "*** WARNING *** ScriptEngine::registerGlobalObject() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name; |
| 327 | + #endif | |
| 324 | 328 | QMetaObject::invokeMethod(this, "registerGlobalObject", |
| 325 | 329 | Q_ARG(const QString&, name), |
| 326 | 330 | Q_ARG(QObject*, object)); |
| 327 | 331 | return; |
| 328 | 332 | } |
| 329 | − //qDebug() << "ScriptEngine::registerGlobalObject() called on thread [" << QThread::currentThread() << "] name:" << name; | |
| 333 | + #ifdef THREAD_DEBUGGING | |
| 334 | + qDebug() << "ScriptEngine::registerGlobalObject() called on thread [" << QThread::currentThread() << "] name:" << name; | |
| 335 | + #endif | |
| 330 | 336 | |
| 331 | 337 | if (object) { |
| 332 | 338 | QScriptValue value = newQObject(object); |
| @@ -336,14 +342,18 @@ void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { · 3 unmodified lines | ||
| 336 | 342 | |
| 337 | 343 | void ScriptEngine::registerFunction(const QString& name, QScriptEngine::FunctionSignature functionSignature, int numArguments) { |
| 338 | 344 | if (QThread::currentThread() != thread()) { |
| 345 | + #ifdef THREAD_DEBUGGING | |
| 339 | 346 | qDebug() << "*** WARNING *** ScriptEngine::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] name:" << name; |
| 347 | + #endif | |
| 340 | 348 | QMetaObject::invokeMethod(this, "registerFunction", |
| 341 | 349 | Q_ARG(const QString&, name), |
| 342 | 350 | Q_ARG(QScriptEngine::FunctionSignature, functionSignature), |
| 343 | 351 | Q_ARG(int, numArguments)); |
| 344 | 352 | return; |
| 345 | 353 | } |
| 346 | − //qDebug() << "ScriptEngine::registerFunction() called on thread [" << QThread::currentThread() << "] name:" << name; | |
| 354 | + #ifdef THREAD_DEBUGGING | |
| 355 | + qDebug() << "ScriptEngine::registerFunction() called on thread [" << QThread::currentThread() << "] name:" << name; | |
| 356 | + #endif | |
| 347 | 357 | |
| 348 | 358 | QScriptValue scriptFun = newFunction(functionSignature, numArguments); |
| 349 | 359 | globalObject().setProperty(name, scriptFun); |
| @@ -351,14 +361,18 @@ void ScriptEngine::registerFunction(const QString& name, QScriptEngine::Function · 1 unmodified line | ||
| 351 | 361 | |
| 352 | 362 | void ScriptEngine::registerFunction(const QString& parent, const QString& name, QScriptEngine::FunctionSignature functionSignature, int numArguments) { |
| 353 | 363 | if (QThread::currentThread() != thread()) { |
| 364 | + #ifdef THREAD_DEBUGGING | |
| 354 | 365 | qDebug() << "*** WARNING *** ScriptEngine::registerFunction() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] parent:" << parent << "name:" << name; |
| 366 | + #endif | |
| 355 | 367 | QMetaObject::invokeMethod(this, "registerFunction", |
| 356 | 368 | Q_ARG(const QString&, name), |
| 357 | 369 | Q_ARG(QScriptEngine::FunctionSignature, functionSignature), |
| 358 | 370 | Q_ARG(int, numArguments)); |
| 359 | 371 | return; |
| 360 | 372 | } |
| 361 | − //qDebug() << "ScriptEngine::registerFunction() called on thread [" << QThread::currentThread() << "] parent:" << parent << "name:" << name; | |
| 373 | + #ifdef THREAD_DEBUGGING | |
| 374 | + qDebug() << "ScriptEngine::registerFunction() called on thread [" << QThread::currentThread() << "] parent:" << parent << "name:" << name; | |
| 375 | + #endif | |
| 362 | 376 | |
| 363 | 377 | QScriptValue object = globalObject().property(parent); |
| 364 | 378 | if (object.isValid()) { |
| @@ -370,8 +384,10 @@ void ScriptEngine::registerFunction(const QString& parent, const QString& name, · 5 unmodified lines | ||
| 370 | 384 | void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter, |
| 371 | 385 | QScriptEngine::FunctionSignature setter, const QString& parent) { |
| 372 | 386 | if (QThread::currentThread() != thread()) { |
| 387 | + #ifdef THREAD_DEBUGGING | |
| 373 | 388 | qDebug() << "*** WARNING *** ScriptEngine::registerGetterSetter() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 374 | 389 | " name:" << name << "parent:" << parent; |
| 390 | + #endif | |
| 375 | 391 | QMetaObject::invokeMethod(this, "registerGetterSetter", |
| 376 | 392 | Q_ARG(const QString&, name), |
| 377 | 393 | Q_ARG(QScriptEngine::FunctionSignature, getter), |
| @@ -379,7 +395,9 @@ void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::Func · 1 unmodified line | ||
| 379 | 395 | Q_ARG(const QString&, parent)); |
| 380 | 396 | return; |
| 381 | 397 | } |
| 382 | − //qDebug() << "ScriptEngine::registerGetterSetter() called on thread [" << QThread::currentThread() << "] name:" << name << "parent:" << parent; | |
| 398 | + #ifdef THREAD_DEBUGGING | |
| 399 | + qDebug() << "ScriptEngine::registerGetterSetter() called on thread [" << QThread::currentThread() << "] name:" << name << "parent:" << parent; | |
| 400 | + #endif | |
| 383 | 401 | |
| 384 | 402 | QScriptValue setterFunction = newFunction(setter, 1); |
| 385 | 403 | QScriptValue getterFunction = newFunction(getter); |
| @@ -399,15 +417,19 @@ void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::Func · 13 unmodified lines | ||
| 399 | 417 | // Unregister the handlers for this eventName and entityID. |
| 400 | 418 | void ScriptEngine::removeEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler) { |
| 401 | 419 | if (QThread::currentThread() != thread()) { |
| 420 | + #ifdef THREAD_DEBUGGING | |
| 402 | 421 | qDebug() << "*** WARNING *** ScriptEngine::removeEventHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 403 | 422 | "entityID:" << entityID << " eventName:" << eventName; |
| 423 | + #endif | |
| 404 | 424 | QMetaObject::invokeMethod(this, "removeEventHandler", |
| 405 | 425 | Q_ARG(const EntityItemID&, entityID), |
| 406 | 426 | Q_ARG(const QString&, eventName), |
| 407 | 427 | Q_ARG(QScriptValue, handler)); |
| 408 | 428 | return; |
| 409 | 429 | } |
| 410 | − //qDebug() << "ScriptEngine::removeEventHandler() called on thread [" << QThread::currentThread() << "] entityID:" << entityID << " eventName : " << eventName; | |
| 430 | + #ifdef THREAD_DEBUGGING | |
| 431 | + qDebug() << "ScriptEngine::removeEventHandler() called on thread [" << QThread::currentThread() << "] entityID:" << entityID << " eventName : " << eventName; | |
| 432 | + #endif | |
| 411 | 433 | |
| 412 | 434 | if (!_registeredHandlers.contains(entityID)) { |
| 413 | 435 | return; |
| @@ -425,15 +447,20 @@ void ScriptEngine::removeEventHandler(const EntityItemID& entityID, const QStrin · 11 unmodified lines | ||
| 425 | 447 | // Register the handler. |
| 426 | 448 | void ScriptEngine::addEventHandler(const EntityItemID& entityID, const QString& eventName, QScriptValue handler) { |
| 427 | 449 | if (QThread::currentThread() != thread()) { |
| 450 | + #ifdef THREAD_DEBUGGING | |
| 428 | 451 | qDebug() << "*** WARNING *** ScriptEngine::addEventHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 429 | 452 | "entityID:" << entityID << " eventName:" << eventName; |
| 453 | + #endif | |
| 454 | + | |
| 430 | 455 | QMetaObject::invokeMethod(this, "addEventHandler", |
| 431 | 456 | Q_ARG(const EntityItemID&, entityID), |
| 432 | 457 | Q_ARG(const QString&, eventName), |
| 433 | 458 | Q_ARG(QScriptValue, handler)); |
| 434 | 459 | return; |
| 435 | 460 | } |
| 436 | − //qDebug() << "ScriptEngine::addEventHandler() called on thread [" << QThread::currentThread() << "] entityID:" << entityID << " eventName : " << eventName; | |
| 461 | + #ifdef THREAD_DEBUGGING | |
| 462 | + qDebug() << "ScriptEngine::addEventHandler() called on thread [" << QThread::currentThread() << "] entityID:" << entityID << " eventName : " << eventName; | |
| 463 | + #endif | |
| 437 | 464 | |
| 438 | 465 | if (_registeredHandlers.count() == 0) { // First time any per-entity handler has been added in this script... |
| 439 | 466 | // Connect up ALL the handlers to the global entities object's signals. |
| @@ -496,8 +523,10 @@ QScriptValue ScriptEngine::evaluate(const QString& program, const QString& fileN · 56 unmodified lines | ||
| 496 | 523 | |
| 497 | 524 | if (QThread::currentThread() != thread()) { |
| 498 | 525 | QScriptValue result; |
| 526 | + #ifdef THREAD_DEBUGGING | |
| 499 | 527 | qDebug() << "*** WARNING *** ScriptEngine::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 500 | 528 | "program:" << program << " fileName:" << fileName << "lineNumber:" << lineNumber; |
| 529 | + #endif | |
| 501 | 530 | QMetaObject::invokeMethod(this, "evaluate", Qt::BlockingQueuedConnection, |
| 502 | 531 | Q_RETURN_ARG(QScriptValue, result), |
| 503 | 532 | Q_ARG(const QString&, program), |
| @@ -854,10 +883,10 @@ void ScriptEngine::generalHandler(const EntityItemID& entityID, const QString& e · 350 unmodified lines | ||
| 854 | 883 | // for the download |
| 855 | 884 | void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) { |
| 856 | 885 | if (QThread::currentThread() != thread()) { |
| 886 | + #ifdef THREAD_DEBUGGING | |
| 857 | 887 | qDebug() << "*** WARNING *** ScriptEngine::loadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 858 | − "entityID:" << entityID << | |
| 859 | − "entityScript:" << entityScript << | |
| 860 | − "forceRedownload:" << forceRedownload; | |
| 888 | + "entityID:" << entityID << "entityScript:" << entityScript <<"forceRedownload:" << forceRedownload; | |
| 889 | + #endif | |
| 861 | 890 | |
| 862 | 891 | QMetaObject::invokeMethod(this, "loadEntityScript", |
| 863 | 892 | Q_ARG(const EntityItemID&, entityID), |
| @@ -865,71 +894,104 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 1 unmodified line | ||
| 865 | 894 | Q_ARG(bool, forceRedownload)); |
| 866 | 895 | return; |
| 867 | 896 | } |
| 897 | + #ifdef THREAD_DEBUGGING | |
| 868 | 898 | qDebug() << "ScriptEngine::loadEntityScript() called on correct thread [" << thread() << "] " |
| 869 | − "entityID:" << entityID << | |
| 870 | − "entityScript:" << entityScript << | |
| 871 | − "forceRedownload:" << forceRedownload; | |
| 899 | + "entityID:" << entityID << "entityScript:" << entityScript << "forceRedownload:" << forceRedownload; | |
| 900 | + #endif | |
| 872 | 901 | |
| 873 | 902 | // If we've been called our known entityScripts should not know about us.. |
| 874 | 903 | assert(!_entityScripts.contains(entityID)); |
| 875 | 904 | |
| 876 | − auto scriptCache = DependencyManager::get<ScriptCache>(); | |
| 905 | + #ifdef THREAD_DEBUGGING | |
| 906 | + qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]"; | |
| 907 | + #endif | |
| 908 | + DependencyManager::get<ScriptCache>()->getScriptContents(entityScript, [=](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) { | |
| 909 | + #ifdef THREAD_DEBUGGING | |
| 910 | + qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]"; | |
| 911 | + #endif | |
| 877 | 912 | |
| 878 | − scriptCache->getScriptContents(entityScript, [=](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) { | |
| 913 | + this->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success); | |
| 914 | + }, forceRedownload); | |
| 915 | +} | |
| 879 | 916 | |
| 880 | − // first check the syntax of the script contents | |
| 881 | − QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(contents); | |
| 882 | − if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) { | |
| 883 | − qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID; | |
| 884 | − qCDebug(scriptengine) << " " << syntaxCheck.errorMessage() << ":" | |
| 885 | − << syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber(); | |
| 886 | − qCDebug(scriptengine) << " SCRIPT:" << scriptOrURL; | |
| 887 | − scriptCache->addScriptToBadScriptList(scriptOrURL); | |
| 888 | − return; // done processing script | |
| 889 | − } | |
| 917 | +// since all of these operations can be asynch we will always do the actual work in the response handler | |
| 918 | +// for the download | |
| 919 | +void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success) { | |
| 920 | + if (QThread::currentThread() != thread()) { | |
| 921 | + #ifdef THREAD_DEBUGGING | |
| 922 | + qDebug() << "*** WARNING *** ScriptEngine::entityScriptContentAvailable() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | |
| 923 | + "entityID:" << entityID << "scriptOrURL:" << scriptOrURL << "contents:" << contents << "isURL:" << isURL << "success:" << success; | |
| 924 | + #endif | |
| 890 | 925 | |
| 891 | − if (isURL) { | |
| 892 | − setParentURL(scriptOrURL); | |
| 893 | − } | |
| 926 | + QMetaObject::invokeMethod(this, "entityScriptContentAvailable", | |
| 927 | + Q_ARG(const EntityItemID&, entityID), | |
| 928 | + Q_ARG(const QString&, scriptOrURL), | |
| 929 | + Q_ARG(const QString&, contents), | |
| 930 | + Q_ARG(bool, isURL), | |
| 931 | + Q_ARG(bool, success)); | |
| 932 | + return; | |
| 933 | + } | |
| 894 | 934 | |
| 895 | − QScriptEngine sandbox; | |
| 896 | − QScriptValue testConstructor = sandbox.evaluate(contents); | |
| 935 | + #ifdef THREAD_DEBUGGING | |
| 936 | + qDebug() << "ScriptEngine::entityScriptContentAvailable() thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]"; | |
| 937 | + #endif | |
| 897 | 938 | |
| 898 | − if (!testConstructor.isFunction()) { | |
| 899 | − qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID; | |
| 900 | − qCDebug(scriptengine) << " NOT CONSTRUCTOR"; | |
| 901 | − qCDebug(scriptengine) << " SCRIPT:" << scriptOrURL; | |
| 902 | − scriptCache->addScriptToBadScriptList(scriptOrURL); | |
| 903 | − return; // done processing script | |
| 904 | − } | |
| 939 | + auto scriptCache = DependencyManager::get<ScriptCache>(); | |
| 905 | 940 | |
| 906 | − QScriptValue entityScriptConstructor = evaluate(contents); | |
| 941 | + // first check the syntax of the script contents | |
| 942 | + QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(contents); | |
| 943 | + if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) { | |
| 944 | + qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID; | |
| 945 | + qCDebug(scriptengine) << " " << syntaxCheck.errorMessage() << ":" | |
| 946 | + << syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber(); | |
| 947 | + qCDebug(scriptengine) << " SCRIPT:" << scriptOrURL; | |
| 948 | + scriptCache->addScriptToBadScriptList(scriptOrURL); | |
| 949 | + return; // done processing script | |
| 950 | + } | |
| 907 | 951 | |
| 908 | − QScriptValue entityScriptObject = entityScriptConstructor.construct(); | |
| 909 | − EntityScriptDetails newDetails = { scriptOrURL, entityScriptObject }; | |
| 910 | − _entityScripts[entityID] = newDetails; | |
| 952 | + if (isURL) { | |
| 953 | + setParentURL(scriptOrURL); | |
| 954 | + } | |
| 911 | 955 | |
| 912 | − if (isURL) { | |
| 913 | − setParentURL(""); | |
| 914 | − } | |
| 956 | + QScriptEngine sandbox; | |
| 957 | + QScriptValue testConstructor = sandbox.evaluate(contents); | |
| 915 | 958 | |
| 916 | − // if we got this far, then call the preload method | |
| 917 | − callEntityScriptMethod(entityID, "preload"); | |
| 959 | + if (!testConstructor.isFunction()) { | |
| 960 | + qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID; | |
| 961 | + qCDebug(scriptengine) << " NOT CONSTRUCTOR"; | |
| 962 | + qCDebug(scriptengine) << " SCRIPT:" << scriptOrURL; | |
| 963 | + scriptCache->addScriptToBadScriptList(scriptOrURL); | |
| 964 | + return; // done processing script | |
| 965 | + } | |
| 966 | + | |
| 967 | + QScriptValue entityScriptConstructor = evaluate(contents); | |
| 918 | 968 | |
| 919 | − }, forceRedownload); | |
| 969 | + QScriptValue entityScriptObject = entityScriptConstructor.construct(); | |
| 970 | + EntityScriptDetails newDetails = { scriptOrURL, entityScriptObject }; | |
| 971 | + _entityScripts[entityID] = newDetails; | |
| 972 | + if (isURL) { | |
| 973 | + setParentURL(""); | |
| 974 | + } | |
| 975 | + | |
| 976 | + // if we got this far, then call the preload method | |
| 977 | + callEntityScriptMethod(entityID, "preload"); | |
| 920 | 978 | } |
| 921 | 979 | |
| 922 | 980 | void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { |
| 923 | 981 | if (QThread::currentThread() != thread()) { |
| 982 | + #ifdef THREAD_DEBUGGING | |
| 924 | 983 | qDebug() << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 925 | 984 | "entityID:" << entityID; |
| 985 | + #endif | |
| 926 | 986 | |
| 927 | 987 | QMetaObject::invokeMethod(this, "unloadEntityScript", |
| 928 | 988 | Q_ARG(const EntityItemID&, entityID)); |
| 929 | 989 | return; |
| 930 | 990 | } |
| 991 | + #ifdef THREAD_DEBUGGING | |
| 931 | 992 | qDebug() << "ScriptEngine::unloadEntityScript() called on correct thread [" << thread() << "] " |
| 932 | 993 | "entityID:" << entityID; |
| 994 | + #endif | |
| 933 | 995 | |
| 934 | 996 | if (_entityScripts.contains(entityID)) { |
| 935 | 997 | callEntityScriptMethod(entityID, "unload"); |
| @@ -939,18 +1001,20 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 3 unmodified lines | ||
| 939 | 1001 | |
| 940 | 1002 | void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName) { |
| 941 | 1003 | if (QThread::currentThread() != thread()) { |
| 1004 | + #ifdef THREAD_DEBUGGING | |
| 942 | 1005 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 943 | − "entityID:" << entityID << | |
| 944 | − "methodName:" << methodName; | |
| 1006 | + "entityID:" << entityID << "methodName:" << methodName; | |
| 1007 | + #endif | |
| 945 | 1008 | |
| 946 | 1009 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", |
| 947 | 1010 | Q_ARG(const EntityItemID&, entityID), |
| 948 | 1011 | Q_ARG(const QString&, methodName)); |
| 949 | 1012 | return; |
| 950 | 1013 | } |
| 1014 | + #ifdef THREAD_DEBUGGING | |
| 951 | 1015 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " |
| 952 | − "entityID:" << entityID << | |
| 953 | − "methodName:" << methodName; | |
| 1016 | + "entityID:" << entityID << "methodName:" << methodName; | |
| 1017 | + #endif | |
| 954 | 1018 | |
| 955 | 1019 | if (_entityScripts.contains(entityID)) { |
| 956 | 1020 | EntityScriptDetails details = _entityScripts[entityID]; |
| @@ -960,15 +1024,16 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 3 unmodified lines | ||
| 960 | 1024 | args << entityID.toScriptValue(this); |
| 961 | 1025 | entityScript.property(methodName).call(entityScript, args); |
| 962 | 1026 | } |
| 1027 | + | |
| 963 | 1028 | } |
| 964 | 1029 | } |
| 965 | 1030 | |
| 966 | 1031 | void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const MouseEvent& event) { |
| 967 | 1032 | if (QThread::currentThread() != thread()) { |
| 1033 | + #ifdef THREAD_DEBUGGING | |
| 968 | 1034 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 969 | − "entityID:" << entityID << | |
| 970 | − "methodName:" << methodName << | |
| 971 | − "event: mouseEvent"; | |
| 1035 | + "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent"; | |
| 1036 | + #endif | |
| 972 | 1037 | |
| 973 | 1038 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", |
| 974 | 1039 | Q_ARG(const EntityItemID&, entityID), |
| @@ -976,10 +1041,10 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 1 unmodified line | ||
| 976 | 1041 | Q_ARG(const MouseEvent&, event)); |
| 977 | 1042 | return; |
| 978 | 1043 | } |
| 1044 | + #ifdef THREAD_DEBUGGING | |
| 979 | 1045 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " |
| 980 | − "entityID:" << entityID << | |
| 981 | − "methodName:" << methodName << | |
| 982 | − "event: mouseEvent"; | |
| 1046 | + "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent"; | |
| 1047 | + #endif | |
| 983 | 1048 | |
| 984 | 1049 | if (_entityScripts.contains(entityID)) { |
| 985 | 1050 | EntityScriptDetails details = _entityScripts[entityID]; |
| @@ -996,11 +1061,10 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 10 unmodified lines | ||
| 996 | 1061 | |
| 997 | 1062 | void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const EntityItemID& otherID, const Collision& collision) { |
| 998 | 1063 | if (QThread::currentThread() != thread()) { |
| 1064 | + #ifdef THREAD_DEBUGGING | |
| 999 | 1065 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 1000 | − "entityID:" << entityID << | |
| 1001 | − "methodName:" << methodName << | |
| 1002 | − "otherID:" << otherID << | |
| 1003 | − "collision: collision"; | |
| 1066 | + "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision"; | |
| 1067 | + #endif | |
| 1004 | 1068 | |
| 1005 | 1069 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", |
| 1006 | 1070 | Q_ARG(const EntityItemID&, entityID), |
| @@ -1009,11 +1073,10 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 2 unmodified lines | ||
| 1009 | 1073 | Q_ARG(const Collision&, collision)); |
| 1010 | 1074 | return; |
| 1011 | 1075 | } |
| 1076 | + #ifdef THREAD_DEBUGGING | |
| 1012 | 1077 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " |
| 1013 | − "entityID:" << entityID << | |
| 1014 | − "methodName:" << methodName << | |
| 1015 | − "otherID:" << otherID << | |
| 1016 | − "collision: collision"; | |
| 1078 | + "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision"; | |
| 1079 | + #endif | |
| 1017 | 1080 | |
| 1018 | 1081 | if (_entityScripts.contains(entityID)) { |
| 1019 | 1082 | EntityScriptDetails details = _entityScripts[entityID]; |