Skip to content
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

Iterate over corpses in active items instead of map tiles for resurrect check #66753

Merged
merged 1 commit into from
Jul 9, 2023

Conversation

SurFlurer
Copy link
Contributor

@SurFlurer SurFlurer commented Jul 8, 2023

Summary

none

Purpose of change

Improve performance when there are necromancers in the reality bubble.

Describe the solution

Use get_active_items_in_radius() to grab nearby corpses only ( neglect other items, and do not iterate over tiles ). This has the advantage of less sees() and is_empty() check, which are both somewhat expensive. This also makes this function not linearly slower when there are large quantities of unrelated items nearby. ( Thanks andrei8l !)

I also made a cache for related map tile attributes to reduce calls of sees() and is_empty() if there are many corpses in one tile.

Describe alternatives you've considered

Testing

In the refugee center, with one necromancer in the backyard zombie horde, waiting for 30 minutes:

  1. With this change:
    image

  2. Without this change:
    image

Additional context

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Jul 8, 2023
@andrei8l
Copy link
Contributor

andrei8l commented Jul 8, 2023

You can probably do even better by only looking at corpses, which are cached separately. NPC AI code does that:

Cataclysm-DDA/src/npcmove.cpp

Lines 3229 to 3230 in b69ae48

for( const item_location &location : here.get_active_items_in_radius( around, range,
special_item_type::corpse ) ) {

@SurFlurer SurFlurer marked this pull request as draft July 8, 2023 16:48
@SurFlurer
Copy link
Contributor Author

SurFlurer commented Jul 8, 2023

You can probably do even better by only looking at corpses, which are cached separately. NPC AI code does that:

Cataclysm-DDA/src/npcmove.cpp

Lines 3229 to 3230 in b69ae48

for( const item_location &location : here.get_active_items_in_radius( around, range,
special_item_type::corpse ) ) {

Great thanks! I was thinking about using the active items cache, but didn't make it to find example usage of it. This is exactly what I need.

The test results did show a great improvement :)
image

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Jul 8, 2023
@SurFlurer SurFlurer marked this pull request as ready for review July 9, 2023 00:09
@SurFlurer SurFlurer changed the title Skip no-item tiles in mattack resurrect check Iterate over active items instead of map tiles for resurrect check Jul 9, 2023
@SurFlurer SurFlurer changed the title Iterate over active items instead of map tiles for resurrect check Iterate over corpses in active items instead of map tiles for resurrect check Jul 9, 2023
@github-actions github-actions bot added the Melee Melee weapons, tactics, techniques, reach attack label Jul 9, 2023
@dseguin dseguin merged commit 0573277 into CleverRaven:master Jul 9, 2023
@SurFlurer SurFlurer deleted the patch-1 branch July 10, 2023 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions Melee Melee weapons, tactics, techniques, reach attack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants