From 0aee45a1174cecca6ed4bd703ef6299185fec6b8 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sun, 23 Jul 2023 22:44:02 +1000 Subject: Cache certain item generation calls from interfaces Helps a little with the lag from recipes when having crafting interfaces open, but it's still noticeable. Also micro-optimized Root maintenance by unlocking the Root mutexes for their respective shared_ptrs earlier once we have our own shared_ptr. --- source/frontend/StarMerchantInterface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/frontend/StarMerchantInterface.cpp') diff --git a/source/frontend/StarMerchantInterface.cpp b/source/frontend/StarMerchantInterface.cpp index 8e3ad3a..17f4995 100644 --- a/source/frontend/StarMerchantInterface.cpp +++ b/source/frontend/StarMerchantInterface.cpp @@ -127,7 +127,7 @@ PanePtr MerchantPane::createTooltip(Vec2I const& screenPosition) { auto entry = m_itemGuiList->itemAt(i); if (entry->getChildAt(screenPosition)) { auto itemConfig = m_itemList.get(i); - ItemPtr item = Root::singleton().itemDatabase()->item(ItemDescriptor(itemConfig.get("item"))); + ItemPtr item = Root::singleton().itemDatabase()->itemShared(ItemDescriptor(itemConfig.get("item"))); return ItemTooltipBuilder::buildItemTooltip(item, m_player); } } @@ -232,7 +232,7 @@ void MerchantPane::buildItemList() { void MerchantPane::setupWidget(WidgetPtr const& widget, Json const& itemConfig) { auto& root = Root::singleton(); auto assets = root.assets(); - ItemPtr item = root.itemDatabase()->item(ItemDescriptor(itemConfig.get("item"))); + ItemPtr item = root.itemDatabase()->itemShared(ItemDescriptor(itemConfig.get("item"))); String name = item->friendlyName(); if (item->count() > 1) @@ -265,7 +265,7 @@ void MerchantPane::updateSelection() { if (m_selectedIndex != NPos) { auto itemConfig = m_itemList.get(m_selectedIndex); - m_selectedItem = Root::singleton().itemDatabase()->item(ItemDescriptor(itemConfig.get("item"))); + m_selectedItem = Root::singleton().itemDatabase()->itemShared(ItemDescriptor(itemConfig.get("item"))); findChild("spinCount.up")->enable(); findChild("spinCount.down")->enable(); m_countTextBox->setColor(Color::White); -- cgit v1.2.3