Skip to content

Commit 13e995b

Browse files
authoredAug 17, 2017
Modernize src/c* src/d* and src/e* files (#6263)
* Modernize src/c* src/d* and src/e* files * default operator * redundant init * delete default constructors on CraftDefinition childs (never used) * fix some missing init values * const ref fix reported by clang-tidy * ranged-based for loops * simple conditions & returns * empty stl function instead of size * emplace_back stl function instead of push_back + construct temp obj * auto for some iterators * code style fixes * c++ stl headers instead of C stl headers (stdio.h -> cstdio)
1 parent 921151d commit 13e995b

25 files changed

+298
-343
lines changed
 

‎src/content_cao.cpp

+46-64
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class TestCAO : public ClientActiveObject
119119
{
120120
public:
121121
TestCAO(Client *client, ClientEnvironment *env);
122-
virtual ~TestCAO();
122+
virtual ~TestCAO() = default;
123123

124124
ActiveObjectType getType() const
125125
{
@@ -155,10 +155,6 @@ TestCAO::TestCAO(Client *client, ClientEnvironment *env):
155155
ClientActiveObject::registerType(getType(), create);
156156
}
157157

158-
TestCAO::~TestCAO()
159-
{
160-
}
161-
162158
ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env)
163159
{
164160
return new TestCAO(client, env);
@@ -261,7 +257,7 @@ class ItemCAO : public ClientActiveObject
261257
{
262258
public:
263259
ItemCAO(Client *client, ClientEnvironment *env);
264-
virtual ~ItemCAO();
260+
virtual ~ItemCAO() = default;
265261

266262
ActiveObjectType getType() const
267263
{
@@ -323,10 +319,6 @@ ItemCAO::ItemCAO(Client *client, ClientEnvironment *env):
323319
}
324320
}
325321

326-
ItemCAO::~ItemCAO()
327-
{
328-
}
329-
330322
ClientActiveObject* ItemCAO::create(Client *client, ClientEnvironment *env)
331323
{
332324
return new ItemCAO(client, env);
@@ -563,7 +555,7 @@ void GenericCAO::initialize(const std::string &data)
563555
player->setCAO(this);
564556
}
565557
if (m_client->getProtoVersion() < 33)
566-
m_env->addPlayerName(m_name.c_str());
558+
m_env->addPlayerName(m_name);
567559
}
568560
}
569561

