Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / XCSoar.cpp
blob38515cc8910e239e8867fbbcf938ce6eeb96acc4
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 /**
25 * This is the main entry point for the application
26 * @file XCSoar.cpp
29 #include "Startup.hpp"
30 #include "resource.h"
31 #include "LocalPath.hpp"
32 #include "Version.hpp"
33 #include "Protection.hpp"
34 #include "Components.hpp"
35 #include "LogFile.hpp"
36 #include "CommandLine.hpp"
37 #include "MainWindow.hpp"
38 #include "Interface.hpp"
39 #include "Compiler.h"
40 #include "Look/Fonts.hpp"
41 #include "Screen/Init.hpp"
42 #include "Net/Init.hpp"
43 #include "UtilsSystem.hpp"
44 #include "ResourceLoader.hpp"
45 #include "Language/Language.hpp"
46 #include "Simulator.hpp"
47 #include "OS/Args.hpp"
48 #include "IO/Async/GlobalIOThread.hpp"
50 #ifndef NDEBUG
51 #include "Thread/Thread.hpp"
52 #endif
54 #ifdef ENABLE_SDL
55 /* this is necessary on Mac OS X, to let libSDL bootstrap Quartz
56 before entering our main() */
57 #include <SDL_main.h>
58 #endif
60 #include <assert.h>
62 static const char *const Usage = "\n"
63 " -datapath= path to XCSoar data can be defined\n"
64 #ifdef SIMULATOR_AVAILABLE
65 " -simulator bypass startup-screen, use simulator mode directly\n"
66 " -fly bypass startup-screen, use fly mode directly\n"
67 #endif
68 " -profile=fname load profile from file fname\n"
69 #if !defined(_WIN32_WCE)
70 " -WIDTHxHEIGHT use screen resolution WIDTH x HEIGHT\n"
71 " -portrait use a 480x640 screen resolution\n"
72 " -square use a 480x480 screen resolution\n"
73 " -small use a 320x240 screen resolution\n"
74 #endif
75 #if !defined(ANDROID) && !defined(_WIN32_WCE)
76 " -dpi=DPI force usage of DPI for pixel density\n"
77 " -dpi=XDPIxYDPI force usage of XDPI and YDPI for pixel density\n"
78 #endif
79 #ifdef HAVE_CMDLINE_FULLSCREEN
80 " -fullscreen full-screen mode\n"
81 #endif
82 #ifdef HAVE_CMDLINE_RESIZABLE
83 " -resizable resizable window\n"
84 #endif
85 #if defined(_WIN32) && !defined(_WIN32_WCE)&& !defined(__WINE__)
86 " -console open debug output console\n"
87 #endif
90 /**
91 * Main entry point for the whole XCSoar application
93 #ifndef WIN32
94 int main(int argc, char **argv)
95 #else
96 int WINAPI
97 WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
98 #ifdef _WIN32_WCE
99 gcc_unused LPWSTR lpCmdLine,
100 #else
101 gcc_unused LPSTR lpCmdLine2,
102 #endif
103 int nCmdShow)
104 #endif
106 #ifdef WIN32
107 ResourceLoader::Init(hInstance);
108 #endif
110 Net::Initialise();
112 InitialiseDataPath();
113 StartupLogFreeRamAndStorage();
115 // Write startup note + version to logfile
116 LogFormat(_T("Starting XCSoar %s"), XCSoar_ProductToken);
118 // Read options from the command line
120 #ifdef WIN32
121 Args args(GetCommandLine(), Usage);
122 #else
123 Args args(argc, argv, Usage);
124 #endif
125 CommandLine::Parse(args);
128 ScreenGlobalInit screen_init;
130 #ifdef WIN32
131 /* try to make the UI most responsive */
132 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
133 #endif
135 AllowLanguage();
137 InitialiseIOThread();
139 // Perform application initialization and run loop
140 int ret = EXIT_FAILURE;
141 if (Startup())
142 ret = CommonInterface::main_window->RunEventLoop();
144 delete CommonInterface::main_window;
146 DeinitialiseIOThread();
148 DisallowLanguage();
150 Fonts::Deinitialize();
152 DeinitialiseDataPath();
153 Net::Deinitialise();
155 assert(!ExistsAnyThread());
157 return ret;