Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Stokes <mogurijin@gmail.com>2012-01-22 09:45:56 +0400
committerMitchell Stokes <mogurijin@gmail.com>2012-01-22 09:45:56 +0400
commit57d48d4493a78d2886f83a28fe66c2654bed4f6c (patch)
tree205e5116b6f6dd9f6031fb1a858559a240b6abbf /source/gameengine/GameLogic
parent4ec5a9a42c00d65898e8a4aef5b73409a5e1785f (diff)
Committing patch "[#29763] Adding an active_events property to SCA_PythonKeyboard and SCA_PythonMouse"
Here is the description: As the summary says, this patch adds a new event to both SCA_PythonKeyboard and SCA_PythonMouse. This property is similar to the events property that both have, but it only returns events which are not KX_NO_INPUTSTATUS. This moves the "no input" check from Python to C, which gave my input handling code a 2x speed up. Python sucks (performance-wise) with iterating lists and SCA_PythonKeyboard has close to 200 events (I think something like 177, but I don't know for sure).
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r--source/gameengine/GameLogic/SCA_PythonKeyboard.cpp18
-rw-r--r--source/gameengine/GameLogic/SCA_PythonKeyboard.h1
-rw-r--r--source/gameengine/GameLogic/SCA_PythonMouse.cpp17
-rw-r--r--source/gameengine/GameLogic/SCA_PythonMouse.h1
4 files changed, 37 insertions, 0 deletions
diff --git a/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp b/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
index 9c7f3831567..46c43b5e339 100644
--- a/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
@@ -84,6 +84,7 @@ PyMethodDef SCA_PythonKeyboard::Methods[] = {
PyAttributeDef SCA_PythonKeyboard::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_PythonKeyboard, pyattr_get_events),
+ KX_PYATTRIBUTE_RO_FUNCTION("active_events", SCA_PythonKeyboard, pyattr_get_active_events),
{ NULL } //Sentinel
};
@@ -101,4 +102,21 @@ PyObject* SCA_PythonKeyboard::pyattr_get_events(void *self_v, const KX_PYATTRIBU
return self->m_event_dict;
}
+PyObject* SCA_PythonKeyboard::pyattr_get_active_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_PythonKeyboard* self = static_cast<SCA_PythonKeyboard*>(self_v);
+
+ PyDict_Clear(self->m_event_dict);
+
+ for (int i=SCA_IInputDevice::KX_BEGINKEY; i<=SCA_IInputDevice::KX_ENDKEY; i++)
+ {
+ const SCA_InputEvent & inevent = self->m_keyboard->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
+
+ if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
+ PyDict_SetItem(self->m_event_dict, PyLong_FromSsize_t(i), PyLong_FromSsize_t(inevent.m_status));
+ }
+ Py_INCREF(self->m_event_dict);
+ return self->m_event_dict;
+}
+
#endif
diff --git a/source/gameengine/GameLogic/SCA_PythonKeyboard.h b/source/gameengine/GameLogic/SCA_PythonKeyboard.h
index 7ecf76d1581..f44bb40e13c 100644
--- a/source/gameengine/GameLogic/SCA_PythonKeyboard.h
+++ b/source/gameengine/GameLogic/SCA_PythonKeyboard.h
@@ -43,6 +43,7 @@ public:
#ifdef WITH_PYTHON
static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_active_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
#endif
};
diff --git a/source/gameengine/GameLogic/SCA_PythonMouse.cpp b/source/gameengine/GameLogic/SCA_PythonMouse.cpp
index 4f06445a79f..cdbeaba2235 100644
--- a/source/gameengine/GameLogic/SCA_PythonMouse.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonMouse.cpp
@@ -86,6 +86,7 @@ PyMethodDef SCA_PythonMouse::Methods[] = {
PyAttributeDef SCA_PythonMouse::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_PythonMouse, pyattr_get_events),
+ KX_PYATTRIBUTE_RO_FUNCTION("active_events", SCA_PythonMouse, pyattr_get_active_events),
KX_PYATTRIBUTE_RW_FUNCTION("position", SCA_PythonMouse, pyattr_get_position, pyattr_set_position),
KX_PYATTRIBUTE_RW_FUNCTION("visible", SCA_PythonMouse, pyattr_get_visible, pyattr_set_visible),
{ NULL } //Sentinel
@@ -105,6 +106,22 @@ PyObject* SCA_PythonMouse::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_
return self->m_event_dict;
}
+PyObject* SCA_PythonMouse::pyattr_get_active_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
+
+ PyDict_Clear(self->m_event_dict);
+
+ for (int i=SCA_IInputDevice::KX_BEGINMOUSE; i<=SCA_IInputDevice::KX_ENDMOUSE; i++)
+ {
+ const SCA_InputEvent & inevent = self->m_mouse->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
+
+ if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
+ PyDict_SetItem(self->m_event_dict, PyLong_FromSsize_t(i), PyLong_FromSsize_t(inevent.m_status));
+ }
+ Py_INCREF(self->m_event_dict);
+ return self->m_event_dict;
+}
PyObject* SCA_PythonMouse::pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
diff --git a/source/gameengine/GameLogic/SCA_PythonMouse.h b/source/gameengine/GameLogic/SCA_PythonMouse.h
index 4ad655dce8f..41d286a8048 100644
--- a/source/gameengine/GameLogic/SCA_PythonMouse.h
+++ b/source/gameengine/GameLogic/SCA_PythonMouse.h
@@ -48,6 +48,7 @@ public:
KX_PYMETHOD_DOC(SCA_PythonMouse, show);
static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static PyObject* pyattr_get_active_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
static int pyattr_set_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject* value);
static PyObject* pyattr_get_visible(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);