-
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
getDigParams: Fix selecting the lowest digging time #5558
Conversation
HybridDog
commented
Apr 10, 2017
•
edited
Loading
edited
- Tidy up code
- Fix selecting the best fitting time: time was compared with result_time before dividing it by the level difference
- Remove dead code (time from last punch)
src/tool.cpp
Outdated
} | ||
|
||
u16 wear_i = 65535.*result_wear; | ||
u16 wear_i = 0xffff * result_wear; |
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.
U16_MAX
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.
Otherwise 👍
src/tool.cpp
Outdated
result_wear = 0; | ||
result_main_group = name; | ||
} | ||
bool time_exists = cap.getTime(itemgroup_get(groups, groupname), &time); |
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.
no need to create variable, just call this into condition
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.
It's not entirely clear what getTime
returns, thus it's better to keep it this way. Makes it easier to understand and the compiler would optimize this anyway.
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
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, however, you quite misunderstood what nerzhul and me actually meant. Your previous commit was good too.
src/tool.cpp
Outdated
//infostream<<"f="<<f<<std::endl; | ||
result_time /= f; | ||
result_wear /= f; | ||
if (f > 1.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 is wrong. It can't be > 1
since last_punch < punch_interval
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.
You're right. Anyway, l just noticed ($ ag -r -A2 getDigParams
) that it's unused code.
l'll remove it in a separate commit.
@@ -219,18 +219,14 @@ int ModApiUtil::l_write_json(lua_State *L) | |||
return 1; | |||
} | |||
|
|||
// get_dig_params(groups, tool_capabilities[, time_from_last_punch]) | |||
// get_dig_params(groups, tool_capabilities) | |||
int ModApiUtil::l_get_dig_params(lua_State *L) |
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.
Mind documenting get_hit_params
and get_dig_params
in the Lua API or does that rather belong into a new pull/issue?
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.
lt belongs to another PR.
Code cleanup should still be a separate commit even if it is acting on the same code, mixiing cleanups with other changes makes review harder and creates a more confusing history. |
3409f33
to
8874520
Compare
paramat, you're right. l added an extra commit which shows a simple (and inefficient) fix. |
Thanks, perhaps the last 2 can be squashed? (this could be done on merge). |
Only thing that failed is an unimportant unittest on OS X |
time was compared with result_time before dividing it by the level difference
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
@SmallJoker still +1? If so this can be merged. |
@paramat Yes. |
Is there a corresponding issue to close? |
AfaIk, there isn't. |