Skip to content

Commit af3badf

Browse files
Dumbeldornerzhul
authored andcommittedJun 21, 2017
C++11 cleanup on constructors dir client (#6012)
* C++11 cleanup on constructors dir client
1 parent 76074ad commit af3badf

File tree

6 files changed

+71
-125
lines changed

6 files changed

+71
-125
lines changed
 

Diff for: ‎src/client/clientlauncher.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3838

3939
/* mainmenumanager.h
4040
*/
41-
gui::IGUIEnvironment *guienv = NULL;
42-
gui::IGUIStaticText *guiroot = NULL;
41+
gui::IGUIEnvironment *guienv = nullptr;
42+
gui::IGUIStaticText *guiroot = nullptr;
4343
MainMenuManager g_menumgr;
4444

4545
bool isMenuActive()
@@ -48,7 +48,7 @@ bool isMenuActive()
4848
}
4949

5050
// Passed to menus to allow disconnecting and exiting
51-
MainGameCallback *g_gamecallback = NULL;
51+
MainGameCallback *g_gamecallback = nullptr;
5252

5353

5454
ClientLauncher::~ClientLauncher()

Diff for: ‎src/client/clientlauncher.h

+18-36
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
class ClientLauncher
2929
{
3030
public:
31-
ClientLauncher() :
32-
list_video_modes(false),
33-
skip_main_menu(false),
34-
use_freetype(false),
35-
random_input(false),
36-
address(""),
37-
playername(""),
38-
password(""),
39-
device(NULL),
40-
input(NULL),
41-
receiver(NULL),
42-
skin(NULL),
43-
font(NULL),
44-
simple_singleplayer_mode(false),
45-
current_playername("inv£lid"),
46-
current_password(""),
47-
current_address("does-not-exist"),
48-
current_port(0)
49-
{}
31+
ClientLauncher() {}
5032

5133
~ClientLauncher();
5234

@@ -66,29 +48,29 @@ class ClientLauncher
6648
void speed_tests();
6749
bool print_video_modes();
6850

69-
bool list_video_modes;
70-
bool skip_main_menu;
71-
bool use_freetype;
72-
bool random_input;
73-
std::string address;
74-
std::string playername;
75-
std::string password;
76-
IrrlichtDevice *device;
77-
InputHandler *input;
78-
MyEventReceiver *receiver;
79-
gui::IGUISkin *skin;
80-
gui::IGUIFont *font;
81-
scene::ISceneManager *smgr;
51+
bool list_video_modes = false;
52+
bool skip_main_menu = false;
53+
bool use_freetype = false;
54+
bool random_input = false;
55+
std::string address = "";
56+
std::string playername = "";
57+
std::string password = "";
58+
IrrlichtDevice *device = nullptr;
59+
InputHandler *input = nullptr;
60+
MyEventReceiver *receiver = nullptr;
61+
gui::IGUISkin *skin = nullptr;
62+
gui::IGUIFont *font = nullptr;
63+
scene::ISceneManager *smgr = nullptr;
8264
SubgameSpec gamespec;
8365
WorldSpec worldspec;
8466
bool simple_singleplayer_mode;
8567

8668
// These are set up based on the menu and other things
8769
// TODO: Are these required since there's already playername, password, etc
88-
std::string current_playername;
89-
std::string current_password;
90-
std::string current_address;
91-
int current_port;
70+
std::string current_playername = "inv£lid";
71+
std::string current_password = "";
72+
std::string current_address = "does-not-exist";
73+
int current_port = 0;
9274
};
9375

9476
#endif

Diff for: ‎src/client/inputhandler.h

+19-29
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,23 @@ class MyEventReceiver : public IEventReceiver
141141

142142
MyEventReceiver()
143143
{
144-
clearInput();
145144
#ifdef HAVE_TOUCHSCREENGUI
146145
m_touchscreengui = NULL;
147146
#endif
148147
}
149148

150-
bool leftclicked;
151-
bool rightclicked;
152-
bool leftreleased;
153-
bool rightreleased;
149+
bool leftclicked = false;
150+
bool rightclicked = false;
151+
bool leftreleased = false;
152+
bool rightreleased = false;
154153

155-
bool left_active;
156-
bool middle_active;
157-
bool right_active;
154+
bool left_active = false;
155+
bool middle_active = false;
156+
bool right_active = false;
158157

159-
s32 mouse_wheel;
158+
s32 mouse_wheel = 0;
160159

