diff --git a/libraries/shared/src/shared/FileUtils.cpp b/libraries/shared/src/shared/FileUtils.cpp index a89a873bea..8c962dfd6d 100644 --- a/libraries/shared/src/shared/FileUtils.cpp +++ b/libraries/shared/src/shared/FileUtils.cpp @@ -9,14 +9,29 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include -#include -#include -#include -#include #include "FileUtils.h" +#include +#include +#include +#include +#include +#include +#include + + +QString FileUtils::readFile(const QString& filename) { + QFile file(filename); + file.open(QFile::Text | QFile::ReadOnly); + QString result; + result.append(QTextStream(&file).readAll()); + return result; +} + +QStringList FileUtils::readLines(const QString& filename, QString::SplitBehavior splitBehavior) { + return readFile(filename).split(QRegularExpression("[\\r\\n]"), QString::SkipEmptyParts); +} void FileUtils::locateFile(QString filePath) { diff --git a/libraries/shared/src/shared/FileUtils.h b/libraries/shared/src/shared/FileUtils.h index d2b30595a7..4f2c1b7af5 100644 --- a/libraries/shared/src/shared/FileUtils.h +++ b/libraries/shared/src/shared/FileUtils.h @@ -19,7 +19,8 @@ class FileUtils { public: static void locateFile(QString fileName); static QString standardPath(QString subfolder); - + static QString readFile(const QString& filename); + static QStringList readLines(const QString& filename, QString::SplitBehavior splitBehavior = QString::KeepEmptyParts); }; #endif // hifi_FileUtils_h diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index 4745529f19..bf1ec283cf 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #include #include @@ -98,57 +100,6 @@ public: } }; -#if 0 -class GlfwCamera : public Camera { - Key forKey(int key) { - switch (key) { - case GLFW_KEY_W: return FORWARD; - case GLFW_KEY_S: return BACK; - case GLFW_KEY_A: return LEFT; - case GLFW_KEY_D: return RIGHT; - case GLFW_KEY_E: return UP; - case GLFW_KEY_C: return DOWN; - case GLFW_MOUSE_BUTTON_LEFT: return MLEFT; - case GLFW_MOUSE_BUTTON_RIGHT: return MRIGHT; - case GLFW_MOUSE_BUTTON_MIDDLE: return MMIDDLE; - default: break; - } - return INVALID; - } - - vec2 _lastMouse; -public: - void keyHandler(int key, int scancode, int action, int mods) { - Key k = forKey(key); - if (k == INVALID) { - return; - } - if (action == GLFW_PRESS) { - keys.set(k); - } else if (action == GLFW_RELEASE) { - keys.reset(k); - } - } - - //static void MouseMoveHandler(GLFWwindow* window, double posx, double posy); - //static void MouseScrollHandler(GLFWwindow* window, double xoffset, double yoffset); - void onMouseMove(double posx, double posy) { - vec2 mouse = vec2(posx, posy); - vec2 delta = mouse - _lastMouse; - if (keys.at(Key::MRIGHT)) { - dolly(delta.y * 0.01f); - } else if (keys.at(Key::MLEFT)) { - rotate(delta.x * -0.01f); - } else if (keys.at(Key::MMIDDLE)) { - delta.y *= -1.0f; - translate(delta * -0.01f); - } - _lastMouse = mouse; - } - -}; -#else - class QWindowCamera : public Camera { Key forKey(int key) { switch (key) { @@ -198,7 +149,6 @@ public: _lastMouse = mouse; } }; -#endif static QString toHumanSize(size_t size, size_t maxUnit = std::numeric_limits::max()) { static const std::vector SUFFIXES{ { "B", "KB", "MB", "GB", "TB", "PB" } }; @@ -241,7 +191,7 @@ public: std::mutex _mutex; std::shared_ptr _backend; std::vector _frameTimes; - size_t _frameIndex; + size_t _frameIndex { 0 }; std::mutex _frameLock; std::queue _pendingFrames; gpu::FramePointer _activeFrame; @@ -253,7 +203,6 @@ public: _pendingFrames.push(frame); } - void initialize(QWindow* window, gl::Context& initContext) { setObjectName("RenderThread"); _context.setWindow(window); @@ -372,7 +321,6 @@ public: } } - bool process() override { std::queue pendingFrames; { @@ -590,6 +538,16 @@ public: DependencyManager::destroy(); } + void loadCommands(const QString& filename) { + QFileInfo fileInfo(filename); + if (!fileInfo.exists()) { + return; + } + _commandPath = fileInfo.absolutePath(); + _commands = FileUtils::readLines(filename); + _commandIndex = 0; + } + protected: bool eventFilter(QObject *obj, QEvent *event) override { @@ -780,10 +738,76 @@ private: #endif } + void runCommand(const QString& command) { + QStringList commandParams = command.split(QRegularExpression(QString("\\s"))); + QString verb = commandParams[0].toLower(); + if (verb == "loop") { + if (commandParams.length() > 1) { + int maxLoops = commandParams[1].toInt(); + if (maxLoops > ++_commandLoops) { + qDebug() << "Exceeded loop count"; + return; + } + } + _commandIndex = 0; + } else if (verb == "wait") { + if (commandParams.length() < 2) { + qDebug() << "No wait time specified"; + return; + } + int seconds = commandParams[1].toInt(); + _nextCommandTime = usecTimestampNow() + seconds * USECS_PER_SECOND; + } else if (verb == "load") { + if (commandParams.length() < 2) { + qDebug() << "No load file specified"; + return; + } + QString file = commandParams[1]; + if (QFileInfo(file).isRelative()) { + file = _commandPath + "/" + file; + } + if (!QFileInfo(file).exists()) { + qDebug() << "Cannot find scene file " + file; + return; + } + + importScene(file); + } else if (verb == "go") { + if (commandParams.length() < 2) { + qDebug() << "No destination specified for go command"; + return; + } + parsePath(commandParams[1]); + } else { + qDebug() << "Unknown command " << command; + } + } + + void runNextCommand(quint64 now) { + if (_commands.empty()) { + return; + } + + if (_commandIndex >= _commands.size()) { + _commands.clear(); + return; + } + + if (now < _nextCommandTime) { + return; + } + + _nextCommandTime = 0; + QString command = _commands[_commandIndex++]; + runCommand(command); + } + void update() { auto now = usecTimestampNow(); static auto last = now; + runNextCommand(now); + float delta = now - last; // Update the camera _camera.update(delta / USECS_PER_SECOND); @@ -936,7 +960,6 @@ private: QString atpUrl = QUrl::fromLocalFile(atpPath).toString(); ResourceManager::setUrlPrefixOverride("atp:/", atpUrl + "/"); } - _settings.setValue(LAST_SCENE_KEY, fileName); _octree->clear(); _octree->getTree()->readFromURL(fileName); } @@ -955,6 +978,7 @@ private: if (fileName.isNull()) { return; } + _settings.setValue(LAST_SCENE_KEY, fileName); importScene(fileName); } @@ -1054,6 +1078,13 @@ private: model::SunSkyStage _sunSkyStage; model::LightPointer _globalLight { std::make_shared() }; bool _ready { false }; + + QStringList _commands; + QString _commandPath; + int _commandLoops { 0 }; + int _commandIndex { -1 }; + uint64_t _nextCommandTime { 0 }; + //TextOverlay* _textOverlay; static bool _cullingEnabled; @@ -1097,6 +1128,7 @@ int main(int argc, char** argv) { QLoggingCategory::setFilterRules(LOG_FILTER_RULES); QTestWindow::setup(); QTestWindow window; + window.loadCommands("C:/Users/bdavis/Git/dreaming/exports/commands.txt"); app.exec(); return 0; }