Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 :
5 : This program is free software; you can redistribute it and/or modify
6 : it under the terms of the GNU Lesser General Public License as published by
7 : the Free Software Foundation; either version 2.1 of the License, or
8 : (at your option) any later version.
9 :
10 : This program is distributed in the hope that it will be useful,
11 : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU Lesser General Public License for more details.
14 :
15 : You should have received a copy of the GNU Lesser General Public License along
16 : with this program; if not, write to the Free Software Foundation, Inc.,
17 : 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #ifndef __CLIENT_LAUNCHER_H__
21 : #define __CLIENT_LAUNCHER_H__
22 :
23 : #include "irrlichttypes_extrabloated.h"
24 : #include "client/inputhandler.h"
25 : #include "gameparams.h"
26 :
27 : // A small helper class
28 1 : class TimeGetter
29 : {
30 : public:
31 : virtual u32 getTime(TimePrecision prec) = 0;
32 : };
33 :
34 : // A precise irrlicht one
35 : class IrrlichtTimeGetter: public TimeGetter
36 : {
37 : public:
38 1 : IrrlichtTimeGetter(IrrlichtDevice *device):
39 1 : m_device(device)
40 1 : {}
41 149466 : u32 getTime(TimePrecision prec)
42 : {
43 149466 : if (prec == PRECISION_MILLI) {
44 149466 : if (m_device == NULL)
45 0 : return 0;
46 149466 : return m_device->getTimer()->getRealTime();
47 : } else {
48 0 : return porting::getTime(prec);
49 : }
50 : }
51 : private:
52 : IrrlichtDevice *m_device;
53 : };
54 : // Not so precise one which works without irrlicht
55 : class SimpleTimeGetter: public TimeGetter
56 : {
57 : public:
58 : u32 getTime(TimePrecision prec)
59 : {
60 : return porting::getTime(prec);
61 : }
62 : };
63 :
64 : class ClientLauncher
65 : {
66 : public:
67 1 : ClientLauncher() :
68 : list_video_modes(false),
69 : skip_main_menu(false),
70 : use_freetype(false),
71 : random_input(false),
72 : address(""),
73 : playername(""),
74 : password(""),
75 : device(NULL),
76 : input(NULL),
77 : receiver(NULL),
78 : skin(NULL),
79 : font(NULL),
80 : simple_singleplayer_mode(false),
81 : current_playername("invĀ£lid"),
82 : current_password(""),
83 : current_address("does-not-exist"),
84 1 : current_port(0)
85 1 : {}
86 :
87 : ~ClientLauncher();
88 :
89 : bool run(GameParams &game_params, const Settings &cmd_args);
90 :
91 : protected:
92 : void init_args(GameParams &game_params, const Settings &cmd_args);
93 : bool init_engine(int log_level);
94 :
95 : bool launch_game(std::string &error_message, GameParams &game_params,
96 : const Settings &cmd_args);
97 :
98 : void main_menu(MainMenuData *menudata);
99 : bool create_engine_device(int log_level);
100 :
101 : void speed_tests();
102 : bool print_video_modes();
103 :
104 : bool list_video_modes;
105 : bool skip_main_menu;
106 : bool use_freetype;
107 : bool random_input;
108 : std::string address;
109 : std::string playername;
110 : std::string password;
111 : IrrlichtDevice *device;
112 : InputHandler *input;
113 : MyEventReceiver *receiver;
114 : gui::IGUISkin *skin;
115 : gui::IGUIFont *font;
116 : scene::ISceneManager *smgr;
117 : SubgameSpec gamespec;
118 : WorldSpec worldspec;
119 : bool simple_singleplayer_mode;
120 :
121 : // These are set up based on the menu and other things
122 : // TODO: Are these required since there's already playername, password, etc
123 : std::string current_playername;
124 : std::string current_password;
125 : std::string current_address;
126 : int current_port;
127 : };
128 :
129 : #endif
|