-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Overmap point refactoring #41693
Overmap point refactoring #41693
Conversation
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 reviewed faction camps, missions, and NPCs, and glanced over map, mapgen, and iexamine. My eyes are beginning to glaze over so I'll come back and review vehicles later.
Overall, this looks great! Clarity is much improved, and I think writing code in the future that deals with overmap scale tripoints should be much easier.
tripoint forest = om_target_tile( omt_pos, 10, 90, hide_locations, true, true, | ||
omt_pos, true ); | ||
if( forest != tripoint( -999, -999, -999 ) ) { | ||
tripoint_abs_omt forest = om_target_tile( omt_pos, 10, 90, hide_locations, true, true, |
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.
Note to self: why isn't this a cata::optional? Oh, right, acidia and I never went back and cleaned up the stuff that mostly worked.
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.
Yeah, I'd like to change that, but trying not to do unrelated refactoring in this commit.
tripoint mapmax = tripoint( 2 * SEEX - 1, 2 * SEEY - 1, omt_tgt.z ); | ||
farm_map.load( project_to<coords::scale::submap>( omt_tgt ), false ); | ||
tripoint mapmin = tripoint( 0, 0, omt_tgt.z() ); | ||
tripoint mapmax = tripoint( 2 * SEEX - 1, 2 * SEEY - 1, omt_tgt.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.
Both of these expressions seem like they should be standard utility functions.
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.
Agreed. But this is mapscale stuff and I was trying to limit these changes to overmap-scale stuff, lest this PR get even more ridiculously large.
for( int x2 = -3; x2 < 3; x2++ ) { | ||
for( int y2 = -3; y2 < 3; y2++ ) { | ||
const point_abs_omt nearby = p + point( x2, y2 ); | ||
cata::optional<basecamp *> bcp = overmap_buffer.find_camp( nearby ); |
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.
Note to self: find_camp should take a search radius.
Thanks for the review @mlangsdorf. Sorry if it appears that I'm deflecting all of your comments because I'm not actually changing anything in response to them. Feel free to push back if my responses are unsatisfactory. |
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 expected there would be a lot more stuff in the vehicle code.
The PR looks good overall. It definitely needs follow-up on the map square and submap scale, and then a general refactor and cleanup of all the ugly code idioms that have snuck in over the years.
And don't worry about not changing anything in response to my questions - sometimes, I just want a justification for why you made a decision, which is why I ask so many questions. If there was something I really felt you needed to change, I would have been much more direct about it.
point omt_diff = omt_path.back().xy() - veh_omt_pos.xy(); | ||
if( omt_diff.x > 3 || omt_diff.x < -3 || omt_diff.y > 3 || omt_diff.y < -3 ) { | ||
point_rel_omt omt_diff = omt_path.back().xy() - veh_omt_pos.xy(); | ||
if( omt_diff.x() > 3 || omt_diff.x() < -3 || omt_diff.y() > 3 || omt_diff.y() < -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.
Note to self: we also need a standard utility function for within_box()
or something similar.
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.
We have box
and rectangle
with contains
methods. We just need a helper function to make a rectangle
from a centre point and bounds.
src/vehicle.cpp
Outdated
const oter_id &cur_om_ter = overmap_buffer.ter( ms_to_omt_copy( g->m.getabs( global_pos3() ) ) ); | ||
// TODO: fix point types | ||
const oter_id &cur_om_ter = | ||
overmap_buffer.ter( tripoint_abs_omt( ms_to_omt_copy( g->m.getabs( global_pos3() ) ) ) ); |
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.
not in the PR, but we also need a single function call that takes a local or absolute map square and returns the tripoint_abs_omt.
43de665
to
89def7c
Compare
I've PRed all the separate parts I was able to pull out of this one. Unfortunately, there are still ~2000 lines of changes, so this is a bit of a beast to review. But it would be hard to split it up any more, so I'm marking it ready to review now. As mentioned above, I tried to be as conservative as possible in my changes, so as to minimize the chance of introducing bugs, but with any change this large (especially after the messy rebase I just completed) there is of course some risk. Nevertheless, I'm fairly confident I'm fixing more bugs than I'm introducing. |
573949f
to
dba15ff
Compare
Working through some compile failures the slow way because they only fail on older compilers in Travis. Will ping here when they're resolved. |
dba15ff
to
9a16301
Compare
OK, looks good to me now. I think the remaining failures are not related to this PR. |
Put the new point types through their paces by changing the types for overmap and overmapbuffer, and dealing with all the consequent fallout. Involves more changes than I originally anticipated, but serves as a good demonstration of the new point type features. Fixed some bugs along the way that were discovered by this new point type safety. The ones I remember are: * The evacuation shelter now correctly calculates the distance and direction to the refugee center, previously it was mostly nonsense (this only affects the message it prints out). * Weather conditions for NPC-planted crops are calculated more reasonably. Previously they were passing an overmap location as a map-square location, which could have caused all sorts of strangeness. * Translocators were similarly confusing map_square and overmap_terrain scales, so they might not have been working properly. * Two places were using map::points_in_radius which truncates to the map boundaries, but were using it for overmap-scale points, so it would only have worked correctly for some regions of the overmap.
9a16301
to
c938bbd
Compare
In the interests of not making this drag on, we can do it later, but can't you forward declare in the header files? |
Forward-declare what? The various |
When working on CleverRaven#41693 I totally forgot that I'd added shorter names for the various coord::scale values to use in project_to etc. without being so verbose. This makes the API more consistent because the names of the scales match the abbreviations in the type names. Convert to the shorter names. Strictly a find-and-replace commit, so hopefully should be safe.
When working on #41693 I totally forgot that I'd added shorter names for the various coord::scale values to use in project_to etc. without being so verbose. This makes the API more consistent because the names of the scales match the abbreviations in the type names. Convert to the shorter names. Strictly a find-and-replace commit, so hopefully should be safe.
I should have been more specific, mostly I was wincing at a new include in character.h |
Well, that specific case might be avoidable in the short term, but sooner or later it'll be needed in Extra compile time is unfortunately a price we pay for these new types. If it starts to rear its head in the build stats then we can explore options, but for now I don't see it there so I'm going to hope it's a problem for another day. |
|
||
for( x = 0, iter.x = origin.x - 1; x <= 2 ; ++iter.x, ++x ) { | ||
for( y = 0, iter.y = origin.y - 1; y <= 2; ++iter.y, ++y ) { | ||
for( int x = -1; x <= 1 ; ++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.
I think that is incorrect to use negative values for array indexes.
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.
Well spotted; this is wrong.
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'll PR a fix.
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.
See #45291.
Refactoring in CleverRaven#41693 accidentally introduced an out-of-bounds array access in overmapbuffer::scents_near. Fix it.
Refactoring in CleverRaven#41693 accidentally introduced an out-of-bounds array access in overmapbuffer::scents_near. Fix it.
Summary
SUMMARY: Infrastructure "Make use of new point types for overmap-scale code"
Purpose of change
I've been working towards greater type-safety in our point types for quite some time. #32017 introduces the new types. However, to know whether they are fit for purpose requires testing them at scale in the codebase. That's what this PR does.
This PR is not really intended to be merged directly. I'm looking for feedback on the new API, as demonstrated by this PR. If it meets with approval, then I can start making more, smaller, PRs to convey these changes more digestibly (although there will still be one giant PR in there with most of these changes, it needn't be all of them).Now I've pulled out all the easily separable pieces, this is now intended to be merged, and is still fairly sizable.
Describe the solution
Refactor
overmap
andovermapbuffer
to use the new point types, and deal with all the consequent fallout.Involves more changes than I originally anticipated, but serves as a good demonstration of the new point type features.
Fixed some bugs along the way that were discovered by this new point type safety. The ones I remember are:
Wherever these new point types interface with legacy point types I've added the comment
// TODO: fix point types
as a reminder that these new types should gradually spread over the rest of the codebase over time.Describe alternatives you've considered
Finding a more reasonable-sized chunk of code to refactor.
Testing
Mostly "if it compiles it works". I tried to be low-risk in my changes wherever possible, and not change behaviour except when I was really sure it was a bug.
Additional context
This took far too long.