diff --git a/include/openspace/scripting/scriptscheduler.h b/include/openspace/scripting/scriptscheduler.h index 64f45a745f..9beafef1d4 100644 --- a/include/openspace/scripting/scriptscheduler.h +++ b/include/openspace/scripting/scriptscheduler.h @@ -25,6 +25,9 @@ #ifndef __OPENSPACE_CORE___SCRIPTSCHEDULER___H__ #define __OPENSPACE_CORE___SCRIPTSCHEDULER___H__ +#include + +#include #include #include @@ -44,8 +47,10 @@ struct LuaLibrary; * Maintains an ordered list of ScheduledScripts and provides a simple * interface for retrieveing scheduled scripts */ -class ScriptScheduler { +class ScriptScheduler : public properties::PropertyOwner { public: + ScriptScheduler(); + struct ScheduledScript { ScheduledScript() = default; ScheduledScript(const ghoul::Dictionary& dict); @@ -137,6 +142,7 @@ public: static documentation::Documentation Documentation(); private: + properties::BoolProperty _enabled; std::vector _timings; std::vector _forwardScripts; std::vector _backwardScripts; diff --git a/src/engine/globals.cpp b/src/engine/globals.cpp index 79667a34bd..a048db90ba 100644 --- a/src/engine/globals.cpp +++ b/src/engine/globals.cpp @@ -381,6 +381,7 @@ void initialize() { rootPropertyOwner->addPropertySubOwner(global::interactionMonitor); rootPropertyOwner->addPropertySubOwner(global::sessionRecording); rootPropertyOwner->addPropertySubOwner(global::timeManager); + rootPropertyOwner->addPropertySubOwner(global::scriptScheduler); rootPropertyOwner->addPropertySubOwner(global::renderEngine); rootPropertyOwner->addPropertySubOwner(global::screenSpaceRootPropertyOwner); diff --git a/src/scripting/scriptscheduler.cpp b/src/scripting/scriptscheduler.cpp index 5d32959f01..9c90c7f28c 100644 --- a/src/scripting/scriptscheduler.cpp +++ b/src/scripting/scriptscheduler.cpp @@ -33,6 +33,14 @@ #include "scriptscheduler_lua.inl" namespace { + constexpr openspace::properties::Property::PropertyInfo EnabledInfo = { + "EnabledInfo", + "Enabled", + "This enables or disables the ScriptScheduler. If disabled, no scheduled scripts " + "will be executed. If enabled, scheduled scripts will be executed at their given " + "time as normal." + }; + struct [[codegen::Dictionary(ScheduledScript)]] Parameters { // The time at which, when the in game time passes it, the two scripts will // be executed. If the traversal is forwards (towards + infinity), the @@ -65,6 +73,13 @@ documentation::Documentation ScriptScheduler::Documentation() { return codegen::doc("core_scheduledscript"); } +ScriptScheduler::ScriptScheduler() + : properties::PropertyOwner({ "ScriptScheduler" }) + , _enabled(EnabledInfo, true) +{ + addProperty(_enabled); +} + ScriptScheduler::ScheduledScript::ScheduledScript(const ghoul::Dictionary& dict) { const Parameters p = codegen::bake(dict); @@ -132,7 +147,7 @@ void ScriptScheduler::clearSchedule() { std::pair ScriptScheduler::progressTo(double newTime) { - if (newTime == _currentTime) { + if (!_enabled || newTime == _currentTime) { return { _forwardScripts.end(), _forwardScripts.end() }; } diff --git a/src/scripting/scriptscheduler_lua.inl b/src/scripting/scriptscheduler_lua.inl index 2fe74d9ede..9bf64dad5e 100644 --- a/src/scripting/scriptscheduler_lua.inl +++ b/src/scripting/scriptscheduler_lua.inl @@ -46,7 +46,7 @@ int loadFile(lua_State* L) { for (size_t i = 1; i <= scriptsDict.size(); ++i) { ghoul::Dictionary d = scriptsDict.value(std::to_string(i)); - scripting::ScriptScheduler::ScheduledScript script = + scripting::ScriptScheduler::ScheduledScript script = scripting::ScriptScheduler::ScheduledScript(d); scripts.push_back(script); }