CDB no longer depends on CInterfaceLink.

This commit is contained in:
dfighter1985 2012-04-16 01:31:21 +02:00
parent f815bb2549
commit 4313f62647
6 changed files with 84 additions and 11 deletions

View file

@ -16,8 +16,6 @@
#include "stdpch.h"
//#define TRACE_READ_DELTA //#define TRACE_READ_DELTA
//#define TRACE_WRITE_DELTA //#define TRACE_WRITE_DELTA
//#define TRACE_SET_VALUE //#define TRACE_SET_VALUE
@ -32,7 +30,6 @@
#include "cdb_leaf.h" #include "cdb_leaf.h"
#include "game_share/xml_auto_ptr.h" #include "game_share/xml_auto_ptr.h"
//#include <iostream.h> //#include <iostream.h>
#include "interface_v3/interface_manager.h"
//////////////// ////////////////
// Namespaces // // Namespaces //
@ -84,6 +81,8 @@ uint CCDBNodeBranch::_FirstLevelIdBitsByBank [NB_CDB_BANKS];
extern const char *CDBBankNames[INVALID_CDB_BANK+1]; extern const char *CDBBankNames[INVALID_CDB_BANK+1];
std::vector< CCDBNodeBranch::IBranchObserverCallFlushObserver* > CCDBNodeBranch::flushObservers;
// reset all static data // reset all static data
void CCDBNodeBranch::reset() void CCDBNodeBranch::reset()
{ {
@ -703,15 +702,46 @@ void CCDBNodeBranch::flushObserversCalls()
} }
nlassert(_FirstNotifiedObs[1 - _CurrNotifiedObsList] == NULL); nlassert(_FirstNotifiedObs[1 - _CurrNotifiedObsList] == NULL);
nlassert(_LastNotifiedObs[1 - _CurrNotifiedObsList] == NULL); nlassert(_LastNotifiedObs[1 - _CurrNotifiedObsList] == NULL);
// update triggered link triggerFlushObservers();
CInterfaceLink::updateTrigeredLinks();
// examine other list to see if nodes have been registered // examine other list to see if nodes have been registered
_CurrNotifiedObs = _FirstNotifiedObs[_CurrNotifiedObsList]; _CurrNotifiedObs = _FirstNotifiedObs[_CurrNotifiedObsList];
} }
CInterfaceLink::updateTrigeredLinks(); // should call it at least once triggerFlushObservers();
// nlassert(_CrtCheckMemory()); // 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) void CCDBNodeBranch::CDBBranchObsInfo::link(uint list, NLMISC::TStringId modifiedLeafName)
{ {

View file

@ -31,6 +31,12 @@
class CCDBNodeBranch : public ICDBNode class CCDBNodeBranch : public ICDBNode
{ {
public: public:
/// Triggered when the branch observers are updated
class IBranchObserverCallFlushObserver : public NLMISC::CRefCount{
public:
virtual ~IBranchObserverCallFlushObserver(){}
virtual void onObserverCallFlush() = 0;
};
// default constructor // default constructor
CCDBNodeBranch(const std::string &name) : ICDBNode(name) CCDBNodeBranch(const std::string &name) : ICDBNode(name)
@ -212,6 +218,13 @@ public:
*/ */
static void flushObserversCalls(); 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 // mark this branch and parent branch as 'modified'. This is usually called by sub-leaves
void linkInModifiedNodeList(NLMISC::TStringId modifiedLeafName); void linkInModifiedNodeList(NLMISC::TStringId modifiedLeafName);
@ -324,6 +337,11 @@ protected:
/// called by clear /// called by clear
void removeAllBranchObserver(); void removeAllBranchObserver();
void removeBranchInfoIt(TObsList::iterator it); void removeBranchInfoIt(TObsList::iterator it);
private:
static std::vector< IBranchObserverCallFlushObserver* > flushObservers;
}; };

View file

@ -130,7 +130,20 @@ static bool affect(const CInterfaceExprValue &value, CInterfaceElement &destElem
return true; return true;
} }
CInterfaceLink::CInterfaceLinkUpdater::CInterfaceLinkUpdater()
{
CCDBNodeBranch::addFlushObserver( this );
}
CInterfaceLink::CInterfaceLinkUpdater::~CInterfaceLinkUpdater()
{
CCDBNodeBranch::removeFlushObserver( this );
}
void CInterfaceLink::CInterfaceLinkUpdater::onObserverCallFlush()
{
CInterfaceLink::updateTrigeredLinks();
}
///////////// /////////////
// MEMBERS // // MEMBERS //

View file

@ -19,12 +19,9 @@
#ifndef CL_INTERFACE_LINK_H #ifndef CL_INTERFACE_LINK_H
#define CL_INTERFACE_LINK_H #define CL_INTERFACE_LINK_H
#include "../cdb.h" #include "../cdb_branch.h"
#include "nel/misc/smart_ptr.h"
class CInterfaceElement; class CInterfaceElement;
class ICDBNode;
class CCDBNodeLeaf;
class CReflectedProperty; class CReflectedProperty;
class CInterfaceExprValue; class CInterfaceExprValue;
class CInterfaceGroup; class CInterfaceGroup;
@ -66,6 +63,17 @@ public:
*/ */
bool affect(const CInterfaceExprValue &value); 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: public:
CInterfaceLink(); CInterfaceLink();
~CInterfaceLink(); // this object should only be destroyed by a CInterfaceElement ~CInterfaceLink(); // this object should only be destroyed by a CInterfaceElement

View file

@ -257,6 +257,7 @@ CInterfaceManager::CInterfaceManager()
{ {
_Instance = this; _Instance = this;
_DbRootNode = new CCDBNodeBranch("ROOT"); _DbRootNode = new CCDBNodeBranch("ROOT");
interfaceLinkUpdater = new CInterfaceLink::CInterfaceLinkUpdater();
_ScreenW = _ScreenH = 0; _ScreenW = _ScreenH = 0;
_LastInGameScreenW = _LastInGameScreenH = 0; _LastInGameScreenW = _LastInGameScreenH = 0;
_Pointer = NULL; _Pointer = NULL;
@ -372,6 +373,8 @@ CInterfaceManager::~CInterfaceManager()
// release the database observers // release the database observers
releaseServerToLocalAutoCopyObservers(); releaseServerToLocalAutoCopyObservers();
delete interfaceLinkUpdater;
interfaceLinkUpdater = NULL;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View file

@ -1063,7 +1063,8 @@ private:
// Update tooltip coordinate if they need to be (getInvalidCoords() returns a value != 0) // Update tooltip coordinate if they need to be (getInvalidCoords() returns a value != 0)
void updateTooltipCoords(CCtrlBase *newCtrl); void updateTooltipCoords(CCtrlBase *newCtrl);
CInterfaceLink::CInterfaceLinkUpdater *interfaceLinkUpdater;
}; };
#endif // NL_INTERFACE_MANAGER_H #endif // NL_INTERFACE_MANAGER_H