qtgui: minor include fiddling
[openc2e.git] / main.cpp
blobcfb14a2f4cd4b9f4fb2b68d81a53463dd4ccc95d
1 /*
2 * main.cpp
3 * openc2e
5 * Created by Alyssa Milburn on Wed 02 Jun 2004.
6 * Copyright (c) 2004-2008 Alyssa Milburn. All rights reserved.
7 * Copyright (c) 2005-2008 Bryan Donlan. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
21 #include "openc2e.h"
22 #include "version.h"
23 #include <iostream>
24 #include "Engine.h"
25 #include "SDLBackend.h"
26 #ifdef OPENAL_SUPPORT
27 #include "OpenALBackend.h"
28 #endif
29 #ifdef QT_SUPPORT
30 #include "qtgui/QtBackend.h"
31 #endif
33 #ifdef _WIN32
34 #include <windows.h>
35 #endif
37 // SDL tries stealing main on some platforms, which we don't want.
38 #undef main
40 extern "C" int main(int argc, char *argv[]) {
41 try {
42 std::string version;
43 #ifdef DEV_BUILD
44 version = "development build";
45 #else
46 version = RELEASE_VERSION;
47 #endif
48 std::cout << "openc2e (" << version << "), built " __DATE__ " " __TIME__ "\nCopyright (c) 2004-2008 "
49 "Alyssa Milburn and others\n\n";
51 engine.addPossibleBackend("sdl", shared_ptr<Backend>(new SDLBackend()));
52 #ifdef QT_SUPPORT
53 boost::shared_ptr<QtBackend> qtbackend = boost::shared_ptr<QtBackend>(new QtBackend());
54 boost::shared_ptr<Backend> qtbackend_generic = boost::dynamic_pointer_cast<class Backend, class QtBackend>(qtbackend);
55 engine.addPossibleBackend("qt", qtbackend_generic); // last-added backend is default
56 #endif
57 #ifdef OPENAL_SUPPORT
58 engine.addPossibleAudioBackend("openal", shared_ptr<AudioBackend>(new OpenALBackend()));
59 #endif
61 // pass command-line flags to the engine, but do no other setup
62 if (!engine.parseCommandLine(argc, argv)) return 1;
64 // get the engine to do all the startup (read catalogue, loading world, etc)
65 if (!engine.initialSetup()) return 0;
67 int ret = engine.backend->run(argc, argv);
69 // we're done, be sure to shut stuff down
70 engine.shutdown();
72 return ret;
73 } catch (std::exception &e) {
74 #ifdef _WIN32
75 MessageBox(NULL, e.what(), "openc2e - Fatal exception encountered:", MB_ICONERROR);
76 #else
77 std::cerr << "Fatal exception encountered: " << e.what() << "\n";
78 #endif
79 return 1;
83 /* vim: set noet: */