Avoid redundant calls to getDbProp in CEntityCL

This commit is contained in:
kaetemi 2013-07-28 06:45:43 +02:00
parent 3fe1a17503
commit 37277019be
3 changed files with 51 additions and 13 deletions

View file

@ -435,28 +435,47 @@ void CEntityManager::initialize(uint nbMaxEntity)
for (i=0; i<MAX_NUM_MISSIONS; i++) for (i=0; i<MAX_NUM_MISSIONS; i++)
for (j=0; j<MAX_NUM_MISSION_TARGETS; j++) for (j=0; j<MAX_NUM_MISSION_TARGETS; j++)
{ {
textId = ICDBNode::CTextId( "SERVER:MISSIONS:"+toString(i)+":TARGET"+toString(j)+":TITLE" ); std::string text = toString("SERVER:MISSIONS:%d:TARGET%d:TITLE", i, j);
textId = ICDBNode::CTextId(text);
NLGUI::CDBManager::getInstance()->getDB()->addObserver(&MissionTargetObserver, textId ); NLGUI::CDBManager::getInstance()->getDB()->addObserver(&MissionTargetObserver, textId );
_MissionTargetTitleDB[i][j] = NLGUI::CDBManager::getInstance()->getDbProp(text, false);
nlassert(_MissionTargetTitleDB[i][j]);
} }
// Add an Observer to the Team database // Add an Observer to the Team database
for (i=0; i<MaxNumPeopleInTeam; i++) for (i=0; i<MaxNumPeopleInTeam; i++)
{ {
textId = ICDBNode::CTextId( toString(TEAM_DB_PATH ":%d:UID", i) ); std::string text = toString(TEAM_DB_PATH ":%d:UID", i);
textId = ICDBNode::CTextId(text);
NLGUI::CDBManager::getInstance()->getDB()->addObserver(&TeamUIDObserver, textId ); NLGUI::CDBManager::getInstance()->getDB()->addObserver(&TeamUIDObserver, textId );
_GroupMemberUidDB[i] = NLGUI::CDBManager::getInstance()->getDbProp(text, false);
nlassert(_GroupMemberUidDB[i]);
textId = ICDBNode::CTextId( toString(TEAM_DB_PATH ":%d:NAME", i) ); text = toString(TEAM_DB_PATH ":%d:NAME", i);
textId = ICDBNode::CTextId(text);
NLGUI::CDBManager::getInstance()->getDB()->addObserver(&TeamPresentObserver, textId ); NLGUI::CDBManager::getInstance()->getDB()->addObserver(&TeamPresentObserver, textId );
_GroupMemberNameDB[i] = NLGUI::CDBManager::getInstance()->getDbProp(text, false);
nlassert(_GroupMemberNameDB[i]);
} }
// Add an Observer to the Animal database // Add an Observer to the Animal database
for (i=0; i<MAX_INVENTORY_ANIMAL; i++) for (i=0; i<MAX_INVENTORY_ANIMAL; i++)
{ {
textId = ICDBNode::CTextId( toString("SERVER:PACK_ANIMAL:BEAST%d:UID",i) ); std::string text = toString("SERVER:PACK_ANIMAL:BEAST%d:UID", i);
NLGUI::CDBManager::getInstance()->getDB()->addObserver(&AnimalUIDObserver, textId ); textId = ICDBNode::CTextId(text);
NLGUI::CDBManager::getInstance()->getDB()->addObserver(&AnimalUIDObserver, textId);
_BeastUidDB[i] = NLGUI::CDBManager::getInstance()->getDbProp(text, false);
nlassert(_BeastUidDB[i]);
textId = ICDBNode::CTextId( toString("SERVER:PACK_ANIMAL:BEAST%d:STATUS",i) ); text = toString("SERVER:PACK_ANIMAL:BEAST%d:STATUS", i);
NLGUI::CDBManager::getInstance()->getDB()->addObserver(&AnimalStatusObserver, textId ); textId = ICDBNode::CTextId(text);
NLGUI::CDBManager::getInstance()->getDB()->addObserver(&AnimalStatusObserver, textId);
_BeastStatusDB[i] = NLGUI::CDBManager::getInstance()->getDbProp(text, false);
nlassert(_BeastStatusDB[i]);
text = toString("SERVER:PACK_ANIMAL:BEAST%d:TYPE", i);
_BeastTypeDB[i] = NLGUI::CDBManager::getInstance()->getDbProp(text, false);
nlassert(_BeastTypeDB[i]);
} }
}// initialize // }// initialize //

View file

