diff --git a/doomsday/client/src/dd_loop.cpp b/doomsday/client/src/dd_loop.cpp index ddd923198a..8a0d22fd2e 100644 --- a/doomsday/client/src/dd_loop.cpp +++ b/doomsday/client/src/dd_loop.cpp @@ -31,6 +31,8 @@ #include "de_ui.h" #include "de_misc.h" +#include + #ifdef __SERVER__ # include #endif @@ -100,7 +102,7 @@ int DD_GameLoopExitCode(void) int DD_GameLoop(void) { // Start the deng2 event loop. - return LegacyCore_RunEventLoop(); + return DENG2_APP->execLoop(); } float DD_GetFrameRate(void) diff --git a/doomsday/client/src/sys_system.cpp b/doomsday/client/src/sys_system.cpp index f3d48c26fc..58072b93db 100644 --- a/doomsday/client/src/sys_system.cpp +++ b/doomsday/client/src/sys_system.cpp @@ -45,6 +45,8 @@ #include "network/net_buf.h" #include "audio/s_main.h" +#include + int novideo; // if true, stay in text mode for debugging static boolean appShutdown = false; ///< Set to true when we should exit (normally). @@ -285,5 +287,5 @@ DENG_EXTERN_C void Sys_Quit(void) appShutdown = true; // It's time to stop the main loop. - LegacyCore_Stop(DD_GameLoopExitCode()); + DENG2_APP->stopLoop(DD_GameLoopExitCode()); } diff --git a/doomsday/client/src/ui/canvaswindow.cpp b/doomsday/client/src/ui/canvaswindow.cpp index d993dd5f8e..39d42136a4 100644 --- a/doomsday/client/src/ui/canvaswindow.cpp +++ b/doomsday/client/src/ui/canvaswindow.cpp @@ -46,7 +46,6 @@ using namespace de; -static String const BUSY_WIDGET_NAME = "busy"; static String const LEGACY_WIDGET_NAME = "legacy"; DENG2_PIMPL(CanvasWindow) @@ -85,7 +84,7 @@ DENG2_PIMPL(CanvasWindow) legacy->disable(); // For busy mode we have an entirely different widget tree. - BusyWidget *busy = new BusyWidget(BUSY_WIDGET_NAME); + BusyWidget *busy = new BusyWidget; busy->rule() .setLeftTop (busyRoot.viewLeft(), busyRoot.viewTop()) .setRightBottom(busyRoot.viewRight(), busyRoot.viewBottom()); @@ -130,7 +129,7 @@ CanvasWindow::CanvasWindow(QWidget *parent) d = new Instance(this); // Create the drawing canvas for this window. - setCentralWidget(d->canvas = new Canvas(this)); // takes ownership + setCentralWidget(d->canvas = new Canvas(this)); // window takes ownership // All input goes to the canvas. d->canvas->setFocus(); @@ -160,7 +159,7 @@ float CanvasWindow::frameRate() const void CanvasWindow::initCanvasAfterRecreation(Canvas &canvas) { CanvasWindow *self = dynamic_cast(canvas.parentWidget()); - assert(self); + DENG2_ASSERT(self); LOG_DEBUG("About to replace Canvas %p with %p") << de::dintptr(self->d->canvas) << de::dintptr(self->d->recreated); @@ -218,7 +217,7 @@ void CanvasWindow::recreateCanvas() Canvas& CanvasWindow::canvas() { - assert(d->canvas != 0); + DENG2_ASSERT(d->canvas != 0); return *d->canvas; } diff --git a/doomsday/client/src/ui/legacywidget.cpp b/doomsday/client/src/ui/legacywidget.cpp index 79388c3663..9cdfbb7e73 100644 --- a/doomsday/client/src/ui/legacywidget.cpp +++ b/doomsday/client/src/ui/legacywidget.cpp @@ -179,5 +179,6 @@ void LegacyWidget::draw() bool LegacyWidget::handleEvent(Event const &/*event*/) { + /// @todo Event processing should occur here, not during Loop_RunTics(). return false; } diff --git a/doomsday/libdeng2/include/de/c_wrapper.h b/doomsday/libdeng2/include/de/c_wrapper.h index fcbaf52f8d..4451efe3bc 100644 --- a/doomsday/libdeng2/include/de/c_wrapper.h +++ b/doomsday/libdeng2/include/de/c_wrapper.h @@ -69,14 +69,6 @@ typedef enum legacycore_loglevel_e { DENG2_PUBLIC LegacyCore *LegacyCore_New(); DENG2_PUBLIC void LegacyCore_Delete(LegacyCore *lc); DENG2_PUBLIC LegacyCore *LegacyCore_Instance(); -//DENG2_PUBLIC void LegacyCore_SetLoopRate(int freqHz); -//DENG2_PUBLIC void LegacyCore_SetLoopFunc(void (*callback)(void)); -//DENG2_PUBLIC void LegacyCore_PushLoop(); -//DENG2_PUBLIC void LegacyCore_PopLoop(); -//DENG2_PUBLIC void LegacyCore_PauseLoop(); -//DENG2_PUBLIC void LegacyCore_ResumeLoop(); -DENG2_PUBLIC int LegacyCore_RunEventLoop(); -DENG2_PUBLIC void LegacyCore_Stop(int exitCode); DENG2_PUBLIC void LegacyCore_Timer(unsigned int milliseconds, void (*callback)(void)); DENG2_PUBLIC int LegacyCore_SetLogFile(char const *filePath); DENG2_PUBLIC char const *LegacyCore_LogFile(); diff --git a/doomsday/libdeng2/include/de/core/textapp.h b/doomsday/libdeng2/include/de/core/textapp.h index 00a31349e2..c8a36cb7ef 100644 --- a/doomsday/libdeng2/include/de/core/textapp.h +++ b/doomsday/libdeng2/include/de/core/textapp.h @@ -45,7 +45,6 @@ class DENG2_PUBLIC TextApp : public QCoreApplication, public App, public: TextApp(int &argc, char **argv); - ~TextApp(); bool notify(QObject *receiver, QEvent *event); diff --git a/doomsday/libdeng2/include/de/legacy/legacycore.h b/doomsday/libdeng2/include/de/legacy/legacycore.h index 033b4236b3..8b32463ec3 100644 --- a/doomsday/libdeng2/include/de/legacy/legacycore.h +++ b/doomsday/libdeng2/include/de/legacy/legacycore.h @@ -30,9 +30,6 @@ namespace de { * libdeng2 functionality. The legacy engine needs to construct one of these * via the deng2 C API and make sure it gets destroyed at shutdown. The C API * can be used to access functionality in LegacyCore. - * - * @todo Move the Loop into its own class and get rid of this one. A Loop - * instance should then be owned by GuiApp and TextApp. */ class DENG2_PUBLIC LegacyCore : public QObject { @@ -46,53 +43,6 @@ class DENG2_PUBLIC LegacyCore : public QObject ~LegacyCore(); - /** - * Starts the deng2 event loop in the current thread. Does not return until - * the loop is stopped. - * - * @return Exit code. - */ - int runEventLoop(); - -#if 0 - /** - * Sets the frequency for calling the loop function (e.g., 35 Hz for a - * dedicated server). Not very accurate: the actual rate at which the - * function is called is probably less. - * - * @param freqHz Frequency in Hz. - */ - void setLoopRate(int freqHz); - - /** - * Sets the callback function that gets called periodically from the main - * loop. The calls are made as often as possible without blocking the loop. - * - * @param callback Loop callback function. - */ - void setLoopFunc(void (*callback)(void)); - - /** - * Saves the current loop rate and function and pushes them on a stack. - */ - void pushLoop(); - - /** - * Pops the loop rate and function from the stack and replaces the current - * with the popped ones. - */ - void popLoop(); - - /** - * Pauses the loop function callback. - */ - void pauseLoop(); - - /** - * Resumes calls to the loop function callback. - */ - void resumeLoop(); -#endif /** * Stops the event loop. This is automatically called when the core is * destroyed. diff --git a/doomsday/libdeng2/src/c_wrapper.cpp b/doomsday/libdeng2/src/c_wrapper.cpp index 6a1c0da4e5..f36ba050d0 100644 --- a/doomsday/libdeng2/src/c_wrapper.cpp +++ b/doomsday/libdeng2/src/c_wrapper.cpp @@ -55,48 +55,6 @@ LegacyCore *LegacyCore_Instance() return reinterpret_cast(&de::LegacyCore::instance()); } -int LegacyCore_RunEventLoop() -{ - return DENG2_LEGACYCORE().runEventLoop(); -} - -void LegacyCore_Stop(int exitCode) -{ - DENG2_LEGACYCORE().stop(exitCode); -} - -/* -void LegacyCore_SetLoopRate(int freqHz) -{ - DENG2_LEGACYCORE().setLoopRate(freqHz); -} - -void LegacyCore_SetLoopFunc(void (*callback)(void)) -{ - return DENG2_LEGACYCORE().setLoopFunc(callback); -} - -void LegacyCore_PushLoop() -{ - DENG2_LEGACYCORE().pushLoop(); -} - -void LegacyCore_PopLoop() -{ - DENG2_LEGACYCORE().popLoop(); -} - -void LegacyCore_PauseLoop() -{ - DENG2_LEGACYCORE().pauseLoop(); -} - -void LegacyCore_ResumeLoop() -{ - DENG2_LEGACYCORE().resumeLoop(); -} -*/ - void LegacyCore_Timer(unsigned int milliseconds, void (*callback)(void)) { DENG2_LEGACYCORE().timer(milliseconds, callback); diff --git a/doomsday/libdeng2/src/core/textapp.cpp b/doomsday/libdeng2/src/core/textapp.cpp index 353baed754..f084587f7a 100644 --- a/doomsday/libdeng2/src/core/textapp.cpp +++ b/doomsday/libdeng2/src/core/textapp.cpp @@ -67,8 +67,13 @@ bool TextApp::notify(QObject *receiver, QEvent *event) int TextApp::execLoop() { + LOG_MSG("Starting TextApp event loop..."); + d->loop.start(); - return QCoreApplication::exec(); + int code = QCoreApplication::exec(); + + LOG_MSG("TextApp event loop exited with code %i") << code; + return code; } void TextApp::stopLoop(int code) diff --git a/doomsday/libdeng2/src/legacy/legacycore.cpp b/doomsday/libdeng2/src/legacy/legacycore.cpp index 320160acc4..ee81d54ac4 100644 --- a/doomsday/libdeng2/src/legacy/legacycore.cpp +++ b/doomsday/libdeng2/src/legacy/legacycore.cpp @@ -35,19 +35,7 @@ LegacyCore *LegacyCore::_appCore; struct LegacyCore::Instance { - /* - struct Loop { - int interval; - bool paused; - void (*func)(void); - Loop() : interval(1), paused(false), func(0) {} - }; - QList loopStack; - */ - App *app; - //QTimer *loopTimer; - //Loop loop; /// Pointer returned to callers, see LegacyCore::logFileName(). std::string logName; @@ -59,19 +47,12 @@ struct LegacyCore::Instance ~Instance() {} }; -LegacyCore::LegacyCore() +LegacyCore::LegacyCore() : d(new Instance) { _appCore = this; - d = new Instance; // Construct a new core application (must have one for the event loop). d->app = DENG2_APP; - - /* - // This will trigger loop callbacks. - d->loopTimer = new QTimer(this); - connect(d->loopTimer, SIGNAL(timeout()), this, SLOT(callback())); - */ } LegacyCore::~LegacyCore() @@ -89,102 +70,8 @@ LegacyCore &LegacyCore::instance() return *_appCore; } -/* -void LegacyCore::setLoopFunc(void (*func)(void)) -{ - LOG_DEBUG("Loop function changed from %p set to %p.") << dintptr(d->loop.func) << dintptr(func); - - d->loopTimer->stop(); - - // Set up a timer to periodically call the provided callback function. - d->loop.func = func; - - // Auto-resume. - d->loop.paused = false; - - if(func) - { - // Start the periodic callback calls. - d->loopTimer->start(d->loop.interval); - } -} - -void LegacyCore::pushLoop() -{ - d->loopStack.append(d->loop); -} - -void LegacyCore::popLoop() -{ - if(d->loopStack.isEmpty()) - { - LOG_CRITICAL("Pop from empty loop stack."); - return; - } - - d->loop = d->loopStack.last(); - d->loopStack.removeLast(); - - LOG_DEBUG("Loop function popped, now %p.") << dintptr(d->loop.func); - - d->loop.paused = true; // Force resume. - resumeLoop(); -} - -void LegacyCore::pauseLoop() -{ - if(d->loop.paused) return; - - d->loop.paused = true; - d->loopTimer->stop(); -} - -void LegacyCore::resumeLoop() -{ - if(!d->loop.paused) return; - - d->loop.paused = false; - if(d->loop.func) - { - // Start the periodic callback calls. - d->loopTimer->start(d->loop.interval); - } -} -*/ - -int LegacyCore::runEventLoop() -{ - LOG_MSG("Starting LegacyCore event loop..."); - - // Run the Qt event loop. In the future this will be replaced by the - // application's main Qt event loop, where deng2 will hook into. - int code = d->app->execLoop(); - - LOG_MSG("Event loop exited with code %i.") << code; - return code; -} - -/* -void LegacyCore::setLoopRate(int freqHz) -{ - int const oldInterval = d->loop.interval; - d->loop.interval = qMax(1, 1000/freqHz); - - if(oldInterval != d->loop.interval) - { - LOG_DEBUG("Loop interval changed to %i ms.") << d->loop.interval; - if(!d->loop.paused) - { - d->loopTimer->stop(); - d->loopTimer->start(d->loop.interval); - } - } -} -*/ - void LegacyCore::stop(int exitCode) { - //d->loopTimer->stop(); d->app->stopLoop(exitCode); } @@ -219,17 +106,4 @@ void LegacyCore::printLogFragment(char const *text, LogEntry::Level level) } } -/* -void LegacyCore::callback() -{ - // Update the application clock. - //Clock::appClock().setTime(Time()); - - if(d->loop.func) - { - d->loop.func(); - } -} -*/ - } // namespace de diff --git a/doomsday/libgui/include/de/gui/guiapp.h b/doomsday/libgui/include/de/gui/guiapp.h index 23e1569d1f..0173ef4ac5 100644 --- a/doomsday/libgui/include/de/gui/guiapp.h +++ b/doomsday/libgui/include/de/gui/guiapp.h @@ -46,7 +46,6 @@ class LIBGUI_PUBLIC GuiApp : public QApplication, public App, public: GuiApp(int &argc, char **argv); - ~GuiApp(); bool notify(QObject *receiver, QEvent *event); diff --git a/doomsday/libgui/src/guiapp.cpp b/doomsday/libgui/src/guiapp.cpp index 92fea8bda2..6ca8b10d3d 100644 --- a/doomsday/libgui/src/guiapp.cpp +++ b/doomsday/libgui/src/guiapp.cpp @@ -69,12 +69,19 @@ void GuiApp::notifyDisplayModeChanged() int GuiApp::execLoop() { + LOG_MSG("Starting GuiApp event loop..."); + d->loop.start(); - return QApplication::exec(); + int code = QApplication::exec(); + + LOG_MSG("GuiApp event loop exited with code %i") << code; + return code; } void GuiApp::stopLoop(int code) { + LOG_MSG("Stopping GuiApp event loop"); + d->loop.stop(); return QApplication::exit(code); } @@ -86,8 +93,8 @@ Loop &GuiApp::loop() void GuiApp::loopIteration() { - // Update the clock time. App listens to this clock and will inform - // subsystems in the order they've been added in. + // Update the clock time. de::App listens to this clock and will inform + // subsystems in the order they've been added. Clock::appClock().setTime(Time()); }