00001
00006
00007 #include "SCA_ISensor.h"
00008 #include "SCA_EventManager.h"
00009 #include "SCA_LogicManager.h"
00010 #include <stdio.h>
00011 void SCA_ISensor::ReParent(SCA_IObject* parent)
00012 {
00013 SCA_ILogicBrick::ReParent(parent);
00014 m_eventmgr->RegisterSensor(this);
00015 this->SetActive(false);
00016 }
00017
00018
00019 PyTypeObject SCA_ISensor::Type = {
00020 PyObject_HEAD_INIT(&PyType_Type)
00021 0,
00022 "SCA_ISensor",
00023 sizeof(SCA_ISensor),
00024 0,
00025 PyDestructor,
00026 0,
00027 __getattr,
00028 __setattr,
00029 0,
00030 __repr,
00031 0,
00032 0,
00033 0,
00034 0,
00035 0
00036 };
00037
00038 PyParentObject SCA_ISensor::Parents[] = {
00039 &SCA_ISensor::Type,
00040 &SCA_ILogicBrick::Type,
00041 &CValue::Type,
00042 NULL
00043 };
00044 PyMethodDef SCA_ISensor::Methods[] = {
00045 {"isPositive", (PyCFunction) SCA_ISensor::sPyIsPositive, METH_VARARGS},
00046 {"getUsePosPulseMode", (PyCFunction) SCA_ISensor::sPyGetUsePosPulseMode, METH_VARARGS, GetUsePosPulseMode_doc},
00047 {"setUsePosPulseMode", (PyCFunction) SCA_ISensor::sPySetUsePosPulseMode, METH_VARARGS, SetUsePosPulseMode_doc},
00048 {"getPosFrequency", (PyCFunction) SCA_ISensor::sPyGetPosFrequency, METH_VARARGS, GetPosFrequency_doc},
00049 {"setPosFrequency", (PyCFunction) SCA_ISensor::sPySetPosFrequency, METH_VARARGS, SetPosFrequency_doc},
00050 {"getUseNegPulseMode", (PyCFunction) SCA_ISensor::sPyGetUseNegPulseMode, METH_VARARGS, GetUseNegPulseMode_doc},
00051 {"setUseNegPulseMode", (PyCFunction) SCA_ISensor::sPySetUseNegPulseMode, METH_VARARGS, SetUseNegPulseMode_doc},
00052 {"getNegFrequency", (PyCFunction) SCA_ISensor::sPyGetNegFrequency, METH_VARARGS, GetNegFrequency_doc},
00053 {"setNegFrequency", (PyCFunction) SCA_ISensor::sPySetNegFrequency, METH_VARARGS, SetNegFrequency_doc},
00054 {"getInvert", (PyCFunction) SCA_ISensor::sPyGetInvert, METH_VARARGS, GetInvert_doc},
00055 {"setInvert", (PyCFunction) SCA_ISensor::sPySetInvert, METH_VARARGS, SetInvert_doc},
00056 {NULL,NULL}
00057 };
00058
00059
00060 PyObject*
00061 SCA_ISensor::_getattr(char* attr)
00062 {
00063 _getattr_up(SCA_ILogicBrick);
00064 }
00065
00066
00067 void SCA_ISensor::RegisterToManager()
00068 {
00069 m_eventmgr->RegisterSensor(this);
00070 }
00071
00072 void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event)
00073 {
00074
00075
00076 bool result = this->Evaluate(event);
00077 if (result) {
00078 logicmgr->AddActivatedSensor(this);
00079 } else
00080 {
00081
00082 if (m_pos_pulsemode) {
00083 m_pos_ticks++;
00084 if (m_pos_ticks > m_pos_pulse_frequency) {
00085 if (this->IsPositiveTrigger())
00086 {
00087 logicmgr->AddActivatedSensor(this);
00088 }
00089 m_pos_ticks = 0;
00090 }
00091 }
00092
00093 if (m_neg_pulsemode)
00094 {
00095 m_neg_ticks++;
00096 if (m_neg_ticks > m_neg_pulse_frequency) {
00097 if (!this->IsPositiveTrigger())
00098 {
00099 logicmgr->AddActivatedSensor(this);
00100 }
00101 m_neg_ticks = 0;
00102 }
00103 }
00104 }
00105 }
00106
00107
00108 char SCA_ISensor::IsPositive_doc[] =
00109 "isPositive()\n"
00110 "\tReturns TRUE if sensor is Positive (result of the check that the sensor evaluates, like collision or keypress),\n"
00111 "\tFALSE if sensor result is Negative.\n" ;
00112 PyObject* SCA_ISensor::PyIsPositive(PyObject* self, PyObject* args, PyObject* kwds)
00113 {
00114 int retval = IsPositiveTrigger();
00115 return PyInt_FromLong(retval);
00116 }
00117
00121 char SCA_ISensor::GetUsePosPulseMode_doc[] =
00122 "getUsePosPulseMode()\n"
00123 "\tReturns KX_TRUE if positive pulse mode is active,\n"
00124 "\tKX_FALSE if positive pulse mode is not active.\n" ;
00125 PyObject* SCA_ISensor::PyGetUsePosPulseMode(PyObject* self, PyObject* args, PyObject* kwds)
00126 {
00127 int retval = 0;
00128
00129 if (m_pos_pulsemode) {
00130 retval = KX_TRUE;
00131 } else {
00132 retval = KX_FALSE;
00133 }
00134
00135 return PyInt_FromLong(retval);
00136 }
00137
00141 char SCA_ISensor::SetUsePosPulseMode_doc[] =
00142 "setUsePosPulseMode(flag)\n"
00143 "\t- flag: KX_TRUE or KX_FALSE.\n"
00144 "\tSet flag to KX_TRUE to switch on positive pulse mode,\n"
00145 "\tKX_FALSE to switch off positive pulse mode.\n" ;
00146 PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* self, PyObject* args, PyObject* kwds)
00147 {
00148 int pulseArg = 0;
00149
00150 if(!PyArg_ParseTuple(args, "i", &pulseArg)) {
00151 return NULL;
00152 }
00153
00154 if (pulseArg == KX_TRUE) {
00155 m_pos_pulsemode = true;
00156 } else if (pulseArg == KX_FALSE){
00157 m_pos_pulsemode = false;
00158 } else {
00159 ;
00160 }
00161
00162 Py_Return;
00163 }
00164
00168 char SCA_ISensor::GetPosFrequency_doc[] =
00169 "getPosFrequency()\n"
00170 "\tReturn the frequency of the updates in positive pulse mode.\n" ;
00171 PyObject* SCA_ISensor::PyGetPosFrequency(PyObject* self, PyObject* args, PyObject* kwds)
00172 {
00173 return PyInt_FromLong(m_pos_pulse_frequency);
00174 }
00175
00179 char SCA_ISensor::SetPosFrequency_doc[] =
00180 "setPosFrequency(pulse_frequency)\n"
00181 "\t- pulse_frequency: integer"
00182 "\tSet the frequency of the updates in positive pulse mode.\n"
00183 "\tIf the frequency is negative, it is set to 0.\n" ;
00184 PyObject* SCA_ISensor::PySetPosFrequency(PyObject* self, PyObject* args, PyObject* kwds)
00185 {
00186 int pulse_frequencyArg = 0;
00187
00188 if(!PyArg_ParseTuple(args, "i", &pulse_frequencyArg)) {
00189 return NULL;
00190 }
00191
00192
00193
00194 if (pulse_frequencyArg < 0) {
00195 pulse_frequencyArg = 0;
00196 };
00197 m_pos_pulse_frequency = pulse_frequencyArg;
00198
00199 Py_Return;
00200 }
00201
00202
00206 char SCA_ISensor::GetInvert_doc[] =
00207 "getInvert()\n"
00208 "\tReturns whether or not pulses from this sensor are inverted.\n" ;
00209 PyObject* SCA_ISensor::PyGetInvert(PyObject* self, PyObject* args, PyObject* kwds)
00210 {
00211 return PyInt_FromLong(m_invert);
00212 }
00213
00217 char SCA_ISensor::SetInvert_doc[] =
00218 "setInvert(invert)\n"
00219 "\t- invert: KX_TRUE or KX_FALSE\n"
00220 "\tSet to KX_TRUE to invert the responses of this sendor,\n"
00221 "\tset to KX_FALSE to keep the normal response.\n" ;
00222 PyObject* SCA_ISensor::PySetInvert(PyObject* self, PyObject* args, PyObject* kwds)
00223 {
00224 int invertArg = 0;
00225
00226 if(!PyArg_ParseTuple(args, "i", &invertArg)) {
00227 return NULL;
00228 }
00229
00230 if (invertArg == KX_TRUE) {
00231 m_invert = true;
00232 } else if (invertArg == KX_FALSE){
00233 m_invert = false;
00234 } else {
00235 ;
00236 }
00237
00238 Py_Return;
00239 }
00240
00244 char SCA_ISensor::GetUseNegPulseMode_doc[] =
00245 "getUseNegPulseMode()\n"
00246 "\tReturns KX_TRUE if negative pulse mode is active,\n"
00247 "\tKX_FALSE if negative pulse mode is not active.\n" ;
00248 PyObject* SCA_ISensor::PyGetUseNegPulseMode(PyObject* self, PyObject* args, PyObject* kwds)
00249 {
00250 int retval = 0;
00251
00252 if (m_neg_pulsemode) {
00253 retval = KX_TRUE;
00254 } else {
00255 retval = KX_FALSE;
00256 }
00257
00258 return PyInt_FromLong(retval);
00259 }
00260
00264 char SCA_ISensor::SetUseNegPulseMode_doc[] =
00265 "setUseNegPulseMode(flag)\n"
00266 "\t- flag: KX_TRUE or KX_FALSE.\n"
00267 "\tSet flag to KX_TRUE to switch on negative pulse mode,\n"
00268 "\tKX_FALSE to switch off negative pulse mode.\n" ;
00269 PyObject* SCA_ISensor::PySetUseNegPulseMode(PyObject* self, PyObject* args, PyObject* kwds)
00270 {
00271 int pulseArg = 0;
00272
00273 if(!PyArg_ParseTuple(args, "i", &pulseArg)) {
00274 return NULL;
00275 }
00276
00277 if (pulseArg == KX_TRUE) {
00278 m_neg_pulsemode = true;
00279 } else if (pulseArg == KX_FALSE){
00280 m_neg_pulsemode = false;
00281 } else {
00282 ;
00283 }
00284
00285 Py_Return;
00286 }
00287
00291 char SCA_ISensor::GetNegFrequency_doc[] =
00292 "getNegFrequency()\n"
00293 "\tReturn the frequency of the updates in negative pulse mode.\n" ;
00294 PyObject* SCA_ISensor::PyGetNegFrequency(PyObject* self, PyObject* args, PyObject* kwds)
00295 {
00296 return PyInt_FromLong(m_neg_pulse_frequency);
00297 }
00298
00302 char SCA_ISensor::SetNegFrequency_doc[] =
00303 "setNegFrequency(pulse_frequency)\n"
00304 "\t- pulse_frequency: integer"
00305 "\tSet the frequency of the updates in negative pulse mode.\n"
00306 "\tIf the frequency is negative, it is set to 0.\n" ;
00307 PyObject* SCA_ISensor::PySetNegFrequency(PyObject* self, PyObject* args, PyObject* kwds)
00308 {
00309 int pulse_frequencyArg = 0;
00310
00311 if(!PyArg_ParseTuple(args, "i", &pulse_frequencyArg)) {
00312 return NULL;
00313 }
00314
00315
00316
00317 if (pulse_frequencyArg < 0) {
00318 pulse_frequencyArg = 0;
00319 };
00320 m_neg_pulse_frequency = pulse_frequencyArg;
00321
00322 Py_Return;
00323 }
00324
00325
00326