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
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
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
00043 };
00044 ~SCA_ISensor() {};
00045 virtual void ReParent(SCA_IObject* parent);
00046
00047
00048
00049
00050
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
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