Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all
Unified · Split
| @@ -573,6 +573,7 @@ void ScriptEngine::registerValue(const QString& valueName, QScriptValue value) { · 572 unmodified lines | |||
| 573 | QMetaObject::invokeMethod(this, "registerValue", | 573 | QMetaObject::invokeMethod(this, "registerValue", |
| 574 | Q_ARG(const QString&, valueName), | 574 | Q_ARG(const QString&, valueName), |
| 575 | Q_ARG(QScriptValue, value)); | 575 | Q_ARG(QScriptValue, value)); |
| 576 | _hasInvokeMethod.wakeAll(); | ||
| 576 | return; | 577 | return; |
| 577 | } | 578 | } |
| 578 | 579 | ||
| @@ -603,6 +604,7 @@ void ScriptEngine::registerGlobalObject(const QString& name, QObject* object) { · 24 unmodified lines | |||
| 603 | QMetaObject::invokeMethod(this, "registerGlobalObject", | 604 | QMetaObject::invokeMethod(this, "registerGlobalObject", |
| 604 | Q_ARG(const QString&, name), | 605 | Q_ARG(const QString&, name), |
| 605 | Q_ARG(QObject*, object)); | 606 | Q_ARG(QObject*, object)); |
| 607 | _hasInvokeMethod.wakeAll(); | ||
| 606 | return; | 608 | return; |
| 607 | } | 609 | } |
| 608 | #ifdef THREAD_DEBUGGING | 610 | #ifdef THREAD_DEBUGGING |
| @@ -628,6 +630,7 @@ void ScriptEngine::registerFunction(const QString& name, QScriptEngine::Function · 19 unmodified lines | |||
| 628 | Q_ARG(const QString&, name), | 630 | Q_ARG(const QString&, name), |
| 629 | Q_ARG(QScriptEngine::FunctionSignature, functionSignature), | 631 | Q_ARG(QScriptEngine::FunctionSignature, functionSignature), |
| 630 | Q_ARG(int, numArguments)); | 632 | Q_ARG(int, numArguments)); |
| 633 | _hasInvokeMethod.wakeAll(); | ||
| 631 | return; | 634 | return; |
| 632 | } | 635 | } |
| 633 | #ifdef THREAD_DEBUGGING | 636 | #ifdef THREAD_DEBUGGING |
| @@ -647,6 +650,7 @@ void ScriptEngine::registerFunction(const QString& parent, const QString& name, · 13 unmodified lines | |||
| 647 | Q_ARG(const QString&, name), | 650 | Q_ARG(const QString&, name), |
| 648 | Q_ARG(QScriptEngine::FunctionSignature, functionSignature), | 651 | Q_ARG(QScriptEngine::FunctionSignature, functionSignature), |
| 649 | Q_ARG(int, numArguments)); | 652 | Q_ARG(int, numArguments)); |
| 653 | _hasInvokeMethod.wakeAll(); | ||
| 650 | return; | 654 | return; |
| 651 | } | 655 | } |
| 652 | #ifdef THREAD_DEBUGGING | 656 | #ifdef THREAD_DEBUGGING |
| @@ -672,6 +676,7 @@ void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::Func · 19 unmodified lines | |||
| 672 | Q_ARG(QScriptEngine::FunctionSignature, getter), | 676 | Q_ARG(QScriptEngine::FunctionSignature, getter), |
| 673 | Q_ARG(QScriptEngine::FunctionSignature, setter), | 677 | Q_ARG(QScriptEngine::FunctionSignature, setter), |
| 674 | Q_ARG(const QString&, parent)); | 678 | Q_ARG(const QString&, parent)); |
| 679 | _hasInvokeMethod.wakeAll(); | ||
| 675 | return; | 680 | return; |
| 676 | } | 681 | } |
| 677 | #ifdef THREAD_DEBUGGING | 682 | #ifdef THREAD_DEBUGGING |
| @@ -704,6 +709,7 @@ void ScriptEngine::removeEventHandler(const EntityItemID& entityID, const QStrin · 26 unmodified lines | |||
| 704 | Q_ARG(const EntityItemID&, entityID), | 709 | Q_ARG(const EntityItemID&, entityID), |
| 705 | Q_ARG(const QString&, eventName), | 710 | Q_ARG(const QString&, eventName), |
| 706 | Q_ARG(QScriptValue, handler)); | 711 | Q_ARG(QScriptValue, handler)); |
| 712 | _hasInvokeMethod.wakeAll(); | ||
| 707 | return; | 713 | return; |
| 708 | } | 714 | } |
| 709 | #ifdef THREAD_DEBUGGING | 715 | #ifdef THREAD_DEBUGGING |
| @@ -735,6 +741,7 @@ void ScriptEngine::addEventHandler(const EntityItemID& entityID, const QString& · 25 unmodified lines | |||
| 735 | Q_ARG(const EntityItemID&, entityID), | 741 | Q_ARG(const EntityItemID&, entityID), |
| 736 | Q_ARG(const QString&, eventName), | 742 | Q_ARG(const QString&, eventName), |
| 737 | Q_ARG(QScriptValue, handler)); | 743 | Q_ARG(QScriptValue, handler)); |
| 744 | _hasInvokeMethod.wakeAll(); | ||
| 738 | return; | 745 | return; |
| 739 | } | 746 | } |
| 740 | #ifdef THREAD_DEBUGGING | 747 | #ifdef THREAD_DEBUGGING |
| @@ -821,6 +828,7 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi · 80 unmodified lines | |||
| 821 | Q_ARG(const QString&, sourceCode), | 828 | Q_ARG(const QString&, sourceCode), |
| 822 | Q_ARG(const QString&, fileName), | 829 | Q_ARG(const QString&, fileName), |
| 823 | Q_ARG(int, lineNumber)); | 830 | Q_ARG(int, lineNumber)); |
| 831 | _hasInvokeMethod.wakeAll(); | ||
| 824 | return result; | 832 | return result; |
| 825 | } | 833 | } |
| 826 | 834 | ||
| @@ -920,7 +928,25 @@ void ScriptEngine::run() { · 93 unmodified lines | |||
| 920 | auto remainingSleepUntil = std::chrono::duration_cast<std::chrono::microseconds>(sleepUntil - clock::now()); | 928 | auto remainingSleepUntil = std::chrono::duration_cast<std::chrono::microseconds>(sleepUntil - clock::now()); |
| 921 | auto closestUntil = std::min(remainingSleepUntil, untilTimer); | 929 | auto closestUntil = std::min(remainingSleepUntil, untilTimer); |
| 922 | auto thisSleepUntil = std::min(sleepUntil, clock::now() + closestUntil); | 930 | auto thisSleepUntil = std::min(sleepUntil, clock::now() + closestUntil); |
| 923 | std::this_thread::sleep_until(thisSleepUntil); | 931 | |
| 932 | // if the sleep until is more than 1 ms away, then don't sleep, and instead use a wait condition | ||
| 933 | // for any possible invoke methods that might also be pending. | ||
| 934 | const std::chrono::microseconds MAX_USECS_TO_SLEEP(USECS_PER_MSEC); | ||
| 935 | if (closestUntil < MAX_USECS_TO_SLEEP) { | ||
| 936 | qDebug() << "about to sleep:" << closestUntil.count() << "usec"; | ||
| 937 | std::this_thread::sleep_until(thisSleepUntil); | ||
| 938 | } else { | ||
| 939 | // FIXME - we might want to make this 1 less ms to wait | ||
| 940 | unsigned long maxWait = closestUntil.count() / USECS_PER_MSEC; | ||
| 941 | qDebug() << "about to wait:" << maxWait << "ms --- closestUntil:" << closestUntil.count() << "usec"; | ||
| 942 | _waitingOnInvokeMethod.lock(); | ||
| 943 | bool signalled = _hasInvokeMethod.wait(&_waitingOnInvokeMethod, maxWait); | ||
| 944 | _waitingOnInvokeMethod.unlock(); | ||
| 945 | if (signalled) { | ||
| 946 | qDebug() << "SIGNALLED!! done waiting... now:" << usecTimestampNow(); | ||
| 947 | } | ||
| 948 | |||
| 949 | } | ||
| 924 | } | 950 | } |
| 925 | 951 | ||
| 926 | #ifdef SCRIPT_DELAY_DEBUG | 952 | #ifdef SCRIPT_DELAY_DEBUG |
| @@ -1058,6 +1084,7 @@ void ScriptEngine::stop(bool marshal) { · 131 unmodified lines | |||
| 1058 | 1084 | ||
| 1059 | if (marshal) { | 1085 | if (marshal) { |
| 1060 | QMetaObject::invokeMethod(this, "stop"); | 1086 | QMetaObject::invokeMethod(this, "stop"); |
| 1087 | _hasInvokeMethod.wakeAll(); | ||
| 1061 | return; | 1088 | return; |
| 1062 | } | 1089 | } |
| 1063 | if (!_isFinished) { | 1090 | if (!_isFinished) { |
| @@ -1078,6 +1105,7 @@ void ScriptEngine::callAnimationStateHandler(QScriptValue callback, AnimVariantM · 14 unmodified lines | |||
| 1078 | Q_ARG(QStringList, names), | 1105 | Q_ARG(QStringList, names), |
| 1079 | Q_ARG(bool, useNames), | 1106 | Q_ARG(bool, useNames), |
| 1080 | Q_ARG(AnimVariantResultHandler, resultHandler)); | 1107 | Q_ARG(AnimVariantResultHandler, resultHandler)); |
| 1108 | _hasInvokeMethod.wakeAll(); | ||
| 1081 | return; | 1109 | return; |
| 1082 | } | 1110 | } |
| 1083 | QScriptValue javascriptParameters = parameters.animVariantMapToScriptValue(this, names, useNames); | 1111 | QScriptValue javascriptParameters = parameters.animVariantMapToScriptValue(this, names, useNames); |
| @@ -1428,6 +1456,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 344 unmodified lines | |||
| 1428 | Q_ARG(const QString&, contents), | 1456 | Q_ARG(const QString&, contents), |
| 1429 | Q_ARG(bool, isURL), | 1457 | Q_ARG(bool, isURL), |
| 1430 | Q_ARG(bool, success)); | 1458 | Q_ARG(bool, success)); |
| 1459 | _hasInvokeMethod.wakeAll(); | ||
| 1431 | return; | 1460 | return; |
| 1432 | } | 1461 | } |
| 1433 | 1462 | ||
| @@ -1526,6 +1555,7 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 92 unmodified lines | |||
| 1526 | 1555 | ||
| 1527 | QMetaObject::invokeMethod(this, "unloadEntityScript", | 1556 | QMetaObject::invokeMethod(this, "unloadEntityScript", |
| 1528 | Q_ARG(const EntityItemID&, entityID)); | 1557 | Q_ARG(const EntityItemID&, entityID)); |
| 1558 | _hasInvokeMethod.wakeAll(); | ||
| 1529 | return; | 1559 | return; |
| 1530 | } | 1560 | } |
| 1531 | #ifdef THREAD_DEBUGGING | 1561 | #ifdef THREAD_DEBUGGING |
| @@ -1547,6 +1577,7 @@ void ScriptEngine::unloadAllEntityScripts() { · 15 unmodified lines | |||
| 1547 | #endif | 1577 | #endif |
| 1548 | 1578 | ||
| 1549 | QMetaObject::invokeMethod(this, "unloadAllEntityScripts"); | 1579 | QMetaObject::invokeMethod(this, "unloadAllEntityScripts"); |
| 1580 | _hasInvokeMethod.wakeAll(); | ||
| 1550 | return; | 1581 | return; |
| 1551 | } | 1582 | } |
| 1552 | #ifdef THREAD_DEBUGGING | 1583 | #ifdef THREAD_DEBUGGING |
| @@ -1639,10 +1670,13 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 86 unmodified lines | |||
| 1639 | "entityID:" << entityID << "methodName:" << methodName; | 1670 | "entityID:" << entityID << "methodName:" << methodName; |
| 1640 | #endif | 1671 | #endif |
| 1641 | 1672 | ||
| 1673 | qDebug() << "about to invokeMethod callEntityScriptMethod() now:" << usecTimestampNow(); | ||
| 1674 | |||
| 1642 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", | 1675 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", |
| 1643 | Q_ARG(const EntityItemID&, entityID), | 1676 | Q_ARG(const EntityItemID&, entityID), |
| 1644 | Q_ARG(const QString&, methodName), | 1677 | Q_ARG(const QString&, methodName), |
| 1645 | Q_ARG(const QStringList&, params)); | 1678 | Q_ARG(const QStringList&, params)); |
| 1679 | _hasInvokeMethod.wakeAll(); | ||
| 1646 | return; | 1680 | return; |
| 1647 | } | 1681 | } |
| 1648 | #ifdef THREAD_DEBUGGING | 1682 | #ifdef THREAD_DEBUGGING |
| @@ -1675,6 +1709,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 26 unmodified lines | |||
| 1675 | Q_ARG(const EntityItemID&, entityID), | 1709 | Q_ARG(const EntityItemID&, entityID), |
| 1676 | Q_ARG(const QString&, methodName), | 1710 | Q_ARG(const QString&, methodName), |
| 1677 | Q_ARG(const PointerEvent&, event)); | 1711 | Q_ARG(const PointerEvent&, event)); |
| 1712 | _hasInvokeMethod.wakeAll(); | ||
| 1678 | return; | 1713 | return; |
| 1679 | } | 1714 | } |
| 1680 | #ifdef THREAD_DEBUGGING | 1715 | #ifdef THREAD_DEBUGGING |
| @@ -1708,6 +1743,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 27 unmodified lines | |||
| 1708 | Q_ARG(const QString&, methodName), | 1743 | Q_ARG(const QString&, methodName), |
| 1709 | Q_ARG(const EntityItemID&, otherID), | 1744 | Q_ARG(const EntityItemID&, otherID), |
| 1710 | Q_ARG(const Collision&, collision)); | 1745 | Q_ARG(const Collision&, collision)); |
| 1746 | _hasInvokeMethod.wakeAll(); | ||
| 1711 | return; | 1747 | return; |
| 1712 | } | 1748 | } |
| 1713 | #ifdef THREAD_DEBUGGING | 1749 | #ifdef THREAD_DEBUGGING |