1 // Copyright (C) 2007 Ole Laursen
2 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include <sigc++/trackable.h>
26 #include <sigc++/functors/mem_fun.h>
33 #include "Configuration.h"
37 struct Main::Impl: public sigc::trackable
42 sigc::connection on_timer_registered(Timing::timer_slot s,
47 static Main *singleton;
49 Main::Main(int &argc, char **&argv)
55 start_test_scenario = false;
56 start_stress_test = false;
64 impl->gtk_main = new Gtk::Main(argc, argv);
66 g_set_application_name("LordsAWar!");
68 Timing::instance().timer_registered.connect(
69 sigc::mem_fun(*impl, &Main::Impl::on_timer_registered));
71 catch (const Glib::Error &ex) {
72 std::cerr << ex.what() << std::endl;
79 delete impl->gtk_main;
84 Main &Main::instance()
86 assert(singleton != 0);
90 bool Main::iterate_main_loop()
94 impl->gtk_main->iteration(false);
96 catch (const Glib::Error &ex) {
97 std::cerr << ex.what() << std::endl;
103 void Main::start_main_loop()
105 if (Configuration::s_decorated)
107 Gtk::RC::add_default_file(File::getMiscFile("gtkrc"));
108 Gtk::RC::reparse_all(Gtk::Settings::get_default(), true);
113 if (impl->driver != NULL)
118 impl->driver = new Driver(load_filename);
119 impl->gtk_main->run();
121 catch (const Glib::Error &ex) {
122 std::cerr << ex.what() << std::endl;
126 void Main::stop_main_loop()
130 impl->gtk_main->quit();
132 catch (const Glib::Error &ex) {
133 std::cerr << ex.what() << std::endl;
137 sigc::connection Main::Impl::on_timer_registered(Timing::timer_slot s,
140 return Glib::signal_timeout().connect(s, msecs_interval);