C++11 cleanup on constructors dir client (#6012)

* C++11 cleanup on constructors dir client
This commit is contained in:
Vincent Glize 2017-06-21 08:04:45 +02:00 committed by Loïc Blot
parent 76074ad81a
commit af3badf7a9
6 changed files with 71 additions and 125 deletions

View File

@ -38,8 +38,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
/* mainmenumanager.h /* mainmenumanager.h
*/ */
gui::IGUIEnvironment *guienv = NULL; gui::IGUIEnvironment *guienv = nullptr;
gui::IGUIStaticText *guiroot = NULL; gui::IGUIStaticText *guiroot = nullptr;
MainMenuManager g_menumgr; MainMenuManager g_menumgr;
bool isMenuActive() bool isMenuActive()
@ -48,7 +48,7 @@ bool isMenuActive()
} }
// Passed to menus to allow disconnecting and exiting // Passed to menus to allow disconnecting and exiting
MainGameCallback *g_gamecallback = NULL; MainGameCallback *g_gamecallback = nullptr;
ClientLauncher::~ClientLauncher() ClientLauncher::~ClientLauncher()

View File

@ -28,25 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class ClientLauncher class ClientLauncher
{ {
public: public:
ClientLauncher() : 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();
@ -66,29 +48,29 @@ protected:
void speed_tests(); void speed_tests();
bool print_video_modes(); bool print_video_modes();
bool list_video_modes; bool list_video_modes = false;
bool skip_main_menu; bool skip_main_menu = false;
bool use_freetype; bool use_freetype = false;
bool random_input; bool random_input = false;
std::string address; std::string address = "";
std::string playername; std::string playername = "";
std::string password; std::string password = "";
IrrlichtDevice *device; IrrlichtDevice *device = nullptr;
InputHandler *input; InputHandler *input = nullptr;
MyEventReceiver *receiver; MyEventReceiver *receiver = nullptr;
gui::IGUISkin *skin; gui::IGUISkin *skin = nullptr;
gui::IGUIFont *font; gui::IGUIFont *font = nullptr;
scene::ISceneManager *smgr; scene::ISceneManager *smgr = nullptr;
SubgameSpec gamespec; SubgameSpec gamespec;
WorldSpec worldspec; WorldSpec worldspec;
bool simple_singleplayer_mode; bool simple_singleplayer_mode;
// These are set up based on the menu and other things // These are set up based on the menu and other things
// TODO: Are these required since there's already playername, password, etc // TODO: Are these required since there's already playername, password, etc
std::string current_playername; std::string current_playername = "inv£lid";
std::string current_password; std::string current_password = "";
std::string current_address; std::string current_address = "does-not-exist";
int current_port; int current_port = 0;
}; };
#endif #endif

View File

@ -141,24 +141,23 @@ public:
MyEventReceiver() MyEventReceiver()
{ {
clearInput();
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
m_touchscreengui = NULL; m_touchscreengui = NULL;
#endif #endif
} }
bool leftclicked; bool leftclicked = false;
bool rightclicked; bool rightclicked = false;
bool leftreleased; bool leftreleased = false;
bool rightreleased; bool rightreleased = false;
bool left_active; bool left_active = false;
bool middle_active; bool middle_active = false;
bool right_active; bool right_active = false;
s32 mouse_wheel; s32 mouse_wheel = 0;
JoystickController *joystick; JoystickController *joystick = nullptr;
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
TouchScreenGUI *m_touchscreengui; TouchScreenGUI *m_touchscreengui;
@ -221,7 +220,7 @@ class RealInputHandler : public InputHandler
{ {
public: public:
RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver) 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; m_receiver->joystick = &joystick;
} }
@ -277,24 +276,15 @@ public:
} }
private: private:
IrrlichtDevice *m_device; IrrlichtDevice *m_device = nullptr;
MyEventReceiver *m_receiver; MyEventReceiver *m_receiver = nullptr;
v2s32 m_mousepos; v2s32 m_mousepos;
}; };
class RandomInputHandler : public InputHandler class RandomInputHandler : public InputHandler
{ {
public: public:
RandomInputHandler() RandomInputHandler() {}
{
leftdown = false;
rightdown = false;
leftclicked = false;
rightclicked = false;
leftreleased = false;
rightreleased = false;
keydown.clear();
}
virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; } virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; }
virtual bool wasKeyDown(const KeyPress &keyCode) { return false; } virtual bool wasKeyDown(const KeyPress &keyCode) { return false; }
virtual v2s32 getMousePos() { return mousepos; } virtual v2s32 getMousePos() { return mousepos; }
@ -390,12 +380,12 @@ private:
KeyList keydown; KeyList keydown;
v2s32 mousepos; v2s32 mousepos;
v2s32 mousespeed; v2s32 mousespeed;
bool leftdown; bool leftdown = false;
bool rightdown; bool rightdown = false;
bool leftclicked; bool leftclicked = false;
bool rightclicked; bool rightclicked = false;
bool leftreleased; bool leftreleased = false;
bool rightreleased; bool rightreleased = false;
}; };
#endif #endif

View File

