-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Clean up l_object.cpp #10512
Clean up l_object.cpp #10512
Conversation
How about 'first_frame' or 'start_frame'? |
as a non native speaker, |
No, anyone can write them again if they need them.
Regarding the renaming: I think it's useful to change the variable if it's misnamed (e.g. |
It was simply a matter of choosing one or the other, as the code featured every variation of it (a lot of them also missed the new line for the body). Relevant discussion: #10480 (comment). As someone who's quite a beginner in C++, |
My point here is that changing bad style (
...just like this wouldn't justify changing |
I understand your point now, I'll avoid doing that in the future, I'm sorry (but please don't make me revert the ones I've already edited, it's... a lot) |
Reverting shouldn't be necessary at this point; it's not like it's a very hard change to review, even if there are a lot. Also, I think |
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.
Looks pretty good. I don't like the weird type checks everywhere, but that's better solved with better Lua-interfacing functions, like extending readParam
and adding something like paramIsType
. But that's for another PR, so I won't press inconsistent type checking here.
if (isNaN(L, 2)) | ||
throw LuaError("ObjectRef::set_yaw: NaN value is not allowed."); | ||
|
||
float yaw = readParam<float>(L, 2) * core::RADTODEG; | ||
co->setRotation(v3f(0, yaw, 0)); | ||
|
||
entitysao->setRotation(v3f(0, yaw, 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.
Question (not related to this cleanup, just a general question), but doesn't setting the other two to 0
reset the pitch and roll of ObjectRef:set_rotation
? If that's so, sounds like a bug.
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 have a feeling that doing this any other way may mess with XYZ/ZYX ordering - ie: the yaw won't turn out correctly
An issue should probably be created from this
Thanks v-rob for the in-depth review, all problems have been addressed, and
Also, I noticed |
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.
Looks good. I'm glad to see cleanups and code consistency.
As I just recolonized this PR removes the pretty well used player:is_player_connected function and breaks some mods on the way. |
|
That might sound silly. It's just I always used this functions like any other so I expected it to be official. I learned minetest modding mostly by doing so I must have seen the function somewhere else. |
is_player does not do the same thing.
See here: (section was added with 5.2.0) Lines 6107 to 6118 in 68cd93b
|
std::vector<MinimapMode> modes; | ||
s16 selected_mode = luaL_checkint(L, 3); |
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.
"2"
is a valid number but fails in luaL_checkint
.
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 type coercion)
return 0; | ||
|
||
u32 id = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : -1; | ||
u32 id = luaL_checkint(L, 2); |
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.
Assuming Krock's related comment is correct, the issue with luaL_checkint
applies here too (strings are valid numbers, but the function won't accept them).
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.
(assuming he's right) why exactly someone should pass a string instead of a number though? The API says nothing about it
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 is called type coercion. Lua should convert strings to numbers when used in a numeric context - although, the documents are unclear as to whether this is just with arithmetic or with other contexts too
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 mean, that's useful for things like print("this is a number: " .. 55)
but I still don't see why someone should pass a string into this function (hud_change
). Anyways, a solution could be to have a readParam<int>(...)
checking for NaN, applying type coercion and then casting into an int (if it's a decimal).
Also, the previous version was wrong too, because I could have passed a float, and HUDs take no floats
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 know how important this really is (do other functions consistently take strings as numbers?), especially since you're not meant to do funny things to HUD IDs.
return 0; | ||
|
||
u32 id = lua_tonumber(L, -1); | ||
u32 id = luaL_checkint(L, 2); |
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
Co-authored-by: Zughy <[email protected]>
So, I've decided cleaning up MT code on the go. I think a consistent ordered code is vital both for core devs and for possible contributors. This is, in short, what I did:
ObjectRef = obj
ServerActiveObject = sao
LuaEntitySAO = entitysao
PlayerSAO = playersao
RemotePlayer = player
NULL
checks. Now there arenullptr
s instead, as I find it more straightforward than!something
//Do it
is_player_connected
, a deprecated method that wasn't even listed in the APIset_bone_position
Things I'm not sure about, core dev help needed:
how to namep
inset_sprite(...)
-1
value of HUD IDs, returned when ID was not a number. I had a look at the code and it doesn't look to me was meaningful at all so I simply removed it, but a double check is always betterdebug lines at 2249 and 2257. Do you want to keep them?To do
This PR is Ready for Review.
How to test
Well: check the code. Also, I might have made a few mistakes as I'm human, even if I double-checked my edits twice. So idk, take a solid game, play it a little bit and see if it all works accordingly.
Lastly, I want to underline how, imho, this should be high priority: I've seen things which were pretty messed up, like edits pushed a couple of weeks ago going completely against the guidelines (the minimap), or useless 8 year old comments who nobody apparently decided to remove. A tidy environment helps a lot. And I've actually had fun doing it, it was relaxing