Skip to content

Commit

Permalink
Refactor|Client: Window resizing moved to CanvasWindow
Browse files Browse the repository at this point in the history
window.cpp is still handling the Window state. In time, the contents
of window.cpp will be revised into CanvasWindow / WindowSystem.
  • Loading branch information
skyjake committed Feb 24, 2013
1 parent f89975d commit 8630ee0
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 105 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -360,6 +360,7 @@ DENG_HEADERS += \
include/ui/ui_main.h \
include/ui/ui_panel.h \
include/ui/window.h \
include/ui/windowsystem.h \
include/ui/zonedebug.h \
include/updater.h \
include/uri.hh \
Expand Down Expand Up @@ -636,6 +637,7 @@ SOURCES += \
src/ui/ui_main.cpp \
src/ui/ui_panel.cpp \
src/ui/window.cpp \
src/ui/windowsystem.cpp \
src/ui/zonedebug.cpp \
src/updater/downloaddialog.cpp \
src/updater/processcheckdialog.cpp \
Expand Down
7 changes: 7 additions & 0 deletions doomsday/client/include/dd_loop.h
Expand Up @@ -47,6 +47,13 @@ int DD_GameLoop(void);
*/
void DD_GameLoopCallback(void);

/**
* Runs one or more tics depending on how much time has passed since the
* previous call to this function. This gets called once per each main loop
* iteration. Finishes as quickly as possible.
*/
void Loop_RunTics(void);

/**
* Window drawing callback.
*
Expand Down
7 changes: 0 additions & 7 deletions doomsday/client/include/ui/canvas.h
Expand Up @@ -74,13 +74,6 @@ class Canvas : public QGLWidget
*/
void setDrawFunc(void (*canvasDrawFunc)(Canvas&));

/**
* Sets the callback function that is called after the size of the canvas changes.
*
* @param canvasResizedFunc Callback.
*/
void setResizedFunc(void (*canvasResizedFunc)(Canvas&));

/**
* Sets the callback function that is called when the window's focus state changes.
* The callback is given @c true or @c false as argument, with
Expand Down
11 changes: 11 additions & 0 deletions doomsday/client/include/ui/window.h
Expand Up @@ -344,4 +344,15 @@ QWidget* Window_Widget(Window* wnd);

CanvasWindow *Window_CanvasWindow(Window *wnd);

/**
* Utility to call after changing the size of a CanvasWindow. This will update
* the Window state.
*
* @param win Window instance.
*
* @deprecated In the future, size management will be done internally in
* CanvasWindow/WindowSystem.
*/
void Window_UpdateAfterResize(Window *win);

#endif /* LIBDENG_SYS_WINDOW_H */
47 changes: 47 additions & 0 deletions doomsday/client/include/ui/windowsystem.h
@@ -0,0 +1,47 @@
/** @file windowsystem.h Window management subsystem.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_WINDOWSYSTEM_H
#define CLIENT_WINDOWSYSTEM_H

#include <de/System>

/**
* Window management subsystem.
*
* The window system processes events produced by the input drivers. In
* practice, the events are passed to the widgets in the windows.
*
* @ingroup gui
*/
class WindowSystem : public de::System
{
public:
WindowSystem();

~WindowSystem();

bool processEvent(de::Event const &);

void timeChanged(de::Clock const &);

private:
DENG2_PRIVATE(d)
};

#endif // CLIENT_WINDOWSYSTEM_H
5 changes: 5 additions & 0 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -34,6 +34,7 @@
#include "con_main.h"
#include "ui/displaymode.h"
#include "sys_system.h"
#include "ui/windowsystem.h"
#include "ui/window.h"
#include "updater.h"

Expand Down Expand Up @@ -66,6 +67,7 @@ DENG2_PIMPL(ClientApp)
{
LegacyCore *de2LegacyCore;
QMenuBar *menuBar;
WindowSystem winSys;
ServerLink *svLink;

Instance(Public *i)
Expand Down Expand Up @@ -124,6 +126,9 @@ ClientApp::ClientApp(int &argc, char **argv)
QCoreApplication::setApplicationVersion (DOOMSDAY_VERSION_BASE);

setTerminateFunc(handleLegacyCoreTerminate);

// Subsystems.
addSystem(d->winSys);
}

