mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-14 22:10:50 -05:00
Move OpenSpaceEngine::isMaster method into WindowWrapper class
This commit is contained in:
@@ -83,10 +83,6 @@ std::pair<int, int> supportedOpenGLVersion() {
|
||||
void mainInitFunc() {
|
||||
LTRACE("main::mainInitFunc(begin)");
|
||||
|
||||
// Is this node the master?
|
||||
// @CLEANUP: This can be removed and replaced with a call to a windowwrapper ---abock
|
||||
OsEng.setMaster(SgctEngine->isMaster());
|
||||
|
||||
LDEBUG("Initializing OpenSpace Engine");
|
||||
// @CLEANUP: The return value should be replaced with an exception ---abock
|
||||
bool success = OsEng.initialize();
|
||||
@@ -210,7 +206,7 @@ void mainPostDrawFunc() {
|
||||
|
||||
void mainExternalControlCallback(const char* receivedChars, int size) {
|
||||
LTRACE("main::mainExternalControlCallback(begin)");
|
||||
if (OsEng.isMaster()) {
|
||||
if (SgctEngine->isMaster()) {
|
||||
OsEng.externalControlCallback(receivedChars, size, 0);
|
||||
}
|
||||
LTRACE("main::mainExternalControlCallback(end)");
|
||||
@@ -218,7 +214,7 @@ void mainExternalControlCallback(const char* receivedChars, int size) {
|
||||
|
||||
void mainKeyboardCallback(int key, int, int action, int mods) {
|
||||
LTRACE("main::mainKeyboardCallback(begin)");
|
||||
if (OsEng.isMaster()) {
|
||||
if (SgctEngine->isMaster()) {
|
||||
OsEng.keyboardCallback(
|
||||
openspace::Key(key),
|
||||
openspace::KeyModifier(mods),
|
||||
@@ -230,7 +226,7 @@ void mainKeyboardCallback(int key, int, int action, int mods) {
|
||||
|
||||
void mainMouseButtonCallback(int key, int action) {
|
||||
LTRACE("main::mainMouseButtonCallback(begin)");
|
||||
if (OsEng.isMaster()) {
|
||||
if (SgctEngine->isMaster()) {
|
||||
OsEng.mouseButtonCallback(
|
||||
openspace::MouseButton(key),
|
||||
openspace::MouseAction(action)
|
||||
@@ -240,19 +236,19 @@ void mainMouseButtonCallback(int key, int action) {
|
||||
}
|
||||
|
||||
void mainMousePosCallback(double x, double y) {
|
||||
if (OsEng.isMaster()) {
|
||||
if (SgctEngine->isMaster()) {
|
||||
OsEng.mousePositionCallback(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void mainMouseScrollCallback(double posX, double posY) {
|
||||
if (OsEng.isMaster()) {
|
||||
if (SgctEngine->isMaster()) {
|
||||
OsEng.mouseScrollWheelCallback(posY);
|
||||
}
|
||||
}
|
||||
|
||||
void mainCharCallback(unsigned int codepoint, int mods) {
|
||||
if (OsEng.isMaster()) {
|
||||
if (SgctEngine->isMaster()) {
|
||||
OsEng.charCallback(codepoint, openspace::KeyModifier(mods));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,6 @@ public:
|
||||
static bool isInitialized();
|
||||
static OpenSpaceEngine& ref();
|
||||
|
||||
bool isMaster();
|
||||
void setMaster(bool master);
|
||||
double runTime();
|
||||
void setRunTime(double t);
|
||||
|
||||
@@ -249,7 +247,6 @@ private:
|
||||
|
||||
} _moduleCallbacks;
|
||||
|
||||
bool _isMaster;
|
||||
double _runTime;
|
||||
|
||||
// Whether the application is currently in shutdown mode (i.e. counting down the timer
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
bool isRegularRendering() const override;
|
||||
bool hasGuiWindow() const override;
|
||||
bool isGuiWindow() const override;
|
||||
bool isMaster() const override;
|
||||
bool isUsingSwapGroups() const override;
|
||||
bool isSwapGroupMaster() const override;
|
||||
|
||||
|
||||
@@ -175,6 +175,13 @@ public:
|
||||
* \return Whether the current rendering window is GUI-only
|
||||
*/
|
||||
virtual bool isGuiWindow() const;
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if this application is the master for a clustered
|
||||
* environment.
|
||||
* \return Whether this applicaiton is the master for a clustered environment.
|
||||
*/
|
||||
virtual bool isMaster() const;
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the current rendering window is using swap groups.
|
||||
|
||||
@@ -105,7 +105,7 @@ OnScreenGUIModule::OnScreenGUIModule()
|
||||
OpenSpaceEngine::CallbackOption::PostSyncPreDraw,
|
||||
[](){
|
||||
WindowWrapper& wrapper = OsEng.windowWrapper();
|
||||
if (OsEng.isMaster() && wrapper.isRegularRendering()) {
|
||||
if (wrapper.isMaster() && wrapper.isRegularRendering()) {
|
||||
glm::vec2 mousePosition = wrapper.mousePosition();
|
||||
//glm::ivec2 drawBufferResolution = _windowWrapper->currentDrawBufferResolution();
|
||||
glm::ivec2 windowSize = wrapper.currentWindowSize();
|
||||
@@ -130,7 +130,7 @@ OnScreenGUIModule::OnScreenGUIModule()
|
||||
[](){
|
||||
WindowWrapper& wrapper = OsEng.windowWrapper();
|
||||
bool showGui = wrapper.hasGuiWindow() ? wrapper.isGuiWindow() : true;
|
||||
if (OsEng.isMaster() && wrapper.isRegularRendering() && showGui) {
|
||||
if (wrapper.isMaster() && wrapper.isRegularRendering() && showGui) {
|
||||
gui.endFrame();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,6 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName,
|
||||
, _parallelConnection(new ParallelConnection)
|
||||
, _windowWrapper(std::move(windowWrapper))
|
||||
, _globalPropertyNamespace(new properties::PropertyOwner)
|
||||
, _isMaster(false)
|
||||
, _runTime(0.0)
|
||||
, _isInShutdownMode(false)
|
||||
, _shutdownCountdown(0.f)
|
||||
@@ -804,14 +803,6 @@ bool OpenSpaceEngine::initializeGL() {
|
||||
return success;
|
||||
}
|
||||
|
||||
bool OpenSpaceEngine::isMaster() {
|
||||
return _isMaster;
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::setMaster(bool master) {
|
||||
_isMaster = master;
|
||||
}
|
||||
|
||||
double OpenSpaceEngine::runTime() {
|
||||
return _runTime;
|
||||
}
|
||||
@@ -827,8 +818,10 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
_windowWrapper->setSynchronization(false);
|
||||
}
|
||||
|
||||
_syncEngine->presync(_isMaster);
|
||||
if (_isMaster) {
|
||||
bool master = _windowWrapper->isMaster();
|
||||
|
||||
_syncEngine->presync(master);
|
||||
if (master) {
|
||||
double dt = _windowWrapper->averageDeltaTime();
|
||||
_timeManager->preSynchronization(dt);
|
||||
|
||||
@@ -855,7 +848,8 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
_syncEngine->postsync(_isMaster);
|
||||
bool master = _windowWrapper->isMaster();
|
||||
_syncEngine->postsync(master);
|
||||
|
||||
if (_isInShutdownMode) {
|
||||
if (_shutdownCountdown <= 0.f) {
|
||||
@@ -870,7 +864,7 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
_renderEngine->updateScreenSpaceRenderables();
|
||||
_renderEngine->updateShaderPrograms();
|
||||
|
||||
if (!_isMaster) {
|
||||
if (!master) {
|
||||
_renderEngine->camera()->invalidateCache();
|
||||
}
|
||||
|
||||
@@ -938,75 +932,65 @@ void OpenSpaceEngine::postDraw() {
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) {
|
||||
if (_isMaster) {
|
||||
for (const auto& func : _moduleCallbacks.keyboard) {
|
||||
bool consumed = func(key, mod, action);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
for (const auto& func : _moduleCallbacks.keyboard) {
|
||||
bool consumed = func(key, mod, action);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == _console->commandInputButton()) {
|
||||
if (action == KeyAction::Press) {
|
||||
_console->toggleMode();
|
||||
}
|
||||
} else if (!_console->isVisible()) {
|
||||
_interactionHandler->keyboardCallback(key, mod, action);
|
||||
} else {
|
||||
_console->keyboardCallback(key, mod, action);
|
||||
}
|
||||
|
||||
if (key == _console->commandInputButton()) {
|
||||
if (action == KeyAction::Press) {
|
||||
_console->toggleMode();
|
||||
}
|
||||
} else if (!_console->isVisible()) {
|
||||
_interactionHandler->keyboardCallback(key, mod, action);
|
||||
} else {
|
||||
_console->keyboardCallback(key, mod, action);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier) {
|
||||
if (_isMaster) {
|
||||
for (const auto& func : _moduleCallbacks.character) {
|
||||
bool consumed = func(codepoint, modifier);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
for (const auto& func : _moduleCallbacks.character) {
|
||||
bool consumed = func(codepoint, modifier);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_console->isVisible()) {
|
||||
_console->charCallback(codepoint, modifier);
|
||||
}
|
||||
if (_console->isVisible()) {
|
||||
_console->charCallback(codepoint, modifier);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action) {
|
||||
if (_isMaster) {
|
||||
for (const auto& func : _moduleCallbacks.mouseButton) {
|
||||
bool consumed = func(button, action);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
for (const auto& func : _moduleCallbacks.mouseButton) {
|
||||
bool consumed = func(button, action);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
|
||||
_interactionHandler->mouseButtonCallback(button, action);
|
||||
}
|
||||
|
||||
_interactionHandler->mouseButtonCallback(button, action);
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::mousePositionCallback(double x, double y) {
|
||||
if (_isMaster) {
|
||||
for (const auto& func : _moduleCallbacks.mousePosition) {
|
||||
func(x, y);
|
||||
}
|
||||
|
||||
_interactionHandler->mousePositionCallback(x, y);
|
||||
for (const auto& func : _moduleCallbacks.mousePosition) {
|
||||
func(x, y);
|
||||
}
|
||||
|
||||
_interactionHandler->mousePositionCallback(x, y);
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::mouseScrollWheelCallback(double pos) {
|
||||
if (_isMaster) {
|
||||
for (const auto& func : _moduleCallbacks.mouseScrollWheel) {
|
||||
bool consumed = func(pos);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
for (const auto& func : _moduleCallbacks.mouseScrollWheel) {
|
||||
bool consumed = func(pos);
|
||||
if (consumed) {
|
||||
return;
|
||||
}
|
||||
|
||||
_interactionHandler->mouseScrollWheelCallback(pos);
|
||||
}
|
||||
|
||||
_interactionHandler->mouseScrollWheelCallback(pos);
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::encode() {
|
||||
|
||||
@@ -162,6 +162,10 @@ bool SGCTWindowWrapper::hasGuiWindow() const {
|
||||
bool SGCTWindowWrapper::isGuiWindow() const {
|
||||
return sgct::Engine::instance()->getCurrentWindowPtr()->getName() == GuiWindowName;
|
||||
}
|
||||
|
||||
bool SGCTWindowWrapper::isMaster() const {
|
||||
return sgct::Engine::instance()->isMaster();
|
||||
}
|
||||
|
||||
bool SGCTWindowWrapper::isSwapGroupMaster() const {
|
||||
return sgct::Engine::instance()->getCurrentWindowPtr()->isSwapGroupMaster();
|
||||
|
||||
@@ -129,6 +129,10 @@ bool WindowWrapper::isGuiWindow() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WindowWrapper::isMaster() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WindowWrapper::isSwapGroupMaster() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -32,19 +32,18 @@ namespace luascriptfunctions {
|
||||
* Set the port for parallel connection
|
||||
*/
|
||||
int setPort(lua_State* L) {
|
||||
|
||||
const bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
if (isFunction) {
|
||||
// If the top of the stack is a function, it is ourself
|
||||
const char* msg = lua_pushfstring(L, "method called without argument");
|
||||
return luaL_error(L, "bad argument (%s)", msg);
|
||||
}
|
||||
|
||||
const bool isNumber = (lua_isnumber(L, -1) != 0);
|
||||
bool isNumber = (lua_isnumber(L, -1) != 0);
|
||||
if (isNumber) {
|
||||
int value = lua_tonumber(L, -1);
|
||||
std::string port = std::to_string(value);
|
||||
if(OsEng.isMaster()){
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().setPort(port);
|
||||
}
|
||||
return 0;
|
||||
@@ -59,18 +58,17 @@ int setPort(lua_State* L) {
|
||||
}
|
||||
|
||||
int setAddress(lua_State* L) {
|
||||
|
||||
const bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
if (isFunction) {
|
||||
// If the top of the stack is a function, it is ourself
|
||||
const char* msg = lua_pushfstring(L, "method called without argument");
|
||||
return luaL_error(L, "bad argument (%s)", msg);
|
||||
}
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
int type = lua_type(L, -1);
|
||||
if (type == LUA_TSTRING) {
|
||||
std::string address = luaL_checkstring(L, -1);
|
||||
if(OsEng.isMaster()){
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().setAddress(address);
|
||||
}
|
||||
return 0;
|
||||
@@ -85,18 +83,17 @@ int setAddress(lua_State* L) {
|
||||
}
|
||||
|
||||
int setPassword(lua_State* L) {
|
||||
|
||||
const bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
if (isFunction) {
|
||||
// If the top of the stack is a function, it is ourself
|
||||
const char* msg = lua_pushfstring(L, "method called without argument");
|
||||
return luaL_error(L, "bad argument (%s)", msg);
|
||||
}
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
int type = lua_type(L, -1);
|
||||
if (type == LUA_TSTRING) {
|
||||
std::string pwd = luaL_checkstring(L, -1);
|
||||
if(OsEng.isMaster()){
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().setPassword(pwd);
|
||||
}
|
||||
return 0;
|
||||
@@ -111,18 +108,17 @@ int setPassword(lua_State* L) {
|
||||
}
|
||||
|
||||
int setDisplayName(lua_State* L) {
|
||||
|
||||
const bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
if (isFunction) {
|
||||
// If the top of the stack is a function, it is ourself
|
||||
const char* msg = lua_pushfstring(L, "method called without argument");
|
||||
return luaL_error(L, "bad argument (%s)", msg);
|
||||
}
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
int type = lua_type(L, -1);
|
||||
if (type == LUA_TSTRING) {
|
||||
std::string name = luaL_checkstring(L, -1);
|
||||
if(OsEng.isMaster()){
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().setName(name);
|
||||
}
|
||||
return 0;
|
||||
@@ -137,40 +133,39 @@ int setDisplayName(lua_State* L) {
|
||||
}
|
||||
|
||||
int connect(lua_State* L) {
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
if(OsEng.isMaster()){
|
||||
}
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().clientConnect();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disconnect(lua_State* L) {
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
if(OsEng.isMaster()){
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
}
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().signalDisconnect();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int requestHostship(lua_State* L) {
|
||||
|
||||
const bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
bool isFunction = (lua_isfunction(L, -1) != 0);
|
||||
if (isFunction) {
|
||||
// If the top of the stack is a function, it is ourself
|
||||
const char* msg = lua_pushfstring(L, "method called without argument");
|
||||
return luaL_error(L, "bad argument (%s)", msg);
|
||||
}
|
||||
|
||||
const int type = lua_type(L, -1);
|
||||
int type = lua_type(L, -1);
|
||||
if (type == LUA_TSTRING) {
|
||||
std::string pwd = luaL_checkstring(L, -1);
|
||||
if(OsEng.isMaster()){
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().requestHostship(pwd);
|
||||
}
|
||||
return 0;
|
||||
@@ -185,11 +180,11 @@ int requestHostship(lua_State* L) {
|
||||
}
|
||||
|
||||
int resignHostship(lua_State* L) {
|
||||
|
||||
int nArguments = lua_gettop(L);
|
||||
if (nArguments != 0)
|
||||
if (nArguments != 0) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments);
|
||||
if (OsEng.isMaster()) {
|
||||
}
|
||||
if (OsEng.windowWrapper().isMaster()) {
|
||||
OsEng.parallelConnection().resignHostship();
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -472,13 +472,15 @@ void RenderEngine::render(const glm::mat4& projectionMatrix, const glm::mat4& vi
|
||||
LTRACE("RenderEngine::render(begin)");
|
||||
_mainCamera->sgctInternal.setViewMatrix(viewMatrix);
|
||||
_mainCamera->sgctInternal.setProjectionMatrix(projectionMatrix);
|
||||
|
||||
WindowWrapper& wrapper = OsEng.windowWrapper();
|
||||
|
||||
if (!(OsEng.isMaster() && _disableMasterRendering) && !OsEng.windowWrapper().isGuiWindow()) {
|
||||
if (!(wrapper.isMaster() && _disableMasterRendering) && !wrapper.isGuiWindow()) {
|
||||
_renderer->render(_globalBlackOutFactor, _performanceManager != nullptr);
|
||||
}
|
||||
|
||||
// Print some useful information on the master viewport
|
||||
if (OsEng.isMaster() && OsEng.windowWrapper().isSimpleRendering()) {
|
||||
if (wrapper.isMaster() && wrapper.isSimpleRendering()) {
|
||||
renderInformation();
|
||||
}
|
||||
|
||||
@@ -487,7 +489,7 @@ void RenderEngine::render(const glm::mat4& projectionMatrix, const glm::mat4& vi
|
||||
OsEng.windowWrapper().viewportPixelCoordinates().w / 3
|
||||
);
|
||||
|
||||
if(_showFrameNumber) {
|
||||
if (_showFrameNumber) {
|
||||
RenderFontCr(*_fontBig, penPosition, "%i", _frameNumber);
|
||||
}
|
||||
|
||||
@@ -495,8 +497,9 @@ void RenderEngine::render(const glm::mat4& projectionMatrix, const glm::mat4& vi
|
||||
|
||||
|
||||
for (auto screenSpaceRenderable : _screenSpaceRenderables) {
|
||||
if (screenSpaceRenderable->isEnabled() && screenSpaceRenderable->isReady())
|
||||
if (screenSpaceRenderable->isEnabled() && screenSpaceRenderable->isReady()) {
|
||||
screenSpaceRenderable->render();
|
||||
}
|
||||
}
|
||||
LTRACE("RenderEngine::render(end)");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user