[dasher: 5/27] Remove RebuildAroundCrosshair; just SetOffset when BP_CONTROL_MODE changes



commit 6ef5fd8f88d7b81c267d5be1fdbfe297a3556a39
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Tue Aug 10 18:57:03 2010 +0100

    Remove RebuildAroundCrosshair; just SetOffset when BP_CONTROL_MODE changes
    
    Fixes problems with caching of probabilities (=> empty space assigned to control
    node and never filled, or no space), not to mention undefined behaviour when
    RebuildAround-ing a control node if that's where the crosshair was when control
    mode was turned it off (!)...complexity of RebuildAroundCrosshair does not seem
    necessary for such infrequent changes to BP_CONTROL_MODE.

 Src/DasherCore/DasherInterfaceBase.cpp |    5 +++-
 Src/DasherCore/DasherModel.cpp         |   42 +++----------------------------
 Src/DasherCore/DasherModel.h           |   17 -------------
 3 files changed, 8 insertions(+), 56 deletions(-)
---
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index 000066f..1321caa 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -291,6 +291,10 @@ void CDasherInterfaceBase::InterfaceEventHandler(Dasher::CEvent *pEvent) {
       ScheduleRedraw();
       break;
     case BP_CONTROL_MODE:
+        //force rebuilding tree/nodes, to get new probabilities (inc/exc control node).
+        // This may move the canvas around a bit, but at least manages to keep/reuse the
+        // existing AlphabetManager, NCManager, etc. objects...
+        SetOffset(m_pDasherModel->GetOffset(), true);
       ScheduleRedraw();
       break;
     case BP_DRAW_MOUSE_LINE:
@@ -1118,7 +1122,6 @@ void CDasherInterfaceBase::ChangeState(ETransition iTransition) {
 }
 
 void CDasherInterfaceBase::SetOffset(int iOffset, bool bForce) {
-  std::cout << "DasherIntf::SetOffset(" << iOffset << "," << bForce << ")" << std::endl;
   m_pDasherModel->SetOffset(iOffset, m_pNCManager->GetAlphabetManager(), m_pDasherView, bForce);
   //ACL TODO note that CTL_MOVE, etc., do not come here (that would probably
   // rebuild the model / violently repaint the screen every time!). But we
diff --git a/Src/DasherCore/DasherModel.cpp b/Src/DasherCore/DasherModel.cpp
index 50e6528..15384dd 100644
--- a/Src/DasherCore/DasherModel.cpp
+++ b/Src/DasherCore/DasherModel.cpp
@@ -105,9 +105,6 @@ void CDasherModel::HandleEvent(Dasher::CEvent *pEvent) {
     Dasher::CParameterNotificationEvent * pEvt(static_cast < Dasher::CParameterNotificationEvent * >(pEvent));
 
     switch (pEvt->m_iParameter) {
-    case BP_CONTROL_MODE: // Rebuild the model if control mode is switched on/off
-      RebuildAroundCrosshair();
-      break;
     case BP_SMOOTH_OFFSET:
       if (!GetBoolParameter(BP_SMOOTH_OFFSET))
         //smoothing has just been turned off. End any transition/jump currently
@@ -134,7 +131,8 @@ void CDasherModel::Make_root(CDasherNode *pNewRoot) {
 
   DASHER_ASSERT(pNewRoot != NULL);
   DASHER_ASSERT(pNewRoot->Parent() == m_Root);
-
+  
+  m_Root->DeleteNephews(pNewRoot);
   m_Root->SetFlag(NF_COMMITTED, true);
 
   // TODO: Is the stack necessary at all? We may as well just keep the
@@ -162,36 +160,6 @@ void CDasherModel::Make_root(CDasherNode *pNewRoot) {
   }
 }
 
-void CDasherModel::RecursiveMakeRoot(CDasherNode *pNewRoot) {
-  DASHER_ASSERT(pNewRoot != NULL);
-  DASHER_ASSERT(m_Root != NULL);
-
-  if(pNewRoot == m_Root)
-    return;
-
-  // TODO: we really ought to check that pNewRoot is actually a
-  // descendent of the root, although that should be guaranteed
-
-  if(pNewRoot->Parent() != m_Root)
-    RecursiveMakeRoot(pNewRoot->Parent());
-
-  Make_root(pNewRoot);
-}
-
-// only used when BP_CONTROL changes, so not very often.
-void CDasherModel::RebuildAroundCrosshair() {
-  CDasherNode *pNode = Get_node_under_crosshair();
-  DASHER_ASSERT(pNode != NULL);
-  DASHER_ASSERT(pNode == m_pLastOutput);
-
-  RecursiveMakeRoot(pNode);
-  DASHER_ASSERT(m_Root == pNode);
-  ClearRootQueue();
-  m_Root->Delete_children();
-
-  m_Root->PopulateChildren();
-}
-
 void CDasherModel::Reparent_root() {
   DASHER_ASSERT(m_Root != NULL);
 
@@ -507,8 +475,7 @@ void CDasherModel::NewGoTo(myint newRootmin, myint newRootmax, Dasher::VECTOR_SY
           //make pChild the root node...but put (newRootmin,newRootmax) somewhere there'll be converted:
           SGotoItem temp; temp.iN1 = newRootmin; temp.iN2 = newRootmax;
           m_deGotoQueue.push_back(temp);
-          m_Root->DeleteNephews(pChild);
-          RecursiveMakeRoot(pChild);
+          Make_root(pChild);
           temp=m_deGotoQueue.back(); m_deGotoQueue.pop_back();
           // std::cout << "NewGoto Recursing - was (" << newRootmin << "," << newRootmax << "), now (" << temp.iN1 << "," << temp.iN2 << ")" << std::endl;
           NewGoTo(temp.iN1, temp.iN2, pAdded,pNumDeleted);
@@ -653,8 +620,7 @@ bool CDasherModel::CheckForNewRoot(CDasherView *pView) {
   }
   ////GAME MODE TEMP - only change the root if it is on the game path/////////
   if (pNewRoot && (!m_bGameMode || pNewRoot->GetFlag(NF_GAME))) {
-    m_Root->DeleteNephews(pNewRoot);
-    RecursiveMakeRoot(pNewRoot);
+    Make_root(pNewRoot);
   }
 
   DASHER_ASSERT(Get_node_under_crosshair() == pOldNode);
diff --git a/Src/DasherCore/DasherModel.h b/Src/DasherCore/DasherModel.h
index 2395d41..f0050eb 100644
--- a/Src/DasherCore/DasherModel.h
+++ b/Src/DasherCore/DasherModel.h
@@ -305,23 +305,6 @@ class Dasher::CDasherModel:public Dasher::CFrameRate, private NoClones
   void Make_root(CDasherNode *pNewRoot); 
 
   ///
-  /// A version of Make_root which is suitable for arbitrary
-  /// descendents of the root, not just immediate children.
-  ///
-
-  void RecursiveMakeRoot(CDasherNode *pNewRoot);
-
-  ///
-  /// Makes the node under the crosshair the root by deleting everything
-  /// outside it, then rebuilds the nodes beneath it. (Thus, the node under
-  /// the crosshair stays in the same place.) Used when control mode is turned
-  /// on or off, or more generally, when the sizes of child nodes may have
-  /// changed.
-  ///
-
-  void RebuildAroundCrosshair();
-
-  ///
   /// Rebuild the parent of the current root - used during backing off
   ///
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]