mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Remove Dictionary use in script scheduling with struct
This commit is contained in:
@@ -33,13 +33,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyTime = "Time";
|
||||
constexpr const char* KeyForwardScript = "ForwardScript";
|
||||
constexpr const char* KeyBackwardScript = "BackwardScript";
|
||||
constexpr const char* KeyUniversalScript = "Script";
|
||||
} // namespace
|
||||
|
||||
namespace ghoul { class Dictionary; }
|
||||
namespace openspace::documentation { struct Documentation; }
|
||||
|
||||
@@ -54,12 +47,11 @@ struct LuaLibrary;
|
||||
class ScriptScheduler {
|
||||
public:
|
||||
struct ScheduledScript {
|
||||
ScheduledScript() = default;
|
||||
ScheduledScript(const ghoul::Dictionary& dictionary);
|
||||
|
||||
double time = -std::numeric_limits<double>::max();
|
||||
std::string forwardScript;
|
||||
std::string backwardScript;
|
||||
std::string universalScript;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -69,7 +61,7 @@ public:
|
||||
* \throw SpecificationError If the dictionary does not adhere to the Documentation as
|
||||
* specified in the openspace::Documentation function
|
||||
*/
|
||||
void loadScripts(const ghoul::Dictionary& dictionary);
|
||||
void loadScripts(std::vector<ScheduledScript> scheduledScripts);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,13 @@
|
||||
|
||||
#include "scriptscheduler_lua.inl"
|
||||
|
||||
namespace {
|
||||
constexpr const char* KeyTime = "Time";
|
||||
constexpr const char* KeyForwardScript = "ForwardScript";
|
||||
constexpr const char* KeyBackwardScript = "BackwardScript";
|
||||
constexpr const char* KeyUniversalScript = "Script";
|
||||
} // namespace
|
||||
|
||||
namespace openspace::scripting {
|
||||
|
||||
documentation::Documentation ScriptScheduler::Documentation() {
|
||||
@@ -40,7 +47,7 @@ documentation::Documentation ScriptScheduler::Documentation() {
|
||||
using TimeVerifier = StringVerifier;
|
||||
using LuaScriptVerifier = StringVerifier;
|
||||
|
||||
return{
|
||||
return {
|
||||
"Scheduled Scripts",
|
||||
"core_scheduledscript",
|
||||
{
|
||||
@@ -88,46 +95,7 @@ documentation::Documentation ScriptScheduler::Documentation() {
|
||||
|
||||
using namespace openspace::interaction;
|
||||
|
||||
ScriptScheduler::ScheduledScript::ScheduledScript(const ghoul::Dictionary& dictionary) {
|
||||
const std::string& timeStr = dictionary.value<std::string>(KeyTime);
|
||||
time = Time::convertTime(timeStr);
|
||||
|
||||
// If a universal script is specified, retrieve it and add a ; as a separator so that
|
||||
// it can be added to the other scripts
|
||||
std::string universal;
|
||||
if (dictionary.hasValue<std::string>(KeyUniversalScript)) {
|
||||
universal = dictionary.value<std::string>(KeyUniversalScript);
|
||||
if (!universal.empty()) {
|
||||
universal += ";";
|
||||
}
|
||||
}
|
||||
|
||||
if (dictionary.hasValue<std::string>(KeyForwardScript)) {
|
||||
forwardScript = universal + dictionary.value<std::string>(KeyForwardScript);
|
||||
}
|
||||
|
||||
if (dictionary.hasValue<std::string>(KeyBackwardScript)) {
|
||||
backwardScript = universal + dictionary.value<std::string>(KeyBackwardScript);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptScheduler::loadScripts(const ghoul::Dictionary& dictionary) {
|
||||
// Check if all of the scheduled scripts are formed correctly
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"ScriptScheduler"
|
||||
);
|
||||
|
||||
// Create all the scheduled script first
|
||||
std::vector<ScheduledScript> scheduledScripts;
|
||||
for (size_t i = 1; i <= dictionary.size(); ++i) {
|
||||
const ghoul::Dictionary& timedScriptDict = dictionary.value<ghoul::Dictionary>(
|
||||
std::to_string(i)
|
||||
);
|
||||
scheduledScripts.emplace_back(timedScriptDict);
|
||||
}
|
||||
|
||||
void ScriptScheduler::loadScripts(std::vector<ScheduledScript> scheduledScripts) {
|
||||
// Sort scripts by time; use a stable_sort as the user might have had an intention
|
||||
// specifying multiple scripts for the same time in a specific order
|
||||
std::stable_sort(
|
||||
@@ -145,12 +113,17 @@ void ScriptScheduler::loadScripts(const ghoul::Dictionary& dictionary) {
|
||||
for (ScheduledScript& script : scheduledScripts) {
|
||||
_timings.push_back(script.time);
|
||||
|
||||
_forwardScripts.push_back(std::move(script.forwardScript));
|
||||
std::string forward =
|
||||
script.universalScript.empty() ?
|
||||
std::move(script.forwardScript) :
|
||||
std::move(script.universalScript) + ';' + std::move(script.forwardScript);
|
||||
_forwardScripts.push_back(forward);
|
||||
|
||||
_backwardScripts.insert(
|
||||
_backwardScripts.begin(),
|
||||
std::move(script.backwardScript)
|
||||
);
|
||||
std::string backward =
|
||||
script.universalScript.empty() ?
|
||||
std::move(script.backwardScript) :
|
||||
std::move(script.universalScript) + ';' + std::move(script.backwardScript);
|
||||
_backwardScripts.insert(_backwardScripts.begin(), backward);
|
||||
}
|
||||
|
||||
// Ensure _currentIndex and _currentTime is accurate after new scripts was added
|
||||
|
||||
@@ -29,19 +29,49 @@ namespace openspace::luascriptfunctions {
|
||||
int loadFile(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadFile");
|
||||
|
||||
const std::string& missionFileName = ghoul::lua::value<std::string>(
|
||||
const std::string& fileName = ghoul::lua::value<std::string>(
|
||||
L,
|
||||
1,
|
||||
ghoul::lua::PopValue::Yes
|
||||
);
|
||||
if (missionFileName.empty()) {
|
||||
if (fileName.empty()) {
|
||||
return ghoul::lua::luaError(L, "filepath string is empty");
|
||||
}
|
||||
|
||||
global::scriptScheduler->loadScripts(
|
||||
ghoul::lua::loadDictionaryFromFile(missionFileName, L)
|
||||
ghoul::Dictionary scriptsDict = ghoul::lua::loadDictionaryFromFile(fileName, L);
|
||||
documentation::testSpecificationAndThrow(
|
||||
scripting::ScriptScheduler::Documentation(),
|
||||
scriptsDict,
|
||||
"ScriptScheduler"
|
||||
);
|
||||
|
||||
|
||||
std::vector<scripting::ScriptScheduler::ScheduledScript> scripts;
|
||||
for (int i = 1; i <= scriptsDict.size(); ++i) {
|
||||
ghoul::Dictionary d = scriptsDict.value<ghoul::Dictionary>(std::to_string(i));
|
||||
|
||||
scripting::ScriptScheduler::ScheduledScript script;
|
||||
constexpr const char* KeyTime = "Time";
|
||||
if (d.hasValue<std::string>(KeyTime)) {
|
||||
script.time = Time::convertTime(d.value<std::string>(KeyTime));
|
||||
}
|
||||
constexpr const char* KeyForwardScript = "ForwardScript";
|
||||
if (d.hasValue<std::string>(KeyForwardScript)) {
|
||||
script.forwardScript = d.value<std::string>(KeyForwardScript);
|
||||
}
|
||||
constexpr const char* KeyBackwardScript = "BackwardScript";
|
||||
if (d.hasValue<std::string>(KeyBackwardScript)) {
|
||||
script.backwardScript = d.value<std::string>(KeyBackwardScript);
|
||||
}
|
||||
constexpr const char* KeyUniversalScript = "Script";
|
||||
if (d.hasValue<std::string>(KeyUniversalScript)) {
|
||||
script.universalScript = d.value<std::string>(KeyUniversalScript);
|
||||
}
|
||||
scripts.push_back(script);
|
||||
}
|
||||
|
||||
global::scriptScheduler->loadScripts(scripts);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
@@ -53,26 +83,26 @@ int loadScheduledScript(lua_State* L) {
|
||||
"lua::loadScheduledScript"
|
||||
);
|
||||
|
||||
std::string time = ghoul::lua::value<std::string>(L, 1);
|
||||
std::string forwardScript = ghoul::lua::value<std::string>(L, 2);
|
||||
scripting::ScriptScheduler::ScheduledScript script;
|
||||
|
||||
ghoul::Dictionary script;
|
||||
script.setValue(KeyTime, std::move(time));
|
||||
script.setValue(KeyForwardScript, std::move(forwardScript));
|
||||
std::string time = ghoul::lua::value<std::string>(L, 1);
|
||||
script.time = Time::convertTime(time);
|
||||
std::string forwardScript = ghoul::lua::value<std::string>(L, 2);
|
||||
script.forwardScript = std::move(forwardScript);
|
||||
|
||||
if (nArguments == 3) {
|
||||
std::string backwardScript = ghoul::lua::value<std::string>(L, 3);
|
||||
script.setValue(KeyBackwardScript, std::move(backwardScript));
|
||||
script.backwardScript = std::move(backwardScript);
|
||||
}
|
||||
else if (nArguments == 4) {
|
||||
std::string backwardScript = ghoul::lua::value<std::string>(L, 3);
|
||||
script.setValue(KeyBackwardScript, std::move(backwardScript));
|
||||
script.backwardScript = std::move(backwardScript);
|
||||
std::string universalScript = ghoul::lua::value<std::string>(L, 4);
|
||||
script.setValue(KeyUniversalScript, std::move(universalScript));
|
||||
script.universalScript = std::move(universalScript);
|
||||
}
|
||||
ghoul::Dictionary list;
|
||||
list.setValue("1", std::move(script));
|
||||
global::scriptScheduler->loadScripts(list);
|
||||
std::vector<scripting::ScriptScheduler::ScheduledScript> scripts;
|
||||
scripts.push_back(std::move(script));
|
||||
global::scriptScheduler->loadScripts(scripts);
|
||||
|
||||
lua_settop(L, 0);
|
||||
|
||||
|
||||
@@ -38,17 +38,16 @@ TEST_CASE("ScriptScheduler: Simple Forward", "[scriptscheduler]") {
|
||||
);
|
||||
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary;
|
||||
testDictionary.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary);
|
||||
ScriptScheduler::ScheduledScript script;
|
||||
script.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script.forwardScript = "ForwardScript1";
|
||||
script.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script);
|
||||
}
|
||||
|
||||
scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01"));
|
||||
@@ -71,21 +70,20 @@ TEST_CASE("ScriptScheduler: Multiple Forward Single Jump", "[scriptscheduler]")
|
||||
);
|
||||
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts.setValue("2", testDictionary2);
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
scripts.push_back(script2);
|
||||
}
|
||||
ScriptScheduler scheduler;
|
||||
|
||||
@@ -115,19 +113,19 @@ TEST_CASE("ScriptScheduler: Multiple Forward Ordering", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts.setValue("2", testDictionary2);
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
scripts.push_back(script2);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -154,13 +152,13 @@ TEST_CASE("ScriptScheduler: Simple Backward", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary;
|
||||
testDictionary.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -186,19 +184,19 @@ TEST_CASE("ScriptScheduler: Multiple Backward Single Jump", "[scriptscheduler]")
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts.setValue("2", testDictionary2);
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
scripts.push_back(script2);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -228,19 +226,19 @@ TEST_CASE("ScriptScheduler: Multiple Backward Ordering", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts.setValue("2", testDictionary2);
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
scripts.push_back(script2);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -297,19 +295,19 @@ TEST_CASE("ScriptScheduler: Forward Backwards", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts.setValue("2", testDictionary2);
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
scripts.push_back(script2);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -343,19 +341,19 @@ TEST_CASE("ScriptScheduler: Rewind", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts.setValue("2", testDictionary2);
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
scripts.push_back(script2);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -405,25 +403,25 @@ TEST_CASE("ScriptScheduler: All Scripts", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts.setValue("2", testDictionary2);
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
scripts.push_back(script2);
|
||||
|
||||
ghoul::Dictionary testDictionary3;
|
||||
testDictionary3.setValue("Time", "2000 JAN 10"s);
|
||||
testDictionary3.setValue("ForwardScript", "ForwardScript3"s);
|
||||
testDictionary3.setValue("BackwardScript", "BackwardScript3"s);
|
||||
scripts.setValue("3", testDictionary3);
|
||||
ScriptScheduler::ScheduledScript script3;
|
||||
script3.time = openspace::Time::convertTime("2000 JAN 10");
|
||||
script3.forwardScript = "ForwardScript3";
|
||||
script3.backwardScript = "BackwardScript3";
|
||||
scripts.push_back(script3);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -447,13 +445,13 @@ TEST_CASE("ScriptScheduler: Jump Equal", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03 12:00:00"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03 12:00:00");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -485,13 +483,13 @@ TEST_CASE("ScriptScheduler: Same Time", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03 12:00:00"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", scripts);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03 12:00:00");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -516,13 +514,13 @@ TEST_CASE("ScriptScheduler: Multi Inner Jump", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts;
|
||||
std::vector<ScriptScheduler::ScheduledScript> scripts;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03 12:00:00"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts.setValue("1", testDictionary1);
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03 12:00:00");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
scripts.push_back(script1);
|
||||
}
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
@@ -556,29 +554,21 @@ TEST_CASE(
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts1;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts1.setValue("1", scripts1);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
|
||||
ghoul::Dictionary scripts2;
|
||||
{
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts2.setValue("1", testDictionary2);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01"));
|
||||
scheduler.loadScripts(scripts1);
|
||||
scheduler.loadScripts(scripts2);
|
||||
scheduler.loadScripts({ script1 });
|
||||
scheduler.loadScripts({ script2 });
|
||||
|
||||
auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 02"));
|
||||
REQUIRE(res.first == res.second);
|
||||
@@ -604,28 +594,20 @@ TEST_CASE("ScriptScheduler: Multiple Forward Ordering Multiple Load" "[scriptsch
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts1;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts1.setValue("1", scripts1);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
|
||||
ghoul::Dictionary scripts2;
|
||||
{
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts2.setValue("1", testDictionary2);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01"));
|
||||
scheduler.loadScripts(scripts1);
|
||||
scheduler.loadScripts(scripts2);
|
||||
scheduler.loadScripts({ script1 });
|
||||
scheduler.loadScripts({ script2 });
|
||||
|
||||
auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 02"));
|
||||
REQUIRE(res.first == res.second);
|
||||
@@ -650,28 +632,20 @@ TEST_CASE(
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts1;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts1.setValue("1", scripts1);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
|
||||
ghoul::Dictionary scripts2;
|
||||
{
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts2.setValue("1", testDictionary2);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07"));
|
||||
scheduler.loadScripts(scripts1);
|
||||
scheduler.loadScripts(scripts2);
|
||||
scheduler.loadScripts({ script1 });
|
||||
scheduler.loadScripts({ script2 });
|
||||
|
||||
auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06"));
|
||||
REQUIRE(res.first == res.second);
|
||||
@@ -701,27 +675,19 @@ TEST_CASE(
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
|
||||
ghoul::Dictionary scripts1;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts1.setValue("1", scripts1);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
|
||||
ghoul::Dictionary scripts2;
|
||||
{
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts2.setValue("1", testDictionary2);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
|
||||
scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07"));
|
||||
scheduler.loadScripts(scripts1);
|
||||
scheduler.loadScripts(scripts2);
|
||||
scheduler.loadScripts({ script1 });
|
||||
scheduler.loadScripts({ script2 });
|
||||
|
||||
std::pair<ScriptScheduler::ScriptIt, ScriptScheduler::ScriptIt> res =
|
||||
scheduler.progressTo(openspace::Time::convertTime("2000 JAN 06"));
|
||||
@@ -744,28 +710,20 @@ TEST_CASE("ScriptScheduler: Forward Backwards Multiple Load", "[scriptscheduler]
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts1;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts1.setValue("1", scripts1);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
|
||||
ghoul::Dictionary scripts2;
|
||||
{
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts2.setValue("1", testDictionary2);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01"));
|
||||
scheduler.loadScripts(scripts1);
|
||||
scheduler.loadScripts(scripts2);
|
||||
scheduler.loadScripts({ script1 });
|
||||
scheduler.loadScripts({ script2 });
|
||||
|
||||
auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 04"));
|
||||
REQUIRE(std::distance(res.first, res.second) == 1);
|
||||
@@ -794,28 +752,20 @@ TEST_CASE("ScriptScheduler: Rewind Multiple Load", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts1;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts1.setValue("1", scripts1);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
|
||||
ghoul::Dictionary scripts2;
|
||||
{
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts2.setValue("1", testDictionary2);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
scheduler.progressTo(openspace::Time::convertTime("2000 JAN 01"));
|
||||
scheduler.loadScripts(scripts1);
|
||||
scheduler.loadScripts(scripts2);
|
||||
scheduler.loadScripts({ script1 });
|
||||
scheduler.loadScripts({ script2 });
|
||||
|
||||
auto res = scheduler.progressTo(openspace::Time::convertTime("2000 JAN 07"));
|
||||
REQUIRE(std::distance(res.first, res.second) == 2);
|
||||
@@ -838,37 +788,25 @@ TEST_CASE("ScriptScheduler: All Scripts Multiple Load", "[scriptscheduler]") {
|
||||
using namespace openspace::scripting;
|
||||
using namespace std::string_literals;
|
||||
|
||||
ghoul::Dictionary scripts1;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts1.setValue("1", testDictionary1);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
|
||||
ghoul::Dictionary scripts2;
|
||||
{
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts2.setValue("1", scripts2);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
|
||||
ghoul::Dictionary scripts3;
|
||||
{
|
||||
ghoul::Dictionary testDictionary3;
|
||||
testDictionary3.setValue("Time", "2000 JAN 10"s);
|
||||
testDictionary3.setValue("ForwardScript", "ForwardScript3"s);
|
||||
testDictionary3.setValue("BackwardScript", "BackwardScript3"s);
|
||||
scripts3.setValue("1", testDictionary3);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script3;
|
||||
script3.time = openspace::Time::convertTime("2000 JAN 10");
|
||||
script3.forwardScript = "ForwardScript3";
|
||||
script3.backwardScript = "BackwardScript3";
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
scheduler.loadScripts(scripts1);
|
||||
scheduler.loadScripts(scripts2);
|
||||
scheduler.loadScripts(scripts3);
|
||||
scheduler.loadScripts({ script1 });
|
||||
scheduler.loadScripts({ script2 });
|
||||
scheduler.loadScripts({ script3 });
|
||||
|
||||
auto allScripts = scheduler.allScripts();
|
||||
REQUIRE(allScripts.size() == 3);
|
||||
@@ -890,33 +828,24 @@ TEST_CASE("ScriptScheduler: All Scripts Mixed Load", "[scriptscheduler]") {
|
||||
|
||||
|
||||
|
||||
ghoul::Dictionary scripts1;
|
||||
{
|
||||
ghoul::Dictionary testDictionary1;
|
||||
testDictionary1.setValue("Time", "2000 JAN 03"s);
|
||||
testDictionary1.setValue("ForwardScript", "ForwardScript1"s);
|
||||
testDictionary1.setValue("BackwardScript", "BackwardScript1"s);
|
||||
scripts1.setValue("1", testDictionary1);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script1;
|
||||
script1.time = openspace::Time::convertTime("2000 JAN 03");
|
||||
script1.forwardScript = "ForwardScript1";
|
||||
script1.backwardScript = "BackwardScript1";
|
||||
|
||||
ghoul::Dictionary scripts2;
|
||||
{
|
||||
ghoul::Dictionary testDictionary2;
|
||||
testDictionary2.setValue("Time", "2000 JAN 05"s);
|
||||
testDictionary2.setValue("ForwardScript", "ForwardScript2"s);
|
||||
testDictionary2.setValue("BackwardScript", "BackwardScript2"s);
|
||||
scripts2.setValue("1", scripts2);
|
||||
ScriptScheduler::ScheduledScript script2;
|
||||
script2.time = openspace::Time::convertTime("2000 JAN 05");
|
||||
script2.forwardScript = "ForwardScript2";
|
||||
script2.backwardScript = "BackwardScript2";
|
||||
|
||||
ghoul::Dictionary testDictionary3;
|
||||
testDictionary3.setValue("Time", "2000 JAN 10"s);
|
||||
testDictionary3.setValue("ForwardScript", "ForwardScript3"s);
|
||||
testDictionary3.setValue("BackwardScript", "BackwardScript3"s);
|
||||
scripts2.setValue("2", testDictionary3);
|
||||
}
|
||||
ScriptScheduler::ScheduledScript script3;
|
||||
script3.time = openspace::Time::convertTime("2000 JAN 10");
|
||||
script3.forwardScript = "ForwardScript3";
|
||||
script3.backwardScript = "BackwardScript3";
|
||||
|
||||
ScriptScheduler scheduler;
|
||||
scheduler.loadScripts(scripts1);
|
||||
scheduler.loadScripts(scripts2);
|
||||
scheduler.loadScripts({ script1 });
|
||||
scheduler.loadScripts({ script2, script3 });
|
||||
|
||||
auto allScripts = scheduler.allScripts();
|
||||
REQUIRE(allScripts.size() == 3);
|
||||
|
||||
Reference in New Issue
Block a user