Skip to content
Permalink
Browse files

Modernize source code: last part (#6285)

* Modernize source code: last par

* Use empty when needed
* Use emplace_back instead of push_back when needed
* For range-based loops
* Initializers fixes
* constructors, destructors default
* c++ C stl includes
  • Loading branch information...
nerzhul committed Aug 20, 2017
1 parent 50669cd commit 1c1c97cbd1d7913ac12bf550ec02c97f843a0fd3
Showing with 445 additions and 583 deletions.
  1. +1 −1 src/camera.h
  2. +2 −2 src/chat.cpp
  3. +1 −1 src/database-dummy.h
  4. +2 −2 src/emerge.h
  5. +3 −3 src/event.h
  6. +8 −11 src/event_manager.h
  7. +2 −1 src/exceptions.h
  8. +36 −50 src/game.cpp
  9. +1 −1 src/gettime.h
  10. +6 −4 src/itemdef.h
  11. +2 −2 src/main.cpp
  12. +2 −0 src/mainmenumanager.h
  13. +2 −3 src/mapnode.cpp
  14. +1 −1 src/network/connection.cpp
  15. +1 −1 src/network/connection.h
  16. +39 −50 src/script/common/c_content.cpp
  17. +0 −4 src/script/common/c_content.h
  18. +2 −2 src/script/common/c_converter.cpp
  19. +0 −2 src/script/common/c_converter.h
  20. +2 −2 src/script/common/c_internal.h
  21. +10 −15 src/script/cpp_api/s_async.cpp
  22. +1 −1 src/script/cpp_api/s_async.h
  23. +1 −1 src/script/cpp_api/s_base.cpp
  24. +2 −2 src/script/cpp_api/s_base.h
  25. +9 −13 src/script/cpp_api/s_inventory.cpp
  26. +6 −4 src/script/cpp_api/s_item.cpp
  27. +2 −8 src/script/cpp_api/s_node.cpp
  28. +2 −2 src/script/cpp_api/s_node.h
  29. +0 −9 src/script/cpp_api/s_nodemeta.cpp
  30. +2 −2 src/script/cpp_api/s_nodemeta.h
  31. +0 −5 src/script/cpp_api/s_player.cpp
  32. +1 −1 src/script/cpp_api/s_player.h
  33. +8 −6 src/script/cpp_api/s_security.cpp
  34. +0 −1 src/script/lua_api/l_client.cpp
  35. +2 −2 src/script/lua_api/l_env.cpp
  36. +17 −16 src/script/lua_api/l_inventory.cpp
  37. +44 −48 src/script/lua_api/l_mainmenu.cpp
  38. +4 −5 src/script/lua_api/l_mapgen.cpp
  39. +3 −4 src/script/lua_api/l_metadata.cpp
  40. +1 −1 src/script/lua_api/l_metadata.h
  41. +1 −1 src/script/lua_api/l_object.cpp
  42. +1 −2 src/script/scripting_client.cpp
  43. +1 −1 src/sky.cpp
  44. +4 −3 src/sound.h
  45. +19 −24 src/sound_openal.cpp
  46. +4 −9 src/staticobject.cpp
  47. +3 −3 src/staticobject.h
  48. +33 −41 src/subgame.cpp
  49. +2 −2 src/subgame.h
  50. +3 −3 src/terminal_chat_console.cpp
  51. +23 −25 src/tool.cpp
  52. +2 −2 src/tool.h
  53. +1 −3 src/touchscreengui.cpp
  54. +12 −14 src/treegen.cpp
  55. +8 −8 src/unittest/test.cpp
  56. +4 −4 src/unittest/test.h
  57. +8 −8 src/unittest/test_compression.cpp
  58. +2 −2 src/unittest/test_nodedef.cpp
  59. +1 −1 src/unittest/test_noise.cpp
  60. +2 −2 src/unittest/test_voxelalgorithms.cpp
  61. +9 −12 src/util/areastore.cpp
  62. +3 −2 src/util/areastore.h
  63. +10 −10 src/util/enriched_string.cpp
  64. +2 −1 src/util/numeric.h
  65. +1 −1 src/util/srp.cpp
  66. +4 −5 src/util/string.cpp
  67. +6 −6 src/util/string.h
  68. +10 −48 src/voxel.cpp
  69. +7 −7 src/voxel.h
  70. +17 −29 src/voxelalgorithms.cpp
  71. +11 −12 src/wieldmesh.cpp
  72. +3 −3 src/wieldmesh.h
@@ -35,7 +35,7 @@ struct Nametag {
Nametag(scene::ISceneNode *a_parent_node,
const std::string &a_nametag_text,
const video::SColor &a_nametag_color,
const v3f a_nametag_pos):
const v3f &a_nametag_pos):
parent_node(a_parent_node),
nametag_text(a_nametag_text),
nametag_color(a_nametag_color),
@@ -365,8 +365,8 @@ s32 ChatBuffer::getBottomScrollPos() const
s32 rows = (s32) m_rows;
if (rows == 0)
return 0;
else
return formatted_count - rows;

return formatted_count - rows;
}


