From af55bab57659ad8e71f561b80a0788d766c81cdc Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 10 Jan 2010 15:36:53 +0000 Subject: [PATCH] Handle SIGINTs --- src/Engine.cpp | 2 +- src/Game.cpp | 2 +- src/Main.cpp | 23 ++++++++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Engine.cpp b/src/Engine.cpp index 02118ba..757c8a4 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -1,5 +1,5 @@ // -// Copyright (C) 2009 Nick Gasson +// Copyright (C) 2009-2010 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/src/Game.cpp b/src/Game.cpp index ec81983..df1ad4c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,5 +1,5 @@ // -// Copyright (C) 2009 Nick Gasson +// Copyright (C) 2009-2010 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/src/Main.cpp b/src/Main.cpp index 755bfb2..2bfb43c 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,5 +1,5 @@ // -// Copyright (C) 2009 Nick Gasson +// Copyright (C) 2009-2010 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -25,11 +25,27 @@ #include #include +#include using namespace boost::filesystem; namespace { IWindowPtr window; + + void SIGINT_handler(int unused) + { + log() << "Caught SIGINT"; + ::window->quit(); + } + + void setupSignalHandlers() + { + struct sigaction sa; + sa.sa_handler = SIGINT_handler; + sa.sa_flags = 0; + + sigaction(SIGINT, &sa, NULL); + } } IWindowPtr getGameWindow() @@ -40,7 +56,7 @@ IWindowPtr getGameWindow() int main(int argc, char** argv) { cout << PACKAGE << " " << VERSION << "." << PATCH << endl << endl - << "Copyright (C) 2009 Nick Gasson" << endl + << "Copyright (C) 2009-2010 Nick Gasson" << endl << "This program comes with ABSOLUTELY NO WARRANTY. " << "This is free software, and" << endl << "you are welcome to redistribute it under certain conditions. " @@ -49,11 +65,12 @@ int main(int argc, char** argv) log() << "Program started"; + setupSignalHandlers(); + try { #ifndef WIN32 if (argc != 2 && argc != 3) throw runtime_error("Usage: TrainGame (edit|play) [map]"); - initResources(); const string mapFile(argc == 3 ? argv[2] : ""); -- 2.39.2