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

Dont recreate stackables every move #4761

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nekiro
Copy link
Member

@nekiro nekiro commented Jun 30, 2024

Pull Request Prelude

Changes Proposed

Don't recreate stackables on every move, create new stackables only when splitting the stack.

Issues addressed:
Stackable items are recreated even when they shouldn't, if you move a full stack of stackable item, why would you create a new item and delete the old one?
This seems pretty wasteful and unnecessary.

@nekiro nekiro changed the title Dont recreate stackables every move Draft: Dont recreate stackables every move Jun 30, 2024
@nekiro nekiro changed the title Draft: Dont recreate stackables every move WIP: Dont recreate stackables every move Jun 30, 2024
@nekiro nekiro marked this pull request as draft June 30, 2024 19:31
@nekiro nekiro marked this pull request as ready for review June 30, 2024 19:40
@nekiro nekiro changed the title WIP: Dont recreate stackables every move Dont recreate stackables every move Jun 30, 2024
Comment on lines +1217 to 1228
if (newCount == item->getItemCount()) {
// full item is moved (move count is the same as item count)
} else if (newCount > 0) {
moveItem = item->clone();
moveItem->setItemCount(newCount);
} else {
if (item->isRemoved()) {
ReleaseItem(item);
}

moveItem = nullptr;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the new count can never be negative, how about this?

Suggested change
if (newCount == item->getItemCount()) {
// full item is moved (move count is the same as item count)
} else if (newCount > 0) {
moveItem = item->clone();
moveItem->setItemCount(newCount);
} else {
if (item->isRemoved()) {
ReleaseItem(item);
}
moveItem = nullptr;
}
assert(newCount >= 0);
if (newCount != item->getItemCount()) {
moveItem = item->clone();
moveItem->setItemCount(newCount);
} else if (newCount == 0) {
if (item->isRemoved()) {
ReleaseItem(item);
}
moveItem = nullptr;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention: the code above may cause duplication bugs that I couldn't trace. Please don't apply it without testing beforehand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants