Re #377 Added a restart method to GfApplication and GfuiApplication classes

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3534 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 30bd395ec8fed9be5fa61ad69031fc56861b3009
Former-commit-id: 631da3c8cd78026db7d122fcd6a8f71b4dc45fb8
This commit is contained in:
pouillot 2011-05-03 09:49:51 +00:00
parent 87c6b19504
commit 2c23d7a135
4 changed files with 46 additions and 6 deletions

View file

@ -128,20 +128,33 @@ GfEventLoop& GfApplication::eventLoop()
return *_pEventLoop;
}
void GfApplication::restart()
{
// Shutdown the gaming framework.
GfShutdown();
// Delete the event loop if any.
delete _pEventLoop;
// Restart.
GfRestart();
}
void GfApplication::exit(int nStatusCode)
{
// Shutdown the gaming framework.
GfShutdown();
// Delete the event loop if any.
delete _pEventLoop;
// Trace what we are doing.
if (!nStatusCode)
GfLogInfo("Exiting normally from %s.\n", _strName.c_str());
else
std::cerr << "Exiting from " << _strName
<< " after some error occurred (see above)." << std::endl;
// Shutdown the gaming framework.
GfShutdown();
// Delete the event loop if any.
delete _pEventLoop;
// The end.
::exit(nStatusCode);
}

View file

@ -176,6 +176,9 @@ class TGF_API GfApplication
void setEventLoop(GfEventLoop* pEventLoop);
GfEventLoop& eventLoop();
//! Restart the app.
virtual void restart();
//! Exit from the app.
virtual void exit(int nStatusCode = 0);

View file

@ -59,6 +59,7 @@ bool GfuiApplication::parseOptions()
bool GfuiApplication::setupWindow(bool bNoMenu)
{
// Initialize the window/screen.
_bWindowUp = true; // In case, GfScrInit() would call restart() ...
_bWindowUp = GfScrInit();
// Initialize the UI menu infrastructure.
@ -79,6 +80,25 @@ GfuiEventLoop& GfuiApplication::eventLoop()
return *dynamic_cast<GfuiEventLoop*>(_pEventLoop);
}
void GfuiApplication::restart()
{
// Shutdown the window/screen.
if (_bWindowUp)
{
GfScrShutdown();
_bWindowUp = false;
}
// Shutdown the gaming framework.
GfShutdown();
// Delete the event loop if any.
delete _pEventLoop;
// Restart.
GfRestart(GfuiMouseIsHWPresent());
}
void GfuiApplication::exit(int nStatusCode)
{
// Shutdown the window/screen.

View file

@ -81,6 +81,7 @@ typedef struct ScreenSize
TGFCLIENT_API bool GfScrInit(void);
TGFCLIENT_API void GfScrShutdown(void);
TGFCLIENT_API void GfScrGetSize(int *scrW, int *scrH, int *viewW, int *viewH);
TGFCLIENT_API bool GfScrToggleFullScreen();
TGFCLIENT_API unsigned char* GfScrCaptureAsImage(int* viewW, int *viewH);
TGFCLIENT_API int GfScrCaptureAsPNG(const char *filename);
@ -640,6 +641,9 @@ class TGFCLIENT_API GfuiApplication : public GfApplication
//! Application event loop.
GfuiEventLoop& eventLoop();
//! Restart the app.
virtual void restart();
//! Exit from the app.
virtual void exit(int nStatusCode = 0);