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

Ensure that casings are stackable #45746

Merged
merged 1 commit into from
Dec 1, 2020

Conversation

Aivean
Copy link
Contributor

@Aivean Aivean commented Dec 1, 2020

Summary

SUMMARY: Bugfixes "Ensure that casings are stackable (fixes pickup performance issues)"

Purpose of change

Fix #44469.

The problem is two-fold:

  1. Some casings are not stackable. When large stacks ammo are deconstructed into non-stackable components, it creates huge amounts of individual items (4000+ casings in the Trying to pick .22 casings lags the whole game to a halt #44469)
  2. Inventory management is slow and generally is not able to handle 4000+ individual items. Specifically, such items are added one by one, and each addition invalidates inventory cache, leading to the full recalculation of Character::drop_invalid_inventory()

Describe the solution

This PR addresses only the first issue. I made all currently existing casings stackable and added a unit test to (hopefully) ensure that all casings added in the future are also stackable.

The downside of this fix is that already disassembled ammo is still saved as individual items and will be slow to pick up. However, I think the issue is uncommon enough to bother with adding any kind of migration.

Describe alternatives you've considered

Alternative would be to address second part of the problem: inventory speed. Unfortunately, fixing that is by no means trivial. There is an ongoing discussion regarding some of the ways such improvements could be done.

Testing

Added unit test, verified that it was failing before the change and succeeds after.
Loaded the save file from #44469, disassembled .22 ammo into the stack of 4000+, picked it up instantaneously.

Additional context

After:
pick_up2

@Aivean Aivean added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Code: Performance Performance boosting code (CPU, memory, etc.) Items: Ammo / Guns Ammunition for all kinds of weapons and these weapons themselves labels Dec 1, 2020
@ZhilkinSerg ZhilkinSerg merged commit 6a993fe into CleverRaven:master Dec 1, 2020
@paulenka-aleh
Copy link

Awesome! Any chance for rags and glass shards?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Performance Performance boosting code (CPU, memory, etc.) Items: Ammo / Guns Ammunition for all kinds of weapons and these weapons themselves [JSON] Changes (can be) made in JSON
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trying to pick .22 casings lags the whole game to a halt
3 participants