@ -154,12 +154,9 @@ JoystickLayout create_xbox_layout()
return jlo; 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++) { for (size_t i = 0; i < KeyType::INTERNAL_ENUM_COUNT; i++) {
m_past_pressed_time[i] = 0; m_past_pressed_time[i] = 0;
} }

View File

@ -155,7 +155,7 @@ private:
s16 m_axes_vals[JA_COUNT]; s16 m_axes_vals[JA_COUNT];
u8 m_joystick_id; u8 m_joystick_id = 0;
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_pressed_keys; std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_pressed_keys;

View File

@ -69,7 +69,7 @@ void clearTextureNameCache();
namespace irr {namespace scene {class IMesh;}} namespace irr {namespace scene {class IMesh;}}
struct TextureFromMeshParams struct TextureFromMeshParams
{ {
scene::IMesh *mesh; scene::IMesh *mesh = nullptr;
core::dimension2d<u32> dim; core::dimension2d<u32> dim;
std::string rtt_texture_name; std::string rtt_texture_name;
bool delete_texture_on_shutdown; bool delete_texture_on_shutdown;
@ -92,7 +92,7 @@ public:
ISimpleTextureSource(){} ISimpleTextureSource(){}
virtual ~ISimpleTextureSource(){} virtual ~ISimpleTextureSource(){}
virtual video::ITexture* getTexture( virtual video::ITexture* getTexture(
const std::string &name, u32 *id = NULL) = 0; const std::string &name, u32 *id = nullptr) = 0;
}; };
class ITextureSource : public ISimpleTextureSource class ITextureSource : public ISimpleTextureSource
@ -104,9 +104,9 @@ public:
virtual std::string getTextureName(u32 id)=0; virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0; virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture( virtual video::ITexture* getTexture(
const std::string &name, u32 *id = NULL)=0; const std::string &name, u32 *id = nullptr)=0;
virtual video::ITexture* getTextureForMesh( 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. * Returns a palette from the given texture name.
* The pointer is valid until the texture source is * The pointer is valid until the texture source is
@ -132,7 +132,7 @@ public:
virtual std::string getTextureName(u32 id)=0; virtual std::string getTextureName(u32 id)=0;
virtual video::ITexture* getTexture(u32 id)=0; virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture( 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 IrrlichtDevice* getDevice()=0;
virtual bool isKnownSourceImage(const std::string &name)=0; virtual bool isKnownSourceImage(const std::string &name)=0;
virtual video::ITexture* generateTextureFromMesh( virtual video::ITexture* generateTextureFromMesh(
@ -180,17 +180,11 @@ enum MaterialType{
*/ */
struct FrameSpec struct FrameSpec
{ {
FrameSpec(): FrameSpec() {}
texture_id(0), u32 texture_id = 0;
texture(NULL), video::ITexture *texture = nullptr;
normal_texture(NULL), video::ITexture *normal_texture = nullptr;
flags_texture(NULL) video::ITexture *flags_texture = nullptr;
{
}
u32 texture_id;
video::ITexture *texture;
video::ITexture *normal_texture;
video::ITexture *flags_texture;
}; };
#define MAX_TILE_LAYERS 2 #define MAX_TILE_LAYERS 2
@ -198,25 +192,7 @@ struct FrameSpec
//! Defines a layer of a tile. //! Defines a layer of a tile.
struct TileLayer struct TileLayer
{ {
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()
{
}
/*! /*!
* Two layers are equal if they can be merged. * Two layers are equal if they can be merged.
@ -287,22 +263,26 @@ struct TileLayer
// Ordered for size, please do not reorder // Ordered for size, please do not reorder
video::ITexture *texture; video::ITexture *texture = nullptr;
video::ITexture *normal_texture; video::ITexture *normal_texture = nullptr;
video::ITexture *flags_texture; video::ITexture *flags_texture = nullptr;
u32 shader_id; u32 shader_id = 0;
u32 texture_id; u32 texture_id = 0;
u16 animation_frame_length_ms; u16 animation_frame_length_ms = 0;
u8 animation_frame_count; u8 animation_frame_count = 1;
u8 material_type; u8 material_type = TILE_MATERIAL_BASIC;
u8 material_flags; 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. //! If true, the tile has its own color.
bool has_color; bool has_color = false;
std::vector<FrameSpec> frames; std::vector<FrameSpec> frames;
@ -318,10 +298,7 @@ struct TileLayer
*/ */
struct TileSpec struct TileSpec
{ {
TileSpec(): TileSpec() {
rotation(0),
emissive_light(0)
{
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
layers[layer] = TileLayer(); layers[layer] = TileLayer();
} }
@ -341,9 +318,9 @@ struct TileSpec
&& emissive_light == other.emissive_light; && emissive_light == other.emissive_light;
} }
u8 rotation; u8 rotation = 0;
//! This much light does the tile emit. //! This much light does the tile emit.
u8 emissive_light; u8 emissive_light = 0;
//! The first is base texture, the second is overlay. //! The first is base texture, the second is overlay.
TileLayer layers[MAX_TILE_LAYERS]; TileLayer layers[MAX_TILE_LAYERS];
}; };