Blender V2.61 - r43446

SCA_ISensor.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00034 #ifndef __SCA_ISENSOR
00035 #define __SCA_ISENSOR
00036 
00037 #include "SCA_IController.h"
00038 
00039 #include <vector>
00040 
00048 class SCA_ISensor : public SCA_ILogicBrick
00049 {
00050     Py_Header
00051 protected:
00052     class SCA_EventManager* m_eventmgr;
00053 
00055     bool m_pos_pulsemode;
00056 
00058     bool m_neg_pulsemode;
00059 
00061     int m_pulse_frequency;
00062 
00064     int m_pos_ticks;
00065 
00067     int m_neg_ticks;
00068 
00070     bool m_invert;
00071 
00073     bool m_level;
00074 
00076     bool m_tap;
00077 
00079     bool m_reset;
00080 
00082     bool m_suspended;
00083 
00085     int m_links;
00086 
00088     bool m_state;
00089 
00091     bool m_prev_state;
00092 
00093     std::vector<class SCA_IController*>     m_linkedcontrollers;
00094 
00095 public:
00096 
00097     enum sensortype {
00098         ST_NONE = 0,
00099         ST_TOUCH,
00100         ST_NEAR,
00101         ST_RADAR,
00102         // to be updated as needed
00103     };
00104 
00105     SCA_ISensor(SCA_IObject* gameobj,
00106                 class SCA_EventManager* eventmgr);
00107     ~SCA_ISensor();
00108     virtual void    ReParent(SCA_IObject* parent);
00109 
00111     /* an implementation on this level. It requires an evaluate on the lower */
00112     /* level of individual sensors. Mapping the old activate()s is easy.     */
00113     /* The IsPosTrig() also has to change, to keep things consistent.        */
00114     void Activate(class SCA_LogicManager* logicmgr);
00115     virtual bool Evaluate() = 0;
00116     virtual bool IsPositiveTrigger();
00117     virtual void Init();
00118 
00119     virtual CValue* GetReplica()=0;
00120 
00126     void SetPulseMode(bool posmode,
00127                       bool negmode,
00128                       int freq);
00129     
00131     void SetInvert(bool inv);
00133     void SetLevel(bool lvl);
00134     void SetTap(bool tap);
00135 
00136     virtual void RegisterToManager();
00137     virtual void UnregisterToManager();
00138     void Replace_EventManager(class SCA_LogicManager* logicmgr);
00139     void ReserveController(int num)
00140     {
00141         m_linkedcontrollers.reserve(num);
00142     }
00143     void LinkToController(SCA_IController* controller);
00144     void UnlinkController(SCA_IController* controller);
00145     void UnlinkAllControllers();
00146     void ActivateControllers(class SCA_LogicManager* logicmgr);
00147 
00148     virtual void ProcessReplica();
00149 
00150     virtual double GetNumber();
00151 
00152     virtual sensortype GetSensorType() { return ST_NONE; }
00153 
00155     void Suspend();
00156 
00158     bool IsSuspended();
00159     
00161     bool GetState()
00162     {
00163         return m_state;
00164     }
00165     
00167     bool GetPrevState()
00168     {
00169         return m_prev_state;
00170     }
00171 
00173     int GetPosTicks()
00174     {
00175         return m_pos_ticks;
00176     }
00177 
00179     int GetNegTicks()
00180     {
00181         return m_neg_ticks;
00182     }
00183 
00185     void Resume();
00186 
00187     void ClrLink()
00188         { m_links = 0; }
00189     void IncLink()
00190         { if (!m_links++) RegisterToManager(); }
00191     void DecLink();
00192     bool IsNoLink() const 
00193         { return !m_links; }
00194 
00195 #ifdef WITH_PYTHON
00196     /* Python functions: */
00197     KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,reset);
00198     
00199     static PyObject*    pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00200     static PyObject*    pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00201     static PyObject*    pyattr_get_status(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00202     static PyObject*    pyattr_get_posTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00203     static PyObject*    pyattr_get_negTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00204 
00205     static int          pyattr_check_level(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00206     static int          pyattr_check_tap(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00207     
00208     enum SensorStatus {
00209         KX_SENSOR_INACTIVE = 0,
00210         KX_SENSOR_JUST_ACTIVATED,
00211         KX_SENSOR_ACTIVE,
00212         KX_SENSOR_JUST_DEACTIVATED
00213     
00214     };
00215 #endif // WITH_PYTHON
00216 };
00217 
00218 #endif //__SCA_ISENSOR
00219