Changing WindowWrapper from pointer to reference

This commit is contained in:
Alexander Bock
2015-10-26 15:10:15 -05:00
parent f3fd055db8
commit 20861d68ad
9 changed files with 32 additions and 31 deletions

View File

@@ -94,7 +94,7 @@ public:
ModuleEngine* moduleEngine();
network::ParallelConnection* parallelConnection();
properties::PropertyOwner* globalPropertyOwner();
WindowWrapper* windowWrapper();
WindowWrapper& windowWrapper();
gui::GUI* gui();

View File

@@ -322,7 +322,7 @@ void ABuffer::invalidateABuffer() {
}
void ABuffer::updateDimensions() {
glm::ivec2 res = OsEng.windowWrapper()->currentWindowResolution();
glm::ivec2 res = OsEng.windowWrapper().currentWindowResolution();
_width = res.x;
_height = res.y;

View File

@@ -116,7 +116,7 @@ void ABufferVisualizer::render() {
modelMatrix = glm::translate(modelMatrix, glm::vec3(0, 0, -1));
modelMatrix = modelMatrix * rotation;
_pointcloudProgram->setUniform("ViewProjection", OsEng.windowWrapper()->viewProjectionMatrix());
_pointcloudProgram->setUniform("ViewProjection", OsEng.windowWrapper().viewProjectionMatrix());
_pointcloudProgram->setUniform("ModelTransform", modelMatrix);
#if defined(MARKER_POINTS)
@@ -148,7 +148,7 @@ void ABufferVisualizer::render() {
const glm::mat4 scale = glm::scale(glm::mat4(1.0), glm::vec3(0.04, 0.04, 0.04));
glm::mat4 translate, mvp;
const glm::mat4 viewProjMatrix = OsEng.windowWrapper()->viewProjectionMatrix();
const glm::mat4 viewProjMatrix = OsEng.windowWrapper().viewProjectionMatrix();
translate = glm::translate(glm::mat4(1.0), glm::vec3(0, 0, 0));
mvp = viewProjMatrix*modelMatrix*translate*rotationText*scale;
Freetype::print3d(fontLight, mvp, "(0,0,0)");

View File

@@ -182,6 +182,7 @@ bool OpenSpaceEngine::create(
ghoul::initialize();
ghoul_assert(!_engine, "OpenSpaceEngine was already created");
ghoul_assert(windowWrapper != nullptr, "No Window Wrapper was provided");
// Initialize the LogManager and add the console log as this will be used every time
// and we need a fall back if something goes wrong between here and when we add the
@@ -834,9 +835,9 @@ properties::PropertyOwner* OpenSpaceEngine::globalPropertyOwner() {
return _globalPropertyNamespace;
}
WindowWrapper* OpenSpaceEngine::windowWrapper() {
WindowWrapper& OpenSpaceEngine::windowWrapper() {
ghoul_assert(_windowWrapper, "Window Wrapper");
return _windowWrapper;
return *_windowWrapper;
}
} // namespace openspace

View File

@@ -282,7 +282,7 @@ void LuaConsole::charCallback(unsigned int codepoint, KeyModifier modifier) {
void LuaConsole::render() {
const float font_size = 10.0f;
glm::ivec4 viewportPixelCoordinates = OsEng.windowWrapper()->viewportPixelCoordinates();
glm::ivec4 viewportPixelCoordinates = OsEng.windowWrapper().viewportPixelCoordinates();
int x1 = viewportPixelCoordinates.x;
int xSize = viewportPixelCoordinates.y;
int y1 = viewportPixelCoordinates.z;

View File

@@ -70,7 +70,7 @@ glm::vec3 MouseController::mapToCamera(glm::vec3 trackballPos) {
void MouseController::trackballRotate(int x, int y) {
// Normalize mouse coordinates to [0,1]
glm::vec2 res = OsEng.windowWrapper()->currentWindowSize();
glm::vec2 res = OsEng.windowWrapper().currentWindowSize();
glm::vec2 mousePos = glm::vec2((float)x / res.x, (float)y / res.y);
mousePos = glm::clamp(mousePos, -0.5f, 1.5f); // Ugly fix #1: Camera position becomes NaN on mouse values outside [-0.5, 1.5]
@@ -163,7 +163,7 @@ void OrbitalMouseController::button(MouseButton button, MouseAction action) {
if (button == MouseButton::Left){
if (action == MouseAction::Press){
_leftMouseButtonDown = true;
_previousCursorPos[MouseButtons::ButtonLeft] = OsEng.windowWrapper()->mousePosition();
_previousCursorPos[MouseButtons::ButtonLeft] = OsEng.windowWrapper().mousePosition();
}
else if (action == MouseAction::Release) {
_leftMouseButtonDown = false;
@@ -173,7 +173,7 @@ void OrbitalMouseController::button(MouseButton button, MouseAction action) {
else if (button == MouseButton::Right){
if (action == MouseAction::Press){
_rightMouseButtonDown = true;
_previousCursorPos[MouseButtons::ButtonRight] = OsEng.windowWrapper()->mousePosition();
_previousCursorPos[MouseButtons::ButtonRight] = OsEng.windowWrapper().mousePosition();
}
else if (action == MouseAction::Release) {
_rightMouseButtonDown = false;
@@ -183,7 +183,7 @@ void OrbitalMouseController::button(MouseButton button, MouseAction action) {
else if (button == MouseButton::Middle){
if (action == MouseAction::Press){
_middleMouseButtonDown = true;
_previousCursorPos[MouseButtons::ButtonMiddle] = OsEng.windowWrapper()->mousePosition();
_previousCursorPos[MouseButtons::ButtonMiddle] = OsEng.windowWrapper().mousePosition();
}
else if (action == MouseAction::Release) {
_middleMouseButtonDown = false;
@@ -194,21 +194,21 @@ void OrbitalMouseController::button(MouseButton button, MouseAction action) {
}
void OrbitalMouseController::move(float x, float y) {
_currentCursorPos = OsEng.windowWrapper()->mousePosition();
_currentCursorPos = OsEng.windowWrapper().mousePosition();
if (_leftMouseButtonDown) {
glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonLeft];
glm::vec2 res = OsEng.windowWrapper()->currentWindowSize();
glm::vec2 res = OsEng.windowWrapper().currentWindowSize();
_currentCursorDiff[MouseButtons::ButtonLeft] = diff / res;
}
if (_rightMouseButtonDown) {
glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonRight];
glm::vec2 res = OsEng.windowWrapper()->currentWindowSize();
glm::vec2 res = OsEng.windowWrapper().currentWindowSize();
_currentCursorDiff[MouseButtons::ButtonRight] = diff / res;
}
if (_middleMouseButtonDown) {
glm::vec2 diff = _currentCursorPos - _previousCursorPos[MouseButtons::ButtonMiddle];
glm::vec2 res = OsEng.windowWrapper()->currentWindowSize();
glm::vec2 res = OsEng.windowWrapper().currentWindowSize();
_currentCursorDiff[MouseButtons::ButtonMiddle] = diff / res;
}
}

View File

@@ -87,7 +87,7 @@ bool NetworkEngine::handleMessage(const std::string& message) {
}
void NetworkEngine::publishStatusMessage() {
if (!_shouldPublishStatusMessage || !OsEng.windowWrapper()->isExternalControlConnected())
if (!_shouldPublishStatusMessage || !OsEng.windowWrapper().isExternalControlConnected())
return;
// Protocol:
// 8 bytes: time as a ET double
@@ -164,7 +164,7 @@ void NetworkEngine::publishMessage(MessageIdentifier identifier, std::vector<cha
}
void NetworkEngine::sendMessages() {
if (!OsEng.windowWrapper()->isExternalControlConnected())
if (!OsEng.windowWrapper().isExternalControlConnected())
return;
for (Message& m : _messagesToSend) {
@@ -180,7 +180,7 @@ void NetworkEngine::sendMessages() {
// Prepending the message identifier to the front
m.body.insert(m.body.begin(), identifier.data.begin(), identifier.data.end());
OsEng.windowWrapper()->sendMessageToExternalControl(m.body);
OsEng.windowWrapper().sendMessageToExternalControl(m.body);
}
_messagesToSend.clear();
@@ -198,7 +198,7 @@ void NetworkEngine::sendInitialInformation() {
std::vector<char> payload = m.body;
payload.insert(payload.begin(), identifier.data.begin(), identifier.data.end());
OsEng.windowWrapper()->sendMessageToExternalControl(payload);
OsEng.windowWrapper().sendMessageToExternalControl(payload);
LINFO("Sent initial message: (s=" << m.body.size() << ") [i=" << identifier.value << "]");
std::this_thread::sleep_for(std::chrono::milliseconds(SleepTime));
@@ -216,7 +216,7 @@ void NetworkEngine::sendInitialInformation() {
std::vector<char> d;
d.insert(d.begin(), identifier.data.begin(), identifier.data.end());
OsEng.windowWrapper()->sendMessageToExternalControl(d);
OsEng.windowWrapper().sendMessageToExternalControl(d);
_shouldPublishStatusMessage = true;
}

View File

@@ -197,7 +197,7 @@ bool RenderEngine::initializeGL() {
// set the close clip plane and the far clip plane to extreme values while in
// development
OsEng.windowWrapper()->setNearFarClippingPlane(0.001f, 1000.f);
OsEng.windowWrapper().setNearFarClippingPlane(0.001f, 1000.f);
// ALL OF THIS HAS TO BE CHECKED
// ---abock
@@ -303,14 +303,14 @@ void RenderEngine::postSynchronizationPreDraw() {
_globalBlackOutFactor = glm::smoothstep(1.f, 0.f, _currentFadeTime / _fadeDuration);
else
_globalBlackOutFactor = glm::smoothstep(0.f, 1.f, _currentFadeTime / _fadeDuration);
_currentFadeTime += static_cast<float>(OsEng.windowWrapper()->averageDeltaTime());
_currentFadeTime += static_cast<float>(OsEng.windowWrapper().averageDeltaTime());
}
}
if (_mainCamera)
_mainCamera->postSynchronizationPreDraw();
bool windowResized = OsEng.windowWrapper()->windowHasResized();
bool windowResized = OsEng.windowWrapper().windowHasResized();
if (windowResized) {
generateGlslConfig();
_abuffer->reinitialize();
@@ -344,7 +344,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
// We need the window pointer
// sgct::SGCTWindow* w = sgct::Engine::instance()->getCurrentWindowPtr();
if (!OsEng.windowWrapper()->isSimpleRendering())
if (!OsEng.windowWrapper().isSimpleRendering())
// if (sgct::Engine::instance()->getCurrentRenderTarget() == sgct::Engine::NonLinearBuffer)
_abuffer->clear();
@@ -415,7 +415,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
// Print some useful information on the master viewport
if (OsEng.ref().isMaster() && OsEng.windowWrapper()->isSimpleRendering()) {
if (OsEng.ref().isMaster() && OsEng.windowWrapper().isSimpleRendering()) {
// TODO: Adjust font_size properly when using retina screen
const int font_size_mono = 10;
const int font_size_time = 15;
@@ -427,7 +427,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
if (_showInfo) {
const sgct_text::Font* font = fontMono;
glm::ivec4 pixelCoords = OsEng.windowWrapper()->viewportPixelCoordinates();
glm::ivec4 pixelCoords = OsEng.windowWrapper().viewportPixelCoordinates();
int x1 = pixelCoords.x;
int xSize = pixelCoords.y;
int y1 = pixelCoords.z;
@@ -470,7 +470,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
float distToSurf = glm::length(nhPos.vec3()) - radius;
PrintText(line++, "Distance to Pluto: % .1f (KM)", distToSurf);
PrintText(line++, "Avg. Frametime: %.5f", OsEng.windowWrapper()->averageDeltaTime());
PrintText(line++, "Avg. Frametime: %.5f", OsEng.windowWrapper().averageDeltaTime());
//PrintText(line++, "Drawtime: %.5f", sgct::Engine::instance()->getDrawTime());
//PrintText(line++, "Frametime: %.5f", sgct::Engine::instance()->getDt());
@@ -589,7 +589,7 @@ void RenderEngine::render(const glm::mat4 &projectionMatrix, const glm::mat4 &vi
for (auto& it = entries.first; it != entries.second; ++it) {
const ScreenLog::LogEntry* e = &(*it);
const double t = OsEng.windowWrapper()->time();
const double t = OsEng.windowWrapper().time();
float diff = static_cast<float>(t - e->timeStamp);
// Since all log entries are ordered, once one is exceeding TTL, all have
@@ -643,7 +643,7 @@ void RenderEngine::postDraw() {
if (Time::ref().timeJumped())
Time::ref().setTimeJumped(false);
if (_takeScreenshot) {
OsEng.windowWrapper()->takeScreenshot();
OsEng.windowWrapper().takeScreenshot();
_takeScreenshot = false;
}
@@ -731,7 +731,7 @@ void RenderEngine::startFading(int direction, float fadeDuration) {
void RenderEngine::generateGlslConfig() {
ghoul_assert(_abuffer != nullptr, "ABuffer not initialized");
LDEBUG("Generating GLSLS config, expect shader recompilation");
glm::ivec2 size = OsEng.windowWrapper()->currentWindowResolution();
glm::ivec2 size = OsEng.windowWrapper().currentWindowResolution();
// TODO: Make this file creation dynamic and better in every way
// TODO: If the screen size changes it is enough if this file is regenerated to

View File

@@ -34,7 +34,7 @@ ScreenLog::ScreenLog() {}
void ScreenLog::log(ghoul::logging::LogManager::LogLevel level, const std::string& category, const std::string& message) {
if (level >= ghoul::logging::LogManager::LogLevel::Info)
_entries.emplace_back(level, OsEng.windowWrapper()->time(), Log::getTimeString(), category, message);
_entries.emplace_back(level, OsEng.windowWrapper().time(), Log::getTimeString(), category, message);
// Once reaching maximum size, reduce to half
if (_entries.size() > MaximumSize) {