@@ -607,7 +599,7 @@ void GenericCAO::processInitData(const std::string &data)
607599
GenericCAO::~GenericCAO()
608600
{
609601
if (m_is_player && m_client->getProtoVersion() < 33) {
610-
m_env->removePlayerName(m_name.c_str());
602+
m_env->removePlayerName(m_name);
611603
}
612604
removeFromScene(true);
613605
}
@@ -628,8 +620,8 @@ v3f GenericCAO::getPosition()
628620
scene::ISceneNode *node = getSceneNode();
629621
if (node)
630622
return node->getAbsolutePosition();
631-
else
632-
return m_position;
623+
624+
return m_position;
633625
}
634626
return pos_translator.vect_show;
635627
}
@@ -638,11 +630,17 @@ scene::ISceneNode* GenericCAO::getSceneNode()
638630
{
639631
if (m_meshnode) {
640632
return m_meshnode;
641-
} else if (m_animated_meshnode) {
633+
}
634+
635+
if (m_animated_meshnode) {
642636
return m_animated_meshnode;
643-
} else if (m_wield_meshnode) {
637+
}
638+
639+
if (m_wield_meshnode) {
644640
return m_wield_meshnode;
645-
} else if (m_spritenode) {
641+
}
642+
643+
if (m_spritenode) {
646644
return m_spritenode;
647645
}
648646
return NULL;
@@ -655,8 +653,8 @@ scene::IAnimatedMeshSceneNode* GenericCAO::getAnimatedMeshSceneNode()
655653

656654
void GenericCAO::setChildrenVisible(bool toset)
657655
{
658-
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
659-
GenericCAO *obj = m_env->getGenericCAO(m_children[i]);
656+
for (u16 cao_id : m_children) {
657+
GenericCAO *obj = m_env->getGenericCAO(cao_id);
660658
if (obj) {
661659
obj->setVisible(toset);
662660
}
@@ -686,8 +684,7 @@ void GenericCAO::removeFromScene(bool permanent)
686684
// Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
687685
if((m_env != NULL) && (permanent))
688686
{
689-
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
690-
u16 ci = m_children[i];
687+
for (u16 ci : m_children) {
691688
if (m_env->attachement_parent_ids[ci] == getId()) {
692689
m_env->attachement_parent_ids[ci] = 0;
693690
}
@@ -858,14 +855,13 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
858855
}
859856
else
860857
errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
861-
}
862-
else if(m_prop.visual == "wielditem") {
858+
} else if (m_prop.visual == "wielditem") {
863859
ItemStack item;
864860
infostream << "GenericCAO::addToScene(): wielditem" << std::endl;
865-
if (m_prop.wield_item == "") {
861+
if (m_prop.wield_item.empty()) {
866862
// Old format, only textures are specified.
867863
infostream << "textures: " << m_prop.textures.size() << std::endl;
868-
if (m_prop.textures.size() >= 1) {
864+
if (!m_prop.textures.empty()) {
869865
infostream << "textures[0]: " << m_prop.textures[0]
870866
<< std::endl;
871867
IItemDefManager *idef = m_client->idef();
@@ -894,7 +890,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
894890
updateTextures(m_current_texture_modifier);
895891

896892
scene::ISceneNode *node = getSceneNode();
897-
if (node && m_prop.nametag != "" && !m_is_local_player) {
893+
if (node && !m_prop.nametag.empty() && !m_is_local_player) {
898894
// Add nametag
899895
v3f pos;
900896
pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f;
@@ -919,8 +915,8 @@ void GenericCAO::updateLight(u8 light_at_pos)
919915
updateLightNoCheck(light_at_pos);
920916

921917
// Update light of all children
922-
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
923-
ClientActiveObject *obj = m_env->getActiveObject(m_children[i]);
918+
for (u16 i : m_children) {
919+
ClientActiveObject *obj = m_env->getActiveObject(i);
924920
if (obj) {
925921
obj->updateLightNoCheck(light_at_pos);
926922
}
@@ -1046,9 +1042,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
10461042

10471043
// Attachments, part 1: All attached objects must be unparented first,
10481044
// or Irrlicht causes a segmentation fault
1049-
for(std::vector<u16>::iterator ci = m_children.begin();
1050-
ci != m_children.end();)
1051-
{
1045+
for (auto ci = m_children.begin(); ci != m_children.end();) {
10521046
if (m_env->attachement_parent_ids[*ci] != getId()) {
10531047
ci = m_children.erase(ci);
10541048
continue;
@@ -1066,9 +1060,9 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
10661060
addToScene(m_client->tsrc());
10671061

10681062
// Attachments, part 2: Now that the parent has been refreshed, put its attachments back
1069-
for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) {
1063+
for (u16 cao_id : m_children) {
10701064
// Get the object of the child
1071-
ClientActiveObject *obj = m_env->getActiveObject(m_children[i]);
1065+
ClientActiveObject *obj = m_env->getActiveObject(cao_id);
10721066
if (obj)
10731067
obj->setAttachments();
10741068
}
@@ -1248,12 +1242,10 @@ void GenericCAO::updateTextures(std::string mod)
12481242
m_previous_texture_modifier = m_current_texture_modifier;
12491243
m_current_texture_modifier = mod;
12501244

1251-
if(m_spritenode)
1252-
{
1253-
if(m_prop.visual == "sprite")
1254-
{
1245+
if (m_spritenode) {
1246+
if (m_prop.visual == "sprite") {
12551247
std::string texturestring = "unknown_node.png";
1256-
if(m_prop.textures.size() >= 1)
1248+
if (!m_prop.textures.empty())
12571249
texturestring = m_prop.textures[0];
12581250
texturestring += mod;
12591251
m_spritenode->setMaterialTexture(0,
@@ -1262,8 +1254,7 @@ void GenericCAO::updateTextures(std::string mod)
12621254
// This allows setting per-material colors. However, until a real lighting
12631255
// system is added, the code below will have no effect. Once MineTest
12641256
// has directional lighting, it should work automatically.
1265-
if(m_prop.colors.size() >= 1)
1266-
{
1257+
if (!m_prop.colors.empty()) {
12671258
m_spritenode->getMaterial(0).AmbientColor = m_prop.colors[0];
12681259
m_spritenode->getMaterial(0).DiffuseColor = m_prop.colors[0];
12691260
m_spritenode->getMaterial(0).SpecularColor = m_prop.colors[0];
@@ -1274,20 +1265,17 @@ void GenericCAO::updateTextures(std::string mod)
12741265
m_spritenode->getMaterial(0).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
12751266
}
12761267
}
1277-
if(m_animated_meshnode)
1278-
{
1279-
if(m_prop.visual == "mesh")
1280-
{
1268+
1269+
if (m_animated_meshnode) {
1270+
if (m_prop.visual == "mesh") {
12811271
for (u32 i = 0; i < m_prop.textures.size() &&
1282-
i < m_animated_meshnode->getMaterialCount(); ++i)
1283-
{
1272+
i < m_animated_meshnode->getMaterialCount(); ++i) {
12841273
std::string texturestring = m_prop.textures[i];
1285-
if(texturestring == "")
1274+
if (texturestring.empty())
12861275
continue; // Empty texture string means don't modify that material
12871276
texturestring += mod;
12881277
video::ITexture* texture = tsrc->getTextureForMesh(texturestring);
1289-
if(!texture)
1290-
{
1278+
if (!texture) {
12911279
errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
12921280
continue;
12931281
}
@@ -1351,13 +1339,11 @@ void GenericCAO::updateTextures(std::string mod)
13511339
m_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
13521340
m_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
13531341
}
1354-
}
1355-
else if(m_prop.visual == "upright_sprite")
1356-
{
1342+
} else if (m_prop.visual == "upright_sprite") {
13571343
scene::IMesh *mesh = m_meshnode->getMesh();
13581344
{
13591345
std::string tname = "unknown_object.png";
1360-
if(m_prop.textures.size() >= 1)
1346+
if (!m_prop.textures.empty())
13611347
tname = m_prop.textures[0];
13621348
tname += mod;
13631349
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
@@ -1367,8 +1353,7 @@ void GenericCAO::updateTextures(std::string mod)
13671353
// This allows setting per-material colors. However, until a real lighting
13681354
// system is added, the code below will have no effect. Once MineTest
13691355
// has directional lighting, it should work automatically.
1370-
if(m_prop.colors.size() >= 1)
1371-
{
1356+
if(!m_prop.colors.empty()) {
13721357
buf->getMaterial().AmbientColor = m_prop.colors[0];
13731358
buf->getMaterial().DiffuseColor = m_prop.colors[0];
13741359
buf->getMaterial().SpecularColor = m_prop.colors[0];
@@ -1380,9 +1365,9 @@ void GenericCAO::updateTextures(std::string mod)
13801365
}
13811366
{
13821367
std::string tname = "unknown_object.png";
1383-
if(m_prop.textures.size() >= 2)
1368+
if (m_prop.textures.size() >= 2)
13841369
tname = m_prop.textures[1];
1385-
else if(m_prop.textures.size() >= 1)
1370+
else if (!m_prop.textures.empty())
13861371
tname = m_prop.textures[0];
13871372
tname += mod;
13881373
scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
@@ -1392,14 +1377,11 @@ void GenericCAO::updateTextures(std::string mod)
13921377
// This allows setting per-material colors. However, until a real lighting
13931378
// system is added, the code below will have no effect. Once MineTest
13941379
// has directional lighting, it should work automatically.
1395-
if(m_prop.colors.size() >= 2)
1396-
{
1380+
if (m_prop.colors.size() >= 2) {
13971381
buf->getMaterial().AmbientColor = m_prop.colors[1];
13981382
buf->getMaterial().DiffuseColor = m_prop.colors[1];
13991383
buf->getMaterial().SpecularColor = m_prop.colors[1];
1400-
}
1401-
else if(m_prop.colors.size() >= 1)
1402-
{
1384+
} else if (!m_prop.colors.empty()) {
14031385
buf->getMaterial().AmbientColor = m_prop.colors[0];
14041386
buf->getMaterial().DiffuseColor = m_prop.colors[0];
14051387
buf->getMaterial().SpecularColor = m_prop.colors[0];
@@ -1476,7 +1458,7 @@ void GenericCAO::updateAttachments()
14761458
scene::ISceneNode *parent_node = getParent()->getSceneNode();
14771459
scene::IAnimatedMeshSceneNode *parent_animated_mesh_node =
14781460
getParent()->getAnimatedMeshSceneNode();
1479-
if (parent_animated_mesh_node && m_attachment_bone != "") {
1461+
if (parent_animated_mesh_node && !m_attachment_bone.empty()) {
14801462
parent_node = parent_animated_mesh_node->getJointNode(m_attachment_bone.c_str());
14811463
}
14821464

@@ -1519,7 +1501,7 @@ void GenericCAO::processMessage(const std::string &data)
15191501
player->setCollisionbox(m_selection_box);
15201502
}
15211503

1522-
if ((m_is_player && !m_is_local_player) && m_prop.nametag == "")
1504+
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
15231505
m_prop.nametag = m_name;
15241506

15251507
expireVisuals();

‎src/content_cao.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ struct SmoothTranslator
4040
v3f vect_show;
4141
v3f vect_aim;
4242
f32 anim_counter = 0;
43-
f32 anim_time;
43+
f32 anim_time = 0;
4444
f32 anim_time_counter = 0;
4545
bool aim_is_end = true;
4646

47-
SmoothTranslator() {};
47+
SmoothTranslator() = default;
4848

4949
void init(v3f vect);
5050

‎src/content_cso.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SmokePuffCSO: public ClientSimpleObject
3030
scene::IBillboardSceneNode *m_spritenode = nullptr;
3131
public:
3232
SmokePuffCSO(scene::ISceneManager *smgr,
33-
ClientEnvironment *env, v3f pos, v2f size)
33+
ClientEnvironment *env, const v3f &pos, const v2f &size)
3434
{
3535
infostream<<"SmokePuffCSO: constructing"<<std::endl;
3636
m_spritenode = smgr->addBillboardSceneNode(

0 commit comments

Comments
 (0)
Please sign in to comment.