-
Notifications
You must be signed in to change notification settings - Fork 483
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
Don't include raiding units in Units::isActive; make getPosition return invalid coords #4959
base: develop
Are you sure you want to change the base?
Changes from 10 commits
e2f1598
6f51b36
b0da75d
556a8bd
8d1ddb7
6f196e2
2750fcf
e9158d4
2995ab9
84e9a09
7664545
2cd932a
fdf8217
a53ed8b
342afcc
b618d45
33aa7db
15547fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,7 +122,11 @@ constexpr uint32_t exclude_flags2 = ( | |
|
||
bool Units::isActive(df::unit *unit) { | ||
CHECK_NULL_POINTER(unit); | ||
return !unit->flags1.bits.inactive; | ||
if (unit->flags1.bits.inactive) | ||
return false; | ||
else if (unit->flags1.bits.move_state || unit->flags1.bits.can_swap) | ||
return true; // These are always unset when leaving the map | ||
return linear_index(world->units.active, &df::unit::id, unit->id) >= 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a check on my fort, and all of my units in I went through all the uses of I don't fully understand There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That call to That test is not acceptable in a high-velocity code path. If we need this information in a high-velocity code path, we need to figure out a way to cache it (on an intra-tick basis) in a manner that doesn't require thousands of scattered reads every time it's used. For example, I'm on board with offering this as a secondary |
||
} | ||
|
||
bool Units::isVisible(df::unit *unit) { | ||
|
@@ -658,7 +662,7 @@ bool Units::isGreatDanger(df::unit *unit) { | |
|
||
bool Units::isUnitInBox(df::unit *u, const cuboid &box) { | ||
CHECK_NULL_POINTER(u); | ||
return box.containsPos(getPosition(u)); | ||
return isActive(u) ? box.containsPos(getPosition(u)) : false; | ||
} | ||
|
||
bool Units::getUnitsInBox(vector<df::unit *> &units, const cuboid &box, std::function<bool(df::unit *)> filter) { | ||
|
@@ -743,6 +747,8 @@ bool Units::getCitizens(vector<df::unit *> &citizens, bool exclude_residents, bo | |
|
||
df::coord Units::getPosition(df::unit *unit) { | ||
CHECK_NULL_POINTER(unit); | ||
if (!isActive(unit)) | ||
return df::coord(); | ||
if (unit->flags1.bits.caged) { | ||
if (auto cage = getContainer(unit)) | ||
return Items::getPosition(cage); | ||
|
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 looks like a backwards-incompatible change to the API that should at least be documented.