Skip to content

Commit

Permalink
UPBGE: Implement SCA_InputEvent attribute helpers.
Browse files Browse the repository at this point in the history
Previously the user needed to read the values or queue list
in an input to know if it was active, inactive, activated or
released.
To simplify this and avoid the lookup in list from python
attributes are added in SCA_InputEvent to do the same, they
are:
inactive
active
activated
released

Note that when they are the status of the input from the last
frame so when an input is released then it is both active
and inactive.
  • Loading branch information
panzergame committed Sep 3, 2017
1 parent f223fff commit 767b9ad
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc/python_api/rst/bge_types/bge.types.SCA_InputEvent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ base class --- :class:`PyObjectPlus`
:type: list of integer.

.. attribute:: inactive

True if the input was inactive from the last frame.

:type: boolean

.. attribute:: active

True if the input was active from the last frame.

:type: boolean

.. attribute:: activated

True if the input was activated from the last frame.

:type: boolean

.. attribute:: released

True if the input was released from the last frame.

:type: boolean

.. attribute:: type

The type of the input.
Expand Down
32 changes: 32 additions & 0 deletions source/gameengine/GameLogic/SCA_InputEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ PyAttributeDef SCA_InputEvent::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("status", SCA_InputEvent, pyattr_get_status),
KX_PYATTRIBUTE_RO_FUNCTION("queue", SCA_InputEvent, pyattr_get_queue),
KX_PYATTRIBUTE_RO_FUNCTION("values", SCA_InputEvent, pyattr_get_values),
KX_PYATTRIBUTE_RO_FUNCTION("inactive", SCA_InputEvent, pyattr_get_inactive),
KX_PYATTRIBUTE_RO_FUNCTION("active", SCA_InputEvent, pyattr_get_active),
KX_PYATTRIBUTE_RO_FUNCTION("activated", SCA_InputEvent, pyattr_get_activated),
KX_PYATTRIBUTE_RO_FUNCTION("released", SCA_InputEvent, pyattr_get_released),
KX_PYATTRIBUTE_INT_RO("type", SCA_InputEvent, m_type),
KX_PYATTRIBUTE_NULL //Sentinel
};
Expand Down Expand Up @@ -191,4 +195,32 @@ PyObject *SCA_InputEvent::pyattr_get_values(PyObjectPlus *self_v, const KX_PYATT
CListWrapper::FLAG_FIND_VALUE))->NewProxy(true);
}

PyObject *SCA_InputEvent::pyattr_get_inactive(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
SCA_InputEvent *self = static_cast<SCA_InputEvent *>(self_v);

return PyBool_FromLong(self->Find(SCA_InputEvent::NONE));
}

PyObject *SCA_InputEvent::pyattr_get_active(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
SCA_InputEvent *self = static_cast<SCA_InputEvent *>(self_v);

return PyBool_FromLong(self->Find(SCA_InputEvent::ACTIVE));
}

PyObject *SCA_InputEvent::pyattr_get_activated(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
SCA_InputEvent *self = static_cast<SCA_InputEvent *>(self_v);

return PyBool_FromLong(self->Find(SCA_InputEvent::JUSTACTIVATED));
}

PyObject *SCA_InputEvent::pyattr_get_released(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
SCA_InputEvent *self = static_cast<SCA_InputEvent *>(self_v);

return PyBool_FromLong(self->Find(SCA_InputEvent::JUSTRELEASED));
}

#endif // WITH_PYTHON
4 changes: 4 additions & 0 deletions source/gameengine/GameLogic/SCA_InputEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ Py_Header
static PyObject *pyattr_get_status(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject *pyattr_get_queue(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject *pyattr_get_values(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject *pyattr_get_inactive(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject *pyattr_get_active(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject *pyattr_get_activated(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject *pyattr_get_released(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
#endif
};

Expand Down

0 comments on commit 767b9ad

Please sign in to comment.