From d0c433ff1009a6609ad5908454a706ec5e19683d Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 9 Jun 2021 16:45:35 +0200 Subject: [PATCH] Add support to pause and continue playing a path --- .../autonavigation/autonavigationhandler.cpp | 66 +++++++++++-------- .../autonavigation/autonavigationhandler.h | 7 +- .../autonavigation/autonavigationmodule.cpp | 21 ++++-- .../autonavigationmodule_lua.inl | 44 ++++++++++--- 4 files changed, 92 insertions(+), 46 deletions(-) diff --git a/modules/autonavigation/autonavigationhandler.cpp b/modules/autonavigation/autonavigationhandler.cpp index 28929e3ebd..a700178d82 100644 --- a/modules/autonavigation/autonavigationhandler.cpp +++ b/modules/autonavigation/autonavigationhandler.cpp @@ -133,12 +133,12 @@ double AutoNavigationHandler::speedScale() const { return _speedScale; } -bool AutoNavigationHandler::noCurrentPath() const { - return _currentPath == nullptr; +bool AutoNavigationHandler::hasCurrentPath() const { + return _currentPath != nullptr; } bool AutoNavigationHandler::hasFinished() const { - if (noCurrentPath()) { + if (!hasCurrentPath()) { return true; } @@ -150,13 +150,13 @@ void AutoNavigationHandler::updateCamera(double deltaTime) { if (!_isPlaying) { // TODO: Determine how this should work - if (_applyStopBehaviorWhenIdle) { + if (hasFinished() && _applyStopBehaviorWhenIdle) { applyStopBehavior(deltaTime); } return; } - if (noCurrentPath()) { + if (!hasCurrentPath()) { return; } @@ -217,7 +217,6 @@ void AutoNavigationHandler::createPath(PathInstruction& instruction) { ); LINFO("Successfully generated camera path"); - startPath(); } void AutoNavigationHandler::clearPath() { @@ -226,7 +225,7 @@ void AutoNavigationHandler::clearPath() { } void AutoNavigationHandler::startPath() { - if (noCurrentPath()) { + if (!hasCurrentPath()) { LERROR("There is no path to start"); return; } @@ -241,21 +240,6 @@ void AutoNavigationHandler::startPath() { _isPlaying = true; } -//void AutoNavigationHandler::continuePath() { -// if (hasFinished()) { -// LERROR("No path to resume (path is empty or has finished)."); -// return; -// } -// -// if (_isPlaying) { -// LERROR("Cannot resume a path that is already playing"); -// return; -// } -// -// LINFO("Continuing path..."); -// _isPlaying = true; -//} - void AutoNavigationHandler::abortPath() { if (!_isPlaying) { LWARNING("No camera path is playing"); @@ -265,10 +249,40 @@ void AutoNavigationHandler::abortPath() { LINFO("Aborted camera path"); } +void AutoNavigationHandler::pausePath() { + if (hasFinished()) { + LERROR("No path to pause (path is empty or has finished)."); + return; + } + + if (!_isPlaying) { + LERROR("Cannot pause a path that is not playing"); + return; + } + + LINFO("Path paused"); + _isPlaying = false; +} + +void AutoNavigationHandler::continuePath() { + if (hasFinished()) { + LERROR("No path to resume (path is empty or has finished)."); + return; + } + + if (_isPlaying) { + LERROR("Cannot resume a path that is already playing"); + return; + } + + LINFO("Continuing path..."); + _isPlaying = true; +} + // TODO: remove when not needed // Created for debugging std::vector AutoNavigationHandler::curvePositions(int nSteps) const { - if (noCurrentPath()) { + if (!hasCurrentPath()) { LERROR("There is no current path to sample points from."); return {}; } @@ -288,7 +302,7 @@ std::vector AutoNavigationHandler::curvePositions(int nSteps) const // TODO: remove when not needed // Created for debugging std::vector AutoNavigationHandler::curveOrientations(int nSteps) const { - if (noCurrentPath()) { + if (!hasCurrentPath()) { LERROR("There is no current path to sample points from."); return {}; } @@ -310,7 +324,7 @@ std::vector AutoNavigationHandler::curveOrientations(int nSteps) con // TODO: remove when not needed or combined into pose version // Created for debugging std::vector AutoNavigationHandler::curveViewDirections(int nSteps) const { - if (noCurrentPath()) { + if (!hasCurrentPath()) { LERROR("There is no current path to sample points from."); return {}; } @@ -337,7 +351,7 @@ std::vector AutoNavigationHandler::curveViewDirections(int nSteps) c // TODO: remove when not needed // Created for debugging std::vector AutoNavigationHandler::controlPoints() const { - if (noCurrentPath()) { + if (!hasCurrentPath()) { LERROR("There is no current path to sample points from."); return {}; } diff --git a/modules/autonavigation/autonavigationhandler.h b/modules/autonavigation/autonavigationhandler.h index b257927a7a..4af1daf40c 100644 --- a/modules/autonavigation/autonavigationhandler.h +++ b/modules/autonavigation/autonavigationhandler.h @@ -54,7 +54,7 @@ public: const SceneGraphNode* anchor() const; double speedScale() const; - bool noCurrentPath() const; + bool hasCurrentPath() const; bool hasFinished() const; void updateCamera(double deltaTime); @@ -62,9 +62,8 @@ public: void clearPath(); void startPath(); void abortPath(); - - // TODO: allow option to pause during a path and then change this to continue playing - //void continuePath(); + void pausePath(); + void continuePath(); // TODO: remove functions for debugging std::vector curvePositions(int nSteps) const; diff --git a/modules/autonavigation/autonavigationmodule.cpp b/modules/autonavigation/autonavigationmodule.cpp index c4d6406890..43423c1245 100644 --- a/modules/autonavigation/autonavigationmodule.cpp +++ b/modules/autonavigation/autonavigationmodule.cpp @@ -144,13 +144,20 @@ scripting::LuaLibrary AutoNavigationModule::luaLibrary() const { "", "Returns true if a camera path is currently running, and false otherwise." }, - //{ - // "continuePath", - // &autonavigation::luascriptfunctions::continuePath, - // {}, - // "", - // "Continue playing a paused camera path." - //}, + { + "continuePath", + &autonavigation::luascriptfunctions::continuePath, + {}, + "", + "Continue playing a paused camera path." + }, + { + "pausePath", + &autonavigation::luascriptfunctions::pausePath, + {}, + "", + "Pause a playing camera path." + }, { "stopPath", &autonavigation::luascriptfunctions::stopPath, diff --git a/modules/autonavigation/autonavigationmodule_lua.inl b/modules/autonavigation/autonavigationmodule_lua.inl index 54ff97b8a4..5608ffb5df 100644 --- a/modules/autonavigation/autonavigationmodule_lua.inl +++ b/modules/autonavigation/autonavigationmodule_lua.inl @@ -56,15 +56,25 @@ int isFlying(lua_State* L) { return 1; } -//int continuePath(lua_State* L) { -// ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::continuePath"); -// -// AutoNavigationModule* module = global::moduleEngine->module(); -// module->AutoNavigationHandler().continuePath(); -// -// ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); -// return 0; -//} +int continuePath(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::continuePath"); + + AutoNavigationModule* module = global::moduleEngine->module(); + module->AutoNavigationHandler().continuePath(); + + ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); + return 0; +} + +int pausePath(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::pausePath"); + + AutoNavigationModule* module = global::moduleEngine->module(); + module->AutoNavigationHandler().pausePath(); + + ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); + return 0; +} int stopPath(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::stopPath"); @@ -149,6 +159,10 @@ int goTo(lua_State* L) { AutoNavigationModule* module = global::moduleEngine->module(); module->AutoNavigationHandler().createPath(instruction); + if (module->AutoNavigationHandler().hasCurrentPath()) { + module->AutoNavigationHandler().startPath(); + } + lua_settop(L, 0); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); return 0; @@ -184,6 +198,10 @@ int goToHeight(lua_State* L) { AutoNavigationModule* module = global::moduleEngine->module(); module->AutoNavigationHandler().createPath(instruction); + if (module->AutoNavigationHandler().hasCurrentPath()) { + module->AutoNavigationHandler().startPath(); + } + lua_settop(L, 0); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); return 0; @@ -239,6 +257,10 @@ int goToGeo(lua_State* L) { AutoNavigationModule* module = global::moduleEngine->module(); module->AutoNavigationHandler().createPath(instruction); + if (module->AutoNavigationHandler().hasCurrentPath()) { + module->AutoNavigationHandler().startPath(); + } + lua_settop(L, 0); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); return 0; @@ -254,6 +276,10 @@ int generatePath(lua_State* L) { AutoNavigationModule* module = global::moduleEngine->module(); module->AutoNavigationHandler().createPath(instruction); + if (module->AutoNavigationHandler().hasCurrentPath()) { + module->AutoNavigationHandler().startPath(); + } + lua_settop(L, 0); ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack"); return 0;