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
Conversation
src/mapblock_mesh.cpp
Outdated
} | ||
|
||
/* | ||
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ;)
To correctly inline functions you need to name them |
src/mapblock_mesh.cpp
Outdated
@@ -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) |
There was a problem hiding this comment.
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 :)
👍 |
src/mapblock_mesh.cpp
Outdated
@@ -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 |
There was a problem hiding this comment.
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();
}
src/mapblock_mesh.cpp
Outdated
default: | ||
break; | ||
switch (tile.rotation) { | ||
case 0: |
There was a problem hiding this comment.
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)
src/mapblock_mesh.cpp
Outdated
material.setTexture(2, p.tile.flags_texture); | ||
} else { | ||
} else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
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 |
Zeno-, l fixed things while rebasing and then force-pushed. |
@HybridDog Ahh... I was probably looking at it during the time you were doing that. It explains the issue anyway :) |
src/mapblock_mesh.cpp
Outdated
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) |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
please feedback |
wow you changed the whole codestyle, it's huge and difficult to review |
src/mapblock_mesh.cpp
Outdated
} | ||
else if(dir == v3s16(0,0,-1)) | ||
{ | ||
} else if(dir == v3s16(0,0,-1)) { |
There was a problem hiding this comment.
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
src/mapblock_mesh.cpp
Outdated
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; |
There was a problem hiding this comment.
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 ?
src/mapblock_mesh.cpp
Outdated
dest); | ||
} | ||
} | ||
for(s16 z = 0; z < MAP_BLOCKSIZE; z++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing spaces
src/mapblock_mesh.cpp
Outdated
@@ -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}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.