From d61bb20992f944175d4fe838b097548b0c814547 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 13 Mar 2017 09:52:06 -0400 Subject: [PATCH] Some more work on RenderableFov Make registerting path tokens through Lua scripts work --- .../newhorizons/rendering/renderablefov.cpp | 6 +- modules/newhorizons/rendering/renderablefov.h | 2 + src/scripting/scriptengine.cpp | 28 +- src/scripting/scriptengine_lua.inl | 261 +++++++++--------- 4 files changed, 152 insertions(+), 145 deletions(-) diff --git a/modules/newhorizons/rendering/renderablefov.cpp b/modules/newhorizons/rendering/renderablefov.cpp index 036e0d5156..b68cdd3209 100644 --- a/modules/newhorizons/rendering/renderablefov.cpp +++ b/modules/newhorizons/rendering/renderablefov.cpp @@ -130,6 +130,7 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _lineWidth("lineWidth", "Line Width", 1.f, 1.f, 20.f) , _drawSolid("solidDraw", "Draw as Quads", false) + , _standOffDistance("standOffDistance", "Standoff Distance", 0.9999, 0.999, 1.0) , _colors({ { "colors.defaultStart", @@ -208,6 +209,7 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary) addProperty(_lineWidth); addProperty(_drawSolid); + addProperty(_standOffDistance); addProperty(_colors.defaultStart); addProperty(_colors.defaultEnd); @@ -448,7 +450,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& glm::vec3 srfVec = r.surfaceVector * 1000.0; // Standoff distance, we would otherwise end up *exactly* on the surface - srfVec *= 0.999; + srfVec *= _standOffDistance; second = { srfVec.x, srfVec.y, srfVec.z, @@ -543,7 +545,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string& // Convert the KM scale that SPICE uses to meter // Standoff distance, we would otherwise end up *exactly* on the surface - return r.surfaceVector * 1000.0 * 0.999; + return r.surfaceVector * 1000.0 * _standOffDistance.value(); }; for (size_t m = 0; m < InterpolationSteps; ++m) { diff --git a/modules/newhorizons/rendering/renderablefov.h b/modules/newhorizons/rendering/renderablefov.h index b1f4ec1da5..fbcda8be87 100644 --- a/modules/newhorizons/rendering/renderablefov.h +++ b/modules/newhorizons/rendering/renderablefov.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -91,6 +92,7 @@ private: // properties properties::FloatProperty _lineWidth; properties::BoolProperty _drawSolid; + properties::DoubleProperty _standOffDistance; std::unique_ptr _programObject; // instance variables diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 72e9536eeb..5206c28fa3 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -375,50 +375,50 @@ void ScriptEngine::addBaseLibrary() { "printDebug", &luascriptfunctions::printDebug, "*", - "Logs the passed value to the installed LogManager with a " - "LogLevel of 'Debug'" + "Logs the passed value to the installed LogManager with a LogLevel of " + "'Debug'" }, { "printInfo", &luascriptfunctions::printInfo, "*", - "Logs the passed value to the installed LogManager with a " - " LogLevel of 'Info'" + "Logs the passed value to the installed LogManager with a LogLevel of " + "'Info'" }, { "printWarning", &luascriptfunctions::printWarning, "*", - "Logs the passed value to the installed LogManager with " - "a LogLevel of 'Warning'" + "Logs the passed value to the installed LogManager with a LogLevel of " + "'Warning'" }, { "printError", &luascriptfunctions::printError, "*", - "Logs the passed value to the installed LogManager with a " - "LogLevel of 'Error'" + "Logs the passed value to the installed LogManager with a LogLevel of " + "'Error'" }, { "printFatal", &luascriptfunctions::printFatal, "*", - "Logs the passed value to the installed LogManager with a " - "LogLevel of 'Fatal'" + "Logs the passed value to the installed LogManager with a LogLevel of " + "'Fatal'" }, { "absPath", &luascriptfunctions::absolutePath, "string", - "Returns the absolute path to the passed path, resolving" - " path tokens as well as resolving relative paths" + "Returns the absolute path to the passed path, resolving path tokens as " + "well as resolving relative paths" }, { "setPathToken", &luascriptfunctions::setPathToken, "string, string", - "Registers a new path token provided by the" - " first argument to the path provided in the second argument" + "Registers a new path token provided by the first argument to the path " + "provided in the second argument" } } }; diff --git a/src/scripting/scriptengine_lua.inl b/src/scripting/scriptengine_lua.inl index 0f5fe9355b..9fdf8c0a0d 100644 --- a/src/scripting/scriptengine_lua.inl +++ b/src/scripting/scriptengine_lua.inl @@ -26,142 +26,145 @@ namespace openspace { namespace luascriptfunctions { - int printInternal(ghoul::logging::LogLevel level, lua_State* L) { - using ghoul::lua::luaTypeToString; - const std::string _loggerCat = "print"; +int printInternal(ghoul::logging::LogLevel level, lua_State* L) { + using ghoul::lua::luaTypeToString; + const std::string _loggerCat = "print"; - int nArguments = lua_gettop(L); - if (nArguments != 1) - return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments); - - const int type = lua_type(L, -1); - switch (type) { - case LUA_TNONE: - case LUA_TLIGHTUSERDATA: - case LUA_TTABLE: - case LUA_TFUNCTION: - case LUA_TUSERDATA: - case LUA_TTHREAD: - LOGC(level, "print", "Function parameter was of type '" << - luaTypeToString(type) << "'"); - case LUA_TNIL: - break; - case LUA_TBOOLEAN: - LOGC(level, "print", lua_toboolean(L, -1)); - break; - case LUA_TNUMBER: - LOGC(level, "print", lua_tonumber(L, -1)); - break; - case LUA_TSTRING: - LOGC(level, "print", lua_tostring(L, -1)); - break; - } - return 0; + int nArguments = lua_gettop(L); + if (nArguments != 1) { + return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments); } - /** - * \ingroup LuaScripts - * printTrace(*): - * Logs the passed value to the installed LogManager with a LogLevel of 'Trace'. - * For Boolean, numbers, and strings, the internal values are printed, for all other - * types, the type is printed instead - */ - int printTrace(lua_State* L) { - return printInternal(ghoul::logging::LogLevel::Trace, L); + const int type = lua_type(L, -1); + switch (type) { + case LUA_TNONE: + case LUA_TLIGHTUSERDATA: + case LUA_TTABLE: + case LUA_TFUNCTION: + case LUA_TUSERDATA: + case LUA_TTHREAD: + LOGC(level, "print", "Function parameter was of type '" << + luaTypeToString(type) << "'"); + case LUA_TNIL: + break; + case LUA_TBOOLEAN: + LOGC(level, "print", lua_toboolean(L, -1)); + break; + case LUA_TNUMBER: + LOGC(level, "print", lua_tonumber(L, -1)); + break; + case LUA_TSTRING: + LOGC(level, "print", lua_tostring(L, -1)); + break; + } + return 0; +} + +/** + * \ingroup LuaScripts + * printTrace(*): + * Logs the passed value to the installed LogManager with a LogLevel of 'Trace'. + * For Boolean, numbers, and strings, the internal values are printed, for all other + * types, the type is printed instead + */ +int printTrace(lua_State* L) { + return printInternal(ghoul::logging::LogLevel::Trace, L); +} + +/** + * \ingroup LuaScripts + * printDebug(*): + * Logs the passed value to the installed LogManager with a LogLevel of 'Debug'. + * For Boolean, numbers, and strings, the internal values are printed, for all other + * types, the type is printed instead + */ +int printDebug(lua_State* L) { + return printInternal(ghoul::logging::LogLevel::Debug, L); +} + +/** + * \ingroup LuaScripts + * printInfo(*): + * Logs the passed value to the installed LogManager with a LogLevel of 'Info'. + * For Boolean, numbers, and strings, the internal values are printed, for all other + * types, the type is printed instead + */ +int printInfo(lua_State* L) { + return printInternal(ghoul::logging::LogLevel::Info, L); +} + +/** + * \ingroup LuaScripts + * printWarning(*): + * Logs the passed value to the installed LogManager with a LogLevel of 'Warning'. + * For Boolean, numbers, and strings, the internal values are printed, for all other + * types, the type is printed instead + */ +int printWarning(lua_State* L) { + return printInternal(ghoul::logging::LogLevel::Warning, L); +} + +/** + * \ingroup LuaScripts + * printError(*): + * Logs the passed value to the installed LogManager with a LogLevel of 'Error'. + * For Boolean, numbers, and strings, the internal values are printed, for all other + * types, the type is printed instead + */ +int printError(lua_State* L) { + return printInternal(ghoul::logging::LogLevel::Error, L); +} + +/** + * \ingroup LuaScripts + * printFatal(*): + * Logs the passed value to the installed LogManager with a LogLevel of 'Fatal'. + * For Boolean, numbers, and strings, the internal values are printed, for all other + * types, the type is printed instead + */ +int printFatal(lua_State* L) { + return printInternal(ghoul::logging::LogLevel::Fatal, L); +} + +/** + * \ingroup LuaScripts + * absPath(string): + * Passes the argument to FileSystem::absolutePath, which resolves occuring path + * tokens and returns the absolute path. + */ +int absolutePath(lua_State* L) { + int nArguments = lua_gettop(L); + if (nArguments != 1) { + return luaL_error(L, "Expected %d arguments, got %d", 1, nArguments); } - /** - * \ingroup LuaScripts - * printDebug(*): - * Logs the passed value to the installed LogManager with a LogLevel of 'Debug'. - * For Boolean, numbers, and strings, the internal values are printed, for all other - * types, the type is printed instead - */ - int printDebug(lua_State* L) { - return printInternal(ghoul::logging::LogLevel::Debug, L); + std::string path = luaL_checkstring(L, -1); + path = absPath(path); + lua_pushstring(L, path.c_str()); + return 1; +} + +/** + * \ingroup LuaScripts + * setPathToken(string, string): + * Registers the path token provided by the first argument to the path in the second + * argument. If the path token already exists, it will be silently overridden. + */ +int setPathToken(lua_State* L) { + int nArguments = lua_gettop(L); + if (nArguments != 2) { + return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments); } - /** - * \ingroup LuaScripts - * printInfo(*): - * Logs the passed value to the installed LogManager with a LogLevel of 'Info'. - * For Boolean, numbers, and strings, the internal values are printed, for all other - * types, the type is printed instead - */ - int printInfo(lua_State* L) { - return printInternal(ghoul::logging::LogLevel::Info, L); - } - - /** - * \ingroup LuaScripts - * printWarning(*): - * Logs the passed value to the installed LogManager with a LogLevel of 'Warning'. - * For Boolean, numbers, and strings, the internal values are printed, for all other - * types, the type is printed instead - */ - int printWarning(lua_State* L) { - return printInternal(ghoul::logging::LogLevel::Warning, L); - } - - /** - * \ingroup LuaScripts - * printError(*): - * Logs the passed value to the installed LogManager with a LogLevel of 'Error'. - * For Boolean, numbers, and strings, the internal values are printed, for all other - * types, the type is printed instead - */ - int printError(lua_State* L) { - return printInternal(ghoul::logging::LogLevel::Error, L); - } - - /** - * \ingroup LuaScripts - * printFatal(*): - * Logs the passed value to the installed LogManager with a LogLevel of 'Fatal'. - * For Boolean, numbers, and strings, the internal values are printed, for all other - * types, the type is printed instead - */ - int printFatal(lua_State* L) { - return printInternal(ghoul::logging::LogLevel::Fatal, L); - } - - /** - * \ingroup LuaScripts - * absPath(string): - * Passes the argument to FileSystem::absolutePath, which resolves occuring path - * tokens and returns the absolute path. - */ - int absolutePath(lua_State* L) { - int nArguments = lua_gettop(L); - if (nArguments != 1) - return luaL_error(L, "Expected %d arguments, got %d", 1, nArguments); - - std::string path = luaL_checkstring(L, -1); - path = absPath(path); - lua_pushstring(L, path.c_str()); - return 1; - } - - /** - * \ingroup LuaScripts - * setPathToken(string, string): - * Registers the path token provided by the first argument to the path in the second - * argument. If the path token already exists, it will be silently overridden. - */ - int setPathToken(lua_State* L) { - int nArguments = lua_gettop(L); - if (nArguments != 2) - return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments); - - std::string pathToken = luaL_checkstring(L, -1); - std::string path = luaL_checkstring(L, -2); - FileSys.registerPathToken( - pathToken, - path, - ghoul::filesystem::FileSystem::Override::Yes - ); - return 0; - } + std::string path = luaL_checkstring(L, -1); + std::string pathToken = luaL_checkstring(L, -2); + FileSys.registerPathToken( + pathToken, + path, + ghoul::filesystem::FileSystem::Override::Yes + ); + return 0; +} } // namespace luascriptfunctions