From 27c5bcaa93abc937b3a44ef5ee7a6cebf58b052d Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 19 Feb 2015 14:43:29 +0100 Subject: [PATCH] Fix bug where a script execution would stop completely if a property was not found Added helper file to ease Lua script callback testing Made errors in setPropertyValue and getPropertyValue functions not fatal --- ext/ghoul | 2 +- include/openspace/scripting/script_helper.h | 36 ++++++++++ include/openspace/scripting/scriptengine.h | 2 +- openspace-data | 2 +- src/scenegraph/scenegraph.cpp | 73 ++++++++++++++++----- 5 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 include/openspace/scripting/script_helper.h diff --git a/ext/ghoul b/ext/ghoul index 41d3165183..740beb2a65 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 41d3165183688497070066f322de7066c307b5c9 +Subproject commit 740beb2a657c41e98bd53f3376eaa97c1483d306 diff --git a/include/openspace/scripting/script_helper.h b/include/openspace/scripting/script_helper.h new file mode 100644 index 0000000000..c5307263ee --- /dev/null +++ b/include/openspace/scripting/script_helper.h @@ -0,0 +1,36 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __SCRIPT_HELPER_H__ +#define __SCRIPT_HELPER_H__ + +#define SCRIPT_CHECK_ARGUMENTS(__stack__, __reqArg__, __realArg__) \ + if (__realArg__ != __reqArg__) { \ + LERROR(ghoul::lua::errorLocation(__stack__) << "Expected " << __reqArg__ << \ + " arguments, got " << __realArg__); \ + return 0; \ + } + + +#endif // __SCRIPT_HELPER_H__ diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index a28219a8ac..8f1b3ab2b1 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -98,7 +98,7 @@ private: std::vector _queuedScripts; std::string _currentSyncedScript; }; - + } // namespace scripting } // namespace openspace diff --git a/openspace-data b/openspace-data index 049eb95dfd..d8bc6ea847 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 049eb95dfd1c739ebbb3c34eba741e68329f155b +Subproject commit d8bc6ea847ff2779380f6cb435fbad3fef67e520 diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index f399b9481a..2a797cc203 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -69,24 +70,29 @@ namespace luascriptfunctions { * with the type the denoted Property expects */ int property_setValue(lua_State* L) { - using ghoul::lua::luaTypeToString; + static const std::string _loggerCat = "property_setValue"; + using ghoul::lua::errorLocation; + using ghoul::lua::luaTypeToString; int nArguments = lua_gettop(L); - if (nArguments != 2) - return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments); + SCRIPT_CHECK_ARGUMENTS(L, 2, nArguments); std::string uri = luaL_checkstring(L, -2); const int type = lua_type(L, -1); openspace::properties::Property* prop = property(uri); - if (!prop) - return luaL_error(L, "Property with URL '%s' could not be found", uri.c_str()); + if (!prop) { + LERROR(errorLocation(L) << "Property with URI '" << uri << "' was not found"); + return 0; + } - if (type != prop->typeLua()) - return luaL_error(L, "Property '%s' does not accept input of type '%s'. \ - Requested type: '%s'", uri.c_str(), - luaTypeToString(type).c_str(), - luaTypeToString(prop->typeLua()).c_str()); + + if (type != prop->typeLua()) { + LERROR(errorLocation(L) << "Property '" << uri << + "' does not accept input of type '" << luaTypeToString(type) << + "'. Requested type: '" << luaTypeToString(prop->typeLua()) << "'"); + return 0; + } else prop->setLua(L); @@ -100,15 +106,19 @@ int property_setValue(lua_State* L) { * be passed to the setPropertyValue method. */ int property_getValue(lua_State* L) { + static const std::string _loggerCat = "property_getValue"; + using ghoul::lua::errorLocation; + int nArguments = lua_gettop(L); - if (nArguments != 1) - return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments); + SCRIPT_CHECK_ARGUMENTS(L, 1, nArguments); std::string uri = luaL_checkstring(L, -1); openspace::properties::Property* prop = property(uri); - if (!prop) - return luaL_error(L, "Property with URL '%s' could not be found", uri.c_str()); + if (!prop) { + LERROR(errorLocation(L) << "Property with URL '" << uri << "' was not found"); + return 0; + } else prop->getLua(L); return 1; @@ -121,9 +131,10 @@ int property_getValue(lua_State* L) { * be passed to the setPropertyValue method. */ int loadScene(lua_State* L) { + static const std::string _loggerCat = "loadScene"; + int nArguments = lua_gettop(L); - if (nArguments != 1) - return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments); + SCRIPT_CHECK_ARGUMENTS(L, 1, nArguments); std::string sceneFile = luaL_checkstring(L, -1); @@ -163,17 +174,45 @@ bool SceneGraph::initialize() // Start Timing for building SceneGraph shaders typedef std::chrono::high_resolution_clock clock_; typedef std::chrono::duration > second_; - std::chrono::time_point beginning(clock_::now()); + std::chrono::time_point beginning(clock_::now()); + // fboPassthrough program + tmpProgram = ProgramObject::Build("fboPassProgram", + "${SHADERS}/fboPass_vs.glsl", + "${SHADERS}/fboPass_fs.glsl"); + if (!tmpProgram) return false; + tmpProgram->setProgramObjectCallback(cb); + _programs.push_back(tmpProgram); + OsEng.ref().configurationManager()->setValue("fboPassProgram", tmpProgram); + + // projection program + tmpProgram = ProgramObject::Build("projectiveProgram", + "${SHADERS}/projectiveTexture_vs.glsl", + "${SHADERS}/projectiveTexture_fs.glsl"); + if (!tmpProgram) return false; + tmpProgram->setProgramObjectCallback(cb); + _programs.push_back(tmpProgram); + OsEng.ref().configurationManager()->setValue("projectiveProgram", tmpProgram); + // pscstandard tmpProgram = ProgramObject::Build("pscstandard", "${SHADERS}/pscstandard_vs.glsl", "${SHADERS}/pscstandard_fs.glsl"); if( ! tmpProgram) return false; tmpProgram->setProgramObjectCallback(cb); + _programs.push_back(tmpProgram); OsEng.ref().configurationManager()->setValue("pscShader", tmpProgram); + // pscstandard + tmpProgram = ProgramObject::Build("FovProgram", + "${SHADERS}/fov_vs.glsl", + "${SHADERS}/fov_fs.glsl"); + if (!tmpProgram) return false; + tmpProgram->setProgramObjectCallback(cb); + _programs.push_back(tmpProgram); + OsEng.ref().configurationManager()->setValue("FovProgram", tmpProgram); + // RaycastProgram tmpProgram = ProgramObject::Build("RaycastProgram", "${SHADERS}/exitpoints.vert",