@ -29,6 +29,10 @@
#include "ground_fx_manager.h" #include "ground_fx_manager.h"
#include "projectile_manager.h" #include "projectile_manager.h"
#include "user_entity.h" #include "user_entity.h"
// Some constants
#include "game_share/mission_desc.h"
#include "interface_v3/people_interraction.h"
#include "game_share/inventories.h"
// Misc. // Misc.
#include "nel/misc/types_nl.h" #include "nel/misc/types_nl.h"
#include "nel/misc/stream.h" #include "nel/misc/stream.h"
@ -149,6 +153,14 @@ private:
NL3D::UInstance _LastInstanceUnderPos; NL3D::UInstance _LastInstanceUnderPos;
// DB node pointers used to update some entity flags
NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> _MissionTargetTitleDB[MAX_NUM_MISSIONS][MAX_NUM_MISSION_TARGETS];
NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> _GroupMemberUidDB[MaxNumPeopleInTeam];
NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> _GroupMemberNameDB[MaxNumPeopleInTeam];
NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> _BeastUidDB[MAX_INVENTORY_ANIMAL];
NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> _BeastStatusDB[MAX_INVENTORY_ANIMAL];
NLMISC::CRefPtr<NLMISC::CCDBNodeLeaf> _BeastTypeDB[MAX_INVENTORY_ANIMAL];
////////////// //////////////
//// DEBUG /// //// DEBUG ///
uint _NbUser; uint _NbUser;
@ -344,6 +356,13 @@ public:
*/ */
void refreshInsceneInterfaceOfFriendNPC(uint slot); void refreshInsceneInterfaceOfFriendNPC(uint slot);
inline NLMISC::CCDBNodeLeaf *getMissionTargetTitleDB(int mission, int target) { return _MissionTargetTitleDB[mission][target]; }
inline NLMISC::CCDBNodeLeaf *getGroupMemberUidDB(int member) { return _GroupMemberUidDB[member]; }
inline NLMISC::CCDBNodeLeaf *getGroupMemberNameDB(int member) { return _GroupMemberNameDB[member]; }
inline NLMISC::CCDBNodeLeaf *getBeastUidDB(int beast) { return _BeastUidDB[beast]; }
inline NLMISC::CCDBNodeLeaf *getBeastStatusDB(int beast) { return _BeastStatusDB[beast]; }
inline NLMISC::CCDBNodeLeaf *getBeastTypeDB(int beast) { return _BeastTypeDB[beast]; }
private: private:
// NB: don't return unselectable entities // NB: don't return unselectable entities

View file

@ -2646,7 +2646,7 @@ void CEntityCL::updateMissionTarget()
for (j=0; j<MAX_NUM_MISSION_TARGETS; j++) for (j=0; j<MAX_NUM_MISSION_TARGETS; j++)
{ {
// Get the db prop // Get the db prop
CCDBNodeLeaf *prop = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:MISSIONS:"+toString(i)+":TARGET"+toString(j)+":TITLE", false); CCDBNodeLeaf *prop = EntitiesMngr.getMissionTargetTitleDB(i, j); // NLGUI::CDBManager::getInstance()->getDbProp("SERVER:MISSIONS:"+toString(i)+":TARGET"+toString(j)+":TITLE", false);
if (prop) if (prop)
{ {
_MissionTarget = _NameId == (uint32)prop->getValue32(); _MissionTarget = _NameId == (uint32)prop->getValue32();
@ -2846,8 +2846,8 @@ void CEntityCL::updateIsInTeam ()
for (uint i=0; i<MaxNumPeopleInTeam; i++) for (uint i=0; i<MaxNumPeopleInTeam; i++)
{ {
// Get the db prop // Get the db prop
CCDBNodeLeaf *uidProp = NLGUI::CDBManager::getInstance()->getDbProp(toString(TEAM_DB_PATH ":%d:UID", i), false); CCDBNodeLeaf *uidProp = EntitiesMngr.getGroupMemberUidDB(i);
CCDBNodeLeaf *presentProp = NLGUI::CDBManager::getInstance()->getDbProp(toString(TEAM_DB_PATH ":%d:NAME", i), false); CCDBNodeLeaf *presentProp = EntitiesMngr.getGroupMemberNameDB(i);
// If same Entity uid than the one in the Database, ok the entity is in the Player TEAM!! // If same Entity uid than the one in the Database, ok the entity is in the Player TEAM!!
if (uidProp && uidProp->getValue32() == (sint32)dataSetId() && if (uidProp && uidProp->getValue32() == (sint32)dataSetId() &&
presentProp && presentProp->getValueBool() ) presentProp && presentProp->getValueBool() )
@ -2876,9 +2876,9 @@ void CEntityCL::updateIsUserAnimal ()
for (uint i=0; i<MAX_INVENTORY_ANIMAL; i++) for (uint i=0; i<MAX_INVENTORY_ANIMAL; i++)
{ {
// Get the db prop // Get the db prop
CCDBNodeLeaf *uidProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:UID", i), false); CCDBNodeLeaf *uidProp = EntitiesMngr.getBeastUidDB(i);
CCDBNodeLeaf *statusProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:STATUS", i), false); CCDBNodeLeaf *statusProp = EntitiesMngr.getBeastStatusDB(i);
CCDBNodeLeaf *typeProp = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:TYPE", i), false); CCDBNodeLeaf *typeProp = EntitiesMngr.getBeastTypeDB(i);
// I must have the same Id, and the animal entry must be ok. // I must have the same Id, and the animal entry must be ok.
if(uidProp && statusProp && typeProp && uidProp->getValue32() == (sint32)dataSetId() && if(uidProp && statusProp && typeProp && uidProp->getValue32() == (sint32)dataSetId() &&
ANIMAL_STATUS::isSpawned((ANIMAL_STATUS::EAnimalStatus)(statusProp->getValue32()) )) ANIMAL_STATUS::isSpawned((ANIMAL_STATUS::EAnimalStatus)(statusProp->getValue32()) ))