Skip to content

Commit

Permalink
C++11 cleanup on constructors dir client (#6012)
Browse files Browse the repository at this point in the history
* C++11 cleanup on constructors dir client
  • Loading branch information
Dumbeldor authored and nerzhul committed Jun 21, 2017
1 parent 76074ad commit af3badf
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 125 deletions.
6 changes: 3 additions & 3 deletions src/client/clientlauncher.cpp
Expand Up @@ -38,8 +38,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,

/* mainmenumanager.h
*/
gui::IGUIEnvironment *guienv = NULL;
gui::IGUIStaticText *guiroot = NULL;
gui::IGUIEnvironment *guienv = nullptr;
gui::IGUIStaticText *guiroot = nullptr;
MainMenuManager g_menumgr;

bool isMenuActive()
Expand All @@ -48,7 +48,7 @@ bool isMenuActive()
}

// Passed to menus to allow disconnecting and exiting
MainGameCallback *g_gamecallback = NULL;
MainGameCallback *g_gamecallback = nullptr;


ClientLauncher::~ClientLauncher()
Expand Down
54 changes: 18 additions & 36 deletions src/client/clientlauncher.h
Expand Up @@ -28,25 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class ClientLauncher
{
public:
ClientLauncher() :
list_video_modes(false),
skip_main_menu(false),
use_freetype(false),
random_input(false),
address(""),
playername(""),
password(""),
device(NULL),
input(NULL),
receiver(NULL),
skin(NULL),
font(NULL),
simple_singleplayer_mode(false),
current_playername("inv£lid"),
current_password(""),
current_address("does-not-exist"),
current_port(0)
{}
ClientLauncher() {}

~ClientLauncher();

Expand All @@ -66,29 +48,29 @@ class ClientLauncher
void speed_tests();
bool print_video_modes();

bool list_video_modes;
bool skip_main_menu;
bool use_freetype;
bool random_input;
std::string address;
std::string playername;
std::string password;
IrrlichtDevice *device;
InputHandler *input;
MyEventReceiver *receiver;
gui::IGUISkin *skin;
gui::IGUIFont *font;
scene::ISceneManager *smgr;
bool list_video_modes = false;
bool skip_main_menu = false;
bool use_freetype = false;
bool random_input = false;
std::string address = "";
std::string playername = "";
std::string password = "";
IrrlichtDevice *device = nullptr;
InputHandler *input = nullptr;
MyEventReceiver *receiver = nullptr;
gui::IGUISkin *skin = nullptr;
gui::IGUIFont *font = nullptr;
scene::ISceneManager *smgr = nullptr;
SubgameSpec gamespec;
WorldSpec worldspec;
bool simple_singleplayer_mode;

// These are set up based on the menu and other things
// TODO: Are these required since there's already playername, password, etc
std::string current_playername;
std::string current_password;
std::string current_address;
int current_port;
std::string current_playername = "inv£lid";
std::string current_password = "";
std::string current_address = "does-not-exist";
int current_port = 0;
};

#endif
48 changes: 19 additions & 29 deletions src/client/inputhandler.h
Expand Up @@ -141,24 +141,23 @@ class MyEventReceiver : public IEventReceiver

MyEventReceiver()
{
clearInput();
#ifdef HAVE_TOUCHSCREENGUI
m_touchscreengui = NULL;
#endif
}

bool leftclicked;
bool rightclicked;
bool leftreleased;
bool rightreleased;
bool leftclicked = false;
bool rightclicked = false;
bool leftreleased = false;
bool rightreleased = false;

bool left_active;
bool middle_active;
bool right_active;
bool left_active = false;
bool middle_active = false;
bool right_active = false;

s32 mouse_wheel;
s32 mouse_wheel = 0;

JoystickController *joystick;
JoystickController *joystick = nullptr;

#ifdef HAVE_TOUCHSCREENGUI
TouchScreenGUI *m_touchscreengui;
Expand Down Expand Up @@ -221,7 +220,7 @@ class RealInputHandler : public InputHandler
{
public:
RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver)
: m_device(device), m_receiver(receiver), m_mousepos(0, 0)
: m_device(device), m_receiver(receiver)
{
m_receiver->joystick = &joystick;
}
Expand Down Expand Up @@ -277,24 +276,15 @@ class RealInputHandler : public InputHandler
}

private:
IrrlichtDevice *m_device;
MyEventReceiver *m_receiver;
IrrlichtDevice *m_device = nullptr;
MyEventReceiver *m_receiver = nullptr;
v2s32 m_mousepos;
};

class RandomInputHandler : public InputHandler
{
public:
RandomInputHandler()
{
leftdown = false;
rightdown = false;
leftclicked = false;
rightclicked = false;
leftreleased = false;
rightreleased = false;
keydown.clear();
}
RandomInputHandler() {}
virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; }
virtual bool wasKeyDown(const KeyPress &keyCode) { return false; }
virtual v2s32 getMousePos() { return mousepos; }
Expand Down Expand Up @@ -390,12 +380,12 @@ class RandomInputHandler : public InputHandler
KeyList keydown;
v2s32 mousepos;
v2s32 mousespeed;
bool leftdown;
bool rightdown;
bool leftclicked;
bool rightclicked;
bool leftreleased;
bool rightreleased;
bool leftdown = false;
bool rightdown = false;
bool leftclicked = false;
bool rightclicked = false;
bool leftreleased = false;
bool rightreleased = false;
};

