Merged 15170:15635 from trunk (no conflicts or even merges)
This commit is contained in:
@@ -52,8 +52,11 @@ SCA_ISensor::SCA_ISensor(SCA_IObject* gameobj,
|
||||
SCA_ILogicBrick(gameobj,T),
|
||||
m_triggered(false)
|
||||
{
|
||||
m_links = 0;
|
||||
m_suspended = false;
|
||||
m_invert = false;
|
||||
m_level = false;
|
||||
m_reset = false;
|
||||
m_pos_ticks = 0;
|
||||
m_neg_ticks = 0;
|
||||
m_pos_pulsemode = false;
|
||||
@@ -94,6 +97,10 @@ void SCA_ISensor::SetInvert(bool inv) {
|
||||
m_invert = inv;
|
||||
}
|
||||
|
||||
void SCA_ISensor::SetLevel(bool lvl) {
|
||||
m_level = lvl;
|
||||
}
|
||||
|
||||
|
||||
float SCA_ISensor::GetNumber() {
|
||||
return IsPositiveTrigger();
|
||||
@@ -111,6 +118,25 @@ void SCA_ISensor::Resume() {
|
||||
m_suspended = false;
|
||||
}
|
||||
|
||||
void SCA_ISensor::Init() {
|
||||
printf("Sensor %s has no init function, please report this bug to Blender.org\n", m_name.Ptr());
|
||||
}
|
||||
|
||||
void SCA_ISensor::DecLink() {
|
||||
m_links--;
|
||||
if (m_links < 0)
|
||||
{
|
||||
printf("Warning: sensor %s has negative m_links: %d\n", m_name.Ptr(), m_links);
|
||||
m_links = 0;
|
||||
}
|
||||
if (!m_links)
|
||||
{
|
||||
// sensor is detached from all controllers, initialize it so that it
|
||||
// is fresh as at startup when it is reattached again.
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
/* python integration */
|
||||
|
||||
PyTypeObject SCA_ISensor::Type = {
|
||||
@@ -157,6 +183,10 @@ PyMethodDef SCA_ISensor::Methods[] = {
|
||||
METH_VARARGS, GetInvert_doc},
|
||||
{"setInvert", (PyCFunction) SCA_ISensor::sPySetInvert,
|
||||
METH_VARARGS, SetInvert_doc},
|
||||
{"getLevel", (PyCFunction) SCA_ISensor::sPyGetLevel,
|
||||
METH_VARARGS, GetLevel_doc},
|
||||
{"setLevel", (PyCFunction) SCA_ISensor::sPySetLevel,
|
||||
METH_VARARGS, SetLevel_doc},
|
||||
{NULL,NULL} //Sentinel
|
||||
};
|
||||
|
||||
@@ -177,7 +207,8 @@ void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event)
|
||||
{
|
||||
|
||||
// calculate if a __triggering__ is wanted
|
||||
if (!m_suspended) {
|
||||
// don't evaluate a sensor that is not connected to any controller
|
||||
if (m_links && !m_suspended) {
|
||||
bool result = this->Evaluate(event);
|
||||
if (result) {
|
||||
logicmgr->AddActivatedSensor(this);
|
||||
@@ -307,6 +338,31 @@ PyObject* SCA_ISensor::PySetInvert(PyObject* self, PyObject* args, PyObject* kwd
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
char SCA_ISensor::GetLevel_doc[] =
|
||||
"getLevel()\n"
|
||||
"\tReturns whether this sensor is a level detector or a edge detector.\n"
|
||||
"\tIt makes a difference only in case of logic state transition (state actuator).\n"
|
||||
"\tA level detector will immediately generate a pulse if the condition for the\n"
|
||||
"\tdetector is met when entering the state. A edge detector will wait for an off-on\n"
|
||||
"\ttransition to occur.\n"
|
||||
"\tOnly some sensors implement this feature: keyboard.\n";
|
||||
PyObject* SCA_ISensor::PyGetLevel(PyObject* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
return BoolToPyArg(m_level);
|
||||
}
|
||||
|
||||
char SCA_ISensor::SetLevel_doc[] =
|
||||
"setLevel(level?)\n"
|
||||
"\t- level?: Detect level instead of edge? (KX_TRUE, KX_FALSE)\n"
|
||||
"\tSet whether to detect level or edge transition when entering a state.\n";
|
||||
PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
int pyarg = 0;
|
||||
if(!PyArg_ParseTuple(args, "i", &pyarg)) { return NULL; }
|
||||
m_level = PyArgToBool(pyarg);
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
char SCA_ISensor::GetUseNegPulseMode_doc[] =
|
||||
"getUseNegPulseMode()\n"
|
||||
"\tReturns whether negative pulse mode is active.\n";
|
||||
|
||||
Reference in New Issue
Block a user