mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-17 18:39:17 -06:00
More work on fixing script access to time
This commit is contained in:
Submodule ext/ghoul updated: 6de5adc0c5...7906906863
@@ -1,3 +1,3 @@
|
||||
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
|
||||
openspace.setTime(1000000)
|
||||
openspace.setDeltaTime(100)
|
||||
openspace.time.setTime(1000000)
|
||||
openspace.time.setDeltaTime(100)
|
||||
@@ -337,11 +337,6 @@ bool OpenSpaceEngine::initialize()
|
||||
// Register Lua script functions
|
||||
scriptEngine().addLibrary(Time::luaLibrary());
|
||||
|
||||
//scripting::ScriptEngine::LuaLibrary timeLibrary = {
|
||||
// "time",
|
||||
//}
|
||||
|
||||
|
||||
// Load scenegraph
|
||||
SceneGraph* sceneGraph = new SceneGraph;
|
||||
_renderEngine->setSceneGraph(sceneGraph);
|
||||
|
||||
@@ -205,7 +205,6 @@ void RenderEngine::render()
|
||||
const PowerScaledScalar pssl = (position - origin).length();
|
||||
|
||||
const std::string time = Time::ref().currentTimeUTC().c_str();
|
||||
LINFO(time);
|
||||
Freetype::print(
|
||||
sgct_text::FontManager::instance()->getFont("SGCTFont", FONT_SIZE),
|
||||
FONT_SIZE, FONT_SIZE * 18, "Date: %s", time.c_str()
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/crc32.h>
|
||||
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <fstream>
|
||||
|
||||
namespace openspace {
|
||||
@@ -88,22 +89,34 @@ bool ScriptEngine::addLibrary(const ScriptEngine::LuaLibrary& library) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_getglobal(_state, _openspaceLibraryName.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
if (library.name.empty()) {
|
||||
//ghoul::lua::logStack(_state);
|
||||
addLibraryFunctions(library, true);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_pop(_state, 1);
|
||||
//ghoul::lua::logStack(_state);
|
||||
}
|
||||
else {
|
||||
const bool allowed = isLibraryNameAllowed(library.name);
|
||||
if (!allowed)
|
||||
return false;
|
||||
|
||||
//ghoul::lua::logStack(_state);
|
||||
|
||||
lua_pushstring(_state, library.name.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_newtable(_state);
|
||||
//ghoul::lua::logStack(_state);
|
||||
addLibraryFunctions(library, false);
|
||||
lua_settable(_state, _setTableOffset);
|
||||
|
||||
//ghoul::lua::logStack(_state);
|
||||
|
||||
_registeredLibraries.insert(ghoul::hashCRC32(library.name));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -199,8 +212,8 @@ bool ScriptEngine::isLibraryNameAllowed(const std::string& name)
|
||||
LERROR("Library name '" << name << "' specifies a thread");
|
||||
break;
|
||||
}
|
||||
|
||||
lua_pop(_state, 1);
|
||||
|
||||
lua_pop(_state, 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -208,16 +221,23 @@ void ScriptEngine::addLibraryFunctions(const LuaLibrary& library, bool replace)
|
||||
{
|
||||
for (std::pair<std::string, lua_CFunction> p : library.functions) {
|
||||
if (!replace) {
|
||||
ghoul::lua::logStack(_state);
|
||||
lua_getfield(_state, -1, p.first.c_str());
|
||||
ghoul::lua::logStack(_state);
|
||||
const bool isNil = lua_isnil(_state, -1);
|
||||
if (!isNil) {
|
||||
LERROR("Function name '" << p.first << "' was already assigned");
|
||||
return;
|
||||
}
|
||||
lua_pop(_state, 1);
|
||||
}
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_pushstring(_state, p.first.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_pushcfunction(_state, p.second);
|
||||
//ghoul::lua::logStack(_state);
|
||||
lua_settable(_state, _setTableOffset);
|
||||
//ghoul::lua::logStack(_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,10 +256,15 @@ void ScriptEngine::addBaseLibrary() {
|
||||
}
|
||||
|
||||
void ScriptEngine::remapPrintFunction() {
|
||||
lua_getglobal(_state, _luaGlobalNamespace.c_str());
|
||||
lua_pushstring(_state, _printFunctionName.c_str());
|
||||
lua_pushcfunction(_state, _printFunctionReplacement);
|
||||
lua_settable(_state, _setTableOffset);
|
||||
//ghoul::lua::logStack(_state);
|
||||
// lua_getglobal(_state, _luaGlobalNamespace.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
// lua_pushstring(_state, _printFunctionName.c_str());
|
||||
//ghoul::lua::logStack(_state);
|
||||
// lua_pushcfunction(_state, _printFunctionReplacement);
|
||||
//ghoul::lua::logStack(_state);
|
||||
// lua_settable(_state, _setTableOffset);
|
||||
//ghoul::lua::logStack(_state);
|
||||
}
|
||||
|
||||
} // namespace scripting
|
||||
|
||||
@@ -136,7 +136,7 @@ std::string Time::currentTimeUTC() const {
|
||||
|
||||
scripting::ScriptEngine::LuaLibrary Time::luaLibrary() {
|
||||
scripting::ScriptEngine::LuaLibrary timeLibrary = {
|
||||
"",
|
||||
"time",
|
||||
{
|
||||
{"setDeltaTime", &time_setDeltaTime},
|
||||
{"deltaTime", &time_deltaTime},
|
||||
|
||||
Reference in New Issue
Block a user