#endif
7 changes: 2 additions & 5 deletions src/client/joystick_controller.cpp
Expand Up @@ -154,12 +154,9 @@ JoystickLayout create_xbox_layout()
return jlo;
}

JoystickController::JoystickController()
JoystickController::JoystickController() :
doubling_dtime(g_settings->getFloat("repeat_joystick_button_time"))
{
m_joystick_id = 0;

doubling_dtime = g_settings->getFloat("repeat_joystick_button_time");

for (size_t i = 0; i < KeyType::INTERNAL_ENUM_COUNT; i++) {
m_past_pressed_time[i] = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/joystick_controller.h
Expand Up @@ -155,7 +155,7 @@ class JoystickController {

s16 m_axes_vals[JA_COUNT];

u8 m_joystick_id;
u8 m_joystick_id = 0;

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

Expand Down
79 changes: 28 additions & 51 deletions src/client/tile.h
Expand Up @@ -69,7 +69,7 @@ void clearTextureNameCache();
namespace irr {namespace scene {class IMesh;}}
struct TextureFromMeshParams
{
scene::IMesh *mesh;
scene::IMesh *mesh = nullptr;
core::dimension2d<u32> dim;
std::string rtt_texture_name;
bool delete_texture_on_shutdown;
Expand All @@ -92,7 +92,7 @@ class ISimpleTextureSource
ISimpleTextureSource(){}
virtual ~ISimpleTextureSource(){}
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = NULL) = 0;
const std::string &name, u32 *id = nullptr) = 0;
};

class ITextureSource : public ISimpleTextureSource
Expand All @@ -104,9 +104,9 @@ class ITextureSource : public ISimpleTextureSource
virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = NULL)=0;
const std::string &name, u32 *id = nullptr)=0;
virtual video::ITexture* getTextureForMesh(
const std::string &name, u32 *id = NULL) = 0;
const std::string &name, u32 *id = nullptr) = 0;
/*!
* Returns a palette from the given texture name.
* The pointer is valid until the texture source is
Expand All @@ -132,7 +132,7 @@ class IWritableTextureSource : public ITextureSource
virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = NULL)=0;
const std::string &name, u32 *id = nullptr)=0;
virtual IrrlichtDevice* getDevice()=0;
virtual bool isKnownSourceImage(const std::string &name)=0;
virtual video::ITexture* generateTextureFromMesh(
Expand Down Expand Up @@ -180,43 +180,19 @@ enum MaterialType{
*/
struct FrameSpec
{
FrameSpec():
texture_id(0),
texture(NULL),
normal_texture(NULL),
flags_texture(NULL)
{
}
u32 texture_id;
video::ITexture *texture;
video::ITexture *normal_texture;
video::ITexture *flags_texture;
FrameSpec() {}
u32 texture_id = 0;
video::ITexture *texture = nullptr;
video::ITexture *normal_texture = nullptr;
video::ITexture *flags_texture = nullptr;
};

#define MAX_TILE_LAYERS 2

//! Defines a layer of a tile.
struct TileLayer
{
TileLayer():
texture(NULL),
normal_texture(NULL),
flags_texture(NULL),
shader_id(0),
texture_id(0),
animation_frame_length_ms(0),
animation_frame_count(1),
material_type(TILE_MATERIAL_BASIC),
material_flags(
//0 // <- DEBUG, Use the one below
MATERIAL_FLAG_BACKFACE_CULLING |
MATERIAL_FLAG_TILEABLE_HORIZONTAL|
MATERIAL_FLAG_TILEABLE_VERTICAL
),
has_color(false),
color()
{
}
TileLayer() {}

/*!
* Two layers are equal if they can be merged.
Expand Down Expand Up @@ -287,22 +263,26 @@ struct TileLayer

// Ordered for size, please do not reorder

video::ITexture *texture;
video::ITexture *normal_texture;
video::ITexture *flags_texture;
video::ITexture *texture = nullptr;
video::ITexture *normal_texture = nullptr;
video::ITexture *flags_texture = nullptr;

u32 shader_id;
u32 shader_id = 0;

u32 texture_id;
u32 texture_id = 0;

u16 animation_frame_length_ms;
u8 animation_frame_count;
u16 animation_frame_length_ms = 0;
u8 animation_frame_count = 1;

u8 material_type;
u8 material_flags;
u8 material_type = TILE_MATERIAL_BASIC;
u8 material_flags =
//0 // <- DEBUG, Use the one below
MATERIAL_FLAG_BACKFACE_CULLING |
MATERIAL_FLAG_TILEABLE_HORIZONTAL|
MATERIAL_FLAG_TILEABLE_VERTICAL;

//! If true, the tile has its own color.
bool has_color;
bool has_color = false;

std::vector<FrameSpec> frames;

Expand All @@ -318,10 +298,7 @@ struct TileLayer
*/
struct TileSpec
{
TileSpec():
rotation(0),
emissive_light(0)
{
TileSpec() {
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
layers[layer] = TileLayer();
}
Expand All @@ -341,9 +318,9 @@ struct TileSpec
&& emissive_light == other.emissive_light;
}

u8 rotation;
u8 rotation = 0;
//! This much light does the tile emit.
u8 emissive_light;
u8 emissive_light = 0;
//! The first is base texture, the second is overlay.
TileLayer layers[MAX_TILE_LAYERS];
};
Expand Down

0 comments on commit af3badf

Please sign in to comment.