From 4313f62647381364714bf651601219771607a901 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 16 Apr 2012 01:31:21 +0200 Subject: [PATCH] CDB no longer depends on CInterfaceLink. --- code/ryzom/client/src/cdb_branch.cpp | 42 ++++++++++++++++--- code/ryzom/client/src/cdb_branch.h | 18 ++++++++ .../src/interface_v3/interface_link.cpp | 13 ++++++ .../client/src/interface_v3/interface_link.h | 16 +++++-- .../src/interface_v3/interface_manager.cpp | 3 ++ .../src/interface_v3/interface_manager.h | 3 +- 6 files changed, 84 insertions(+), 11 deletions(-) diff --git a/code/ryzom/client/src/cdb_branch.cpp b/code/ryzom/client/src/cdb_branch.cpp index 351203493..52c6fe455 100644 --- a/code/ryzom/client/src/cdb_branch.cpp +++ b/code/ryzom/client/src/cdb_branch.cpp @@ -16,8 +16,6 @@ -#include "stdpch.h" - //#define TRACE_READ_DELTA //#define TRACE_WRITE_DELTA //#define TRACE_SET_VALUE @@ -32,7 +30,6 @@ #include "cdb_leaf.h" #include "game_share/xml_auto_ptr.h" //#include -#include "interface_v3/interface_manager.h" //////////////// // Namespaces // @@ -84,6 +81,8 @@ uint CCDBNodeBranch::_FirstLevelIdBitsByBank [NB_CDB_BANKS]; extern const char *CDBBankNames[INVALID_CDB_BANK+1]; +std::vector< CCDBNodeBranch::IBranchObserverCallFlushObserver* > CCDBNodeBranch::flushObservers; + // reset all static data void CCDBNodeBranch::reset() { @@ -703,15 +702,46 @@ void CCDBNodeBranch::flushObserversCalls() } nlassert(_FirstNotifiedObs[1 - _CurrNotifiedObsList] == NULL); nlassert(_LastNotifiedObs[1 - _CurrNotifiedObsList] == NULL); - // update triggered link - CInterfaceLink::updateTrigeredLinks(); + triggerFlushObservers(); // examine other list to see if nodes have been registered _CurrNotifiedObs = _FirstNotifiedObs[_CurrNotifiedObsList]; } - CInterfaceLink::updateTrigeredLinks(); // should call it at least once + triggerFlushObservers(); // nlassert(_CrtCheckMemory()); } +void CCDBNodeBranch::triggerFlushObservers() +{ + for( std::vector< IBranchObserverCallFlushObserver* >::iterator itr = flushObservers.begin(); itr != flushObservers.end(); itr++ ) + { + (*itr)->onObserverCallFlush(); + } +} + +void CCDBNodeBranch::addFlushObserver( CCDBNodeBranch::IBranchObserverCallFlushObserver *observer ) +{ + std::vector< IBranchObserverCallFlushObserver* >::iterator itr + = std::find( flushObservers.begin(), flushObservers.end(), observer ); + + // Already exists + if( itr != flushObservers.end() ) + return; + + flushObservers.push_back( observer ); +} + +void CCDBNodeBranch::removeFlushObserver( CCDBNodeBranch::IBranchObserverCallFlushObserver *observer ) +{ + std::vector< IBranchObserverCallFlushObserver* >::iterator itr + = std::find( flushObservers.begin(), flushObservers.end(), observer ); + + // Isn't in our list + if( itr == flushObservers.end() ) + return; + + flushObservers.erase( itr ); +} + //----------------------------------------------- void CCDBNodeBranch::CDBBranchObsInfo::link(uint list, NLMISC::TStringId modifiedLeafName) { diff --git a/code/ryzom/client/src/cdb_branch.h b/code/ryzom/client/src/cdb_branch.h index 74e085ca4..3c4cb736c 100644 --- a/code/ryzom/client/src/cdb_branch.h +++ b/code/ryzom/client/src/cdb_branch.h @@ -31,6 +31,12 @@ class CCDBNodeBranch : public ICDBNode { public: + /// Triggered when the branch observers are updated + class IBranchObserverCallFlushObserver : public NLMISC::CRefCount{ + public: + virtual ~IBranchObserverCallFlushObserver(){} + virtual void onObserverCallFlush() = 0; + }; // default constructor CCDBNodeBranch(const std::string &name) : ICDBNode(name) @@ -212,6 +218,13 @@ public: */ static void flushObserversCalls(); +private: + static void triggerFlushObservers(); + +public: + static void addFlushObserver( IBranchObserverCallFlushObserver *observer ); + static void removeFlushObserver( IBranchObserverCallFlushObserver *observer ); + // mark this branch and parent branch as 'modified'. This is usually called by sub-leaves void linkInModifiedNodeList(NLMISC::TStringId modifiedLeafName); @@ -324,6 +337,11 @@ protected: /// called by clear void removeAllBranchObserver(); void removeBranchInfoIt(TObsList::iterator it); + + +private: + static std::vector< IBranchObserverCallFlushObserver* > flushObservers; + }; diff --git a/code/ryzom/client/src/interface_v3/interface_link.cpp b/code/ryzom/client/src/interface_v3/interface_link.cpp index e8f583bea..69274dbd7 100644 --- a/code/ryzom/client/src/interface_v3/interface_link.cpp +++ b/code/ryzom/client/src/interface_v3/interface_link.cpp @@ -130,7 +130,20 @@ static bool affect(const CInterfaceExprValue &value, CInterfaceElement &destElem return true; } +CInterfaceLink::CInterfaceLinkUpdater::CInterfaceLinkUpdater() +{ + CCDBNodeBranch::addFlushObserver( this ); +} +CInterfaceLink::CInterfaceLinkUpdater::~CInterfaceLinkUpdater() +{ + CCDBNodeBranch::removeFlushObserver( this ); +} + +void CInterfaceLink::CInterfaceLinkUpdater::onObserverCallFlush() +{ + CInterfaceLink::updateTrigeredLinks(); +} ///////////// // MEMBERS // diff --git a/code/ryzom/client/src/interface_v3/interface_link.h b/code/ryzom/client/src/interface_v3/interface_link.h index 5b7e6d9fb..49abe429c 100644 --- a/code/ryzom/client/src/interface_v3/interface_link.h +++ b/code/ryzom/client/src/interface_v3/interface_link.h @@ -19,12 +19,9 @@ #ifndef CL_INTERFACE_LINK_H #define CL_INTERFACE_LINK_H -#include "../cdb.h" -#include "nel/misc/smart_ptr.h" +#include "../cdb_branch.h" class CInterfaceElement; -class ICDBNode; -class CCDBNodeLeaf; class CReflectedProperty; class CInterfaceExprValue; class CInterfaceGroup; @@ -66,6 +63,17 @@ public: */ bool affect(const CInterfaceExprValue &value); }; + + + /// Updates triggered interface links when triggered by the observed branch + class CInterfaceLinkUpdater : public CCDBNodeBranch::IBranchObserverCallFlushObserver + { + public: + CInterfaceLinkUpdater(); + ~CInterfaceLinkUpdater(); + void onObserverCallFlush(); + }; + public: CInterfaceLink(); ~CInterfaceLink(); // this object should only be destroyed by a CInterfaceElement diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index cfae646d2..2c0ab250c 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -257,6 +257,7 @@ CInterfaceManager::CInterfaceManager() { _Instance = this; _DbRootNode = new CCDBNodeBranch("ROOT"); + interfaceLinkUpdater = new CInterfaceLink::CInterfaceLinkUpdater(); _ScreenW = _ScreenH = 0; _LastInGameScreenW = _LastInGameScreenH = 0; _Pointer = NULL; @@ -372,6 +373,8 @@ CInterfaceManager::~CInterfaceManager() // release the database observers releaseServerToLocalAutoCopyObservers(); + delete interfaceLinkUpdater; + interfaceLinkUpdater = NULL; } // ------------------------------------------------------------------------------------------------ diff --git a/code/ryzom/client/src/interface_v3/interface_manager.h b/code/ryzom/client/src/interface_v3/interface_manager.h index 7ee6d1951..615378d92 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.h +++ b/code/ryzom/client/src/interface_v3/interface_manager.h @@ -1063,7 +1063,8 @@ private: // Update tooltip coordinate if they need to be (getInvalidCoords() returns a value != 0) void updateTooltipCoords(CCtrlBase *newCtrl); - + + CInterfaceLink::CInterfaceLinkUpdater *interfaceLinkUpdater; }; #endif // NL_INTERFACE_MANAGER_H