Started change moving from explicit SGCT functions to wrapper class

This commit is contained in:
Alexander Bock
2015-10-25 13:50:39 -05:00
parent 26ea512910
commit 5456b5ee85
9 changed files with 133 additions and 44 deletions

View File

@@ -23,7 +23,7 @@
****************************************************************************************/
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/sgctwindow.h>
#include <openspace/engine/sgctwindowhandler.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logging>
#include <openspace/rendering/renderengine.h>
@@ -87,7 +87,7 @@ int main(int argc, char** argv) {
std::vector<std::string> sgctArguments;
const bool success = openspace::OpenSpaceEngine::create(
argc, argv,
new openspace::SGCTWindow,
new openspace::SGCTWindowHandler,
sgctArguments
);
if (!success)

View File

@@ -46,7 +46,7 @@ class GUI;
class RenderEngine;
class SyncBuffer;
class ModuleEngine;
class Window;
class WindowHandler;
namespace interaction {
class InteractionHandler;
@@ -68,7 +68,7 @@ namespace properties {
class OpenSpaceEngine {
public:
static bool create(int argc, char** argv, Window* windowHandler, std::vector<std::string>& sgctArguments);
static bool create(int argc, char** argv, WindowHandler* windowHandler, std::vector<std::string>& sgctArguments);
static void destroy();
static OpenSpaceEngine& ref();
@@ -90,7 +90,7 @@ public:
ModuleEngine* moduleEngine();
network::ParallelConnection* parallelConnection();
properties::PropertyOwner* globalPropertyOwner();
Window* windowWrapper();
WindowHandler* windowWrapper();
gui::GUI* gui();
@@ -115,7 +115,7 @@ public:
void runSettingsScripts();
private:
OpenSpaceEngine(std::string programName, Window* windowHandler);
OpenSpaceEngine(std::string programName, WindowHandler* windowHandler);
~OpenSpaceEngine();
OpenSpaceEngine(const OpenSpaceEngine& rhs) = delete;
@@ -139,7 +139,7 @@ private:
ModuleEngine* _moduleEngine;
gui::GUI* _gui;
network::ParallelConnection* _parallelConnection;
Window* _windowWrapper;
WindowHandler* _windowHandler;
properties::PropertyOwner* _globalPropertyNamespace;

View File

@@ -22,18 +22,28 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __SGCTWINDOW_H__
#define __SGCTWINDOW_H__
#ifndef __SGCTWINDOWHANDLER_H__
#define __SGCTWINDOWHANDLER_H__
#include <openspace/engine/window.h>
#include <openspace/engine/windowhandler.h>
namespace openspace {
class SGCTWindow : public Window {
class SGCTWindowHandler : public WindowHandler {
public:
void setBarrier(bool enabled) override;
void clearAllWindows() override;
double averageDeltaTime() override;
glm::vec2 mousePosition() override;
glm::ivec2 currentWindowSize() override;
glm::ivec2 currentWindowResolution() override;
// void forEachWindow(std::function<void (void)> function) override;
};
} // namespace openspace
#endif // __SGCTWINDOW_H__
#endif // __SGCTWINDOWHANDLER_H__

View File

@@ -22,14 +22,29 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __WINDOW_H__
#define __WINDOW_H__
#ifndef __WINDOWHANDLER_H__
#define __WINDOWHANDLER_H__
#include <ghoul/glm.h>
#include <functional>
namespace openspace {
class Window {
class WindowHandler {
public:
virtual void setBarrier(bool enabled) = 0;
virtual void clearAllWindows() = 0;
virtual double averageDeltaTime() = 0;
virtual glm::vec2 mousePosition() = 0;
virtual glm::ivec2 currentWindowSize() = 0;
virtual glm::ivec2 currentWindowResolution() = 0;
//virtual void forEachWindow(std::function<void (void)> function) = 0;
};
} // namespace openspace

View File

@@ -33,9 +33,9 @@ set(OPENSPACE_SOURCE
${OPENSPACE_BASE_DIR}/src/engine/downloadmanager.cpp
${OPENSPACE_BASE_DIR}/src/engine/logfactory.cpp
${OPENSPACE_BASE_DIR}/src/engine/moduleengine.cpp
${OPENSPACE_BASE_DIR}/src/engine/sgctwindow.cpp
${OPENSPACE_BASE_DIR}/src/engine/sgctwindowhandler.cpp
${OPENSPACE_BASE_DIR}/src/engine/openspaceengine.cpp
${OPENSPACE_BASE_DIR}/src/engine/window.cpp
${OPENSPACE_BASE_DIR}/src/engine/windowhandler.cpp
${OPENSPACE_BASE_DIR}/src/interaction/controller.cpp
${OPENSPACE_BASE_DIR}/src/interaction/deviceidentifier.cpp
${OPENSPACE_BASE_DIR}/src/interaction/interactionhandler.cpp
@@ -99,9 +99,9 @@ set(OPENSPACE_HEADER
${OPENSPACE_BASE_DIR}/include/openspace/engine/downloadmanager.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/logfactory.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/moduleengine.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/sgctwindow.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/sgctwindowhandler.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/openspaceengine.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/window.h
${OPENSPACE_BASE_DIR}/include/openspace/engine/windowhandler.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/controller.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/deviceidentifier.h
${OPENSPACE_BASE_DIR}/include/openspace/interaction/interactionhandler.h

View File

@@ -32,6 +32,7 @@
#include <openspace/engine/configurationmanager.h>
#include <openspace/engine/logfactory.h>
#include <openspace/engine/windowhandler.h>
#include <openspace/interaction/interactionhandler.h>
#include <openspace/interaction/keyboardcontroller.h>
#include <openspace/interaction/luaconsole.h>
@@ -101,7 +102,7 @@ namespace openspace {
OpenSpaceEngine* OpenSpaceEngine::_engine = nullptr;
OpenSpaceEngine::OpenSpaceEngine(std::string programName, Window* windowHandler)
OpenSpaceEngine::OpenSpaceEngine(std::string programName, WindowHandler* windowHandler)
: _configurationManager(new ConfigurationManager)
, _interactionHandler(new interaction::InteractionHandler)
, _renderEngine(new RenderEngine)
@@ -112,7 +113,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName, Window* windowHandler)
, _moduleEngine(new ModuleEngine)
, _gui(new gui::GUI)
, _parallelConnection(new network::ParallelConnection)
, _windowWrapper(windowHandler)
, _windowHandler(windowHandler)
, _globalPropertyNamespace(new properties::PropertyOwner)
, _isMaster(false)
, _runTime(0.0)
@@ -132,8 +133,8 @@ OpenSpaceEngine::~OpenSpaceEngine() {
delete _globalPropertyNamespace;
_globalPropertyNamespace = nullptr;
delete _windowWrapper;
_windowWrapper = nullptr;
delete _windowHandler;
_windowHandler = nullptr;
delete _parallelConnection;
_parallelConnection = nullptr;
@@ -176,7 +177,7 @@ OpenSpaceEngine& OpenSpaceEngine::ref() {
bool OpenSpaceEngine::create(
int argc, char** argv,
Window* windowHandler,
WindowHandler* windowHandler,
std::vector<std::string>& sgctArguments)
{
ghoul::initialize();
@@ -422,13 +423,7 @@ bool OpenSpaceEngine::isInitialized() {
}
void OpenSpaceEngine::clearAllWindows() {
size_t n = sgct::Engine::instance()->getNumberOfWindows();
for (size_t i = 0; i < n; ++i) {
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLFWwindow* win = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle();
glfwSwapBuffers(win);
}
_windowHandler->clearAllWindows();
}
bool OpenSpaceEngine::gatherCommandlineArguments() {
@@ -672,8 +667,7 @@ void OpenSpaceEngine::setRunTime(double d){
void OpenSpaceEngine::preSynchronization() {
FileSys.triggerFilesystemEvents();
if (_isMaster) {
//const double dt = sgct::Engine::instance()->getDt();
const double dt = sgct::Engine::instance()->getAvgDt();
double dt = _windowHandler->averageDeltaTime();
Time::ref().advanceTime(dt);
Time::ref().preSynchronization();
@@ -696,18 +690,15 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
if (_isMaster && _gui->isEnabled()) {
double posX, posY;
sgct::Engine::instance()->getMousePos(0, &posX, &posY);
int x,y;
sgct::Engine::instance()->getWindowPtr(0)->getFinalFBODimensions(x, y);
glm::vec2 mousePosition = _windowHandler->mousePosition();
glm::ivec2 windowResolution = _windowHandler->currentWindowResolution();
int button0 = sgct::Engine::instance()->getMouseButton(0, 0);
int button1 = sgct::Engine::instance()->getMouseButton(0, 1);
bool buttons[2] = { button0 != 0, button1 != 0 };
double dt = std::max(sgct::Engine::instance()->getDt(), 1.0/60.0);
_gui->startFrame(static_cast<float>(dt), glm::vec2(glm::ivec2(x,y)), glm::vec2(posX, posY), buttons);
_gui->startFrame(static_cast<float>(dt), glm::vec2(windowResolution), mousePosition, buttons);
}
}
@@ -831,11 +822,11 @@ void OpenSpaceEngine::externalControlCallback(const char* receivedChars,
}
void OpenSpaceEngine::enableBarrier() {
sgct::SGCTWindow::setBarrier(true);
_windowHandler->setBarrier(true);
}
void OpenSpaceEngine::disableBarrier() {
sgct::SGCTWindow::setBarrier(false);
_windowHandler->setBarrier(false);
}
NetworkEngine* OpenSpaceEngine::networkEngine() {
@@ -856,9 +847,9 @@ properties::PropertyOwner* OpenSpaceEngine::globalPropertyOwner() {
return _globalPropertyNamespace;
}
Window* OpenSpaceEngine::windowWrapper() {
ghoul_assert(_windowWrapper, "Window Wrapper");
return _windowWrapper;
WindowHandler* OpenSpaceEngine::windowWrapper() {
ghoul_assert(_windowHandler, "Window Wrapper");
return _windowHandler;
}
} // namespace openspace

View File

@@ -0,0 +1,73 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#include <ghoul/opengl/ghoul_gl.h>
#include "sgct.h"
#include <openspace/engine/sgctwindowhandler.h>
namespace openspace {
void SGCTWindowHandler::setBarrier(bool enabled) {
sgct::SGCTWindow::setBarrier(enabled);
}
void SGCTWindowHandler::clearAllWindows() {
size_t n = sgct::Engine::instance()->getNumberOfWindows();
for (size_t i = 0; i < n; ++i) {
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLFWwindow* win = sgct::Engine::instance()->getWindowPtr(i)->getWindowHandle();
glfwSwapBuffers(win);
}
}
double SGCTWindowHandler::averageDeltaTime() {
return sgct::Engine::instance()->getAvgDt();
}
glm::vec2 SGCTWindowHandler::mousePosition() {
double posX, posY;
sgct::Engine::instance()->getMousePos(0, &posX, &posY);
return glm::vec2(posX, posY);
}
glm::ivec2 SGCTWindowHandler::currentWindowSize() {
return glm::ivec2(0);
}
glm::ivec2 SGCTWindowHandler::currentWindowResolution() {
int x,y;
sgct::Engine::instance()->getWindowPtr(0)->getFinalFBODimensions(x, y);
return glm::ivec2(x, y);
}
//void forEachWindow(std::function<void (void)> function) {
// size_t n = sgct::Engine::instance()->getNumberOfWindows();
// for (size_t i = 0; i < n; ++i)
// function();
//}
} // namespace openspace

View File