Skip to content

Commit

Permalink
libdeng2: Cleanup
Browse files Browse the repository at this point in the history
Removed obsolete stuff from LegacyCore. The app event loop is now
started and stopped directly via App.
  • Loading branch information
skyjake committed Feb 26, 2013
1 parent d28d443 commit 2fdbeca
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 240 deletions.
4 changes: 3 additions & 1 deletion doomsday/client/src/dd_loop.cpp
Expand Up @@ -31,6 +31,8 @@
#include "de_ui.h"
#include "de_misc.h"

#include <de/App>

#ifdef __SERVER__
# include <de/TextApp>
#endif
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion doomsday/client/src/sys_system.cpp
Expand Up @@ -45,6 +45,8 @@
#include "network/net_buf.h"
#include "audio/s_main.h"

#include <de/App>

int novideo; // if true, stay in text mode for debugging

static boolean appShutdown = false; ///< Set to true when we should exit (normally).
Expand Down Expand Up @@ -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());
}
9 changes: 4 additions & 5 deletions doomsday/client/src/ui/canvaswindow.cpp
Expand Up @@ -46,7 +46,6 @@

using namespace de;

static String const BUSY_WIDGET_NAME = "busy";
static String const LEGACY_WIDGET_NAME = "legacy";

DENG2_PIMPL(CanvasWindow)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -160,7 +159,7 @@ float CanvasWindow::frameRate() const
void CanvasWindow::initCanvasAfterRecreation(Canvas &canvas)
{
CanvasWindow *self = dynamic_cast<CanvasWindow *>(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);
Expand Down Expand Up @@ -218,7 +217,7 @@ void CanvasWindow::recreateCanvas()

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

Expand Down
1 change: 1 addition & 0 deletions doomsday/client/src/ui/legacywidget.cpp
Expand Up @@ -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;
}
8 changes: 0 additions & 8 deletions doomsday/libdeng2/include/de/c_wrapper.h
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion doomsday/libdeng2/include/de/core/textapp.h
Expand Up @@ -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);
Expand Down
50 changes: 0 additions & 50 deletions doomsday/libdeng2/include/de/legacy/legacycore.h
Expand Up @@ -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
{
Expand All @@ -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.
Expand Down
42 changes: 0 additions & 42 deletions doomsday/libdeng2/src/c_wrapper.cpp
Expand Up @@ -55,48 +55,6 @@ LegacyCore *LegacyCore_Instance()
return reinterpret_cast<LegacyCore *>(&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);
Expand Down
7 changes: 6 additions & 1 deletion doomsday/libdeng2/src/core/textapp.cpp
Expand Up @@ -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)
Expand Down
128 changes: 1 addition & 127 deletions doomsday/libdeng2/src/legacy/legacycore.cpp
Expand Up @@ -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<Loop> loopStack;
*/

App *app;
//QTimer *loopTimer;
//Loop loop;

/// Pointer returned to callers, see LegacyCore::logFileName().
std::string logName;
Expand All @@ -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()
Expand All @@ -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);
}

Expand Down Expand Up @@ -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

0 comments on commit 2fdbeca

Please sign in to comment.