From bcb1aa242d152e0d260da4bb87ce3755209c8926 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 13 Jan 2016 20:04:01 +0100 Subject: [PATCH] Fixed: Use map for faster search for example (implemented a TODO of GUIGUI) --HG-- branch : develop --- .../src/game_share/visual_slot_manager.cpp | 51 ++++++++----------- .../src/game_share/visual_slot_manager.h | 6 +++ .../tools/leveldesign/mp_generator/main.cpp | 1 + 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/code/ryzom/common/src/game_share/visual_slot_manager.cpp b/code/ryzom/common/src/game_share/visual_slot_manager.cpp index eed01388d..bc2410eea 100644 --- a/code/ryzom/common/src/game_share/visual_slot_manager.cpp +++ b/code/ryzom/common/src/game_share/visual_slot_manager.cpp @@ -94,70 +94,59 @@ void CVisualSlotManager::init() f.close(); // Display elements read. -// for(uint i=0; i<_VisualSlot.size(); ++i) -// { + for(uint i=0, len = _VisualSlot.size(); i you probably need to rebuild the tab."); - - // No Item - return 0; + return sheet2Index(id, SLOTTYPE::RIGHT_HAND_SLOT); }// rightItem2Index // //----------------------------------------------- // leftItem2Index : // Return the visual slot index from a sheet Id for items in left hand. -// \todo GUIGUI : Use map for faster search for example //----------------------------------------------- uint32 CVisualSlotManager::leftItem2Index(const NLMISC::CSheetId &id) { - if(SLOTTYPE::LEFT_HAND_SLOT < _VisualSlot.size()) - { - for(uint i=0; i<_VisualSlot[SLOTTYPE::LEFT_HAND_SLOT].Element.size(); ++i) - if(_VisualSlot[SLOTTYPE::LEFT_HAND_SLOT].Element[i].SheetId == id) - return _VisualSlot[SLOTTYPE::LEFT_HAND_SLOT].Element[i].Index; - } - else - nlwarning("VSMngr:leftItem2Index: Bad slot -> you probably need to rebuild the tab."); - - // No Item - return 0; + return sheet2Index(id, SLOTTYPE::LEFT_HAND_SLOT); }// leftItem2Index // //----------------------------------------------- // sheet2Index : // Return the visual index from a sheet Id and the visual slot. -// \todo GUIGUI : Use map for faster search for example //----------------------------------------------- uint32 CVisualSlotManager::sheet2Index(const NLMISC::CSheetId &id, SLOTTYPE::EVisualSlot slot) { if((uint)slot < _VisualSlot.size()) { - for(uint i=0; i<_VisualSlot[slot].Element.size(); ++i) - if(_VisualSlot[slot].Element[i].SheetId == id) - return _VisualSlot[slot].Element[i].Index; + const TElementList &el = _VisualSlot[slot]; + TElementList::SheetIdToIndexMapType::const_iterator it = el.SheetIdToIndexMap.find(id); + if (it != el.SheetIdToIndexMap.end()) return it->second; } else nlwarning("VSMngr:sheet2Index: Bad slot '%d' -> you probably need to rebuild the tab.", (sint)slot); diff --git a/code/ryzom/common/src/game_share/visual_slot_manager.h b/code/ryzom/common/src/game_share/visual_slot_manager.h index 9d2f67dc0..ee9d8371a 100644 --- a/code/ryzom/common/src/game_share/visual_slot_manager.h +++ b/code/ryzom/common/src/game_share/visual_slot_manager.h @@ -71,11 +71,17 @@ public: // elements list for a visual slot. std::vector Element; + // std::map to increase access speed + typedef std::map SheetIdToIndexMapType; + SheetIdToIndexMapType SheetIdToIndexMap; + /// Load/Save the values using the serial system void serial(class NLMISC::IStream &s) throw(NLMISC::EStream) { s.serialCont(Element); } + + void updateMaps(); } TElementList; typedef std::vector TVisualSlot; diff --git a/code/ryzom/tools/leveldesign/mp_generator/main.cpp b/code/ryzom/tools/leveldesign/mp_generator/main.cpp index 45ae45b05..935ba31d6 100644 --- a/code/ryzom/tools/leveldesign/mp_generator/main.cpp +++ b/code/ryzom/tools/leveldesign/mp_generator/main.cpp @@ -1472,6 +1472,7 @@ void SetupDirectories() data.readFromFile( "raw_material_generation.cfg" ); + // beurk :s Use CConfigFile instead LEVEL_DESIGN_PATH = data.splitFrom( "LevelDesignPath = \"").splitTo( "\"" ); TRANSLATION_PATH = data.splitFrom( "TranslationPath = \"" ).splitTo( "\"" );