Move OpenSpaceEngine::isMaster method into WindowWrapper class

This commit is contained in:
Alexander Bock
2017-02-25 11:29:28 -05:00
parent 4f64cbb141
commit 6c4efc4eec
10 changed files with 99 additions and 108 deletions
+43 -59
View File
@@ -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() {
+4
View File
@@ -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();
+4
View File
@@ -129,6 +129,10 @@ bool WindowWrapper::isGuiWindow() const {
return false;
}
bool WindowWrapper::isMaster() const {
return false;
}
bool WindowWrapper::isSwapGroupMaster() const {
return false;
}
+25 -30
View File
@@ -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;
+7 -4
View File
@@ -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)");
}