161-
JoystickController *joystick;
160+
JoystickController *joystick = nullptr;
162161

163162
#ifdef HAVE_TOUCHSCREENGUI
164163
TouchScreenGUI *m_touchscreengui;
@@ -221,7 +220,7 @@ class RealInputHandler : public InputHandler
221220
{
222221
public:
223222
RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver)
224-
: m_device(device), m_receiver(receiver), m_mousepos(0, 0)
223+
: m_device(device), m_receiver(receiver)
225224
{
226225
m_receiver->joystick = &joystick;
227226
}
@@ -277,24 +276,15 @@ class RealInputHandler : public InputHandler
277276
}
278277

279278
private:
280-
IrrlichtDevice *m_device;
281-
MyEventReceiver *m_receiver;
279+
IrrlichtDevice *m_device = nullptr;
280+
MyEventReceiver *m_receiver = nullptr;
282281
v2s32 m_mousepos;
283282
};
284283

285284
class RandomInputHandler : public InputHandler
286285
{
287286
public:
288-
RandomInputHandler()
289-
{
290-
leftdown = false;
291-
rightdown = false;
292-
leftclicked = false;
293-
rightclicked = false;
294-
leftreleased = false;
295-
rightreleased = false;
296-
keydown.clear();
297-
}
287+
RandomInputHandler() {}
298288
virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; }
299289
virtual bool wasKeyDown(const KeyPress &keyCode) { return false; }
300290
virtual v2s32 getMousePos() { return mousepos; }
@@ -390,12 +380,12 @@ class RandomInputHandler : public InputHandler
390380
KeyList keydown;
391381
v2s32 mousepos;
392382
v2s32 mousespeed;
393-
bool leftdown;
394-
bool rightdown;
395-
bool leftclicked;
396-
bool rightclicked;
397-
bool leftreleased;
398-
bool rightreleased;
383+
bool leftdown = false;
384+
bool rightdown = false;
385+
bool leftclicked = false;
386+
bool rightclicked = false;
387+
bool leftreleased = false;
388+
bool rightreleased = false;
399389
};
400390

401391
#endif

Diff for: ‎src/client/joystick_controller.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,9 @@ JoystickLayout create_xbox_layout()
154154
return jlo;
155155
}
156156

157-
JoystickController::JoystickController()
157+
JoystickController::JoystickController() :
158+
doubling_dtime(g_settings->getFloat("repeat_joystick_button_time"))
158159
{
159-
m_joystick_id = 0;
160-
161-
doubling_dtime = g_settings->getFloat("repeat_joystick_button_time");
162-
163160
for (size_t i = 0; i < KeyType::INTERNAL_ENUM_COUNT; i++) {
164161
m_past_pressed_time[i] = 0;
165162
}

Diff for: ‎src/client/joystick_controller.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class JoystickController {
155155

156156
s16 m_axes_vals[JA_COUNT];
157157

158-
u8 m_joystick_id;
158+
u8 m_joystick_id = 0;
159159

160160
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_pressed_keys;
161161

Diff for: ‎src/client/tile.h

+28-51
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void clearTextureNameCache();
6969
namespace irr {namespace scene {class IMesh;}}
7070
struct TextureFromMeshParams
7171
{
72-
scene::IMesh *mesh;
72+
scene::IMesh *mesh = nullptr;
7373
core::dimension2d<u32> dim;
7474
std::string rtt_texture_name;
7575
bool delete_texture_on_shutdown;
@@ -92,7 +92,7 @@ class ISimpleTextureSource
9292
ISimpleTextureSource(){}
9393
virtual ~ISimpleTextureSource(){}
9494
virtual video::ITexture* getTexture(
95-
const std::string &name, u32 *id = NULL) = 0;
95+
const std::string &name, u32 *id = nullptr) = 0;
9696
};
9797

9898
class ITextureSource : public ISimpleTextureSource
@@ -104,9 +104,9 @@ class ITextureSource : public ISimpleTextureSource
104104
virtual std::string getTextureName(u32 id)=0;
105105
virtual video::ITexture* getTexture(u32 id)=0;
106106
virtual video::ITexture* getTexture(
107-
const std::string &name, u32 *id = NULL)=0;
107+
const std::string &name, u32 *id = nullptr)=0;
108108
virtual video::ITexture* getTextureForMesh(
109-
const std::string &name, u32 *id = NULL) = 0;
109+
const std::string &name, u32 *id = nullptr) = 0;
110110
/*!
111111
* Returns a palette from the given texture name.
112112
* The pointer is valid until the texture source is
@@ -132,7 +132,7 @@ class IWritableTextureSource : public ITextureSource
132132
virtual std::string getTextureName(u32 id)=0;
133133
virtual video::ITexture* getTexture(u32 id)=0;
134134
virtual video::ITexture* getTexture(
135-
const std::string &name, u32 *id = NULL)=0;
135+
const std::string &name, u32 *id = nullptr)=0;
136136
virtual IrrlichtDevice* getDevice()=0;
137137
virtual bool isKnownSourceImage(const std::string &name)=0;
138138
virtual video::ITexture* generateTextureFromMesh(
@@ -180,43 +180,19 @@ enum MaterialType{
180180
*/
181181
struct FrameSpec
182182
{
183-
FrameSpec():
184-
texture_id(0),
185-
texture(NULL),
186-
normal_texture(NULL),
187-
flags_texture(NULL)
188-
{
189-
}
190-
u32 texture_id;
191-
video::ITexture *texture;
192-
video::ITexture *normal_texture;
193-
video::ITexture *flags_texture;
183+
FrameSpec() {}
184+
u32 texture_id = 0;
185+
video::ITexture *texture = nullptr;
186+
video::ITexture *normal_texture = nullptr;
187+
video::ITexture *flags_texture = nullptr;
194188
};
195189

