From bef5ba382cd061717a7a453172edee505afd5a33 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sun, 28 Jul 2013 07:55:16 +0200 Subject: [PATCH] Avoid redundant calls to getDbProp("UI:SAVE:INSCENE:...") --- .../interface_v3/group_in_scene_user_info.cpp | 103 ++++++++++++++---- .../interface_v3/group_in_scene_user_info.h | 2 +- 2 files changed, 82 insertions(+), 23 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/group_in_scene_user_info.cpp b/code/ryzom/client/src/interface_v3/group_in_scene_user_info.cpp index 679a9a16d..449265f8a 100644 --- a/code/ryzom/client/src/interface_v3/group_in_scene_user_info.cpp +++ b/code/ryzom/client/src/interface_v3/group_in_scene_user_info.cpp @@ -47,11 +47,71 @@ NLMISC::CRefPtr CGroupInSceneUserInfo::_GuildIconLeaf[256] NLMISC_REGISTER_OBJECT(CViewBase, CGroupInSceneUserInfo, std::string, "in_scene_user_info"); REGISTER_UI_CLASS(CGroupInSceneUserInfo) +namespace { + +// Has more entries than actually in config, as not all types have all entries. +class CConfigSaveInsceneDB +{ +public: + void setPrefix(const std::string &prefix) { _DBPrefix = prefix; } + inline NLMISC::CCDBNodeLeaf *getGuildSymbol() { return _GuildSymbol ? (&*_GuildSymbol) : (_GuildSymbol = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "GUILD_SYMBOL")); } + inline NLMISC::CCDBNodeLeaf *getName() { return _Name ? (&*_Name) : (_Name = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "NAME")); } + inline NLMISC::CCDBNodeLeaf *getTitle() { return _Title ? (&*_Title) : (_Title = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "TITLE")); } + inline NLMISC::CCDBNodeLeaf *getRPTags() { return _RPTags ? (&*_RPTags) : (_RPTags = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "RPTAGS")); } + inline NLMISC::CCDBNodeLeaf *getGuildName() { return _GuildName ? (&*_GuildName) : (_GuildName = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "GUILD_NAME")); } + inline NLMISC::CCDBNodeLeaf *getHP() { return _HP ? (&*_HP) : (_HP = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "HP")); } + inline NLMISC::CCDBNodeLeaf *getSta() { return _Sta ? (&*_Sta) : (_Sta = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "STA")); } + inline NLMISC::CCDBNodeLeaf *getSap() { return _Sap ? (&*_Sap) : (_Sap = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "SAP")); } + inline NLMISC::CCDBNodeLeaf *getFocus() { return _Focus ? (&*_Focus) : (_Focus = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "FOCUS")); } + inline NLMISC::CCDBNodeLeaf *getAction() { return _Action ? (&*_Action) : (_Action = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "ACTION")); } + inline NLMISC::CCDBNodeLeaf *getMessages() { return _Messages ? (&*_Messages) : (_Messages = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "MESSAGES")); } + inline NLMISC::CCDBNodeLeaf *getPvPLogo() { return _PvPLogo ? (&*_PvPLogo) : (_PvPLogo = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "PVP_LOGO")); } + inline NLMISC::CCDBNodeLeaf *getNPCName() { return _NPCName ? (&*_NPCName) : (_NPCName = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "NPCNAME")); } + inline NLMISC::CCDBNodeLeaf *getNPCTitle() { return _NPCTitle ? (&*_NPCTitle) : (_NPCTitle = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "NPCTITLE")); } + inline NLMISC::CCDBNodeLeaf *getMissionIcon() { return _MissionIcon ? (&*_MissionIcon) : (_MissionIcon = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "MISSION_ICON")); } + inline NLMISC::CCDBNodeLeaf *getMiniMissionIcon() { return _MiniMissionIcon ? (&*_MiniMissionIcon) : (_MiniMissionIcon = NLGUI::CDBManager::getInstance()->getDbProp(_DBPrefix + "MINI_MISSION_ICON")); } +private: + std::string _DBPrefix; + NLMISC::CRefPtr _GuildSymbol; + NLMISC::CRefPtr _Name; + NLMISC::CRefPtr _Title; + NLMISC::CRefPtr _RPTags; + NLMISC::CRefPtr _GuildName; + NLMISC::CRefPtr _HP; + NLMISC::CRefPtr _Sta; + NLMISC::CRefPtr _Sap; + NLMISC::CRefPtr _Focus; + NLMISC::CRefPtr _Action; + NLMISC::CRefPtr _Messages; + NLMISC::CRefPtr _PvPLogo; + NLMISC::CRefPtr _NPCName; + NLMISC::CRefPtr _NPCTitle; + NLMISC::CRefPtr _MissionIcon; + NLMISC::CRefPtr _MiniMissionIcon; +}; + +CConfigSaveInsceneDB _ConfigSaveInsceneDB[4]; // USER/FRIEND/ENEMY/SOURCE +bool _ConfigSaveInsceneDBInit = false; + +#define SAVE_USER 0 +#define SAVE_FRIEND 1 +#define SAVE_ENEMY 2 +#define SAVE_SOURCE 3 + +} CGroupInSceneUserInfo::CGroupInSceneUserInfo(const TCtorParam ¶m) : CGroupInScene(param) { + if (!_ConfigSaveInsceneDBInit) + { + _ConfigSaveInsceneDB[0].setPrefix("UI:SAVE:INSCENE:USER:"); + _ConfigSaveInsceneDB[1].setPrefix("UI:SAVE:INSCENE:FRIEND:"); + _ConfigSaveInsceneDB[2].setPrefix("UI:SAVE:INSCENE:ENEMY:"); + _ConfigSaveInsceneDB[3].setPrefix("UI:SAVE:INSCENE:SOURCE:"); + _ConfigSaveInsceneDBInit = true; + } _Name = NULL; _Title = NULL; _GuildName = NULL; @@ -131,7 +191,7 @@ CGroupInSceneUserInfo *CGroupInSceneUserInfo::build (CEntityCL *entity) bool needPvPLogo= false; bool permanentContent = false; bool rpTags = false; - bool displayMissionIcons = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:INSCENE:FRIEND:MISSION_ICON")->getValueBool(); + bool displayMissionIcons = _ConfigSaveInsceneDB[SAVE_FRIEND].getMissionIcon()->getValueBool(); // Names const char *templateName; @@ -157,7 +217,6 @@ CGroupInSceneUserInfo *CGroupInSceneUserInfo::build (CEntityCL *entity) // Active fields and bars if ( isForageSource ) { - string dbEntry = "UI:SAVE:INSCENE:SOURCE:"; CForageSourceCL *forageSource = static_cast(entity); name = !entityName.empty() /*&& NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"NAME")->getValueBool()*/; @@ -176,32 +235,32 @@ CGroupInSceneUserInfo *CGroupInSceneUserInfo::build (CEntityCL *entity) } else if(npcFriendAndNeutral) { - string dbEntry; + int dbEntry; getBarSettings( pIM, user, entity->isPlayer(), _friend, dbEntry, bars ); // For RoleMasters, merchants etc... must display name and function, and nothing else for(uint i=0;igetDbProp(dbEntry+"NPCNAME")->getValueBool(); + name= !entityName.empty() && _ConfigSaveInsceneDB[dbEntry].getNPCName()->getValueBool(); symbol= false; - title= !entityTitle.empty() && CDBManager::getInstance()->getDbProp(dbEntry+"NPCTITLE")->getValueBool(); + title= !entityTitle.empty() && _ConfigSaveInsceneDB[dbEntry].getNPCTitle()->getValueBool(); guildName= false; templateName = "in_scene_user_info"; - rpTags = (!entityTag1.empty() || !entityTag2.empty() || !entityTag3.empty() || !entityTag4.empty() ) && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"RPTAGS")->getValueBool(); + rpTags = (!entityTag1.empty() || !entityTag2.empty() || !entityTag3.empty() || !entityTag4.empty() ) && _ConfigSaveInsceneDB[dbEntry].getRPTags()->getValueBool(); } else { // Base entry in database - string dbEntry; + int dbEntry; getBarSettings( pIM, user, entity->isPlayer(), _friend, dbEntry, bars ); - name = !entityName.empty() && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"NAME")->getValueBool(); - title = !entityTitle.empty() && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"TITLE")->getValueBool(); - rpTags = (!entityTag1.empty() || !entityTag2.empty() || !entityTag3.empty() || !entityTag4.empty() ) && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"RPTAGS")->getValueBool(); + name = !entityName.empty() && _ConfigSaveInsceneDB[dbEntry].getName()->getValueBool(); + title = !entityTitle.empty() && _ConfigSaveInsceneDB[dbEntry].getTitle()->getValueBool(); + rpTags = (!entityTag1.empty() || !entityTag2.empty() || !entityTag3.empty() || !entityTag4.empty() ) && _ConfigSaveInsceneDB[dbEntry].getRPTags()->getValueBool(); // if name is empty but not title, title is displayed as name - if (!title && entityName.empty() && !entityTitle.empty() && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"NAME")->getValueBool()) + if (!title && entityName.empty() && !entityTitle.empty() && _ConfigSaveInsceneDB[dbEntry].getName()->getValueBool()) title = true; templateName = "in_scene_user_info"; // special guild - if(NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"GUILD_SYMBOL")->getValueBool()) + if(_ConfigSaveInsceneDB[dbEntry].getGuildSymbol()->getValueBool()) { // if symbol not still available, wait for one when VP received symbol = (entity->getGuildSymbol() != 0); @@ -212,7 +271,7 @@ CGroupInSceneUserInfo *CGroupInSceneUserInfo::build (CEntityCL *entity) symbol= false; needGuildSymbolId = false; } - if(NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"GUILD_NAME")->getValueBool()) + if(_ConfigSaveInsceneDB[dbEntry].getGuildName()->getValueBool()) { // if guild name not still available, wait for one when VP received guildName = (entity->getGuildNameID() != 0); @@ -223,7 +282,7 @@ CGroupInSceneUserInfo *CGroupInSceneUserInfo::build (CEntityCL *entity) guildName= false; needGuildNameId= false; } - needPvPLogo = NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"PVP_LOGO")->getValueBool(); + needPvPLogo = _ConfigSaveInsceneDB[dbEntry].getPvPLogo()->getValueBool(); eventFaction = (entity->getEventFactionID() != 0); } @@ -800,9 +859,9 @@ REGISTER_ACTION_HANDLER( CHandlerResetCharacterInScene, "reset_character_in_scen // *************************************************************************** -void CGroupInSceneUserInfo::getBarSettings( CInterfaceManager* pIM, bool isUser, bool isPlayer, bool isFriend, std::string& dbEntry, bool *bars ) +void CGroupInSceneUserInfo::getBarSettings( CInterfaceManager* pIM, bool isUser, bool isPlayer, bool isFriend, int &dbEntry, bool *bars ) { - dbEntry = isUser?"UI:SAVE:INSCENE:USER:":isFriend?"UI:SAVE:INSCENE:FRIEND:":"UI:SAVE:INSCENE:ENEMY:"; + dbEntry = isUser?SAVE_USER:isFriend?SAVE_FRIEND:SAVE_ENEMY; // if currently is edition mode, then bars are not displayed if (ClientCfg.R2EDEnabled && R2::isEditionCurrent()) { @@ -814,11 +873,11 @@ void CGroupInSceneUserInfo::getBarSettings( CInterfaceManager* pIM, bool isUser, } else { - bars[HP] = NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"HP")->getValueBool(); - bars[SAP] = (isUser || isFriend) && (isUser || isPlayer) && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"SAP")->getValueBool(); - bars[STA] = (isUser || isFriend) && (isUser || isPlayer) && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"STA")->getValueBool(); - bars[Focus] = (isUser || isFriend) && (isUser || isPlayer) && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"FOCUS")->getValueBool(); - bars[Action] = (isUser) && NLGUI::CDBManager::getInstance()->getDbProp(dbEntry+"ACTION")->getValueBool(); + bars[HP] = _ConfigSaveInsceneDB[dbEntry].getHP()->getValueBool(); + bars[SAP] = (isUser || isFriend) && (isUser || isPlayer) && _ConfigSaveInsceneDB[dbEntry].getSap()->getValueBool(); + bars[STA] = (isUser || isFriend) && (isUser || isPlayer) && _ConfigSaveInsceneDB[dbEntry].getSta()->getValueBool(); + bars[Focus] = (isUser || isFriend) && (isUser || isPlayer) && _ConfigSaveInsceneDB[dbEntry].getFocus()->getValueBool(); + bars[Action] = (isUser) && _ConfigSaveInsceneDB[dbEntry].getAction()->getValueBool(); } } @@ -832,7 +891,7 @@ void CGroupInSceneUserInfo::setLeftGroupActive( bool active ) if ( _Entity->isUser() || _Entity->isForageSource() ) return; - string dbEntry; + int dbEntry; bool barSettings [NumBars]; getBarSettings( CInterfaceManager::getInstance(), _Entity->isUser(), _Entity->isPlayer(), _Entity->isViewedAsFriend(), dbEntry, barSettings ); diff --git a/code/ryzom/client/src/interface_v3/group_in_scene_user_info.h b/code/ryzom/client/src/interface_v3/group_in_scene_user_info.h index 1f9db3a4c..3869a74b1 100644 --- a/code/ryzom/client/src/interface_v3/group_in_scene_user_info.h +++ b/code/ryzom/client/src/interface_v3/group_in_scene_user_info.h @@ -72,7 +72,7 @@ protected: }; /// Fill NumBars elements into bars and set dbEntry - static void getBarSettings( CInterfaceManager* pIM, bool isUser, bool isPlayer, bool isFriend, std::string& dbEntry, bool *bars ); + static void getBarSettings( CInterfaceManager* pIM, bool isUser, bool isPlayer, bool isFriend, int &dbEntry, bool *bars ); // The entity (character or forage source) CEntityCL *_Entity;