[dasher: 2/27] Remove NCManager from DasherModel, combine InitialiseAtOffset into SetOffset
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 2/27] Remove NCManager from DasherModel, combine InitialiseAtOffset into SetOffset
- Date: Wed, 18 Aug 2010 15:09:51 +0000 (UTC)
commit bbdd3c253ced42652538e14b525df950e76b191a
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Wed Aug 4 16:51:25 2010 +0100
Remove NCManager from DasherModel, combine InitialiseAtOffset into SetOffset
...with explicit AlphabetManager as parameter and extra bool to force recreation
of node tree even if offset hasn't changed
CNodeCreationManager::GetAlphRoot removed in favour of GetAlphabet()->GetRoot
Src/DasherCore/ControlManager.cpp | 6 ++--
Src/DasherCore/ConversionManager.cpp | 2 +-
Src/DasherCore/DasherInterfaceBase.cpp | 10 ++++--
Src/DasherCore/DasherModel.cpp | 48 +++++++------------------------
Src/DasherCore/DasherModel.h | 34 +++++++++-------------
Src/DasherCore/NodeCreationManager.cpp | 4 --
Src/DasherCore/NodeCreationManager.h | 2 +-
7 files changed, 37 insertions(+), 69 deletions(-)
---
diff --git a/Src/DasherCore/ControlManager.cpp b/Src/DasherCore/ControlManager.cpp
index b546f87..1023052 100644
--- a/Src/DasherCore/ControlManager.cpp
+++ b/Src/DasherCore/ControlManager.cpp
@@ -49,7 +49,7 @@ void CControlBase::SetRootTemplate(NodeTemplate *pRoot) {
}
CDasherNode *CControlBase::GetRoot(CDasherNode *pParent, unsigned int iLower, unsigned int iUpper, int iOffset) {
- if (!m_pRoot) return m_pNCManager->GetAlphRoot(pParent, iLower, iUpper, false, iOffset);
+ if (!m_pRoot) return m_pNCManager->GetAlphabetManager()->GetRoot(pParent, iLower, iUpper, false, iOffset);
CContNode *pNewNode = new CContNode(pParent, iOffset, iLower, iUpper, m_pRoot, this);
@@ -95,7 +95,7 @@ void CControlBase::CContNode::PopulateChildren() {
if( *it == NULL ) {
// Escape back to alphabet
- pNewNode = m_pMgr->m_pNCManager->GetAlphRoot(this, iLbnd, iHbnd, false, offset()+1);
+ pNewNode = m_pMgr->m_pNCManager->GetAlphabetManager()->GetRoot(this, iLbnd, iHbnd, false, offset()+1);
}
else {
@@ -489,4 +489,4 @@ void CControlManager::updateActions() {
//copy anything else (custom) that might have been added...
while (it != vOldRootSuccessors.end()) vRootSuccessors.push_back(*it++);
-}
\ No newline at end of file
+}
diff --git a/Src/DasherCore/ConversionManager.cpp b/Src/DasherCore/ConversionManager.cpp
index b71fef6..406d589 100644
--- a/Src/DasherCore/ConversionManager.cpp
+++ b/Src/DasherCore/ConversionManager.cpp
@@ -97,7 +97,7 @@ void CConversionManager::CConvNode::PopulateChildren() {
unsigned int iLbnd(0);
unsigned int iHbnd(m_pMgr->m_pNCManager->GetLongParameter(LP_NORMALIZATION));
- CDasherNode *pNewNode = m_pMgr->m_pNCManager->GetAlphRoot(this, iLbnd, iHbnd, false, offset() + 1);
+ CDasherNode *pNewNode = m_pMgr->m_pNCManager->GetAlphabetManager()->GetRoot(this, iLbnd, iHbnd, false, offset() + 1);
DASHER_ASSERT(GetChildren().back()==pNewNode);
}
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index 32c76d4..facb2b9 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -385,7 +385,8 @@ void CDasherInterfaceBase::CreateModel(int iOffset) {
delete m_pDasherModel;
// TODO: Eventually we'll not have to pass the NC manager to the model...(?)
- m_pDasherModel = new CDasherModel(m_pEventHandler, m_pSettingsStore, m_pNCManager, this, m_pDasherView, iOffset);
+ m_pDasherModel = new CDasherModel(m_pEventHandler, m_pSettingsStore, this);
+ m_pDasherModel->SetOffset(iOffset, m_pNCManager->GetAlphabetManager(), m_pDasherView, true);
// Notify the teacher of the new model
if(GameMode::CDasherGameMode* pTeacher = GameMode::CDasherGameMode::GetTeacher())
@@ -599,7 +600,10 @@ void CDasherInterfaceBase::Redraw(bool bRedrawNodes, CExpansionPolicy &policy) {
// Draw the nodes
if(bRedrawNodes) {
m_pDasherView->Screen()->SendMarker(0);
- if (m_pDasherModel) m_bLastChanged |= m_pDasherModel->RenderToView(m_pDasherView,policy);
+ if (m_pDasherModel) {
+ m_pDasherModel->RenderToView(m_pDasherView,policy);
+ m_bLastChanged |= policy.apply(m_pNCManager, m_pDasherModel);
+ }
}
// Draw the decorations
@@ -1141,7 +1145,7 @@ void CDasherInterfaceBase::UnsetBuffer() {
void CDasherInterfaceBase::SetOffset(int iOffset) {
if(m_pDasherModel)
- m_pDasherModel->SetOffset(iOffset, m_pDasherView);
+ m_pDasherModel->SetOffset(iOffset, m_pNCManager->GetAlphabetManager(), m_pDasherView, false);
//ACL TODO FIXME check that CTL_MOVE, etc., eventually come here?
for (set<TextAction *>::iterator it = m_vTextActions.begin(); it!=m_vTextActions.end(); it++) {
(*it)->NotifyOffset(iOffset);
diff --git a/Src/DasherCore/DasherModel.cpp b/Src/DasherCore/DasherModel.cpp
index fbd6a15..50e6528 100644
--- a/Src/DasherCore/DasherModel.cpp
+++ b/Src/DasherCore/DasherModel.cpp
@@ -52,16 +52,12 @@ static char THIS_FILE[] = __FILE__;
CDasherModel::CDasherModel(CEventHandler *pEventHandler,
CSettingsStore *pSettingsStore,
- CNodeCreationManager *pNCManager,
- CDasherInterfaceBase *pDasherInterface,
- CDasherView *pView, int iOffset)
+ CDasherInterfaceBase *pDasherInterface)
: CFrameRate(pEventHandler, pSettingsStore) {
- m_pNodeCreationManager = pNCManager;
m_pDasherInterface = pDasherInterface;
m_bGameMode = GetBoolParameter(BP_GAME_MODE);
- DASHER_ASSERT(m_pNodeCreationManager != NULL);
DASHER_ASSERT(m_pDasherInterface != NULL);
m_pLastOutput = m_Root = NULL;
@@ -86,7 +82,6 @@ CDasherModel::CDasherModel(CEventHandler *pEventHandler,
m_Rootmin_min = int64_min / iNormalization / 2;
m_Rootmax_max = int64_max / iNormalization / 2;
- InitialiseAtOffset(iOffset, pView);
}
CDasherModel::~CDasherModel() {
@@ -265,17 +260,17 @@ CDasherNode *CDasherModel::Get_node_under_crosshair() {
return m_Root->Get_node_under(GetLongParameter(LP_NORMALIZATION), m_Rootmin + m_iDisplayOffset, m_Rootmax + m_iDisplayOffset, GetLongParameter(LP_OX), GetLongParameter(LP_OY));
}
-void CDasherModel::DeleteTree() {
- ClearRootQueue();
- delete m_Root;
- m_Root = NULL;
-}
+void CDasherModel::SetOffset(int iOffset, CAlphabetManager *pMgr, CDasherView *pView, bool bForce) {
+ //if we don't have a root, always "re"build the tree!
+ // (if we have a root, only rebuild to move location or if bForce says to)
+ if (m_Root && iOffset == GetOffset() && !bForce) return;
-void CDasherModel::InitialiseAtOffset(int iOffset, CDasherView *pView) {
if (m_pLastOutput) m_pLastOutput->Leave();
- DeleteTree();
-
- m_Root = m_pNodeCreationManager->GetAlphRoot(NULL, 0,GetLongParameter(LP_NORMALIZATION), iOffset!=0, iOffset);
+
+ ClearRootQueue();
+ delete m_Root;
+
+ m_Root = pMgr->GetRoot(NULL, 0,GetLongParameter(LP_NORMALIZATION), iOffset!=0, iOffset);
m_pLastOutput = (m_Root->GetFlag(NF_SEEN)) ? m_Root : NULL;
// Create children of the root...
@@ -599,7 +594,7 @@ void CDasherModel::ExpandNode(CDasherNode *pNode) {
}
-bool CDasherModel::RenderToView(CDasherView *pView, CExpansionPolicy &policy) {
+void CDasherModel::RenderToView(CDasherView *pView, CExpansionPolicy &policy) {
DASHER_ASSERT(pView != NULL);
DASHER_ASSERT(m_Root != NULL);
@@ -607,8 +602,6 @@ bool CDasherModel::RenderToView(CDasherView *pView, CExpansionPolicy &policy) {
// XXX we HandleOutput in RenderToView
// DASHER_ASSERT(Get_node_under_crosshair() == m_pLastOutput);
- bool bReturnValue = false;
-
// The Render routine will fill iGameTargetY with the Dasher Coordinate of the
// youngest node with NF_GAME set. The model is responsible for setting NF_GAME on
// the appropriate Nodes.
@@ -629,12 +622,6 @@ bool CDasherModel::RenderToView(CDasherView *pView, CExpansionPolicy &policy) {
// TODO: Fix up stats
// TODO: Is this the right way to handle this?
HandleOutput(NULL, NULL);
-
- //ACL Off-screen nodes (zero collapse cost) will have been collapsed already.
- //Hence, this acts to maintain the node budget....or whatever the queue's policy is!
- if (policy.apply(m_pNodeCreationManager,this)) bReturnValue=true;
-
- return bReturnValue;
}
bool CDasherModel::CheckForNewRoot(CDasherView *pView) {
@@ -774,16 +761,3 @@ void CDasherModel::LimitRoot(int iMaxWidth) {
m_Rootmax = GetLongParameter(LP_MAX_Y) / 2 + iMaxWidth / 2;
}
-void CDasherModel::SetOffset(int iLocation, CDasherView *pView) {
- if(iLocation == GetOffset())
- return; // We're already there
-
- // std::cout << "Initialising at offset: " << iLocation << std::endl;
-
- // TODO: Special cases, ie this can be done without rebuilding the
- // model
-
- // Now actually rebuild the model
- InitialiseAtOffset(iLocation, pView);
-}
-
diff --git a/Src/DasherCore/DasherModel.h b/Src/DasherCore/DasherModel.h
index f3614ed..2395d41 100644
--- a/Src/DasherCore/DasherModel.h
+++ b/Src/DasherCore/DasherModel.h
@@ -59,8 +59,9 @@ namespace Dasher {
class Dasher::CDasherModel:public Dasher::CFrameRate, private NoClones
{
public:
-
- CDasherModel(CEventHandler * pEventHandler, CSettingsStore * pSettingsStore, CNodeCreationManager *pNCManager, CDasherInterfaceBase *pDashIface, CDasherView *pView, int iOffset);
+ /// Constructs a new CDasherModel. Note, must be followed by a call to
+ /// SetOffset() before the model can be used.
+ CDasherModel(CEventHandler * pEventHandler, CSettingsStore * pSettingsStore, CDasherInterfaceBase *pDashIface);
~CDasherModel();
///
@@ -121,12 +122,10 @@ class Dasher::CDasherModel:public Dasher::CFrameRate, private NoClones
/// @{
///
- /// Render the model to a given view. Return if any nodes were
- /// expanded, as if so we may want to render *another* frame to
- /// perform further expansion.
+ /// Render the model to a given view, and cause output to happen.
+ /// Note, enqueues nodes onto the Expansion Policy, but does not apply it.
///
-
- bool RenderToView(CDasherView *pView, CExpansionPolicy &policy);
+ void RenderToView(CDasherView *pView, CExpansionPolicy &policy);
/// @}
@@ -178,13 +177,16 @@ class Dasher::CDasherModel:public Dasher::CFrameRate, private NoClones
bool CheckForNewRoot(CDasherView *pView);
///
- /// Notify of a change of cursor position within the attached
- /// buffer. Resulting action should be appropriate - ie don't
- /// completely rebuild the model if an existing node covers this
- /// point
+ /// Rebuild the tree of nodes (may reuse the existing ones if !bForce).
+ /// @param iLocation offset (cursor position) in attached buffer from which to obtain context
+ /// @param pMgr Manager to use to create nodes
+ /// @param bForce if true, model should be completely rebuilt (even for
+ /// same offset) - characters at old offsets may have changed, or we have
+ /// a new AlphabetManager. If false, assume buffer and alphabet unchanged,
+ /// so no need to rebuild the model if an existing node covers this point.
///
- void SetOffset(int iLocation, CDasherView *pView);
+ void SetOffset(int iLocation, CAlphabetManager *pMgr, CDasherView *pView, bool bForce);
///
/// The current offset of the cursor/insertion point in the text buffer
@@ -213,7 +215,6 @@ class Dasher::CDasherModel:public Dasher::CFrameRate, private NoClones
// Pointers to various auxilliary objects
CDasherInterfaceBase *m_pDasherInterface;
- CNodeCreationManager *m_pNodeCreationManager;
// The root of the Dasher tree
CDasherNode *m_Root;
@@ -297,13 +298,6 @@ class Dasher::CDasherModel:public Dasher::CFrameRate, private NoClones
///
void Get_new_root_coords(myint mousex, myint mousey, myint &iNewMin, myint &iNewMax, unsigned long iTime);
-
- /// Should be public?
- void InitialiseAtOffset(int iOffset, CDasherView *pView);
-
- /// Called from InitialiseAtOffset
- void DeleteTree();
-
///
/// Make a child of the root into a new root
///
diff --git a/Src/DasherCore/NodeCreationManager.cpp b/Src/DasherCore/NodeCreationManager.cpp
index c321056..9392ca6 100644
--- a/Src/DasherCore/NodeCreationManager.cpp
+++ b/Src/DasherCore/NodeCreationManager.cpp
@@ -152,10 +152,6 @@ CNodeCreationManager::~CNodeCreationManager() {
if (m_pConversionManager) m_pConversionManager->Unref();
}
-CDasherNode *CNodeCreationManager::GetAlphRoot(Dasher::CDasherNode *pParent, unsigned int iLower, unsigned int iUpper, bool bEnteredLast, int iOffset) {
- return m_pAlphabetManager->GetRoot(pParent, iLower, iUpper, bEnteredLast, iOffset);
-}
-
CDasherNode *CNodeCreationManager::GetConvRoot(Dasher::CDasherNode *pParent, unsigned int iLower, unsigned int iUpper, int iOffset) {
if(m_pConversionManager)
return m_pConversionManager->GetRoot(pParent, iLower, iUpper, iOffset);
diff --git a/Src/DasherCore/NodeCreationManager.h b/Src/DasherCore/NodeCreationManager.h
index 0f16117..e50d322 100644
--- a/Src/DasherCore/NodeCreationManager.h
+++ b/Src/DasherCore/NodeCreationManager.h
@@ -36,7 +36,7 @@ class CNodeCreationManager : public Dasher::CDasherComponent {
/// Get a root node of a particular type
///
- Dasher::CDasherNode *GetAlphRoot(Dasher::CDasherNode *pParent, unsigned int iLower, unsigned int iUpper, bool bEnteredLast, int iOffset);
+ Dasher::CAlphabetManager *GetAlphabetManager() {return m_pAlphabetManager;}
Dasher::CDasherNode *GetConvRoot(Dasher::CDasherNode *pParent, unsigned int iLower, unsigned int iUpper, int iOffset);
Dasher::CControlManager *GetControlManager() {return m_pControlManager;}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]