From fb17aa63e15ad50332588908751933b6f140644e Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 29 Sep 2012 14:35:43 +0200 Subject: [PATCH] Fixed: #1497 optimize the drawing of radar by removing multiple access to local db (patch provided by yricl, a big thanks!) --- .../client/src/interface_v3/view_radar.cpp | 41 +++++++++++++++---- .../client/src/interface_v3/view_radar.h | 21 ++++++++-- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/view_radar.cpp b/code/ryzom/client/src/interface_v3/view_radar.cpp index 6c5f4eaf4..5f3cb77d1 100644 --- a/code/ryzom/client/src/interface_v3/view_radar.cpp +++ b/code/ryzom/client/src/interface_v3/view_radar.cpp @@ -39,6 +39,25 @@ NLMISC_REGISTER_OBJECT(CViewBase, CViewRadar, std::string, "radar"); // ---------------------------------------------------------------------------- +CViewRadar::CViewRadar(const TCtorParam ¶m) + : CViewBase(param) +{ + CInterfaceManager *pIM = CInterfaceManager::getInstance(); + CCDBNodeLeaf *pUIMI = pIM->getDbProp( "UI:SAVE:INSCENE:FRIEND:MISSION_ICON" ); + if (pUIMI) + { + ICDBNode::CTextId textId; + pUIMI->addObserver( &_MissionIconsObs, textId); + } + + CCDBNodeLeaf *pUIMMI = pIM->getDbProp( "UI:SAVE:INSCENE:FRIEND:MINI_MISSION_ICON" ); + if (pUIMMI) + { + ICDBNode::CTextId textId; + pUIMMI->addObserver( &_MiniMissionSpotsObs, textId); + } +} + bool CViewRadar::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) { CXMLAutoPtr prop; @@ -109,8 +128,9 @@ void CViewRadar::draw () CEntityCL *user = EntitiesMngr.entity(0); if (user == NULL) return; + CVectorD xyzRef = user->pos(); - CVector dir = user->front(); + const CVector dir = user->front(); float angle = (float)(atan2(dir.y, dir.x) - (Pi / 2.0)); CMatrix mat; @@ -124,9 +144,6 @@ void CViewRadar::draw () float maxSqrRadius= (float)sqr(_WorldSize/2); - const bool displayMissionSpots = pIM->getDbProp("UI:SAVE:INSCENE:FRIEND:MISSION_ICON")->getValueBool(); - const bool displayMiniMissionSpots = pIM->getDbProp("UI:SAVE:INSCENE:FRIEND:MINI_MISSION_ICON")->getValueBool(); - for (sint32 i = 1; i < 256; ++i) { CEntityCL *entity = EntitiesMngr.entity(i); @@ -160,8 +177,8 @@ void CViewRadar::draw () // Select the icon to display and draw it uint spotId = CNPCIconCache::getInstance().getNPCIcon(entity).getSpotId(); CRadarSpotDesc spotDesc = _SpotDescriptions[spotId]; - - if (!displayMissionSpots) + + if (!_MissionIconsObs._displayMissionSpots) spotDesc = _SpotDescriptions[0]; if (spotDesc.isMissionSpot) @@ -171,7 +188,7 @@ void CViewRadar::draw () spotId = 4; // to make it over other spots // Draw it (and make sure mission icons are drawn over regular dot; caution: don't exceed the render layer range) - if (spotDesc.isMissionSpot && displayMiniMissionSpots) + if (spotDesc.isMissionSpot && _MiniMissionSpotsObs._displayMiniMissionSpots) rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.MTxW/2)+(_WReal/2), _YReal+y-(spotDesc.MTxH/2)+(_HReal/2), spotDesc.MTxW, spotDesc.MTxH, 0, false, spotDesc.MiniTextureId, col ); else @@ -185,3 +202,13 @@ void CViewRadar::updateCoords() { CViewBase::updateCoords(); } + +void CViewRadar::CDBMissionIconqObs::update(ICDBNode *node) +{ + _displayMissionSpots = ((CCDBNodeLeaf*)node)->getValueBool(); +} + +void CViewRadar::CDBMiniMissionSpotsObs::update(ICDBNode *node) +{ + _displayMiniMissionSpots = ((CCDBNodeLeaf*)node)->getValueBool(); +} diff --git a/code/ryzom/client/src/interface_v3/view_radar.h b/code/ryzom/client/src/interface_v3/view_radar.h index b2eb31685..0f9fc1a5f 100644 --- a/code/ryzom/client/src/interface_v3/view_radar.h +++ b/code/ryzom/client/src/interface_v3/view_radar.h @@ -45,9 +45,7 @@ public: }; /// Constructor - CViewRadar(const TCtorParam ¶m) : CViewBase(param) - { - } + CViewRadar(const TCtorParam ¶m); bool parse(xmlNodePtr cur,CInterfaceGroup * parentGroup); @@ -79,7 +77,24 @@ protected: sint32 MTxH; }; +private: CRadarSpotDesc _SpotDescriptions[NbRadarSpotIds]; + + class CDBMissionIconqObs : public ICDBNode::IPropertyObserver + { + public: + virtual void update(ICDBNode *node); + bool _displayMissionSpots; + }; + CDBMissionIconqObs _MissionIconsObs; + + class CDBMiniMissionSpotsObs : public ICDBNode::IPropertyObserver + { + public: + virtual void update(ICDBNode *node); + bool _displayMiniMissionSpots; + }; + CDBMiniMissionSpotsObs _MiniMissionSpotsObs; }; #endif // RY_VIEW_RADAR_H