Skip to content

Commit 8f77857

Browse files
authoredJun 17, 2017
Cpp11 initializers 2 (#5999)
* C++11 patchset 10: continue cleanup on constructors * Drop obsolete bool MainMenuData::enable_public (setting is called with cURL in server loop) * More classes cleanup * More classes cleanup + change NULL tests to boolean tests
1 parent 76be103 commit 8f77857

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+333
-646
lines changed
 

‎src/client.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Client::~Client()
221221
scene::IAnimatedMesh *mesh =
222222
m_device->getSceneManager()->getMeshCache()->getMeshByIndex(0);
223223

224-
if (mesh != NULL)
224+
if (mesh)
225225
m_device->getSceneManager()->getMeshCache()->removeMesh(mesh);
226226
}
227227

@@ -383,7 +383,7 @@ void Client::step(float dtime)
383383
*/
384384
// Control local player (0ms)
385385
LocalPlayer *player = m_env.getLocalPlayer();
386-
assert(player != NULL);
386+
assert(player);
387387
player->applyControl(dtime);
388388

389389
// Step environment
@@ -459,7 +459,7 @@ void Client::step(float dtime)
459459
if (block) {
460460
// Delete the old mesh
461461
delete block->mesh;
462-
block->mesh = NULL;
462+
block->mesh = nullptr;
463463

464464
if (r.mesh) {
465465
minimap_mapblock = r.mesh->moveMinimapMapblock();
@@ -1370,7 +1370,7 @@ void Client::addNode(v3s16 p, MapNode n, bool remove_metadata)
13701370
void Client::setPlayerControl(PlayerControl &control)
13711371
{
13721372
LocalPlayer *player = m_env.getLocalPlayer();
1373-
assert(player != NULL);
1373+
assert(player);
13741374
player->control = control;
13751375
}
13761376

@@ -1394,7 +1394,7 @@ bool Client::getLocalInventoryUpdated()
13941394
void Client::getLocalInventory(Inventory &dst)
13951395
{
13961396
LocalPlayer *player = m_env.getLocalPlayer();
1397-
assert(player != NULL);
1397+
assert(player);
13981398
dst = player->inventory;
13991399
}
14001400

@@ -1407,7 +1407,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
14071407
case InventoryLocation::CURRENT_PLAYER:
14081408
{
14091409
LocalPlayer *player = m_env.getLocalPlayer();
1410-
assert(player != NULL);
1410+
assert(player);
14111411
return &player->inventory;
14121412
}
14131413
break;
@@ -1496,7 +1496,7 @@ void Client::setCrack(int level, v3s16 pos)
14961496
u16 Client::getHP()
14971497
{
14981498
LocalPlayer *player = m_env.getLocalPlayer();
1499-
assert(player != NULL);
1499+
assert(player);
15001500
return player->hp;
15011501
}
15021502

@@ -1529,7 +1529,7 @@ void Client::typeChatMessage(const std::wstring &message)
15291529
// compatibility code
15301530
if (m_proto_ver < 29) {
15311531
LocalPlayer *player = m_env.getLocalPlayer();
1532-
assert(player != NULL);
1532+
assert(player);
15331533
std::wstring name = narrow_to_wide(player->getName());
15341534
pushToChatQueue((std::wstring)L"<" + name + L"> " + message);
15351535
}

‎src/client.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
457457
bool nodedefReceived()
458458
{ return m_nodedef_received; }
459459
bool mediaReceived()
460-
{ return m_media_downloader == NULL; }
460+
{ return !m_media_downloader; }
461461

462462
u8 getProtoVersion()
463463
{ return m_proto_ver; }

5 commit comments

Comments
 (5)

paramat commented on Jun 20, 2017

@paramat
Contributor
 MapgenFlatParams::MapgenFlatParams()
 {
-	spflags          = 0;
-	ground_level     = 8;
-	large_cave_depth = -33;
-	cave_width       = 0.09;
-	lake_threshold   = -0.45;
-	lake_steepness   = 48.0;
-	hill_threshold   = 0.45;
-	hill_steepness   = 64.0;

@nerzhul this is a bit of a shock, how do i decide whether a parameter can remain here or not? Why do the noise parameters remain here?

nerzhul commented on Jun 20, 2017

@nerzhul
ContributorAuthor

@paramat look at the header file directly

-	u32 spflags;
-	s16 ground_level;
-	s16 large_cave_depth;
-	float cave_width;
-	float lake_threshold;
-	float lake_steepness;
-	float hill_threshold;
-	float hill_steepness;
+	u32 spflags = 0;
+	s16 ground_level = 8;
+	s16 large_cave_depth = -33;
+	float cave_width = 0.09f;
+	float lake_threshold = -0.45f;
+	float lake_steepness = 48.0f;
+	float hill_threshold = 0.45f;
+	float hill_steepness = 64.0f;

in C++11 all trivial types defaults should be defined with membler declaration. You can do that for noise params too if needed, i just moved trivial types.

paramat commented on Jun 20, 2017

@paramat
Contributor

Ok thanks.

paramat commented on Jul 5, 2017

@paramat
Contributor

@nerzhul i find it very useful when workng on the 7 mapgens to have all mapgen parameters in one place and just above the parameter getters and setters in the .cpp file, please can i move these simple parameters back to the .cpp file?

I don't mind simple parameters being moved anywhere else in the code, just in the files of the 7 core mapgens.

I considered moving the noise parameters to the .h file but the addition of 'NoiseParams' to each line will make the lines excessively long and they will become less unreadable (for me) if i split the lines.

paramat commented on Jul 6, 2017

@paramat
Contributor

Not sure i can be bothered to move them again, i'll try to get used to it first :]

Please sign in to comment.