4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
30 /** \file SCA_IController.h
32 * \brief Interface Class for all logic Sensors. Implements
33 * pulsemode and pulsefrequency, and event suppression.
39 #include "SCA_IController.h"
44 * Interface Class for all logic Sensors. Implements
45 * pulsemode,pulsefrequency
46 * Use of SG_DList element: link sensors to their respective event manager
47 * Head: SCA_EventManager::m_sensors
48 * Use of SG_QList element: not used
50 class SCA_ISensor : public SCA_ILogicBrick
54 class SCA_EventManager* m_eventmgr;
56 /** Pulse positive pulses? */
59 /** Pulse negative pulses? */
62 /** Repeat frequency in pulse mode. */
63 int m_pulse_frequency;
65 /** Number of ticks since the last positive pulse. */
68 /** Number of ticks since the last negative pulse. */
71 /** invert the output signal*/
74 /** detect level instead of edge*/
80 /** sensor has been reset */
83 /** Sensor must ignore updates? */
86 /** number of connections to controller */
89 /** current sensor state */
92 /** previous state (for tap option) */
95 std::vector<class SCA_IController*> m_linkedcontrollers;
104 // to be updated as needed
107 SCA_ISensor(SCA_IObject* gameobj,
108 class SCA_EventManager* eventmgr);
110 virtual void ReParent(SCA_IObject* parent);
112 /** Because we want sensors to share some behaviour, the Activate has */
113 /* an implementation on this level. It requires an evaluate on the lower */
114 /* level of individual sensors. Mapping the old activate()s is easy. */
115 /* The IsPosTrig() also has to change, to keep things consistent. */
116 void Activate(class SCA_LogicManager* logicmgr);
117 virtual bool Evaluate() = 0;
118 virtual bool IsPositiveTrigger();
121 virtual CValue* GetReplica()=0;
123 /** Set parameters for the pulsing behaviour.
124 * @param posmode Trigger positive pulses?
125 * @param negmode Trigger negative pulses?
126 * @param freq Frequency to use when doing pulsing.
128 void SetPulseMode(bool posmode,
132 /** Set inversion of pulses on or off. */
133 void SetInvert(bool inv);
134 /** set the level detection on or off */
135 void SetLevel(bool lvl);
136 void SetTap(bool tap);
138 virtual void RegisterToManager();
139 virtual void UnregisterToManager();
140 void Replace_EventManager(class SCA_LogicManager* logicmgr);
141 void ReserveController(int num)
143 m_linkedcontrollers.reserve(num);
145 void LinkToController(SCA_IController* controller);
146 void UnlinkController(SCA_IController* controller);
147 void UnlinkAllControllers();
148 void ActivateControllers(class SCA_LogicManager* logicmgr);
150 virtual void ProcessReplica();
152 virtual double GetNumber();
154 virtual sensortype GetSensorType() { return ST_NONE; }
156 /** Stop sensing for a while. */
159 /** Is this sensor switched off? */
162 /** get the state of the sensor: positive or negative */
168 /** get the previous state of the sensor: positive or negative */
174 /** get the number of ticks since the last positive pulse */
180 /** get the number of ticks since the last negative pulse */
186 /** Resume sensing. */
192 { if (!m_links++) RegisterToManager(); }
194 bool IsNoLink() const
198 /* Python functions: */
199 KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,reset);
201 static PyObject* pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
202 static PyObject* pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
203 static PyObject* pyattr_get_status(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
204 static PyObject* pyattr_get_posTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
205 static PyObject* pyattr_get_negTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
207 static int pyattr_check_level(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
208 static int pyattr_check_tap(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
211 KX_SENSOR_INACTIVE = 0,
212 KX_SENSOR_JUST_ACTIVATED,
214 KX_SENSOR_JUST_DEACTIVATED
217 #endif // WITH_PYTHON
220 #endif //__SCA_ISENSOR