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