Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapblock_mesh.cpp: Fix code style and simplify a bit code #4558

Merged
merged 3 commits into from Aug 28, 2017

Conversation

HybridDog
Copy link
Contributor

No description provided.

}

/*
Gets nth node tile (0 <= n <= 5).
*/
TileSpec getNodeTileN(MapNode mn, v3s16 p, u8 tileindex, MeshMakeData *data)
inline TileSpec getNodeTileN(MapNode mn, v3s16 p, u8 tileindex, MeshMakeData *data)
Copy link
Contributor

@Foghrye4 Foghrye4 Oct 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a really experienced C++ programmer and so i confused a little bit. I noticed, that gcc C++ compiler at Win platform raise an error undefined reference to getNodeTileN.
So, what happened, when you make inline non-void function?

Copy link
Contributor

@Foghrye4 Foghrye4 Oct 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HybridDog I've got an info as in this article: https://en.wikipedia.org/wiki/Inline_function
that inline keyword is an instruction for a compiler to replace a function call with a code, which is written in a function body. Therefore I don't quite understand, what compiler would do when function return something and this "something" assigned to object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think getNodeTileN() can be inlined (not in the manner suggested here anyway). It's used at least 7 times in content_mapblock.cpp and there is a function prototype for it in mapblock_mesh.h.

The real mystery, if there is any, is why it compiles ok on Linux ;)

@sfan5
Copy link
Member

sfan5 commented Oct 2, 2016

To correctly inline functions you need to name them static inline, however it seems to me that inlining these functions isn't that useful. (gcc would do it by itself if it is useful)

@sfan5 sfan5 added the Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements label Oct 2, 2016
@@ -1389,9 +1329,8 @@ void MapBlockMesh::updateCameraOffset(v3s16 camera_offset)
{
if (camera_offset != m_camera_offset) {
translateMesh(m_mesh, intToFloat(m_camera_offset-camera_offset, BS));
if (m_enable_vbo) {
if (m_enable_vbo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really think these braces needed to be removed because they were used in a consistent manner. But don't put them back, I'm just making a comment :)

@Zeno-
Copy link
Contributor

Zeno- commented Oct 7, 2016

👍

@@ -258,9 +253,8 @@ static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data)
light_day += decode_light(n.getLightNoChecks(LIGHTBANK_DAY, &f));
light_night += decode_light(n.getLightNoChecks(LIGHTBANK_NIGHT, &f));
light_count++;
} else {
} else
Copy link
Member

@SmallJoker SmallJoker Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (condition) {
    do_this();
    do_that();
} else {
    otherwise();
}

default:
break;
switch (tile.rotation) {
case 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was fine before:

switch (action) {
case KOBJ_ADD:
    return "add";
case KOBJ_REMOVE:
    return "remove";

(also from the Linux kernel code style guidelines)

material.setTexture(2, p.tile.flags_texture);
} else {
} else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@Zeno-
Copy link
Contributor

Zeno- commented Oct 7, 2016

I have no idea if I'm looking at the correct commits LOL. I click View Changes and... not found. Weird, it's always worked before. shrug

@HybridDog
Copy link
Contributor Author

Zeno-, l fixed things while rebasing and then force-pushed.
l do not know how to close a review and if l wrote "fixed" (or sth similar), l would further bloat the page.

@Zeno-
Copy link
Contributor

Zeno- commented Oct 7, 2016

@HybridDog Ahh... I was probably looking at it during the time you were doing that. It explains the issue anyway :)

if (scale.X < 0.999 || scale.X > 1.001) abs_scale = scale.X;
else if(scale.Y < 0.999 || scale.Y > 1.001) abs_scale = scale.Y;
else if(scale.Z < 0.999 || scale.Z > 1.001) abs_scale = scale.Z;
if (scale.X < 0.999 || scale.X > 1.001)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the former is an acceptable exception to the code style IMO (if you add a space after else if)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@HybridDog
Copy link
Contributor Author

please feedback

@nerzhul nerzhul removed the Rebase needed The PR needs to be rebased by its author. label Aug 28, 2017
@nerzhul
Copy link
Member

nerzhul commented Aug 28, 2017

wow you changed the whole codestyle, it's huge and difficult to review

}
else if(dir == v3s16(0,0,-1))
{
} else if(dir == v3s16(0,0,-1)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces in all if

if (scale.X < 0.999 || scale.X > 1.001) abs_scale = scale.X;
else if(scale.Y < 0.999 || scale.Y > 1.001) abs_scale = scale.Y;
else if(scale.Z < 0.999 || scale.Z > 1.001) abs_scale = scale.Z;
if (scale.X < 0.999 || scale.X > 1.001) abs_scale = scale.X;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add f to float values please ?

dest);
}
}
for(s16 z = 0; z < MAP_BLOCKSIZE; z++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces

@@ -1048,8 +1018,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
//TimeTaker timer2("MeshCollector building");

for (const FastFace &f : fastfaces_new) {
const u16 indices[] = {0,1,2,2,3,0};
const u16 indices_alternate[] = {0,1,3,2,3,1};
const u16 indices[] = {0, 1, 2, 2, 3, 0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all those should be static

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nerzhul nerzhul merged commit 7e38475 into minetest:master Aug 28, 2017
@HybridDog HybridDog deleted the mameshort branch August 28, 2017 18:33
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 11, 2019
)

* mapblock_mesh.cpp: Fix code style and simplify a bit code
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 23, 2019
)

* mapblock_mesh.cpp: Fix code style and simplify a bit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants