diff --git a/src/common/database.hpp b/src/common/database.hpp index fea450f98a..633f85bb90 100644 --- a/src/common/database.hpp +++ b/src/common/database.hpp @@ -166,6 +166,10 @@ public: } } + std::vector> getCache() { + return this->cache; + } + virtual size_t calculateCacheKey( keytype key ){ return key; } diff --git a/src/map/achievement.cpp b/src/map/achievement.cpp index 318fd8bfb6..40b584bfb1 100644 --- a/src/map/achievement.cpp +++ b/src/map/achievement.cpp @@ -365,6 +365,8 @@ void AchievementDatabase::loadingFinished(){ ach->dependent_ids.shrink_to_fit(); } + + TypesafeYamlDatabase::loadingFinished(); } AchievementDatabase achievement_db; diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 34749868e7..5270ed9671 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -3912,7 +3912,7 @@ ACMD_FUNC(mapexit) ACMD_FUNC(idsearch) { char item_name[100]; - unsigned int i, match; + uint16 i, match; struct item_data *item_array[MAX_SEARCH]; nullpo_retr(-1, sd); @@ -7613,8 +7613,7 @@ ACMD_FUNC(mobinfo) unsigned char melement[ELE_ALL][8] = { "Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead" }; char atcmd_output2[CHAT_SIZE_MAX]; struct item_data *item_data; - uint16 mob_ids[MAX_SEARCH]; - int count; + uint16 mob_ids[MAX_SEARCH], count; int i, k; memset(atcmd_output, '\0', sizeof(atcmd_output)); @@ -8151,7 +8150,7 @@ ACMD_FUNC(homshuffle) ACMD_FUNC(iteminfo) { struct item_data *item_array[MAX_SEARCH]; - int i, count = 1; + uint16 i, count = 1; if (!message || !*message) { clif_displaymessage(fd, msg_txt(sd,1276)); // Please enter an item name/ID (usage: @ii/@iteminfo ). @@ -8202,7 +8201,7 @@ ACMD_FUNC(iteminfo) ACMD_FUNC(whodrops) { struct item_data *item_data, *item_array[MAX_SEARCH]; - int i,j, count = 1; + uint16 i, j, count = 1; if (!message || !*message) { clif_displaymessage(fd, msg_txt(sd,1284)); // Please enter item name/ID (usage: @whodrops ). @@ -8257,8 +8256,7 @@ ACMD_FUNC(whodrops) ACMD_FUNC(whereis) { - uint16 mob_ids[MAX_SEARCH] = {0}; - int count = 0; + uint16 mob_ids[MAX_SEARCH] = {0}, count; if (!message || !*message) { clif_displaymessage(fd, msg_txt(sd,1288)); // Please enter a monster name/ID (usage: @whereis ). diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index 07941665ba..990fbeb033 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -1168,6 +1168,8 @@ void ItemDatabase::loadingFinished(){ item_db.put( ITEMID_DUMMY, dummy_item ); } + + TypesafeCachedYamlDatabase::loadingFinished(); } /** @@ -1668,14 +1670,17 @@ LaphineUpgradeDatabase laphine_upgrade_db; * @param str * @return Number of matches item *------------------------------------------*/ -int itemdb_searchname_array(struct item_data** data, int size, const char *str) +uint16 itemdb_searchname_array(struct item_data** data, uint16 size, const char *str) { - int count = 0; + uint16 count = 0; + const auto &item_list = item_db.getCache(); - for (const auto &it : item_db) { + for (const auto &item : item_list) { + if (item == nullptr) + continue; if (count < size) { - if (stristr(it.second->name.c_str(), str) != nullptr || stristr(it.second->ename.c_str(), str) != nullptr || strcmpi(it.second->ename.c_str(), str) == 0) - data[count++] = it.second.get(); + if (stristr(item->name.c_str(), str) != nullptr || stristr(item->ename.c_str(), str) != nullptr || strcmpi(item->ename.c_str(), str) == 0) + data[count++] = item.get(); } else break; } @@ -2351,6 +2356,8 @@ void ItemGroupDatabase::loadingFinished() { } } } + + TypesafeYamlDatabase::loadingFinished(); } /** Read item forbidden by mapflag (can't equip item) @@ -2527,6 +2534,8 @@ void ComboDatabase::loadingFinished() { it->combos.push_back(combo.second); } } + + TypesafeYamlDatabase::loadingFinished(); } /** @@ -3115,6 +3124,8 @@ void RandomOptionDatabase::loadingFinished(){ script_set_constant( name.c_str(), pair.first, false, false ); } + + TypesafeYamlDatabase::loadingFinished(); } RandomOptionDatabase random_option_db; diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp index 4cdc74bf68..c669b1cfda 100644 --- a/src/map/itemdb.hpp +++ b/src/map/itemdb.hpp @@ -22,7 +22,9 @@ const t_itemid UNKNOWN_ITEM_ID = 512; /// The maximum number of item delays #define MAX_ITEMDELAYS 10 ///Designed for search functions, species max number of matches to display. -#define MAX_SEARCH 5 +#ifndef MAX_SEARCH +#define MAX_SEARCH 10 +#endif #define MAX_ROULETTE_LEVEL 7 /** client-defined value **/ #define MAX_ROULETTE_COLUMNS 9 /** client-defined value **/ @@ -1360,7 +1362,7 @@ public: extern LaphineUpgradeDatabase laphine_upgrade_db; -int itemdb_searchname_array(struct item_data** data, int size, const char *str); +uint16 itemdb_searchname_array(struct item_data** data, uint16 size, const char *str); struct item_data* itemdb_search(t_itemid nameid); struct item_data* itemdb_exists(t_itemid nameid); #define itemdb_name(n) itemdb_search(n)->name.c_str() diff --git a/src/map/mob.cpp b/src/map/mob.cpp index 16edfb7a6b..f8d26bcacf 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -315,14 +315,17 @@ std::shared_ptr mobdb_search_aegisname( const char* str ){ /*========================================== * Founds up to N matches. Returns number of matches [Skotlex] *------------------------------------------*/ -int mobdb_searchname_array_(const char *str, uint16 * out, int size, bool full_cmp) +uint16 mobdb_searchname_array_(const char *str, uint16 * out, uint16 size, bool full_cmp) { - unsigned short count = 0; - for( auto const &mobdb_pair : mob_db ) { - const uint16 mob_id = mobdb_pair.first; - if( mobdb_searchname_sub(mob_id, str, full_cmp) ) { + uint16 count = 0; + const auto &mob_list = mob_db.getCache(); + + for( const auto &mob : mob_list ) { + if (mob == nullptr) + continue; + if( mobdb_searchname_sub(mob->id, str, full_cmp) ) { if( count < size ) - out[count] = mob_id; + out[count] = mob->id; count++; } } @@ -330,7 +333,7 @@ int mobdb_searchname_array_(const char *str, uint16 * out, int size, bool full_c return count; } -int mobdb_searchname_array(const char *str, uint16 * out, int size) +uint16 mobdb_searchname_array(const char *str, uint16 * out, uint16 size) { return mobdb_searchname_array_(str, out, size, false); } @@ -4974,6 +4977,8 @@ void MobDatabase::loadingFinished() { mob->status.hp = mob->status.max_hp; mob->status.sp = mob->status.max_sp; } + + TypesafeCachedYamlDatabase::loadingFinished(); } MobDatabase mob_db; diff --git a/src/map/mob.hpp b/src/map/mob.hpp index c555be295a..a0572744a6 100644 --- a/src/map/mob.hpp +++ b/src/map/mob.hpp @@ -447,7 +447,7 @@ struct item_drop_list { uint16 mobdb_searchname(const char * const str); std::shared_ptr mobdb_search_aegisname( const char* str ); -int mobdb_searchname_array(const char *str, uint16 * out, int size); +uint16 mobdb_searchname_array(const char *str, uint16 * out, uint16 size); int mobdb_checkid(const int id); struct view_data* mob_get_viewdata(int mob_id); void mob_set_dynamic_viewdata( struct mob_data* md ); diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 80a784906f..f808f94d4d 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -833,6 +833,8 @@ void BarterDatabase::loadingFinished(){ } } } + + TypesafeYamlDatabase::loadingFinished(); } BarterDatabase barter_db; diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 468f3d58b5..d80886ff2f 100755 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -357,6 +357,8 @@ void PenaltyDatabase::loadingFinished(){ } } } + + TypesafeYamlDatabase::loadingFinished(); } PenaltyDatabase penalty_db; @@ -12990,6 +12992,8 @@ void SkillTreeDatabase::loadingFinished() { } } } + + TypesafeYamlDatabase::loadingFinished(); } /** @@ -13546,6 +13550,8 @@ void JobDatabase::loadingFinished() { } } } + + TypesafeCachedYamlDatabase::loadingFinished(); } /** @@ -13708,6 +13714,8 @@ void PlayerStatPointDatabase::loadingFinished(){ // Store it for next iteration last_level = entry; } + + TypesafeCachedYamlDatabase::loadingFinished(); } /*========================================== diff --git a/src/map/pc_groups.cpp b/src/map/pc_groups.cpp index 4fe3e44329..f78088b16f 100644 --- a/src/map/pc_groups.cpp +++ b/src/map/pc_groups.cpp @@ -304,6 +304,8 @@ void PlayerGroupDatabase::loadingFinished(){ // Initialize command cache atcommand_db_load_groups(); + + TypesafeYamlDatabase::loadingFinished(); } PlayerGroupDatabase player_group_db; diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 95691ba2fe..6ab1209f95 100755 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -24022,6 +24022,8 @@ void SkillDatabase::loadingFinished(){ if( this->skill_num > MAX_SKILL ){ ShowError( "There are more skills defined in the skill database (%d) than the MAX_SKILL (%d) define. Please increase it and recompile.\n", this->skill_num, MAX_SKILL ); } + + TypesafeYamlDatabase::loadingFinished(); } /** diff --git a/src/map/status.cpp b/src/map/status.cpp index ae6b1208cb..003c0e5578 100644 --- a/src/map/status.cpp +++ b/src/map/status.cpp @@ -933,6 +933,8 @@ void EnchantgradeDatabase::loadingFinished(){ } } } + + TypesafeYamlDatabase::loadingFinished(); } EnchantgradeDatabase enchantgrade_db; @@ -15542,6 +15544,8 @@ void StatusDatabase::loadingFinished(){ this->StatusRelevantBLTypes[status->icon] = BL_PC; } } + + TypesafeYamlDatabase::loadingFinished(); } StatusDatabase status_db;