@@ -35,7 +35,7 @@ class Database_Dummy : public MapDatabase, public PlayerDatabase
void savePlayer(RemotePlayer *player) {}
bool loadPlayer(RemotePlayer *player, PlayerSAO *sao) { return true; }
bool removePlayer(const std::string &name) { return true; }
void listPlayers(std::vector<std::string> &) {}
void listPlayers(std::vector<std::string> &res) {}

void beginSave() {}
void endSave() {}
@@ -29,10 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define BLOCK_EMERGE_ALLOW_GEN (1 << 0)
#define BLOCK_EMERGE_FORCE_QUEUE (1 << 1)

#define EMERGE_DBG_OUT(x) do { \
#define EMERGE_DBG_OUT(x) { \
if (enable_mapgen_debug_info) \
infostream << "EmergeThread: " x << std::endl; \
} while (0)
}

class EmergeThread;
class INodeDefManager;
@@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class MtEvent
{
public:
virtual ~MtEvent() {};
virtual ~MtEvent() = default;
//virtual MtEvent* clone(){ return new IEvent; }
virtual const char* getType() const = 0;

@@ -49,7 +49,7 @@ class SimpleTriggerEvent: public MtEvent
class MtEventReceiver
{
public:
virtual ~MtEventReceiver(){};
virtual ~MtEventReceiver() = default;
virtual void onEvent(MtEvent *e) = 0;
};

@@ -58,7 +58,7 @@ typedef void (*event_receive_func)(MtEvent *e, void *data);
class MtEventManager
{
public:
virtual ~MtEventManager(){};
virtual ~MtEventManager() = default;
virtual void put(MtEvent *e) = 0;
virtual void reg(const char *type, event_receive_func f, void *data) = 0;
// If data==NULL, every occurence of f is deregistered.
@@ -43,17 +43,15 @@ class EventManager: public MtEventManager
std::map<std::string, Dest> m_dest;

public:
~EventManager()
{
}
~EventManager() = default;

void put(MtEvent *e)
{
std::map<std::string, Dest>::iterator i = m_dest.find(e->getType());
if(i != m_dest.end()){
std::list<FuncSpec> &funcs = i->second.funcs;
for(std::list<FuncSpec>::iterator i = funcs.begin();
i != funcs.end(); ++i){
(*(i->f))(e, i->d);
for (FuncSpec &func : funcs) {
(*(func.f))(e, func.d);
}
}
delete e;
@@ -62,11 +60,11 @@ class EventManager: public MtEventManager
{
std::map<std::string, Dest>::iterator i = m_dest.find(type);
if(i != m_dest.end()){
i->second.funcs.push_back(FuncSpec(f, data));
i->second.funcs.emplace_back(f, data);
} else{
std::list<FuncSpec> funcs;
Dest dest;
dest.funcs.push_back(FuncSpec(f, data));
dest.funcs.emplace_back(f, data);
m_dest[type] = dest;
}
}
@@ -86,9 +84,8 @@ class EventManager: public MtEventManager
}
}
} else{
for(std::map<std::string, Dest>::iterator
i = m_dest.begin(); i != m_dest.end(); ++i){
std::list<FuncSpec> &funcs = i->second.funcs;
for (auto &dest : m_dest) {
std::list<FuncSpec> &funcs = dest.second.funcs;
std::list<FuncSpec>::iterator j = funcs.begin();
while(j != funcs.end()){
bool remove = (j->f == f && (!data || j->d == data));
@@ -27,7 +27,8 @@ class BaseException : public std::exception
{
public:
BaseException(const std::string &s) throw(): m_s(s) {}
~BaseException() throw() {}
~BaseException() throw() = default;

virtual const char * what() const throw()
{
return m_s.c_str();
@@ -69,8 +69,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sound_openal.h"
#endif

extern Settings *g_settings;
extern Profiler *g_profiler;

/*
Text input system
@@ -248,7 +246,7 @@ void update_profiler_gui(gui::IGUIStaticText *guitext_profiler, FontEngine *fe,
setStaticText(guitext_profiler, text.c_str());
guitext_profiler->setVisible(true);

s32 w = fe->getTextWidth(text.c_str());
s32 w = fe->getTextWidth(text);

if (w < 400)
w = 400;
@@ -291,11 +289,9 @@ class ProfilerGraph
};
std::deque<Piece> m_log;
public:
u32 m_log_max_size;
u32 m_log_max_size = 200;

ProfilerGraph():
m_log_max_size(200)
{}
ProfilerGraph() = default;

void put(const Profiler::GraphValues &values)
{
@@ -314,14 +310,10 @@ class ProfilerGraph
// to be the same for each call to prevent flickering
std::map<std::string, Meta> m_meta;

for (std::deque<Piece>::const_iterator k = m_log.begin();
k != m_log.end(); ++k) {
const Piece &piece = *k;

for (Profiler::GraphValues::const_iterator i = piece.values.begin();
i != piece.values.end(); ++i) {
const std::string &id = i->first;
const float &value = i->second;
for (const Piece &piece : m_log) {
for (const auto &i : piece.values) {
const std::string &id = i.first;
const float &value = i.second;
std::map<std::string, Meta>::iterator j = m_meta.find(id);

if (j == m_meta.end()) {
@@ -349,9 +341,8 @@ class ProfilerGraph
sizeof(usable_colors) / sizeof(*usable_colors);
u32 next_color_i = 0;

for (std::map<std::string, Meta>::iterator i = m_meta.begin();
i != m_meta.end(); ++i) {
Meta &meta = i->second;
for (auto &i : m_meta) {
Meta &meta = i.second;
video::SColor color(255, 200, 200, 200);

if (next_color_i < usable_colors_count)
@@ -401,9 +392,7 @@ class ProfilerGraph
float lastscaledvalue = 0.0;
bool lastscaledvalue_exists = false;

for (std::deque<Piece>::const_iterator j = m_log.begin();
j != m_log.end(); ++j) {
const Piece &piece = *j;
for (const Piece &piece : m_log) {
float value = 0;
bool value_exists = false;
Profiler::GraphValues::const_iterator k =
@@ -763,8 +752,8 @@ class GameGlobalShaderConstantSetterFactory : public IShaderConstantSetterFactor

void setSky(Sky *sky) {
m_sky = sky;
for (size_t i = 0; i < created_nosky.size(); ++i) {
created_nosky[i]->setSky(m_sky);
for (GameGlobalShaderConstantSetter *ggscs : created_nosky) {
ggscs->setSky(m_sky);
}
created_nosky.clear();
}
@@ -793,7 +782,7 @@ bool nodePlacementPrediction(Client &client, const ItemDefinition &playeritem_de
if (!is_valid_position)
return false;

if (prediction != "" && !nodedef->get(node).rightclickable) {
if (!prediction.empty() && !nodedef->get(node).rightclickable) {
verbosestream << "Node placement prediction for "
<< playeritem_def.name << " is "
<< prediction << std::endl;
@@ -978,7 +967,7 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
}

// Get new messages from client
std::wstring message = L"";
std::wstring message;
while (client.getChatMessage(message)) {
chat_backend.addUnparsedMessage(message);
}
@@ -1116,8 +1105,8 @@ void KeyCache::populate()
if (handler) {
// First clear all keys, then re-add the ones we listen for
handler->dontListenForKeys();
for (size_t i = 0; i < KeyType::INTERNAL_ENUM_COUNT; i++) {
handler->listenForKey(key[i]);
for (const KeyPress &k : key) {
handler->listenForKey(k);
}
handler->listenForKey(EscapeKey);
handler->listenForKey(CancelKey);
@@ -1384,7 +1373,7 @@ class Game {

GameOnDemandSoundFetcher soundfetcher; // useful when testing
ISoundManager *sound;
bool sound_is_dummy;
bool sound_is_dummy = false;
SoundMaker *soundmaker;

ChatBackend *chat_backend;
@@ -1464,9 +1453,9 @@ class Game {
f32 m_cache_cam_smoothing;
f32 m_cache_fog_start;

bool m_invert_mouse;
bool m_first_loop_after_window_activation;
bool m_camera_offset_changed;
bool m_invert_mouse = false;
bool m_first_loop_after_window_activation = false;
bool m_camera_offset_changed = false;

#ifdef __ANDROID__
bool m_cache_hold_aux1;
@@ -1482,7 +1471,6 @@ Game::Game() :
itemdef_manager(NULL),
nodedef_manager(NULL),
sound(NULL),
sound_is_dummy(false),
soundmaker(NULL),
chat_backend(NULL),
current_formspec(NULL),
@@ -1496,10 +1484,7 @@ Game::Game() :
sky(NULL),
local_inventory(NULL),
hud(NULL),
mapper(NULL),
m_invert_mouse(false),
m_first_loop_after_window_activation(false),
m_camera_offset_changed(false)
mapper(NULL)
{
g_settings->registerChangedCallback("doubletap_jump",
&settingChangedCallback, this);
@@ -1806,7 +1791,7 @@ bool Game::init(
return false;

// Create a server if not connecting to an existing one
if (*address == "") {
if (address->empty()) {
if (!createSingleplayerServer(map_dir, gamespec, port, address))
return false;
}
@@ -2168,7 +2153,7 @@ bool Game::connectToServer(const std::string &playername,

wait_time += dtime;
// Only time out if we aren't waiting for the server we started
if ((*address != "") && (wait_time > 10)) {
if ((!address->empty()) && (wait_time > 10)) {
bool sent_old_init = g_settings->getFlag("send_pre_v25_init");
// If no pre v25 init was sent, and no answer was received,
// but the low level connection could be established
@@ -3175,8 +3160,9 @@ void Game::processClientEvents(CameraOrientation *cam)
break;

case CE_SHOW_FORMSPEC:
if (*(event.show_formspec.formspec) == "") {
if (current_formspec && ( *(event.show_formspec.formname) == "" || *(event.show_formspec.formname) == cur_formname) ){
if (event.show_formspec.formspec->empty()) {
if (current_formspec && (event.show_formspec.formname->empty()
|| *(event.show_formspec.formname) == cur_formname)) {
current_formspec->quitMenu();
}
} else {
@@ -3713,7 +3699,7 @@ PointedThing Game::updatePointedThing(
}

// Update selection mesh light level and vertex colors
if (selectionboxes->size() > 0) {
if (!selectionboxes->empty()) {
v3f pf = hud->getSelectionPos();
v3s16 p = floatToInt(pf, BS);

@@ -3722,8 +3708,8 @@ PointedThing Game::updatePointedThing(
u16 node_light = getInteriorLight(n, -1, nodedef);
u16 light_level = node_light;

for (u8 i = 0; i < 6; i++) {
n = map.getNodeNoEx(p + g_6dirs[i]);
for (const v3s16 &dir : g_6dirs) {
n = map.getNodeNoEx(p + dir);
node_light = getInteriorLight(n, -1, nodedef);
if (node_light > light_level)
light_level = node_light;
@@ -3797,7 +3783,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
runData.repeat_rightclick_timer = 0;
infostream << "Ground right-clicked" << std::endl;

if (meta && meta->getString("formspec") != "" && !random_input
if (meta && !meta->getString("formspec").empty() && !random_input
&& !isKeyDown(KeyType::SNEAK)) {
// Report right click to server
if (nodedef_manager->get(map.getNodeNoEx(nodepos)).rightclickable) {
@@ -3842,7 +3828,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
soundmaker->m_player_rightpunch_sound =
SimpleSoundSpec();

if (playeritem_def.node_placement_prediction == "" ||
if (playeritem_def.node_placement_prediction.empty() ||
nodedef_manager->get(map.getNodeNoEx(nodepos)).rightclickable) {
client->interact(3, pointed); // Report to server
} else {
@@ -3862,7 +3848,7 @@ void Game::handlePointingAtObject(const PointedThing &pointed, const ItemStack &
utf8_to_wide(runData.selected_object->infoText()));

if (show_debug) {
if (infotext != L"") {
if (!infotext.empty()) {
infotext += L"\n";
}
infotext += unescape_enriched(utf8_to_wide(
@@ -3973,7 +3959,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,

if (sound_dig.exists() && params.diggable) {
if (sound_dig.name == "__group") {
if (params.main_group != "") {
if (!params.main_group.empty()) {
soundmaker->m_player_leftpunch_sound.gain = 0.5;
soundmaker->m_player_leftpunch_sound.name =
std::string("default_dig_") +
@@ -4649,7 +4635,7 @@ void Game::showPauseMenu()
static const std::string mode = strgettext("- Mode: ");
if (!simple_singleplayer_mode) {
Address serverAddress = client->getServerAddress();
if (address != "") {
if (!address.empty()) {
os << mode << strgettext("Remote server") << "\n"
<< strgettext("- Address: ") << address;
} else {
@@ -4659,7 +4645,7 @@ void Game::showPauseMenu()
} else {
os << mode << strgettext("Singleplayer") << "\n";
}
if (simple_singleplayer_mode || address == "") {
if (simple_singleplayer_mode || address.empty()) {
static const std::string on = strgettext("On");
static const std::string off = strgettext("Off");
const std::string &damage = g_settings->getBool("enable_damage") ? on : off;
@@ -4673,7 +4659,7 @@ void Game::showPauseMenu()
<< strgettext("- Public: ") << announced << "\n";
std::string server_name = g_settings->get("server_name");
str_formspec_escape(server_name);
if (announced == on && server_name != "")
if (announced == on && !server_name.empty())
os << strgettext("- Server Name: ") << server_name;

}
Oops, something went wrong.

0 comments on commit 1c1c97c

Please sign in to comment.
You can’t perform that action at this time.