JK2eA
 All Classes Functions Variables
ControllerStep.h
00001 #pragma once
00002 
00003 
00004 #include "Controller.h"
00005 #ifdef _JK2_VERBOSE
00006 #include <JK2lib.h>
00007 #endif
00008 
00015 template<class T>
00016 class CControllerStep : public CController {
00017 private:
00018         T               m_startVal;             
00019         T               m_endVal;               
00020 
00021         T               m_step;                 
00022         float   m_fDelay;               
00023 
00024         //
00025         T*              m_pParameter;   
00026 public:
00032         CControllerStep(const std::string& name, T* pParameter);
00037         CControllerStep(const std::string& name);
00041         virtual ~CControllerStep();
00048         virtual void Update(float dt);
00053         void Connect(T* pParameter);
00058         T& GetStep();
00063         float& GetDelay();
00068         T& GetStartVal();
00073         T& GetEndVal();
00074         
00075 
00076         CNTRL_CLASS_NAME(CControllerStep)
00077 
00078 };
00079 
00080 
00081 template<class T>
00082 CControllerStep<T>::CControllerStep(const std::string& name, T* pParameter) : 
00083         CController(name), 
00084         m_pParameter(pParameter),
00085         m_startVal(0),
00086         m_endVal(10),
00087         m_step(1),
00088         m_fDelay(1.0f)
00089 {
00090 #ifdef _JK2_VERBOSE
00091         LOGMsg("Creating Controller - %s (%s)", m_sName.c_str(), GetCntrlType());
00092 #endif
00093 }
00094 template<class T>
00095 CControllerStep<T>::CControllerStep(const std::string& name) : 
00096         CController(name), 
00097         m_pParameter(NULL),
00098         m_startVal(0),
00099         m_endVal(10),
00100         m_step(1),
00101         m_fDelay(1.0f)
00102 {
00103 #ifdef _JK2_VERBOSE
00104         LOGMsg("Creating Controller - %s (%s)", m_sName.c_str(), GetCntrlType());
00105 #endif
00106 }
00107 template<class T>
00108 CControllerStep<T>::~CControllerStep()
00109 {
00110 #ifdef _JK2_VERBOSE
00111         LOGMsg("Destroying Controller - %s (%s)", m_sName.c_str(), GetCntrlType());
00112 #endif
00113 }
00114 template<class T>
00115 void CControllerStep<T>::Update(float dt)
00116 {
00117         if(m_pParameter == NULL) return;
00118 
00119         m_fLocalTime += dt * m_fTimeScale;
00120 
00121         if(m_fLocalTime > m_fDelay) {
00122                 *m_pParameter += (m_endVal - m_startVal) / m_step;
00123                 m_fLocalTime = 0.0f;
00124         }
00125         if(*m_pParameter > m_endVal) {
00126 
00127                 if(m_eORT == ORT_LOOP) {
00128                         *m_pParameter = m_startVal;
00129                 } else {
00130                         m_eState = CLS_FINISHED;
00131                 }
00132         }
00133 }
00134 
00135 //set
00136 template<class T>
00137 void CControllerStep<T>::Connect(T* pParameter)
00138 {
00139         m_pParameter = pParameter;
00140 }
00141 
00142 //get - Address 
00143 template<class T>
00144 T& CControllerStep<T>::GetStep()
00145 {
00146         return m_step;
00147 }
00148 template<class T>
00149 float& CControllerStep<T>::GetDelay()
00150 {
00151         return m_fDelay;
00152 }
00153 template<class T>
00154 T& CControllerStep<T>::GetStartVal()
00155 {
00156         return m_startVal;
00157 }
00158 template<class T>
00159 T& CControllerStep<T>::GetEndVal()
00160 {
00161         return m_endVal;
00162 }