History

debugging

Brad Hefta-Gaub committed 9 years ago

Commit 82ab8631 parent 74384a63 files · +24 −8Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+11−6
@@ -928,22 +928,23 @@ void ScriptEngine::run() { · 927 unmodified lines
928 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());
929 auto closestUntil = std::min(remainingSleepUntil, untilTimer);929 auto closestUntil = std::min(remainingSleepUntil, untilTimer);
930 auto thisSleepUntil = std::min(sleepUntil, clock::now() + closestUntil);930 auto thisSleepUntil = std::min(sleepUntil, clock::now() + closestUntil);
931 auto untilThisSleepUntil = std::chrono::duration_cast<std::chrono::microseconds>(thisSleepUntil - clock::now());
931 932
932 // if the sleep until is more than 1 ms away, then don't sleep, and instead use a wait condition 933 // 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 // for any possible invoke methods that might also be pending.
934 const std::chrono::microseconds MAX_USECS_TO_SLEEP(USECS_PER_MSEC);935 const std::chrono::microseconds MAX_USECS_TO_SLEEP(USECS_PER_MSEC);
935 if (closestUntil < MAX_USECS_TO_SLEEP) {936 if (untilThisSleepUntil < MAX_USECS_TO_SLEEP) {
936 qDebug() << "about to sleep:" << closestUntil.count() << "usec";937 qDebug() << "[" << getFilename() << "]" << "about to sleep untilThisSleepUntil:" << untilThisSleepUntil.count() << "usec -- averageTimerPerFrame:" << averageTimerPerFrame.count();
937 std::this_thread::sleep_until(thisSleepUntil);938 std::this_thread::sleep_until(thisSleepUntil);
938 } else {939 } else {
939 // FIXME - we might want to make this 1 less ms to wait940 // FIXME - we might want to make this 1 less ms to wait
940 unsigned long maxWait = closestUntil.count() / USECS_PER_MSEC;941 unsigned long maxWait = untilThisSleepUntil.count() / USECS_PER_MSEC;
941 qDebug() << "about to wait:" << maxWait << "ms --- closestUntil:" << closestUntil.count() << "usec";942 qDebug() << "[" << getFilename() << "]" << "about to wait:" << maxWait << "ms --- untilThisSleepUntil:" << untilThisSleepUntil.count() << "usec -- averageTimerPerFrame:" << averageTimerPerFrame.count();
942 _waitingOnInvokeMethod.lock();943 _waitingOnInvokeMethod.lock();
943 bool signalled = _hasInvokeMethod.wait(&_waitingOnInvokeMethod, maxWait);944 bool signalled = _hasInvokeMethod.wait(&_waitingOnInvokeMethod, maxWait);
944 _waitingOnInvokeMethod.unlock();945 _waitingOnInvokeMethod.unlock();
945 if (signalled) {946 if (signalled) {
946 qDebug() << "SIGNALLED!! done waiting... now:" << usecTimestampNow();947 qDebug() << "[" << getFilename() << "]" << "SIGNALLED!! done waiting... now:" << usecTimestampNow();
947 }948 }
948 949
949 }950 }
@@ -1664,13 +1665,15 @@ void ScriptEngine::callWithEnvironment(const EntityItemID& entityID, const QUrl& · 714 unmodified lines
1664}1665}
1665 1666
1666void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const QStringList& params) {1667void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QString& methodName, const QStringList& params) {
1668 qDebug() << "[" << getFilename() << "]" << __FUNCTION__ << "method:" << methodName << "now:" << usecTimestampNow();
1669
1667 if (QThread::currentThread() != thread()) {1670 if (QThread::currentThread() != thread()) {
1668#ifdef THREAD_DEBUGGING1671#ifdef THREAD_DEBUGGING
1669 qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "1672 qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
1670 "entityID:" << entityID << "methodName:" << methodName;1673 "entityID:" << entityID << "methodName:" << methodName;
1671#endif1674#endif
1672 1675
1673 qDebug() << "about to invokeMethod callEntityScriptMethod() now:" << usecTimestampNow();1676 qDebug() << "[" << getFilename() << "]" << "about to invokeMethod callEntityScriptMethod() now:" << usecTimestampNow();
1674 1677
1675 QMetaObject::invokeMethod(this, "callEntityScriptMethod",1678 QMetaObject::invokeMethod(this, "callEntityScriptMethod",
1676 Q_ARG(const EntityItemID&, entityID),1679 Q_ARG(const EntityItemID&, entityID),
@@ -1692,6 +1695,8 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 15 unmodified lines
1692 QScriptValueList args;1695 QScriptValueList args;
1693 args << entityID.toScriptValue(this);1696 args << entityID.toScriptValue(this);
1694 args << qScriptValueFromSequence(this, params);1697 args << qScriptValueFromSequence(this, params);
1698
1699 qDebug() << "[" << getFilename() << "]" << __FUNCTION__ << "about to callWithEnvironment()... method:" << methodName << "now:" << usecTimestampNow();
1695 callWithEnvironment(entityID, details.definingSandboxURL, entityScript.property(methodName), entityScript, args);1700 callWithEnvironment(entityID, details.definingSandboxURL, entityScript.property(methodName), entityScript, args);
1696 }1701 }
1697 1702