Fix various copy instead of const ref reported by cppcheck (part 3) (#5616)
[oweals/minetest.git] / src / client / clientlauncher.h
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 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         IrrlichtTimeGetter(IrrlichtDevice *device):
39                 m_device(device)
40         {}
41         u32 getTime(TimePrecision prec)
42         {
43                 if (prec == PRECISION_MILLI) {
44                         if (m_device == NULL)
45                                 return 0;
46                         return m_device->getTimer()->getRealTime();
47                 } else {
48                         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         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                 current_port(0)
85         {}
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();
94         void init_input();
95
96         bool launch_game(std::string &error_message, bool reconnect_requested,
97                 GameParams &game_params, const Settings &cmd_args);
98
99         void main_menu(MainMenuData *menudata);
100         bool create_engine_device();
101
102         void speed_tests();
103         bool print_video_modes();
104
105         bool list_video_modes;
106         bool skip_main_menu;
107         bool use_freetype;
108         bool random_input;
109         std::string address;
110         std::string playername;
111         std::string password;
112         IrrlichtDevice *device;
113         InputHandler *input;
114         MyEventReceiver *receiver;
115         gui::IGUISkin *skin;
116         gui::IGUIFont *font;
117         scene::ISceneManager *smgr;
118         SubgameSpec gamespec;
119         WorldSpec worldspec;
120         bool simple_singleplayer_mode;
121
122         // These are set up based on the menu and other things
123         // TODO: Are these required since there's already playername, password, etc
124         std::string current_playername;
125         std::string current_password;
126         std::string current_address;
127         int current_port;
128 };
129
130 #endif