[dasher] Rename BP_DELAY_VIEW to BP_SMOOTH_OFFSET and tidy handling thereof.



commit df20a2094155389ea8401ef71b83731c587c1064
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Thu Jul 2 13:29:59 2009 +0100

    Rename BP_DELAY_VIEW to BP_SMOOTH_OFFSET and tidy handling thereof.
    
    It causes the effect of CDasherModel::Offset, used by dynamic button
    modes, to be smoothed over several frames. Also renamed the accompanying
    MatchTarget method to AbortOffset.

 ChangeLog                                 |    1 +
 Src/DasherCore/DasherModel.cpp            |   41 +++++++++++++++-------------
 Src/DasherCore/DasherModel.h              |   12 ++++----
 Src/DasherCore/DynamicFilter.cpp          |    4 ---
 Src/DasherCore/Parameters.h               |    4 +-
 Src/DasherCore/TwoButtonDynamicFilter.cpp |   21 +++++++++++++-
 Src/DasherCore/TwoButtonDynamicFilter.h   |    5 +++
 Src/DasherCore/TwoPushDynamicFilter.cpp   |   21 +++++++++++++-
 Src/DasherCore/TwoPushDynamicFilter.h     |    4 +++
 9 files changed, 78 insertions(+), 35 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6fe7da7..974263c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
 	files and move CFrameRate class into namespace Dasher.
 	* Remove NodeManagerFactory class.
 	* Remove CControlManagerFactory class.
+	* Rename BP_DELAY_VIEW to BP_SMOOTH_OFFSET and tidy its handling.
 
 2009-07-02  Patrick Welche <prlw1 cam ac uk>
 
