1 /** @file clientapp.h  The client application.
2  *
3  * @authors Copyright © 2013-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  * @authors Copyright © 2013-2015 Daniel Swanson <danij@dengine.net>
5  *
6  * @par License
7  * GPL: http://www.gnu.org/licenses/gpl.html
8  *
9  * <small>This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version. This program is distributed in the hope that it
13  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details. You should have received a copy of the GNU
16  * General Public License along with this program; if not, see:
17  * http://www.gnu.org/licenses</small>
18  */
19 
20 #ifndef CLIENTAPP_H
21 #define CLIENTAPP_H
22 
23 #include <de/BaseGuiApp>
24 #include <doomsday/doomsdayapp.h>
25 #include <QUrl>
26 
27 class AudioSystem;
28 class ClientPlayer;
29 class ClientResources;
30 class ClientServerWorld;
31 class ClientWindowSystem;
32 class ConfigProfiles;
33 class InFineSystem;
34 class InputSystem;
35 class RenderSystem;
36 class ServerLink;
37 class Updater;
38 
39 #if !defined (DENG_MOBILE)
40 #  define DENG_HAVE_BUSYRUNNER 1
41 class BusyRunner;
42 #endif
43 
44 /**
45  * The client application.
46  */
47 class ClientApp : public de::BaseGuiApp, public DoomsdayApp
48 {
49     Q_OBJECT
50 
51 public:
52     ClientApp(int &argc, char **argv);
53 
54     /**
55      * Sets up all the subsystems of the application. Must be called before the
56      * event loop is started. At the end of this method, the bootstrap script is
57      * executed.
58      */
59     void initialize();
60 
61     void preFrame();
62     void postFrame();
63 
64     void checkPackageCompatibility(
65             de::StringList const &packageIds,
66             de::String const &userMessageIfIncompatible,
67             std::function<void ()> finalizeFunc) override;
68 
69     void gameSessionWasSaved(AbstractSession const &session, GameStateFolder &toFolder) override;
70     void gameSessionWasLoaded(AbstractSession const &session, GameStateFolder const &fromFolder) override;
71 
72 public:
73     /**
74      * Reports a new alert to the user.
75      *
76      * @param msg    Message to show. May contain style escapes.
77      * @param level  Importance of the message.
78      */
79     static void alert(de::String const &msg, de::LogEntry::Level level = de::LogEntry::Message);
80 
81     static ClientPlayer &player(int console);
82     static de::LoopResult forLocalPlayers(const std::function<de::LoopResult (ClientPlayer &)> &func);
83 
84     static ClientApp &          app();
85     static ConfigProfiles &     logSettings();
86     static ConfigProfiles &     networkSettings();
87     static ConfigProfiles &     audioSettings();    ///< @todo Belongs in AudioSystem.
88     static ConfigProfiles &     uiSettings();
89     static ServerLink &         serverLink();
90     static InFineSystem &       infineSystem();
91     static InputSystem &        inputSystem();
92     static ClientWindowSystem & windowSystem();
93     static AudioSystem &        audioSystem();
94     static RenderSystem &       renderSystem();
95     static ClientResources &    resources();
96     static ClientServerWorld &  world();
97 
98 #if defined (DENG_HAVE_BUSYRUNNER)
99     static BusyRunner &         busyRunner();
100 #endif
101 
102     static bool hasInputSystem();
103     static bool hasRenderSystem();
104     static bool hasAudioSystem();
105 
106 #if defined (DENG_HAVE_UPDATER)
107     static Updater &updater();
108 #endif
109 
110 public slots:
111     void openHomepageInBrowser();
112     void openInBrowser(QUrl url);
113 
114 protected:
115     void unloadGame(GameProfile const &upcomingGame) override;
116     void makeGameCurrent(GameProfile const &newGame) override;
117     void reset() override;
118 
119 private:
120     DENG2_PRIVATE(d)
121 };
122 
123 #endif  // CLIENTAPP_H
124