Fixed: #1497 optimize the drawing of radar by removing multiple access to local db (patch provided by yricl, a big thanks!)

This commit is contained in:
kervala 2012-09-29 14:35:43 +02:00
parent 29359a552e
commit 5c82fcd39c
2 changed files with 52 additions and 10 deletions

View file

@ -39,6 +39,25 @@ NLMISC_REGISTER_OBJECT(CViewBase, CViewRadar, std::string, "radar");
// ----------------------------------------------------------------------------
CViewRadar::CViewRadar(const TCtorParam &param)
: 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();
}

View file

@ -45,9 +45,7 @@ public:
};
/// Constructor
CViewRadar(const TCtorParam &param) : CViewBase(param)
{
}
CViewRadar(const TCtorParam &param);
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