Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SCA_ISensor.h

Go to the documentation of this file.
00001 #ifndef __SCA_ISENSOR
00002 #define __SCA_ISENSOR
00003 
00004 #include "SCA_ILogicBrick.h"
00005 
00006 
00007 
00011 class SCA_ISensor : public SCA_ILogicBrick
00012 {
00013         Py_Header;
00014         class SCA_EventManager* m_eventmgr;
00015         bool    m_triggered;
00016         /* pulse mode: one positive mode, one negative mode */
00017         bool m_pos_pulsemode;
00018         bool m_neg_pulsemode;
00019         int m_pos_pulse_frequency;
00020         int m_neg_pulse_frequency;
00021         int m_pos_ticks;
00022         int m_neg_ticks;
00023         /* invert the output signal*/
00024         bool m_invert;
00025         
00026 public:
00027         SCA_ISensor(SCA_IObject* gameobj,
00028                            class SCA_EventManager* eventmgr,
00029                            PyTypeObject* T ) :
00030                 SCA_ILogicBrick(gameobj,T),
00031                 m_triggered(false)
00032                 {
00033                         m_invert = false;
00034                         m_pos_ticks = 0;
00035                         m_neg_ticks = 0;
00036                         m_pos_pulsemode = false;
00037                         m_pos_pulse_frequency = 0;
00038                         m_neg_pulsemode = false;
00039                         m_neg_pulse_frequency = 0;
00040 
00041                         m_eventmgr = eventmgr;
00042                         //SetDrawColor(0xffffffff);
00043                 };
00044         ~SCA_ISensor()  {};
00045         virtual void    ReParent(SCA_IObject* parent);
00046 
00047         /* Because we want sensors to share some behaviour, the Activate has     */
00048         /* an implementation on this level. It requires an evaluate on the lower */
00049         /* level of individual sensors. Mapping the old activate()s is easy.     */
00050         /* The IsPosTrig() also has to change, to keep things consistent.        */
00051         void Activate(class SCA_LogicManager* logicmgr,CValue* event);
00052         virtual bool Evaluate(CValue* event) = 0;
00053         virtual bool IsPositiveTrigger() { 
00054                 bool result = false;
00055 
00056                 if (m_eventval) {
00057                         result = (m_eventval->GetNumber() != 0.0);
00058                 }
00059                 if (m_invert) {
00060                         result = !result;
00061                 }
00062                 
00063                 return result;
00064         }
00065 
00066         virtual PyObject*  _getattr(char *attr);
00067         virtual CValue* GetReplica()=0;
00068 
00069         void SetPulseMode(bool posmode, bool negmode,
00070                                           int posfreq, int negfreq) {
00071                 m_pos_pulsemode = posmode;
00072                 m_neg_pulsemode = negmode;
00073                 m_pos_pulse_frequency = posfreq;
00074                 m_neg_pulse_frequency = negfreq;
00075         };
00076         void SetInvert(bool inv) {
00077                 m_invert = inv;
00078         };
00079 
00080         
00081         void RegisterToManager();
00082         virtual float GetNumber() {
00083                 return IsPositiveTrigger();
00084         }
00085 
00086 
00087         /* Python functions: */
00088         KX_PYMETHOD_DOC(SCA_ISensor,IsPositive);
00089 
00091         KX_PYMETHOD_DOC(SCA_ISensor,GetUsePosPulseMode);
00093         KX_PYMETHOD_DOC(SCA_ISensor,SetUsePosPulseMode);
00095         KX_PYMETHOD_DOC(SCA_ISensor,GetPosFrequency);
00097         KX_PYMETHOD_DOC(SCA_ISensor,SetPosFrequency);
00099         KX_PYMETHOD_DOC(SCA_ISensor,GetUseNegPulseMode);
00101         KX_PYMETHOD_DOC(SCA_ISensor,SetUseNegPulseMode);
00103         KX_PYMETHOD_DOC(SCA_ISensor,GetNegFrequency);
00105         KX_PYMETHOD_DOC(SCA_ISensor,SetNegFrequency);
00107         KX_PYMETHOD_DOC(SCA_ISensor,GetInvert);
00109         KX_PYMETHOD_DOC(SCA_ISensor,SetInvert);
00110 
00111 };
00112 
00113 #endif //__SCA_ISENSOR

Generated at Thu Feb 1 13:03:10 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000