summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tilesdl.cc
diff options
context:
space:
mode:
authorennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-03 23:03:35 +0000
committerennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-03 23:03:35 +0000
commit97c06946c95207850b2e6b40a269c95c6599388c (patch)
treeb22c4a1cbe494fe0994ca791ae1ae1771f17e55b /crawl-ref/source/tilesdl.cc
parent708a45a49cb9b098013fd0f07ed623f1da3fb808 (diff)
downloadcrawl-ref-97c06946c95207850b2e6b40a269c95c6599388c.tar.gz
crawl-ref-97c06946c95207850b2e6b40a269c95c6599388c.zip
Properly handle the window being closed (by saving). Also, reattaching stdout/stderr on Windows.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8186 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/tilesdl.cc')
-rw-r--r--crawl-ref/source/tilesdl.cc37
1 files changed, 35 insertions, 2 deletions
diff --git a/crawl-ref/source/tilesdl.cc b/crawl-ref/source/tilesdl.cc
index e170ed75c3..bcd6432337 100644
--- a/crawl-ref/source/tilesdl.cc
+++ b/crawl-ref/source/tilesdl.cc
@@ -2,6 +2,7 @@
#include "itemname.h"
#include "items.h"
#include "itemprop.h"
+#include "files.h"
#include "mon-util.h"
#include "player.h"
#include "randart.h"
@@ -107,6 +108,33 @@ TilesFramework::~TilesFramework()
{
}
+static void _init_consoles()
+{
+#ifdef WIN32TILES
+ typedef BOOL (WINAPI *ac_func)(DWORD);
+ ac_func attach_console = (ac_func)GetProcAddress(
+ GetModuleHandle(TEXT("kernel32.dll")), "AttachConsole");
+
+ if (attach_console)
+ {
+ // Redirect output to the console
+ attach_console((DWORD)-1);
+ freopen("CONOUT$", "wb", stdout);
+ freopen("CONOUT$", "wb", stderr);
+ }
+#endif
+}
+
+static void _shutdown_console()
+{
+#ifdef WIN32TILES
+ typedef BOOL (WINAPI *fc_func)(void);
+ fc_func free_console = (fc_func)GetProcAddress(
+ GetModuleHandle(TEXT("kernel32.dll")), "FreeConsole");
+ if (free_console)
+ free_console();
+#endif
+}
void TilesFramework::shutdown()
{
delete m_region_tile;
@@ -135,6 +163,8 @@ void TilesFramework::shutdown()
}
SDL_Quit();
+
+ _shutdown_console();
}
bool TilesFramework::initialise()
@@ -144,6 +174,8 @@ bool TilesFramework::initialise()
putenv("SDL_VIDEO_CENTERED=1");
#endif
+ _init_consoles();
+
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
{
printf("Failed to initialise SDL: %s\n", SDL_GetError());
@@ -742,8 +774,9 @@ int TilesFramework::getch_ck()
break;
case SDL_QUIT:
- // TODO enne
- exit(0);
+ save_game(true);
+ ASSERT(!"Shouldn't get here");
+ break;
case SDL_USEREVENT:
default: