Showing the changes to interface/src/scripting/TestScriptingInterface.cpp (1 of 7 files). Show all
Unified · Split
| @@ -5,15 +5,17 @@ · 4 unmodified lines | |||
| 5 | // Distributed under the Apache License, Version 2.0. | 5 | // Distributed under the Apache License, Version 2.0. |
| 6 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | 6 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 7 | // | 7 | // |
| 8 | |||
| 9 | |||
| 10 | #include "TestScriptingInterface.h" | 8 | #include "TestScriptingInterface.h" |
| 11 | 9 | ||
| 12 | #include <QtCore/QCoreApplication> | 10 | #include <QtCore/QCoreApplication> |
| 13 | #include <QtCore/QLoggingCategory> | 11 | #include <QtCore/QLoggingCategory> |
| 12 | #include <QtCore/QThread> | ||
| 14 | 13 | ||
| 15 | #include <DependencyManager.h> | 14 | #include <DependencyManager.h> |
| 16 | #include <Trace.h> | 15 | #include <Trace.h> |
| 16 | #include <StatTracker.h> | ||
| 17 | |||
| 18 | #include "Application.h" | ||
| 17 | 19 | ||
| 18 | TestScriptingInterface* TestScriptingInterface::getInstance() { | 20 | TestScriptingInterface* TestScriptingInterface::getInstance() { |
| 19 | static TestScriptingInterface sharedInstance; | 21 | static TestScriptingInterface sharedInstance; |
| @@ -25,12 +27,51 @@ void TestScriptingInterface::quit() { · 5 unmodified lines | |||
| 25 | } | 27 | } |
| 26 | 28 | ||
| 27 | void TestScriptingInterface::waitForTextureIdle() { | 29 | void TestScriptingInterface::waitForTextureIdle() { |
| 30 | waitForCondition(0, []()->bool { | ||
| 31 | return (0 == gpu::Context::getTextureGPUTransferCount()); | ||
| 32 | }); | ||
| 28 | } | 33 | } |
| 29 | 34 | ||
| 30 | void TestScriptingInterface::waitForDownloadIdle() { | 35 | void TestScriptingInterface::waitForDownloadIdle() { |
| 36 | waitForCondition(0, []()->bool { | ||
| 37 | return (0 == ResourceCache::getLoadingRequestCount()) && (0 == ResourceCache::getPendingRequestCount()); | ||
| 38 | }); | ||
| 39 | } | ||
| 40 | |||
| 41 | void TestScriptingInterface::waitForProcessingIdle() { | ||
| 42 | auto statTracker = DependencyManager::get<StatTracker>(); | ||
| 43 | waitForCondition(0, [statTracker]()->bool { | ||
| 44 | return (0 == statTracker->getStat("Processing").toInt() && 0 == statTracker->getStat("PendingProcessing").toInt()); | ||
| 45 | }); | ||
| 31 | } | 46 | } |
| 32 | 47 | ||
| 33 | void TestScriptingInterface::waitIdle() { | 48 | void TestScriptingInterface::waitIdle() { |
| 49 | // Initial wait for some incoming work | ||
| 50 | QThread::sleep(1); | ||
| 51 | waitForDownloadIdle(); | ||
| 52 | waitForProcessingIdle(); | ||
| 53 | waitForTextureIdle(); | ||
| 54 | } | ||
| 55 | |||
| 56 | bool TestScriptingInterface::loadTestScene(QString scene) { | ||
| 57 | // FIXME implement | ||
| 58 | // qApp->postLambdaEvent([isClient] { | ||
| 59 | // auto tree = qApp->getEntityClipboard(); | ||
| 60 | // tree->setIsClient(isClient); | ||
| 61 | // }); | ||
| 62 | /* | ||
| 63 | Test.setClientTree(false); | ||
| 64 | Resources.overrideUrlPrefix("atp:/", TEST_BINARY_ROOT + scene + ".atp/"); | ||
| 65 | if (!Clipboard.importEntities(TEST_SCENES_ROOT + scene + ".json")) { | ||
| 66 | return false; | ||
| 67 | } | ||
| 68 | var position = { x: 0, y: 0, z: 0 }; | ||
| 69 | var pastedEntityIDs = Clipboard.pasteEntities(position); | ||
| 70 | for (var id in pastedEntityIDs) { | ||
| 71 | print("QQQ ID imported " + id); | ||
| 72 | } | ||
| 73 | */ | ||
| 74 | return false; | ||
| 34 | } | 75 | } |
| 35 | 76 | ||
| 36 | bool TestScriptingInterface::startTracing(QString logrules) { | 77 | bool TestScriptingInterface::startTracing(QString logrules) { |
| @@ -55,4 +96,35 @@ bool TestScriptingInterface::stopTracing(QString filename) { · 18 unmodified lines | |||
| 55 | tracer->stopTracing(); | 96 | tracer->stopTracing(); |
| 56 | tracer->serialize(filename); | 97 | tracer->serialize(filename); |
| 57 | return true; | 98 | return true; |
| 58 | } | 99 | } |
| 100 | |||
| 101 | void TestScriptingInterface::clear() { | ||
| 102 | qApp->postLambdaEvent([] { | ||
| 103 | qApp->getEntities()->clear(); | ||
| 104 | }); | ||
| 105 | } | ||
| 106 | |||
| 107 | bool TestScriptingInterface::waitForConnection(qint64 maxWaitMs) { | ||
| 108 | // Wait for any previous connection to die | ||
| 109 | QThread::sleep(1); | ||
| 110 | return waitForCondition(maxWaitMs, []()->bool { | ||
| 111 | return DependencyManager::get<NodeList>()->getDomainHandler().isConnected(); | ||
| 112 | }); | ||
| 113 | } | ||
| 114 | |||
| 115 | void TestScriptingInterface::wait(int milliseconds) { | ||
| 116 | QThread::msleep(milliseconds); | ||
| 117 | } | ||
| 118 | |||
| 119 | bool TestScriptingInterface::waitForCondition(qint64 maxWaitMs, std::function<bool()> condition) { | ||
| 120 | QElapsedTimer elapsed; | ||
| 121 | elapsed.start(); | ||
| 122 | while (!condition()) { | ||
| 123 | if (maxWaitMs > 0 && elapsed.elapsed() > maxWaitMs) { | ||
| 124 | return false; | ||
| 125 | } | ||
| 126 | QThread::msleep(1); | ||
| 127 | } | ||
| 128 | return condition(); | ||
| 129 | } | ||
| 130 | |||