diff --git a/include/openspace/engine/wrapper/sgctwindowwrapper.h b/include/openspace/engine/wrapper/sgctwindowwrapper.h index 59f73443cd..c27aa006f3 100644 --- a/include/openspace/engine/wrapper/sgctwindowwrapper.h +++ b/include/openspace/engine/wrapper/sgctwindowwrapper.h @@ -65,6 +65,7 @@ public: bool hasGuiWindow() const override; bool isGuiWindow() const override; bool isMaster() const override; + int clusterId() const override; bool isUsingSwapGroups() const override; bool isSwapGroupMaster() const override; diff --git a/include/openspace/engine/wrapper/windowwrapper.h b/include/openspace/engine/wrapper/windowwrapper.h index c8ae700f3b..2c5dea6a2a 100644 --- a/include/openspace/engine/wrapper/windowwrapper.h +++ b/include/openspace/engine/wrapper/windowwrapper.h @@ -207,6 +207,13 @@ public: */ virtual bool isMaster() const; + /** + * Returns the unique identifier of this OpenSpace instance within the current cluster + * configuration. If this instance is not part of a cluster, this value is always 0. + * \return The cluster identifier of this OpenSpace instance + */ + virtual int clusterId() const; + /** * Returns true if the current rendering window is using swap groups. */ diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 2c2ee219db..969adb278f 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1564,6 +1564,23 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { {}, "string, string", "Removes a tag (second argument) from a scene graph node (first argument)" + }, + { + "isMaster", + &luascriptfunctions::isMaster, + {}, + "", + "Returns whether the current OpenSpace instance is the master node of a " + "cluster configuration. If this instance is not part of a cluster, this " + "function also returns 'true'." + }, + { + "clusterId", + &luascriptfunctions::clusterId, + {}, + "Returns the zero-based identifier for this OpenSpace instance in a " + "cluster configuration. If this instance is not part of a cluster, this " + "identifier is always 0." } }, { diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index f0858aefff..6b5561859a 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -262,4 +262,16 @@ int downloadFile(lua_State* L) { return 0; } +int isMaster(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::isMaster"); + ghoul::lua::push(L, OsEng.windowWrapper().isMaster()); + return 1; +} + +int clusterId(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::clusterId"); + ghoul::lua::push(L, OsEng.windowWrapper().clusterId()); + return 1; +} + } // namespace openspace::luascriptfunctions diff --git a/src/engine/wrapper/sgctwindowwrapper.cpp b/src/engine/wrapper/sgctwindowwrapper.cpp index c242259ad9..7e063dfb3b 100644 --- a/src/engine/wrapper/sgctwindowwrapper.cpp +++ b/src/engine/wrapper/sgctwindowwrapper.cpp @@ -217,6 +217,10 @@ bool SGCTWindowWrapper::isMaster() const { return sgct::Engine::instance()->isMaster(); } +int SGCTWindowWrapper::clusterId() const { + return sgct_core::ClusterManager::instance()->getThisNodeId(); +} + bool SGCTWindowWrapper::isSwapGroupMaster() const { return sgct::Engine::instance()->getCurrentWindowPtr()->isSwapGroupMaster(); } diff --git a/src/engine/wrapper/windowwrapper.cpp b/src/engine/wrapper/windowwrapper.cpp index e29a664a94..d4818913d9 100644 --- a/src/engine/wrapper/windowwrapper.cpp +++ b/src/engine/wrapper/windowwrapper.cpp @@ -145,6 +145,10 @@ bool WindowWrapper::isMaster() const { return false; } +int WindowWrapper::clusterId() const { + return 0; +} + bool WindowWrapper::isSwapGroupMaster() const { return false; }