ClientApp::~ClientApp()
Expand Down
41 changes: 9 additions & 32 deletions doomsday/client/src/dd_loop.cpp
Expand Up @@ -47,13 +47,6 @@
*/
#define MAX_FRAME_TIME (1.0/MIN_TIC_RATE)

/**
* Maximum number of milliseconds spent uploading textures at the beginning
* of a frame. Note that non-uploaded textures will appear as pure white
* until their content gets uploaded (you should precache them).
*/
#define FRAME_DEFERRED_UPLOAD_TIMEOUT 20

int maxFrameRate = 120; // Zero means 'unlimited'.
// Refresh frame count (independant of the viewport-specific frameCount).
int rFrameCount = 0;
Expand Down Expand Up @@ -81,8 +74,6 @@ static int timeDeltasIndex = 0;

static float realFrameTimePos = 0;

static void runTics(void);

void DD_RegisterLoop(void)
{
C_VAR_BYTE("input-sharp-lateprocessing", &processSharpEventsAfterTickers, 0, 0, 1);
Expand Down Expand Up @@ -130,7 +121,7 @@ void DD_GameLoopCallback(void)

LegacyCore_SetLoopRate(count || !noninteractive? 35 : 3);

runTics();
Loop_RunTics();

// Update clients at regular intervals.
Sv_TransmitFrame();
Expand All @@ -139,27 +130,18 @@ void DD_GameLoopCallback(void)

#ifdef __CLIENT__
{
// Normal client-side/singleplayer mode.
//assert(!novideo);

// We may be performing GL operations.
Window_GLActivate(Window_Main());

// Run at least one (fractional) tic.
runTics();

// We may have received a Quit message from the windowing system
// during events/tics processing.
if(Sys_IsShuttingDown())
return;

GL_ProcessDeferredTasks(FRAME_DEFERRED_UPLOAD_TIMEOUT);
/**
* @todo The appropriate way to update the window is to have a
* repeating GuiApp::refresh() method posting window update events
* continually. We are drawing from here because LegacyCore is still
* controlling the main loop.
*/

// Request update of window contents.
Window_Draw(Window_Main());

// After the first frame, start timedemo.
DD_CheckTimeDemo();
//DD_CheckTimeDemo();
}
#endif
}
Expand Down Expand Up @@ -516,12 +498,7 @@ timespan_t DD_LatestRunTicsStartTime(void)
return lastRunTicsTime;
}

