Adding a Lua function to manually enable/disable the frame synchronization

This commit is contained in:
Alexander Bock
2016-09-24 14:55:20 +02:00
parent 8cf39cdd29
commit 616a115536
7 changed files with 63 additions and 23 deletions

View File

@@ -28,17 +28,14 @@
#include <openspace/util/keys.h>
#include <openspace/util/mouse.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/scripting/scriptscheduler.h>
#include <ghoul/glm.h>
#include <ghoul/misc/dictionary.h>
#include <memory>
#include <string>
#include <vector>
namespace ghoul {
class Dictionary;
namespace cmdparser { class CommandlineParser; }
namespace fontrendering { class FontManager; }
}
@@ -61,6 +58,9 @@ namespace gui { class GUI; }
//namespace scripting { class ScriptEngine; }
namespace network { class ParallelConnection; }
namespace properties { class PropertyOwner; }
namespace scripting { struct LuaLibrary; }
namespace scripting { class ScriptScheduler; }
namespace scripting { class ScriptEngine; }
class OpenSpaceEngine {
public:
@@ -132,7 +132,7 @@ private:
~OpenSpaceEngine();
void clearAllWindows();
bool gatherCommandlineArguments();
void gatherCommandlineArguments();
void loadFonts();
void runScripts(const ghoul::Dictionary& scripts);
void runPreInitializationScripts(const std::string& sceneDescription);

View File

@@ -34,6 +34,8 @@
namespace openspace {
namespace scripting { struct LuaLibrary; }
/**
* A WindowWrapper is a class that handles the abstraction between OpenSpace and a
* specific window creation framework.<br>
@@ -42,6 +44,12 @@ namespace openspace {
*/
class WindowWrapper {
public:
/**
* Returns the Lua library that contains all Lua functions available to affect the
* windowing system.
*/
static scripting::LuaLibrary luaLibrary();
/**
* This method closes the application by calling the necessary terminate function of
* the window management system

View File

@@ -27,7 +27,7 @@
#include <openspace/util/spicemanager.h>
#include <modules/newhorizons/util/missionmanager.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/scripting/scriptengine.h>
namespace {

View File

@@ -53,7 +53,6 @@
#include <openspace/util/syncbuffer.h>
#include <openspace/util/transformationmanager.h>
#include <ghoul/ghoul.h>
#include <ghoul/cmdparser/commandlineparser.h>
#include <ghoul/cmdparser/singlecommand.h>
@@ -65,8 +64,9 @@
#include <ghoul/logging/visualstudiooutputlog.h>
#include <ghoul/lua/ghoul_lua.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/systemcapabilities/systemcapabilities>
#include <ghoul/misc/dictionary.h>
#include <ghoul/misc/onscopeexit.h>
#include <ghoul/systemcapabilities/systemcapabilities>
#include <fstream>
#include <queue>
@@ -243,9 +243,7 @@ bool OpenSpaceEngine::create(int argc, char** argv,
_engine = new OpenSpaceEngine(std::string(argv[0]), std::move(windowWrapper));
// Query modules for commandline arguments
bool gatherSuccess = _engine->gatherCommandlineArguments();
if (!gatherSuccess)
return false;
_engine->gatherCommandlineArguments();
// Parse commandline arguments
std::vector<std::string> args(argv, argv + argc);
@@ -420,6 +418,7 @@ bool OpenSpaceEngine::initialize() {
_scriptEngine->addLibrary(network::ParallelConnection::luaLibrary());
_scriptEngine->addLibrary(ModuleEngine::luaLibrary());
_scriptEngine->addLibrary(ScriptScheduler::luaLibrary());
_scriptEngine->addLibrary(WindowWrapper::luaLibrary());
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
_scriptEngine->addLibrary(IswaManager::luaLibrary());
@@ -587,9 +586,7 @@ void OpenSpaceEngine::clearAllWindows() {
_windowWrapper->clearAllWindows(glm::vec4(0.f, 0.f, 0.f, 1.f));
}
bool OpenSpaceEngine::gatherCommandlineArguments() {
// TODO: Get commandline arguments from all modules
void OpenSpaceEngine::gatherCommandlineArguments() {
commandlineArgumentPlaceholders.configurationName = "";
_commandlineParser->addCommand(std::make_unique<SingleCommand<std::string>>(
&commandlineArgumentPlaceholders.configurationName, "-config", "-c",
@@ -615,9 +612,6 @@ bool OpenSpaceEngine::gatherCommandlineArguments() {
"path to a cache file, overriding the value set in the OpenSpace configuration "
"file"
));
return true;
}
void OpenSpaceEngine::runScripts(const ghoul::Dictionary& scripts) {
@@ -691,9 +685,9 @@ void OpenSpaceEngine::runPostInitializationScripts(const std::string& sceneDescr
LINFO("Running Setup scripts");
lua_State* state = ghoul::lua::createNewLuaState();
OnExit(
// Delete the Lua state at the end of the scope, no matter what
[state](){ghoul::lua::destroyLuaState(state);}
);
// Delete the Lua state at the end of the scope, no matter what
[state](){ghoul::lua::destroyLuaState(state);}
);
OsEng.scriptEngine().initializeLuaState(state);
// First execute the script to get all global variables
@@ -713,7 +707,8 @@ void OpenSpaceEngine::runPostInitializationScripts(const std::string& sceneDescr
int success = lua_pcall(state, 0, 0, 0);
if (success != 0) {
LERROR("Error executing '" << PostInitializationFunction << "': " <<
lua_tostring(state, -1));
lua_tostring(state, -1)
);
}
}

View File

@@ -23,15 +23,52 @@
****************************************************************************************/
#include <openspace/engine/wrapper/windowwrapper.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/scripting/lualibrary.h>
#include <openspace/scripting/scriptengine.h>
#include <ghoul/misc/exception.h>
#include <string>
namespace luascriptfunctions {
int setSynchronization(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 1) {
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
}
bool b = lua_toboolean(L, -1) != 0;
OsEng.windowWrapper().setSynchronization(b);
return 0;
}
} // namespace luascriptfunctions
namespace openspace {
WindowWrapper::WindowWrapperException::WindowWrapperException(const std::string& msg)
: ghoul::RuntimeError(msg, "WindowWrapper")
{}
scripting::LuaLibrary WindowWrapper::luaLibrary() {
return {
"cluster",
{
{
"setSynchronization",
&luascriptfunctions::setSynchronization,
"bool",
"Enables or disables the frame synchronization of the cluster. If the "
"synchronization is enabled, the computers in the cluster will swap "
"their backbuffers at the same time, either supported by hardware or by "
"network signals."
}
}
};
}
void WindowWrapper::terminate() {}
void WindowWrapper::setBarrier(bool) {}

View File

@@ -714,7 +714,7 @@ void RenderEngine::setNAaSamples(int nAaSamples) {
}
scripting::LuaLibrary RenderEngine::luaLibrary() {
return{
return {
"",
{
{

View File

@@ -43,7 +43,7 @@ int takeScreenshot(lua_State* L) {
return 0;
}
else {
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
return luaL_error(L, "Expected %i or %i arguments, got %i", 0, 1, nArguments);
}
}