Skip to content

Commit

Permalink
Refactor: Renaming Window member functions
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 11, 2012
1 parent 5ad19ed commit c61e78f
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 161 deletions.
4 changes: 3 additions & 1 deletion doomsday/engine/portable/include/canvaswindow.h
Expand Up @@ -36,6 +36,7 @@ class CanvasWindow : public QMainWindow

public:
explicit CanvasWindow(QWidget *parent = 0);
~CanvasWindow();

Canvas& canvas();

Expand All @@ -50,7 +51,8 @@ class CanvasWindow : public QMainWindow
public slots:

private:
Canvas* _canvas;
struct Instance;
Instance* d;
};

#endif // CANVASWINDOW_H
9 changes: 9 additions & 0 deletions doomsday/engine/portable/include/dd_loop.h
Expand Up @@ -41,8 +41,17 @@ void DD_RegisterLoop(void);
*/
int DD_GameLoop(void);

/**
* Called periodically while the game loop is running.
*/
void DD_GameLoopCallback(void);

/**
* Window drawing callback.
*
* Drawing anything outside this routine is frowned upon.
* Seriously frowned! (Don't do it.)
*/
void DD_GameLoopDrawer(void);

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/sys_console.h
Expand Up @@ -53,7 +53,7 @@ typedef struct consolewindow_s {
Window* Sys_ConInit(const char* title);
void Sys_ConShutdown(uint idx);

void Sys_ConSetTitle(uint idx, const char* title);
void ConsoleWindow_SetTitle(const Window *window, const char* title);

/**
* @param flags @see consolePrintFlags
Expand Down
24 changes: 13 additions & 11 deletions doomsday/engine/portable/include/sys_window.h
Expand Up @@ -112,10 +112,14 @@ boolean Sys_GetDesktopBPP(int* bpp);
*
* @return If @c 0, window creation was unsuccessful,
* ELSE 1-based index identifier of the new window.
*
* @todo Refactor for New/Delete convention.
*/
uint Sys_CreateWindow(application_t* app, const Point2Raw* origin,
const Size2Raw* size, int bpp, int flags, ddwindowtype_t type, const char* title, void* data);
boolean Sys_DestroyWindow(uint idx);
uint Window_Create(application_t* app, const Point2Raw* origin,
const Size2Raw* size, int bpp, int flags, ddwindowtype_t type,
const char* title, void* data);

boolean Window_Destroy(uint idx);

void Window_Show(Window* wnd, boolean show);

Expand Down Expand Up @@ -146,15 +150,13 @@ int Window_BitsPerPixel(const Window* wnd);
*/
const Size2Raw* Window_Size(const Window* wnd);

void Sys_UpdateWindow(uint idx);
void Window_SwapBuffers(const Window* win);

boolean Sys_GetWindowBPP(uint idx, int* bpp);
boolean Sys_GetWindowFullscreen(uint idx, boolean* fullscreen);
boolean Sys_GetWindowVisibility(uint idx, boolean* show);
boolean Sys_GetWindowFullscreen(uint idx, boolean* fullscreen); /// @todo refactor

boolean Sys_SetActiveWindow(uint idx);
boolean Sys_SetWindow(uint idx, int x, int y, int w, int h, int bpp, uint wflags, uint uflags);
boolean Sys_SetWindowTitle(uint idx, const char* title);

void Window_SetTitle(const Window *win, const char* title);

/**
* Sets the function who will draw the contents of the window when needed.
Expand All @@ -171,8 +173,8 @@ void Window_SetDrawFunction(Window* win, void (*drawFunc)(void));
*/
void Window_Draw(Window* win);

Window* Sys_Window(uint idx);
Window* Sys_MainWindow(void);
Window* Window_ByIndex(uint idx);
Window* Window_Main(void);

/**
*\todo This is a compromise to prevent having to refactor half the
Expand Down
20 changes: 16 additions & 4 deletions doomsday/engine/portable/src/canvaswindow.cpp
Expand Up @@ -25,20 +25,32 @@

#include <QGLFormat>

struct CanvasWindow::Instance
{
Canvas* canvas;
};

CanvasWindow::CanvasWindow(QWidget *parent)
: QMainWindow(parent)
{
d = new Instance;

// Create the drawing canvas for this window.
setCentralWidget(_canvas = new Canvas); // takes ownership
setCentralWidget(d->canvas = new Canvas); // takes ownership
}

CanvasWindow::~CanvasWindow()
{
delete d;
}

Canvas& CanvasWindow::canvas()
{
assert(_canvas != 0);
return *_canvas;
assert(d->canvas != 0);
return *d->canvas;
}

void CanvasWindow::setDefaultGLFormat()
void CanvasWindow::setDefaultGLFormat() // static
{
// Configure the GL settings for all subsequently created canvases.
QGLFormat fmt;
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/src/con_busy.c
Expand Up @@ -191,7 +191,7 @@ int Con_Busy2(BusyTask* task)
DD_ResetTimer();

// Resume drawing with the game loop drawer.
Window_SetDrawFunction(Sys_MainWindow(), !Sys_IsShuttingDown()? DD_GameLoopDrawer : 0);
Window_SetDrawFunction(Window_Main(), !Sys_IsShuttingDown()? DD_GameLoopDrawer : 0);

return result;
}
Expand Down Expand Up @@ -436,7 +436,7 @@ static void Con_BusyLoop(void)
glLoadIdentity();
glOrtho(0, Window_Width(theWindow), Window_Height(theWindow), 0, -1, 1);

Window_SetDrawFunction(Sys_MainWindow(), Con_BusyDrawer);
Window_SetDrawFunction(Window_Main(), Con_BusyDrawer);
}

Sys_Lock(busy_Mutex);
Expand Down Expand Up @@ -472,7 +472,7 @@ static void Con_BusyLoop(void)
// Time for an update?
if(canDraw)
{
Window_Draw(Sys_MainWindow());
Window_Draw(Window_Main());
}

// Make sure the audio system gets regularly updated.
Expand All @@ -492,7 +492,7 @@ static void Con_BusyLoop(void)
glPopMatrix();

// Must not call the busy drawer outside of this loop.
Window_SetDrawFunction(Sys_MainWindow(), 0);
Window_SetDrawFunction(Window_Main(), 0);
}
}

Expand Down Expand Up @@ -780,7 +780,7 @@ static void Con_BusyDrawer(void)
Z_DebugDrawer();
#endif

Sys_UpdateWindow(mainWindowIdx);
Window_SwapBuffers(theWindow);
}

boolean Con_TransitionInProgress(void)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dd_init.cpp
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char** argv)
#endif

// Show the main window. This also completes the initialization.
Window_Show(Sys_MainWindow(), true);
Window_Show(Window_Main(), true);

// Run the main loop.
int result = DD_GameLoop();
Expand Down
8 changes: 1 addition & 7 deletions doomsday/engine/portable/src/dd_loop.c
Expand Up @@ -145,18 +145,12 @@ void DD_GameLoopCallback(void)
endFrame();

// Draw the frame.
Window_Draw(Sys_MainWindow());
Window_Draw(Window_Main());

// After the first frame, start timedemo.
DD_CheckTimeDemo();
}

/**
* Window drawing callback.
*
* Drawing anything outside this routine is frowned upon.
* Seriously frowned! (Don't do it.)
*/
void DD_GameLoopDrawer(void)
{
if(novideo)
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -1194,7 +1194,7 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload)
Library_ReleaseGames();

DD_ComposeMainWindowTitle(buf);
Sys_SetWindowTitle(mainWindowIdx, buf);
Window_SetTitle(theWindow, buf);

if(!DD_IsShuttingDown())
{
Expand All @@ -1213,7 +1213,7 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload)
theGame = game;

DD_ComposeMainWindowTitle(buf);
Sys_SetWindowTitle(mainWindowIdx, buf);
Window_SetTitle(theWindow, buf);

/**
* If we aren't shutting down then we are either loading a game or switching
Expand Down Expand Up @@ -1450,7 +1450,7 @@ void DD_FinishInitializationAfterWindowReady(void)
{
char buf[256];
DD_ComposeMainWindowTitle(buf);
Sys_SetWindowTitle(mainWindowIdx, buf);
Window_SetTitle(theWindow, buf);
}

// Initialize engine subsystems and initial state.
Expand All @@ -1464,7 +1464,7 @@ void DD_FinishInitializationAfterWindowReady(void)
LegacyCore_SetLoopFunc(de2LegacyCore, DD_GameLoopCallback);

// Start drawing with the game loop drawer.
Window_SetDrawFunction(Sys_MainWindow(), DD_GameLoopDrawer);
Window_SetDrawFunction(Window_Main(), DD_GameLoopDrawer);
}

/**
Expand Down
7 changes: 1 addition & 6 deletions doomsday/engine/portable/src/gl_main.c
Expand Up @@ -179,7 +179,7 @@ void GL_DoUpdate(void)
DD_WaitForOptimalUpdateTime();

// Blit screen to video.
Sys_UpdateWindow(mainWindowIdx);
Window_SwapBuffers(theWindow);

// Increment frame counter.
r_framecounter++;
Expand Down Expand Up @@ -448,11 +448,6 @@ boolean GL_EarlyInit(void)

Con_Message("Using restricted texture w/h ratio (1:8).\n");
ratioLimit = 8;
Sys_GetWindowBPP(mainWindowIdx, &bpp);
if(bpp == 32)
{
Con_Message("Warning: Are you sure your video card accelerates a 32 bit mode?\n");
}
}
// Set a custom maximum size?
if(ArgCheckWith("-maxtex", 1))
Expand Down

0 comments on commit c61e78f

Please sign in to comment.