[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43598] trunk/blender: Committing patch "[ #29763] Adding an active_events property to SCA_PythonKeyboard and SCA_PythonMouse "

Mitchell Stokes mogurijin at gmail.com
Sun Jan 22 06:46:13 CET 2012


Revision: 43598
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43598
Author:   moguri
Date:     2012-01-22 05:45:56 +0000 (Sun, 22 Jan 2012)
Log Message:
-----------
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).

Modified Paths:
--------------
    trunk/blender/doc/python_api/rst/bge.types.rst
    trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.h
    trunk/blender/source/gameengine/GameLogic/SCA_PythonMouse.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PythonMouse.h

Modified: trunk/blender/doc/python_api/rst/bge.types.rst
===================================================================
--- trunk/blender/doc/python_api/rst/bge.types.rst	2012-01-22 04:39:33 UTC (rev 43597)
+++ trunk/blender/doc/python_api/rst/bge.types.rst	2012-01-22 05:45:56 UTC (rev 43598)
@@ -66,6 +66,12 @@
 
       :type: dictionary {:ref:`keycode<keyboard-keys>`::ref:`status<input-status>`, ...}
 
+   .. attribute:: active_events
+
+      A dictionary containing the status of only the active keyboard events or keys. (read-only).
+
+      :type: dictionary {:ref:`keycode<keyboard-keys>`::ref:`status<input-status>`, ...}
+
 .. class:: SCA_PythonMouse(PyObjectPlus)
 
    The current mouse.
@@ -75,6 +81,12 @@
       a dictionary containing the status of each mouse event. (read-only).
 
       :type: dictionary {:ref:`keycode<mouse-keys>`::ref:`status<input-status>`, ...}
+
+   .. attribute:: active_events
+
+      a dictionary containing the status of only the active mouse events. (read-only).
+
+      :type: dictionary {:ref:`keycode<mouse-keys>`::ref:`status<input-status>`, ...}
       
    .. attribute:: position
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp	2012-01-22 04:39:33 UTC (rev 43597)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp	2012-01-22 05:45:56 UTC (rev 43598)
@@ -84,6 +84,7 @@
 
 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 @@
 	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

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.h	2012-01-22 04:39:33 UTC (rev 43597)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonKeyboard.h	2012-01-22 05:45:56 UTC (rev 43598)
@@ -43,6 +43,7 @@
 
 #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
 };
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonMouse.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonMouse.cpp	2012-01-22 04:39:33 UTC (rev 43597)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonMouse.cpp	2012-01-22 05:45:56 UTC (rev 43598)
@@ -86,6 +86,7 @@
 
 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,7 +106,23 @@
 	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)
 {
 	SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonMouse.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonMouse.h	2012-01-22 04:39:33 UTC (rev 43597)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonMouse.h	2012-01-22 05:45:56 UTC (rev 43598)
@@ -48,6 +48,7 @@
 	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);



More information about the Bf-blender-cvs mailing list