mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 10:40:09 -06:00
Modernize the handling of missions
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
-- Many of the values (especially days of the month if 01 or 30 or 31 and hh::mm::ss if all 0)
|
||||
-- are approximate and need fixing
|
||||
|
||||
return {
|
||||
local Mission = {
|
||||
Name = "New Horizons",
|
||||
Phases = {
|
||||
{
|
||||
@@ -120,3 +120,11 @@ return {
|
||||
}
|
||||
}
|
||||
|
||||
asset.onInitialize(function()
|
||||
openspace.loadMission(Mission)
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.unloadMission(Mission.Name)
|
||||
end)
|
||||
|
||||
@@ -8,13 +8,4 @@ asset.require('./charon')
|
||||
|
||||
asset.require('./othermoons')
|
||||
|
||||
local mission = asset.localResource("newhorizons.mission")
|
||||
local missionName
|
||||
|
||||
asset.onInitialize(function()
|
||||
missionName = openspace.loadMission(mission)
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.unloadMission(missionName)
|
||||
end)
|
||||
asset.require('./mission')
|
||||
|
||||
@@ -24,7 +24,7 @@ References:
|
||||
|
||||
--]]
|
||||
|
||||
return {
|
||||
local Mission = {
|
||||
Name = "OSIRIS-REx",
|
||||
Phases = {
|
||||
-- All 1-level phases based on [1]
|
||||
@@ -384,3 +384,12 @@ return {
|
||||
-- End of [1]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
asset.onInitialize(function()
|
||||
openspace.loadMission(Mission)
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.unloadMission(Mission.Name)
|
||||
end)
|
||||
@@ -4,14 +4,4 @@ asset.require('./trail')
|
||||
asset.require('scene/solarsystem/sun/marker')
|
||||
|
||||
asset.require('./script_schedule')
|
||||
|
||||
local mission = asset.localResource('osirisrex.mission')
|
||||
local missionName
|
||||
|
||||
asset.onInitialize(function()
|
||||
missionName = openspace.loadMission(mission)
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.unloadMission(missionName)
|
||||
end)
|
||||
asset.require('./mission')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
return
|
||||
{ Name = "Nominal_Observations_Science", Phases = {
|
||||
local Mission = {
|
||||
Name = "Nominal_Observations_Science", Phases = {
|
||||
{ Name = "03_Approach", Phases = {
|
||||
{ Name = "DustSearch_v1", Phases = {
|
||||
{ Name = "Phase03_AP_DustSearch_1.bc", TimeRange = { Start = "2018-SEP-11 21:31:01.183", End = "2018-SEP-12 02:18:41.183" }},
|
||||
@@ -93,3 +93,12 @@ return
|
||||
}},
|
||||
}},
|
||||
}}
|
||||
|
||||
|
||||
asset.onInitialize(function()
|
||||
openspace.loadMission(Mission)
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.unloadMission(Mission.Name)
|
||||
end)
|
||||
@@ -150,7 +150,7 @@ using Mission = MissionPhase;
|
||||
* \pre \p filename must not contain tokens
|
||||
* \pre \p filename must exist
|
||||
*/
|
||||
Mission missionFromFile(const std::string& filename);
|
||||
//Mission missionFromFile(const std::string& filename);
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -48,16 +48,11 @@ public:
|
||||
MissionManager();
|
||||
|
||||
/**
|
||||
* Reads a mission from file and maps the mission name to the Mission object. If
|
||||
* this is the first mission to be loaded, the mission will also be set as the
|
||||
* current active mission.
|
||||
* \param filename The file that contains the mission that is to be loaded
|
||||
* \return The name of the mission that was loaded
|
||||
* \pre \p filename must not be empty
|
||||
* \pre \p filename must not contain tokens
|
||||
* \pre \p filename must exist
|
||||
*/
|
||||
std::string loadMission(const std::string& filename);
|
||||
* Loads a mission into the mission manager.
|
||||
*
|
||||
* \param mission The mission to be loaded
|
||||
*/
|
||||
void loadMission(Mission mission);
|
||||
|
||||
/**
|
||||
* Unloads a previously loaded mission identified by the provided \p missionName.
|
||||
@@ -76,31 +71,29 @@ public:
|
||||
bool hasMission(const std::string& missionName);
|
||||
|
||||
/**
|
||||
* Sets the mission with the name <missionName> as the current mission. The current
|
||||
* mission is what is return by `currentMission()`.
|
||||
* \pre missionName must not be empty
|
||||
*/
|
||||
* Sets the mission with the name <missionName> as the current mission. The current
|
||||
* mission is what is return by `currentMission()`.
|
||||
* \pre missionName must not be empty
|
||||
*/
|
||||
void setCurrentMission(const std::string& missionName);
|
||||
|
||||
/**
|
||||
* Returns true if a current mission exists
|
||||
*/
|
||||
* Returns true if a current mission exists
|
||||
*/
|
||||
bool hasCurrentMission() const;
|
||||
|
||||
/**
|
||||
* Returns the latest mission specified to `setCurrentMission()`. If no mission has
|
||||
* been specified, the first mission loaded will be returned. If no mission has been
|
||||
* loaded, a warning will be printed and a dummy mission will be returned.
|
||||
*/
|
||||
* Returns the latest mission specified to `setCurrentMission()`. If no mission has
|
||||
* been specified, the first mission loaded will be returned. If no mission has been
|
||||
* loaded, a warning will be printed and a dummy mission will be returned.
|
||||
*/
|
||||
const Mission& currentMission();
|
||||
|
||||
static scripting::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
using MissionMap = std::map<std::string, Mission>;
|
||||
MissionMap _missionMap;
|
||||
|
||||
MissionMap::iterator _currentMission;
|
||||
std::map<std::string, Mission> _missionMap;
|
||||
std::map<std::string, Mission>::iterator _currentMission;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -162,21 +162,21 @@ void MissionPhase::phaseTrace(double time, Trace& trace, int maxDepth) const {
|
||||
}
|
||||
}
|
||||
|
||||
Mission missionFromFile(const std::string& filename) {
|
||||
ghoul_assert(!filename.empty(), "filename must not be empty");
|
||||
ghoul_assert(!FileSys.containsToken(filename), "filename must not contain tokens");
|
||||
ghoul_assert(FileSys.fileExists(filename), "filename must exist");
|
||||
|
||||
ghoul::Dictionary missionDict;
|
||||
ghoul::lua::loadDictionaryFromFile(filename, missionDict);
|
||||
|
||||
documentation::testSpecificationAndThrow(
|
||||
MissionPhase::Documentation(),
|
||||
missionDict,
|
||||
"Mission"
|
||||
);
|
||||
|
||||
return MissionPhase(missionDict);
|
||||
}
|
||||
//Mission missionFromFile(const std::string& filename) {
|
||||
// ghoul_assert(!filename.empty(), "filename must not be empty");
|
||||
// ghoul_assert(!FileSys.containsToken(filename), "filename must not contain tokens");
|
||||
// ghoul_assert(FileSys.fileExists(filename), "filename must exist");
|
||||
//
|
||||
// ghoul::Dictionary missionDict;
|
||||
// ghoul::lua::loadDictionaryFromFile(filename, missionDict);
|
||||
//
|
||||
// documentation::testSpecificationAndThrow(
|
||||
// MissionPhase::Documentation(),
|
||||
// missionDict,
|
||||
// "Mission"
|
||||
// );
|
||||
//
|
||||
// return MissionPhase(missionDict);
|
||||
//}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -55,15 +55,9 @@ bool MissionManager::hasCurrentMission() const {
|
||||
return _currentMission != _missionMap.end();
|
||||
}
|
||||
|
||||
std::string MissionManager::loadMission(const std::string& filename) {
|
||||
ghoul_assert(!filename.empty(), "filename must not be empty");
|
||||
ghoul_assert(!FileSys.containsToken(filename), "filename must not contain tokens");
|
||||
ghoul_assert(FileSys.fileExists(filename), "filename " + filename + " must exist");
|
||||
void MissionManager::loadMission(Mission mission) {
|
||||
std::string currentMission = hasCurrentMission() ? _currentMission->first : "";
|
||||
|
||||
// Changing the values might invalidate the _currentMission iterator
|
||||
std::string currentMission = hasCurrentMission() ? _currentMission->first : "";
|
||||
|
||||
Mission mission = missionFromFile(filename);
|
||||
std::string missionName = mission.name();
|
||||
_missionMap.insert({ missionName, std::move(mission) });
|
||||
if (_missionMap.size() == 1) {
|
||||
@@ -73,8 +67,6 @@ std::string MissionManager::loadMission(const std::string& filename) {
|
||||
if (!currentMission.empty()) {
|
||||
setCurrentMission(currentMission);
|
||||
}
|
||||
|
||||
return missionName;
|
||||
}
|
||||
|
||||
void MissionManager::unloadMission(const std::string& missionName) {
|
||||
@@ -109,7 +101,7 @@ scripting::LuaLibrary MissionManager::luaLibrary() {
|
||||
&luascriptfunctions::loadMission,
|
||||
{},
|
||||
"string",
|
||||
"Load mission phases from file"
|
||||
"Load mission phases specified in a dictionary"
|
||||
},
|
||||
{
|
||||
"unloadMission",
|
||||
@@ -123,14 +115,14 @@ scripting::LuaLibrary MissionManager::luaLibrary() {
|
||||
&luascriptfunctions::hasMission,
|
||||
{},
|
||||
"string",
|
||||
"Returns whether a mission with the provided name has been loaded"
|
||||
"Returns whether a mission with the provided identifier has been loaded"
|
||||
},
|
||||
{
|
||||
"setCurrentMission",
|
||||
&luascriptfunctions::setCurrentMission,
|
||||
{},
|
||||
"string",
|
||||
"Set the currnet mission"
|
||||
"Set the current mission"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,20 +29,17 @@ namespace openspace::luascriptfunctions {
|
||||
int loadMission(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::loadMission");
|
||||
|
||||
const std::string& missionFileName = ghoul::lua::value<std::string>(
|
||||
ghoul::Dictionary dict = ghoul::lua::value<ghoul::Dictionary>(
|
||||
L,
|
||||
1,
|
||||
ghoul::lua::PopValue::Yes
|
||||
);
|
||||
if (missionFileName.empty()) {
|
||||
return ghoul::lua::luaError(L, "Filepath is empty");
|
||||
}
|
||||
|
||||
std::string name = global::missionManager->loadMission(absPath(missionFileName));
|
||||
ghoul::lua::push(L, name);
|
||||
Mission mission = Mission(dict);
|
||||
global::missionManager->loadMission(mission);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack");
|
||||
return 1;
|
||||
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unloadMission(lua_State* L) {
|
||||
|
||||
Reference in New Issue
Block a user