Skip to content

Commit

Permalink
fix: disable internalCollectManagedItems
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Sep 30, 2024
1 parent 76cf986 commit 439b49b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2418,7 +2418,7 @@ std::tuple<ReturnValue, uint32_t, uint32_t> Game::addItemBatch(const std::shared
}
// If it failed to add to the autoContainer, or it's not set, use the current logic
if (!addedToAutoContainer) {
ret = internalCollectManagedItems(player, item, g_game().getObjectCategory(item), false);
//ret = internalCollectManagedItems(player, item, g_game().getObjectCategory(item), false);
// If it can't place in the player's backpacks, add normally
if (ret != RETURNVALUE_NOERROR) {
ret = internalAddItem(destination, item, CONST_SLOT_WHEREEVER, flags, false, remainderCount);
Expand Down
2 changes: 1 addition & 1 deletion src/io/functions/iologindata_load_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void IOLoginDataLoad::loadPlayerInventoryItems(std::shared_ptr<Player> player, D
}

// Now that all items and containers have been added and parent chain is established, start decay
for (const auto& item : itemsToStartDecaying) {
for (const auto &item : itemsToStartDecaying) {
item->startDecaying();
}

Expand Down
16 changes: 16 additions & 0 deletions src/items/containers/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,19 @@ std::shared_ptr<Item> ContainerIterator::operator*() const {
bool ContainerIterator::hasReachedMaxDepth() const {
return m_maxDepthReached;
}

std::shared_ptr<Container> ContainerIterator::getCurrentContainer() const {
if (states.empty()) {
return nullptr;
}
const auto &top = states.back();
return top.container.lock();
}

size_t ContainerIterator::getCurrentIndex() const {
if (states.empty()) {
return 0;
}
const auto &top = states.back();
return top.index;
}
3 changes: 3 additions & 0 deletions src/items/containers/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class ContainerIterator {

bool hasReachedMaxDepth() const;

std::shared_ptr<Container> getCurrentContainer() const;
size_t getCurrentIndex() const;

private:
/**
* @brief Represents the state of the iterator at a given point in time.
Expand Down
29 changes: 16 additions & 13 deletions tests/unit/items/containers/container_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ suite<"ContainerIteratorTest"> containerIteratorTest = [] {
DI::setTestContainer(&InMemoryLogger::install(injector));
auto& logger = dynamic_cast<InMemoryLogger&>(injector.create<Logger&>());

auto createNestedContainers = [](size_t depth, size_t itemsPerContainer) -> std::shared_ptr<Container> {
if (depth == 0) {
return std::make_shared<Container>(ITEM_SHOPPING_BAG);
}
std::function<std::shared_ptr<Container>(size_t, size_t)> createNestedContainers =
[&](size_t depth, size_t itemsPerContainer) -> std::shared_ptr<Container> {
if (depth == 0) {
return std::make_shared<Container>(ITEM_SHOPPING_BAG);
}

auto container = std::make_shared<Container>(ITEM_SHOPPING_BAG);
for (size_t i = 0; i < itemsPerContainer; ++i) {
auto item = Item::CreateItem(ITEM_GOLD_COIN, 1);
container->addItem(item);
}
auto container = std::make_shared<Container>(ITEM_SHOPPING_BAG);
for (size_t i = 0; i < itemsPerContainer; ++i) {
auto item = Item::CreateItem(ITEM_GOLD_COIN, 1);
container->addItem(item);
}

auto nestedContainer = createNestedContainers(depth - 1, itemsPerContainer);
container->addItem(nestedContainer);
// Recursive call
auto nestedContainer = createNestedContainers(depth - 1, itemsPerContainer);
container->addItem(nestedContainer);

return container;
};

return container;
};

test("ContainerIterator performance com contêineres profundamente aninhados") = [&]() {
size_t depth = 100;
Expand Down

0 comments on commit 439b49b

Please sign in to comment.