Added support for scripting

This commit is contained in:
Alexander Bock
2014-09-13 18:25:14 +02:00
parent b6246f6538
commit 3afa0ecaa1
4 changed files with 61 additions and 10 deletions

View File

@@ -25,6 +25,8 @@
#ifndef __TIME_H__
#define __TIME_H__
#include <openspace/scripting/scriptengine.h>
#include <string>
namespace openspace {
@@ -46,6 +48,8 @@ public:
void setDeltaTime(double deltaT);
double deltaTime() const;
static scripting::ScriptEngine::LuaLibrary luaLibrary();
private:
Time();
Time(const Time& src) = delete;

View File

@@ -1 +1,3 @@
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
openspace.setTime(1000000)
openspace.setDeltaTime(100)

View File

@@ -110,8 +110,10 @@ OpenSpaceEngine& OpenSpaceEngine::ref()
bool OpenSpaceEngine::gatherCommandlineArguments()
{
// TODO: Get commandline arguments from all modules
CommandlineCommand* configurationFileCommand = new SingleCommand<std::string>(&commandlineArgumentPlaceholders.configurationName, "-config", "-c", "Provides the path to the OpenSpace configuration file");
CommandlineCommand* configurationFileCommand = new SingleCommand<std::string>(
&commandlineArgumentPlaceholders.configurationName, "-config", "-c",
"Provides the path to the OpenSpace configuration file");
_commandlineParser->addCommand(configurationFileCommand);
return true;
@@ -313,9 +315,6 @@ bool OpenSpaceEngine::initialize()
// registerFilePaths();
_context.createContextFromGLContext();
// initialize the configurationmanager with the default configuration
//_configurationManager->loadConfiguration(absPath("${SCRIPTS}/DefaultConfig.lua"));
// Detect and log OpenCL and OpenGL versions and available devices
ghoul::systemcapabilities::SystemCapabilities::initialize();
SysCap.addComponent(new ghoul::systemcapabilities::CPUCapabilitiesComponent);
@@ -324,6 +323,7 @@ bool OpenSpaceEngine::initialize()
SysCap.detectCapabilities();
SysCap.logCapabilities();
// initialize OpenSpace helpers
SpiceManager::initialize();
Time::initialize();
@@ -331,11 +331,16 @@ bool OpenSpaceEngine::initialize()
Spice::ref().loadDefaultKernels();
FactoryManager::initialize();
scriptEngine().initialize();
// scriptEngine().addLibrary(ScriptEngine::LuaLibrary());
// _engine->scriptEngine().runScript("return mylib.mysin(4)");
// Register Lua script functions
scriptEngine().addLibrary(Time::luaLibrary());
//scripting::ScriptEngine::LuaLibrary timeLibrary = {
// "time",
//}
// Load scenegraph
SceneGraph* sceneGraph = new SceneGraph;

View File

@@ -33,6 +33,33 @@
namespace {
const std::string _loggerCat = "Time";
int time_setDeltaTime(lua_State* L) {
const std::string _loggerCat = "time_setDeltaTime";
double value = luaL_checknumber(L, -1);
openspace::Time::ref().setDeltaTime(value);
return 0;
}
int time_deltaTime(lua_State* L) {
const std::string _loggerCat = "time_deltaTime";
lua_pushnumber(L, openspace::Time::ref().deltaTime());
return 1;
}
int time_setTime(lua_State* L) {
const std::string _loggerCat = "time_setTime";
double value = luaL_checknumber(L, -1);
openspace::Time::ref().setTime(value);
return 0;
}
int time_currentTime(lua_State* L) {
const std::string _loggerCat = "time_time";
lua_pushnumber(L, openspace::Time::ref().currentTime());
return 1;
}
}
namespace openspace {
@@ -107,4 +134,17 @@ std::string Time::currentTimeUTC() const {
return SpiceManager::ref().convertTdbSecondsToString(_time, "MON DD,YYYY HR:MN:SC.#### (TDB) ::TDB");
}
scripting::ScriptEngine::LuaLibrary Time::luaLibrary() {
scripting::ScriptEngine::LuaLibrary timeLibrary = {
"",
{
{"setDeltaTime", &time_setDeltaTime},
{"deltaTime", &time_deltaTime},
{"setTime", &time_setTime},
{"currentTime", &time_currentTime}
}
};
return std::move(timeLibrary);
}
} // namespace openspace