Enable global variables for module Lua scripts (closing #172)

Adapt New Horizons kernels to global switch between accurate and publicly avaiable kernels
This commit is contained in:
Alexander Bock
2016-04-14 22:33:28 -04:00
parent dcf5507e1c
commit ef2981f535
12 changed files with 38 additions and 62 deletions

View File

@@ -1,6 +1,4 @@
UseAccurateKernels = false
if UseAccurateKernels then
if UseAccurateNewHorizonsKernels then
NewHorizonsKernels = {
"${SPICE}/nh_kernels/spk/NavSE_plu047_od122.bsp"
}

View File

@@ -1,3 +1,5 @@
UseAccurateNewHorizonsKernels = false
return {
ScenePath = ".",
CommonFolder = "common",
@@ -14,7 +16,6 @@ return {
"saturn",
"uranus",
"neptune",
--"PlutoProjection",
"plutoprojectionhybrid",
"charonprojection",
"kerberos",
@@ -38,17 +39,6 @@ return {
"callistoprojection",
"newhorizons",
"newhorizonsfov",
--"gridGalactic",
--"gridEcliptic",
--"gridEquatorial",
-- "ephemeris",
-- "newhorizonspath",
-- "newhorizonstrail",
-- "enlil",
-- "volumegl3",
-- "volumegl2",
-- "volumegl",
}
}

View File

@@ -1,6 +1,4 @@
UseAccurateKernels = false
if UseAccurateKernels then
if UseAccurateNewHorizonsKernels then
NewHorizonsKernels = {
"${SPICE}/nh_kernels/spk/NavSE_plu047_od122.bsp"
}

View File

@@ -1,6 +1,4 @@
UseAccurateKernels = false
if UseAccurateKernels then
if UseAccurateNewHorizonsKernels then
NewHorizonsKernels = {
"${SPICE}/nh_kernels/spk/NavSE_plu047_od122.bsp"
}

View File

@@ -1,6 +1,4 @@
UseAccurateKernels = false
if UseAccurateKernels then
if UseAccurateNewHorizonsKernels then
NewHorizonsKernels = {
-- SCLK
"${SPICE}/nh_kernels/sclk/new-horizons_0976.tsc",

View File

@@ -1,6 +1,4 @@
UseAccurateKernels = false
if UseAccurateKernels then
if UseAccurateNewHorizonsKernels then
NewHorizonsKernels = {
"${SPICE}/nh_kernels/spk/NavSE_plu047_od122.bsp"
}

View File

@@ -1,6 +1,4 @@
UseAccurateKernels = false
if UseAccurateKernels then
if UseAccurateNewHorizonsKernels then
NewHorizonsKernels = {
"${SPICE}/nh_kernels/spk/NavPE_de433_od122.bsp",
"${SPICE}/nh_kernels/spk/NavSE_plu047_od122.bsp"

View File

@@ -1,6 +1,4 @@
UseAccurateKernels = false
if UseAccurateKernels then
if UseAccurateNewHorizonsKernels then
NewHorizonsKernels = {
"${SPICE}/nh_kernels/spk/NavSE_plu047_od122.bsp"
}

View File

@@ -8,11 +8,7 @@ return {
-- Sets the scene that is to be loaded by OpenSpace. A scene file is a description
-- of all entities that will be visible during an instance of OpenSpace
Scene = "${SCENE}/default_nh.scene",
-- Scene = "${SCENE}/default.scene",
-- Scene = "${SCENE}/default-modified.scene",
-- Scene = "${SCENE}/rosetta.scene",
-- Scene = "${SCENE}/dawn.scene",
Paths = {
SGCT = "${BASE_PATH}/config/sgct",
SCRIPTS = "${BASE_PATH}/scripts",

View File

@@ -126,10 +126,16 @@ bool SceneGraph::loadFromFile(const std::string& sceneDescription) {
if (!success)
// There are no modules that are loaded
return true;
lua_State* state = ghoul::lua::createNewLuaState();
OsEng.scriptEngine().initializeLuaState(state);
// Above we generated a ghoul::Dictionary from the scene file; now we run the scene
// file again to load any variables defined inside into the state that is passed to
// the modules. This allows us to specify global variables that can then be used
// inside the modules to toggle settings
ghoul::lua::runScriptFile(state, absSceneFile);
// Get the common directory
bool commonFolderSpecified = sceneDictionary.hasKey(KeyCommonFolder);
bool commonFolderCorrectType = sceneDictionary.hasKeyAndValue<std::string>(KeyCommonFolder);

View File

@@ -141,22 +141,20 @@ bool ScriptEngine::runScript(const std::string& script) {
return false;
}
int status = luaL_loadstring(_state, script.c_str());
if (status != LUA_OK) {
LERROR("Error loading script: '" << lua_tostring(_state, -1) << "'");
try {
ghoul::lua::runScript(_state, script);
}
catch (const ghoul::lua::LuaLoadingException& e) {
LERRORC(e.component, e.message);
return false;
}
catch (const ghoul::lua::LuaExecutionException& e) {
LERRORC(e.component, e.message);
return false;
}
//LDEBUG("Executing script");
//LINFO(script);
if (lua_pcall(_state, 0, LUA_MULTRET, 0)) {
LERROR("Error executing script: " << lua_tostring(_state, -1));
return false;
}
//if we're currently hosting the parallel session, find out if script should be synchronized.
if (OsEng.parallelConnection().isHost()){
// if we're currently hosting the parallel session, find out if script should be synchronized.
if (OsEng.parallelConnection().isHost()) {
std::string lib, func;
if (parseLibraryAndFunctionNames(lib, func, script) && shouldScriptBeSent(lib, func)){
// OsEng.parallelConnection()->sendScript(script);
@@ -177,18 +175,18 @@ bool ScriptEngine::runScriptFile(const std::string& filename) {
return false;
}
int status = luaL_loadfile(_state, filename.c_str());
if (status != LUA_OK) {
LERROR("Error loading script: '" << lua_tostring(_state, -1) << "'");
try {
ghoul::lua::runScriptFile(_state, filename);
}
catch (const ghoul::lua::LuaLoadingException& e) {
LERRORC(e.component, e.message);
return false;
}
catch (const ghoul::lua::LuaExecutionException& e) {
LERRORC(e.component, e.message);
return false;
}
LDEBUG("Executing script '" << filename << "'");
if (lua_pcall(_state, 0, LUA_MULTRET, 0)) {
LERROR("Error executing script: " << lua_tostring(_state, -1));
return false;
}
return true;
}