/**
* Runs one or more tics depending on how much time has passed since the
* previous call to this function. This gets called once per each main loop
* iteration. Finishes as quickly as possible.
*/
static void runTics(void)
void Loop_RunTics(void)
{
double elapsedTime, ticLength, nowTime;

Expand Down
5 changes: 1 addition & 4 deletions doomsday/client/src/gl/gl_defer.cpp
Expand Up @@ -407,10 +407,7 @@ void GL_ProcessDeferredTasks(uint timeOutMilliSeconds)
deferredtask_t* d;
uint startTime;

if(novideo) return;

if(!inited)
Con_Error("GL_ProcessDeferredTasks: Deferred GL task system not initialized.");
if(novideo || !inited) return;

LIBDENG_ASSERT_IN_MAIN_THREAD();
LIBDENG_ASSERT_GL_CONTEXT_ACTIVE();
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/network/net_buf.cpp
Expand Up @@ -210,6 +210,8 @@ void N_ReleaseMessage(netmessage_t *msg)
*/
void N_ClearMessages(void)
{
if(!msgMutex) return; // Not initialized yet.

netmessage_t *msg;
float oldSim = netSimulatedLatencySeconds;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/network/sys_network.cpp
@@ -1,4 +1,4 @@
/** @file sys_network.cpp Low-level network socket routines.
/** @file sys_network.cpp Low-level network socket routines (deprecated).
* @ingroup network
*
* @todo Remove this source file entirely once dependent code is revised.
Expand Down
13 changes: 0 additions & 13 deletions doomsday/client/src/ui/canvas.cpp
Expand Up @@ -69,7 +69,6 @@ struct Canvas::Instance
QSize currentSize;
void (*initCallback)(Canvas&);
void (*drawCallback)(Canvas&);
void (*resizedCallback)(Canvas&);
void (*focusCallback)(Canvas&, bool);
bool cursorHidden;
bool mouseGrabbed;
Expand All @@ -84,7 +83,6 @@ struct Canvas::Instance
: self(c),
initNotified(false), initCallback(0),
drawCallback(0),
resizedCallback(0),
focusCallback(0),
cursorHidden(false),
mouseGrabbed(false)
Expand Down Expand Up @@ -197,11 +195,6 @@ void Canvas::setDrawFunc(void (*canvasDrawFunc)(Canvas&))
d->drawCallback = canvasDrawFunc;
}

void Canvas::setResizedFunc(void (*canvasResizedFunc)(Canvas&))
{
d->resizedCallback = canvasResizedFunc;
}

void Canvas::setFocusFunc(void (*canvasFocusChanged)(Canvas&, bool))
{
d->focusCallback = canvasFocusChanged;
Expand All @@ -211,7 +204,6 @@ void Canvas::useCallbacksFrom(Canvas &other)
{
d->drawCallback = other.d->drawCallback;
d->focusCallback = other.d->focusCallback;
d->resizedCallback = other.d->resizedCallback;
}

QImage Canvas::grabImage(const QSize& outputSize)
Expand Down Expand Up @@ -296,11 +288,6 @@ void Canvas::resizeGL(int w, int h)
if(d->currentSize != newSize)
{
d->currentSize = newSize;

if(d->resizedCallback)
{
d->resizedCallback(*this);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion doomsday/client/src/ui/canvaswindow.cpp
Expand Up @@ -219,13 +219,17 @@ void CanvasWindow::moveEvent(QMoveEvent *ev)
}
}

void CanvasWindow::resizeEvent(QResizeEvent *)
void CanvasWindow::resizeEvent(QResizeEvent *ev)
{
QMainWindow::resizeEvent(ev);

LOG_AS("CanvasWindow");

de::Vector2i size(width(), height());
LOG_DEBUG("Resized ") << size.asText();

Window_UpdateAfterResize(Window_Main()); /// @todo remove this

d->rootWidget.setViewSize(size);
}

Expand Down
46 changes: 45 additions & 1 deletion doomsday/client/src/ui/legacywidget.cpp
Expand Up @@ -22,12 +22,22 @@
#include "ui/ui2_main.h"
#include "ui/busyvisual.h"
#include "dd_main.h"
#include "dd_loop.h"
#include "sys_system.h"
#include "map/gamemap.h"
#include "network/net_main.h"
#include "render/rend_list.h"
#include "render/rend_console.h"
#include "audio/s_main.h"
#include "gl/sys_opengl.h"
#include "gl/gl_defer.h"

/**
* Maximum number of milliseconds spent uploading textures at the beginning
* of a frame. Note that non-uploaded textures will appear as pure white
* until their content gets uploaded (you should precache them).
*/
#define FRAME_DEFERRED_UPLOAD_TIMEOUT 20

boolean drawGame = true; // If false the game viewport won't be rendered

Expand All @@ -50,10 +60,44 @@ LegacyWidget::~LegacyWidget()

void LegacyWidget::viewResized()
{
LOG_AS("LegacyWidget");
LOG_DEBUG("View resized to ") << root().viewSize().asText();

// Update viewports.
R_SetViewGrid(0, 0);
if(BusyMode_Active() || UI_IsActive() || !App_GameLoaded())
{
// Update for busy mode.
R_UseViewPort(0);
}
R_LoadSystemFonts();
if(UI_IsActive())
{
UI_UpdatePageLayout();
}
}

void LegacyWidget::update()
{
{
if(BusyMode_Active())
{
/// @todo During busy mode, a BusyWidget should be in the widget
/// tree instead of a LegacyWidget.
return;
}

// We may be performing GL operations.
Window_GLActivate(Window_Main());

// Run at least one (fractional) tic.
Loop_RunTics();

// We may have received a Quit message from the windowing system
// during events/tics processing.
if(Sys_IsShuttingDown())
return;

GL_ProcessDeferredTasks(FRAME_DEFERRED_UPLOAD_TIMEOUT);
}

void LegacyWidget::draw()
Expand Down

0 comments on commit 8630ee0

Please sign in to comment.