196190
#define MAX_TILE_LAYERS 2
197191

198192
//! Defines a layer of a tile.
199193
struct TileLayer
200194
{
201-
TileLayer():
202-
texture(NULL),
203-
normal_texture(NULL),
204-
flags_texture(NULL),
205-
shader_id(0),
206-
texture_id(0),
207-
animation_frame_length_ms(0),
208-
animation_frame_count(1),
209-
material_type(TILE_MATERIAL_BASIC),
210-
material_flags(
211-
//0 // <- DEBUG, Use the one below
212-
MATERIAL_FLAG_BACKFACE_CULLING |
213-
MATERIAL_FLAG_TILEABLE_HORIZONTAL|
214-
MATERIAL_FLAG_TILEABLE_VERTICAL
215-
),
216-
has_color(false),
217-
color()
218-
{
219-
}
195+
TileLayer() {}
220196

221197
/*!
222198
* Two layers are equal if they can be merged.
@@ -287,22 +263,26 @@ struct TileLayer
287263

288264
// Ordered for size, please do not reorder
289265

290-
video::ITexture *texture;
291-
video::ITexture *normal_texture;
292-
video::ITexture *flags_texture;
266+
video::ITexture *texture = nullptr;
267+
video::ITexture *normal_texture = nullptr;
268+
video::ITexture *flags_texture = nullptr;
293269

294-
u32 shader_id;
270+
u32 shader_id = 0;
295271

296-
u32 texture_id;
272+
u32 texture_id = 0;
297273

298-
u16 animation_frame_length_ms;
299-
u8 animation_frame_count;
274+
u16 animation_frame_length_ms = 0;
275+
u8 animation_frame_count = 1;
300276

301-
u8 material_type;
302-
u8 material_flags;
277+
u8 material_type = TILE_MATERIAL_BASIC;
278+
u8 material_flags =
279+
//0 // <- DEBUG, Use the one below
280+
MATERIAL_FLAG_BACKFACE_CULLING |
281+
MATERIAL_FLAG_TILEABLE_HORIZONTAL|
282+
MATERIAL_FLAG_TILEABLE_VERTICAL;
303283

304284
//! If true, the tile has its own color.
305-
bool has_color;
285+
bool has_color = false;
306286

307287
std::vector<FrameSpec> frames;
308288

@@ -318,10 +298,7 @@ struct TileLayer
318298
*/
319299
struct TileSpec
320300
{
321-
TileSpec():
322-
rotation(0),
323-
emissive_light(0)
324-
{
301+
TileSpec() {
325302
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
326303
layers[layer] = TileLayer();
327304
}
@@ -341,9 +318,9 @@ struct TileSpec
341318
&& emissive_light == other.emissive_light;
342319
}
343320

344-
u8 rotation;
321+
u8 rotation = 0;
345322
//! This much light does the tile emit.
346-
u8 emissive_light;
323+
u8 emissive_light = 0;
347324
//! The first is base texture, the second is overlay.
348325
TileLayer layers[MAX_TILE_LAYERS];
349326
};

0 commit comments

Comments
 (0)
Please sign in to comment.