diff --git a/Src/DasherCore/DasherModel.cpp b/Src/DasherCore/DasherModel.cpp
index 41d66df..e646aff 100644
--- a/Src/DasherCore/DasherModel.cpp
+++ b/Src/DasherCore/DasherModel.cpp
@@ -73,7 +73,7 @@ CDasherModel::CDasherModel(CEventHandler *pEventHandler,
 
   m_Rootmin = 0;
   m_Rootmax = 0;
-  m_iTargetOffset = 0;
+  m_iDisplayOffset = 0;
   m_dTotalNats = 0.0;
  
   // TODO: Need to rationalise the require conversion methods
@@ -118,8 +118,11 @@ void CDasherModel::HandleEvent(Dasher::CEvent *pEvent) {
     case BP_CONTROL_MODE: // Rebuild the model if control mode is switched on/off
       RebuildAroundNode(Get_node_under_crosshair());
       break;
-    case BP_DELAY_VIEW:
-      MatchTarget(GetBoolParameter(BP_DELAY_VIEW));
+    case BP_SMOOTH_OFFSET:
+      if (!GetBoolParameter(BP_SMOOTH_OFFSET))
+        //smoothing has just been turned off. End any transition/jump currently
+        // in progress at it's current point
+        AbortOffset();
       break;
     case BP_DASHER_PAUSED:
       if(GetBoolParameter(BP_SLOW_START))
@@ -301,13 +304,13 @@ void CDasherModel::ClearRootQueue() {
 CDasherNode *CDasherModel::Get_node_under_crosshair() {
   DASHER_ASSERT(m_Root != NULL);
 
-  return m_Root->Get_node_under(GetLongParameter(LP_NORMALIZATION), m_Rootmin + m_iTargetOffset, m_Rootmax + m_iTargetOffset, GetLongParameter(LP_OX), GetLongParameter(LP_OY));
+  return m_Root->Get_node_under(GetLongParameter(LP_NORMALIZATION), m_Rootmin + m_iDisplayOffset, m_Rootmax + m_iDisplayOffset, GetLongParameter(LP_OX), GetLongParameter(LP_OY));
 }
 
 CDasherNode *CDasherModel::Get_node_under_mouse(myint Mousex, myint Mousey) {
   DASHER_ASSERT(m_Root != NULL);
 
-  return m_Root->Get_node_under(GetLongParameter(LP_NORMALIZATION), m_Rootmin + m_iTargetOffset, m_Rootmax + m_iTargetOffset, Mousex, Mousey);
+  return m_Root->Get_node_under(GetLongParameter(LP_NORMALIZATION), m_Rootmin + m_iDisplayOffset, m_Rootmax + m_iDisplayOffset, Mousex, Mousey);
 }
 
 void CDasherModel::DeleteTree() {
@@ -356,7 +359,7 @@ void CDasherModel::InitialiseAtOffset(int iOffset, CDasherView *pView) {
   m_Rootmin = GetLongParameter(LP_MAX_Y) / 2 - iWidth / 2;
   m_Rootmax = GetLongParameter(LP_MAX_Y) / 2 + iWidth / 2;
 
-  m_iTargetOffset = 0;
+  m_iDisplayOffset = 0;
 
   if(pView) {
     while(pView->IsNodeVisible(m_Rootmin,m_Rootmax)) {
@@ -596,11 +599,11 @@ void CDasherModel::NewGoTo(myint newRootmin, myint newRootmax, Dasher::VECTOR_SY
   // Update the max and min of the root node to make iTargetMin and
   // iTargetMax the edges of the viewport.
 
-  if(newRootmin + m_iTargetOffset > (myint)GetLongParameter(LP_MAX_Y) / 2 - 1)
-    newRootmin = (myint)GetLongParameter(LP_MAX_Y) / 2 - 1 - m_iTargetOffset;
+  if(newRootmin + m_iDisplayOffset > (myint)GetLongParameter(LP_MAX_Y) / 2 - 1)
+    newRootmin = (myint)GetLongParameter(LP_MAX_Y) / 2 - 1 - m_iDisplayOffset;
 
-  if(newRootmax + m_iTargetOffset < (myint)GetLongParameter(LP_MAX_Y) / 2 + 1)
-    newRootmax = (myint)GetLongParameter(LP_MAX_Y) / 2 + 1 - m_iTargetOffset;
+  if(newRootmax + m_iDisplayOffset < (myint)GetLongParameter(LP_MAX_Y) / 2 + 1)
+    newRootmax = (myint)GetLongParameter(LP_MAX_Y) / 2 + 1 - m_iDisplayOffset;
 
   // Check that we haven't drifted too far. The rule is that we're not
   // allowed to let the root max and min cross the midpoint of the
@@ -618,7 +621,7 @@ void CDasherModel::NewGoTo(myint newRootmin, myint newRootmax, Dasher::VECTOR_SY
     m_Rootmax = newRootmax;
     m_Rootmin = newRootmin;
 
-    m_iTargetOffset = (m_iTargetOffset * 90) / 100;
+    m_iDisplayOffset = (m_iDisplayOffset * 90) / 100;
   }
   else {
     // TODO - force a new root to be chosen, so that we get better
@@ -844,7 +847,7 @@ bool CDasherModel::RenderToView(CDasherView *pView, bool bRedrawDisplay, SLockDa
   // 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.
-  bReturnValue = pView->Render(m_Root, m_Rootmin + m_iTargetOffset, m_Rootmax + m_iTargetOffset, vNodeList, vDeleteList, bRedrawDisplay, &vGameTargetY);
+  bReturnValue = pView->Render(m_Root, m_Rootmin + m_iDisplayOffset, m_Rootmax + m_iDisplayOffset, vNodeList, vDeleteList, bRedrawDisplay, &vGameTargetY);
   
 
   /////////GAME MODE TEMP//////////////
@@ -1020,16 +1023,16 @@ void CDasherModel::Offset(int iOffset) {
   m_Rootmin += iOffset;
   m_Rootmax += iOffset;
 
-  m_iTargetOffset -= iOffset;
+  if (GetBoolParameter(BP_SMOOTH_OFFSET))
+    m_iDisplayOffset -= iOffset;
 } 
 
-void CDasherModel::MatchTarget(bool bReverse) {
-  // TODO: Does anything need to happen wrt bReverse here?
-
-  m_Rootmin += m_iTargetOffset;
-  m_Rootmax += m_iTargetOffset;
+void CDasherModel::AbortOffset() {
+  
+  m_Rootmin += m_iDisplayOffset;
+  m_Rootmax += m_iDisplayOffset;
 
-  m_iTargetOffset = 0;
+  m_iDisplayOffset = 0;
 }
 
 void CDasherModel::LimitRoot(int iMaxWidth) {
diff --git a/Src/DasherCore/DasherModel.h b/Src/DasherCore/DasherModel.h
index 74c0618..4b273dd 100644
--- a/Src/DasherCore/DasherModel.h
+++ b/Src/DasherCore/DasherModel.h
@@ -90,11 +90,11 @@ class Dasher::CDasherModel:public CFrameRate, private NoClones
   void Offset(int iOffset);
  
   ///
-  /// Reset the 'target' root coordinates to match those currently visible. 
-  /// Appropriate for abrubt changes in behaviour (such as backing off in 
-  /// button modes)
-  /// 
-  void MatchTarget(bool bReverse);
+  /// Make the 'target' root coordinates match those currently visible, so any
+  /// Offset(int) currently in progress (i.e. being smoothed over several
+  /// frames) stops (at whatever point it's currently reached). Appropriate for
+  /// abrupt changes in behaviour (such as backing off in  button modes)
+  void AbortOffset();
 
   /// @}
 
@@ -231,7 +231,7 @@ class Dasher::CDasherModel:public CFrameRate, private NoClones
 
   // Offset used when presenting the model to the user, specified as
   // Displayed rootmin/max - actual rootmin/rootmax
-  myint m_iTargetOffset; 
+  myint m_iDisplayOffset; 
 
   CDasherNode *m_pLastOutput;
 
diff --git a/Src/DasherCore/DynamicFilter.cpp b/Src/DasherCore/DynamicFilter.cpp
index 8821244..8c1416f 100644
--- a/Src/DasherCore/DynamicFilter.cpp
+++ b/Src/DasherCore/DynamicFilter.cpp
@@ -94,7 +94,6 @@ void CDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pMod
     if(pUserLog)
       pUserLog->KeyDown(iButton, iType, 1);
     m_pInterface->Unpause(iTime);
-    SetBoolParameter(BP_DELAY_VIEW, true);
     run(0);
   } else if (isReversing()) {
     if(pUserLog)
@@ -110,13 +109,11 @@ void CDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pMod
 	if(pUserLog)
 	  pUserLog->KeyDown(iButton, iType, 2);
 	pause();
-	SetBoolParameter(BP_DELAY_VIEW, false);
 	m_pInterface->PauseAt(0, 0);
       }
       else if(iButton == 1) {
 	if(pUserLog)
 	  pUserLog->KeyDown(iButton, iType, 6);
-	SetBoolParameter(BP_DELAY_VIEW, false);
 	reverse();
       }
       else {
@@ -128,7 +125,6 @@ void CDynamicFilter::Event(int iTime, int iButton, int iType, CDasherModel *pMod
       if((iButton >= 2) && (iButton <= 4)) {
 	if(pUserLog)
 	  pUserLog->KeyDown(iButton, iType, 6);
-	SetBoolParameter(BP_DELAY_VIEW, false);
 	reverse(); //reversing!
        }
       else {
diff --git a/Src/DasherCore/Parameters.h b/Src/DasherCore/Parameters.h
index ce2965c..68df370 100644
--- a/Src/DasherCore/Parameters.h
+++ b/Src/DasherCore/Parameters.h
@@ -43,7 +43,7 @@ enum {
   BP_BUTTONDIRECT, BP_BUTTONFOURDIRECT, BP_BUTTONALTERNATINGDIRECT,
   BP_COMPASSMODE, BP_SOCKET_INPUT_ENABLE, BP_SOCKET_DEBUG, 
   BP_OLD_STYLE_PUSH, BP_CIRCLE_START, BP_GLOBAL_KEYBOARD, 
-  BP_DELAY_VIEW, BP_CONVERSION_MODE, BP_PAUSE_OUTSIDE, BP_BACKOFF_BUTTON, 
+  BP_SMOOTH_OFFSET, BP_CONVERSION_MODE, BP_PAUSE_OUTSIDE, BP_BACKOFF_BUTTON, 
   BP_TWOBUTTON_REVERSE, BP_SLOW_START, BP_FIXED_MARKERS, END_OF_BPS
 };
 
@@ -157,7 +157,7 @@ static bp_table boolparamtable[] = {
   {BP_OLD_STYLE_PUSH, "OldStylePush", PERS, false, "Old style node pushing algorithm"},
   {BP_CIRCLE_START, "CircleStart", PERS, false, "Start on circle mode"},
   {BP_GLOBAL_KEYBOARD, "GlobalKeyboard", PERS, false, "Whether to assume global control of the keyboard"},
-  {BP_DELAY_VIEW, "DelayView", !PERS, false, "Delayed dynamics (for two button mode)"},
+  {BP_SMOOTH_OFFSET, "DelayView", !PERS, false, "Smooth dynamic button mode jumps over several frames"},
   {BP_CONVERSION_MODE, "ConversionMode", !PERS, false, "Whether Dasher is operating in conversion (eg Japanese) mode"},
   {BP_PAUSE_OUTSIDE, "PauseOutside", PERS, false, "Whether to pause when pointer leaves canvas area"},
   {BP_BACKOFF_BUTTON, "BackoffButton", PERS, true, "Whether to enable the extra backoff button in dynamic mode"},
diff --git a/Src/DasherCore/TwoButtonDynamicFilter.cpp b/Src/DasherCore/TwoButtonDynamicFilter.cpp
index beee743..8802f41 100644
--- a/Src/DasherCore/TwoButtonDynamicFilter.cpp
+++ b/Src/DasherCore/TwoButtonDynamicFilter.cpp
@@ -94,11 +94,28 @@ bool CTwoButtonDynamicFilter::TimerImpl(int Time, CDasherView *m_pDasherView, CD
 }
 
 void CTwoButtonDynamicFilter::Activate() {
-  SetBoolParameter(BP_DELAY_VIEW, true);
+  SetBoolParameter(BP_SMOOTH_OFFSET, true);
 }
 
 void CTwoButtonDynamicFilter::Deactivate() {
-  SetBoolParameter(BP_DELAY_VIEW, false);
+  SetBoolParameter(BP_SMOOTH_OFFSET, false);
+}
+
+void CTwoButtonDynamicFilter::run(int iState) {
+  SetBoolParameter(BP_SMOOTH_OFFSET, true);
+  CDynamicFilter::run(iState);
+}
+
+void CTwoButtonDynamicFilter::pause() {
+  SetBoolParameter(BP_SMOOTH_OFFSET, false);
+  CDynamicFilter::pause();
+}
+
+void CTwoButtonDynamicFilter::reverse() {
+  //hmmmm. If we ever actually did Offset() while reversing,
+  // we might want BP_SMOOTH_OFFSET on....
+  SetBoolParameter(BP_SMOOTH_OFFSET, false);
+  CDynamicFilter::reverse();
 }
 
 void CTwoButtonDynamicFilter::ActionButton(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog) {
diff --git a/Src/DasherCore/TwoButtonDynamicFilter.h b/Src/DasherCore/TwoButtonDynamicFilter.h
index 3c7cb8d..1362926 100644
--- a/Src/DasherCore/TwoButtonDynamicFilter.h
+++ b/Src/DasherCore/TwoButtonDynamicFilter.h
@@ -43,6 +43,11 @@ class CTwoButtonDynamicFilter : public CButtonMultiPress {
 
   virtual void HandleEvent(Dasher::CEvent *pEvent);
   
+ protected:
+  virtual void run(int iState);
+  virtual void pause();
+  virtual void reverse();
+
  private:
   virtual bool TimerImpl(int Time, CDasherView *m_pDasherView, CDasherModel *m_pDasherModel, Dasher::VECTOR_SYMBOL_PROB *pAdded, int *pNumDeleted);
   virtual void ActionButton(int iTime, int iButton, int iType, CDasherModel *pModel, CUserLogBase *pUserLog);
diff --git a/Src/DasherCore/TwoPushDynamicFilter.cpp b/Src/DasherCore/TwoPushDynamicFilter.cpp
index be6b124..b7ba7f1 100644
--- a/Src/DasherCore/TwoPushDynamicFilter.cpp
+++ b/Src/DasherCore/TwoPushDynamicFilter.cpp
@@ -256,11 +256,28 @@ bool CTwoPushDynamicFilter::TimerImpl(int iTime, CDasherView *m_pDasherView, CDa
 }
 
 void CTwoPushDynamicFilter::Activate() {
-  SetBoolParameter(BP_DELAY_VIEW, true);
+  SetBoolParameter(BP_SMOOTH_OFFSET, true);
 }
 
 void CTwoPushDynamicFilter::Deactivate() {
-  SetBoolParameter(BP_DELAY_VIEW, false);
+  SetBoolParameter(BP_SMOOTH_OFFSET, false);
+}
+
+void CTwoPushDynamicFilter::run(int iState) {
+  SetBoolParameter(BP_SMOOTH_OFFSET, true);
+  CDynamicFilter::run(iState);
+}
+
+void CTwoPushDynamicFilter::pause() {
+  SetBoolParameter(BP_SMOOTH_OFFSET, false);
+  CDynamicFilter::pause();
+}
+
+void CTwoPushDynamicFilter::reverse() {
+  //hmmmm. If we ever actually did Offset() while reversing,
+  // we might want BP_SMOOTH_OFFSET on....
+  SetBoolParameter(BP_SMOOTH_OFFSET, false);
+  CDynamicFilter::reverse();
 }
 
 bool CTwoPushDynamicFilter::GetSettings(SModuleSettings **pSettings, int *iCount) {
diff --git a/Src/DasherCore/TwoPushDynamicFilter.h b/Src/DasherCore/TwoPushDynamicFilter.h
index 4f72c57..cd705d6 100644
--- a/Src/DasherCore/TwoPushDynamicFilter.h
+++ b/Src/DasherCore/TwoPushDynamicFilter.h
@@ -42,6 +42,10 @@ class CTwoPushDynamicFilter : public CDynamicFilter /*long push, but do our own
 
   virtual void HandleEvent(Dasher::CEvent * pEvent);
 
+  virtual void run(int iState);
+  virtual void pause();
+  virtual void reverse();
+
  private:
   double m_dLogUpMul, m_dLogDownMul, m_dLagBits;
   double m_dMinShortTwoPushTime, m_dMaxShortTwoPushTime,



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