BGE Python API
authorCampbell Barton <ideasman42@gmail.com>
Mon, 6 Apr 2009 13:27:28 +0000 (13:27 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 6 Apr 2009 13:27:28 +0000 (13:27 +0000)
- added a module for the BGE - GameTypes, only contains types.
- added KX_PYATTRIBUTE_DUMMY attributes for KX_Light, KX_PolyProxy, KX_VertexProxy, so all types should give correct results from a dir().
- added a script to check for missing methods in the epydocs - bge_api_validate_py.txt

source/gameengine/GameLogic/SCA_MouseSensor.cpp
source/gameengine/Ketsji/KX_Light.cpp
source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
source/gameengine/Ketsji/KX_PolyProxy.cpp
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/Ketsji/KX_PythonInitTypes.cpp
source/gameengine/Ketsji/KX_VertexProxy.cpp
source/gameengine/PyDoc/bge_api_validate_py.txt [new file with mode: 0644]

index c5f6fdabbe876a9cb3065a857d6f7274ccca7678..3cd32391ce2f3cfcab569003f3b3b7bf34c2d4d0 100644 (file)
@@ -275,7 +275,7 @@ PyObject* SCA_MouseSensor::PyGetYPosition(PyObject* self,
 
 KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus,
 "getButtonStatus(button)\n"
-"\tGet the given button's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n")
+"\tGet the given button's status (KX_INPUT_NONE, KX_INPUT_NONE, KX_INPUT_JUST_ACTIVATED, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED).\n")
 {
        if (PyInt_Check(value))
        {
index 6f9d8b0211b4afa143a14e019070913bca6679b8..7b5b77ccacfce2ff689aa032c7bb7d08714f328c 100644 (file)
@@ -236,7 +236,7 @@ int       KX_LightObject::py_setattro(PyObject *attr, PyObject *pyvalue)
                }
        }
        
-       if (PyFloat_Check(pyvalue))
+       if (PyFloat_Check(pyvalue) || PyInt_Check(pyvalue))
        {
                float value = PyFloat_AsDouble(pyvalue);
                if (!strcmp(attr_str, "energy"))
@@ -306,10 +306,22 @@ PyMethodDef KX_LightObject::Methods[] = {
 };
 
 PyAttributeDef KX_LightObject::Attributes[] = {
+       KX_PYATTRIBUTE_DUMMY("layer"),
+       KX_PYATTRIBUTE_DUMMY("energy"),
+       KX_PYATTRIBUTE_DUMMY("distance"),
+       KX_PYATTRIBUTE_DUMMY("colour"),
+       KX_PYATTRIBUTE_DUMMY("color"),
+       KX_PYATTRIBUTE_DUMMY("lin_attenuation"),
+       KX_PYATTRIBUTE_DUMMY("quad_attenuation"),
+       KX_PYATTRIBUTE_DUMMY("spotsize"),
+       KX_PYATTRIBUTE_DUMMY("spotblend"),
+       KX_PYATTRIBUTE_DUMMY("SPOT"),
+       KX_PYATTRIBUTE_DUMMY("SUN"),
+       KX_PYATTRIBUTE_DUMMY("NORMAL"),
+       KX_PYATTRIBUTE_DUMMY("type"),
        { NULL }        //Sentinel
 };
 
-
 PyTypeObject KX_LightObject::Type = {
        PyObject_HEAD_INIT(NULL)
                0,
index 72a0381e8dca052972328c379b451a35e8e80ab6..4afc6d6f1b8ccb0a4d4acf0a38f53d3421f395c2 100644 (file)
@@ -343,7 +343,7 @@ PyObject* KX_MouseFocusSensor::py_getattro(PyObject *attr) {
 
 const char KX_MouseFocusSensor::GetHitObject_doc[] = 
 "getHitObject()\n"
-"\tReturns the name of the object that was hit by this ray.\n";
+"\tReturns the object that was hit by this ray.\n";
 PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self)
 {
        if (m_hitObject)
@@ -374,7 +374,7 @@ PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self)
 
 const char KX_MouseFocusSensor::GetHitNormal_doc[] = 
 "getHitNormal()\n"
-"\tReturns the normal (in worldcoordinates) of the object at the location where the object was hit by this ray.\n";
+"\tReturns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray.\n";
 PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self)
 {
        return PyObjectFrom(m_hitNormal);
index 6f74c3ed3f901782cfed79c00380bf8fa788e5e3..39eb622586418676099ddbb374d9e81893b30ae7 100644 (file)
@@ -78,6 +78,17 @@ PyMethodDef KX_PolyProxy::Methods[] = {
 };
 
 PyAttributeDef KX_PolyProxy::Attributes[] = {
+       /* All dummy's so they come up in a dir() */
+       KX_PYATTRIBUTE_DUMMY("matname"),
+       KX_PYATTRIBUTE_DUMMY("texture"),
+       KX_PYATTRIBUTE_DUMMY("material"),
+       KX_PYATTRIBUTE_DUMMY("matid"),
+       KX_PYATTRIBUTE_DUMMY("v1"),
+       KX_PYATTRIBUTE_DUMMY("v2"),
+       KX_PYATTRIBUTE_DUMMY("v3"),
+       KX_PYATTRIBUTE_DUMMY("v4"),
+       KX_PYATTRIBUTE_DUMMY("visible"),
+       KX_PYATTRIBUTE_DUMMY("collide"),
        { NULL }        //Sentinel
 };
 
index 9929e66c3a4cf89677a2f38743357caa222fdecd..9a6565d76273e4e3fce5824c06812abd6795f131 100644 (file)
@@ -1099,9 +1099,9 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
        KX_MACRO_addTypesToDict(d, KX_INPUT_ACTIVE, SCA_InputEvent::KX_ACTIVE);
        KX_MACRO_addTypesToDict(d, KX_INPUT_JUST_RELEASED, SCA_InputEvent::KX_JUSTRELEASED);
        
-       KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_LEFT, SCA_InputEvent::KX_LEFTMOUSE);
-       KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_InputEvent::KX_MIDDLEMOUSE);
-       KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_InputEvent::KX_RIGHTMOUSE);
+       KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_LEFT, SCA_IInputDevice::KX_LEFTMOUSE);
+       KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_IInputDevice::KX_MIDDLEMOUSE);
+       KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_IInputDevice::KX_RIGHTMOUSE);
 
        // Check for errors
        if (PyErr_Occurred())
index 8eeed5d853b2ee44bb64ceaa80a782e888606e3b..29a7a5f85f2f3cb167f15d88020c944f6e4fcf40 100644 (file)
@@ -129,6 +129,13 @@ void initPyObjectPlusType(PyTypeObject **parents)
 
 
 
+static int PyType_Ready_ADD(PyObject *dict, PyTypeObject * tp)
+{
+       PyType_Ready(tp);
+       PyDict_SetItemString(dict, tp->tp_name, (PyObject *)tp);
+}
+
+
 void initPyTypes(void)
 {
        
@@ -138,69 +145,76 @@ void initPyTypes(void)
 */
 
        /* For now just do PyType_Ready */
-
-       PyType_Ready(&BL_ActionActuator::Type);
-       PyType_Ready(&BL_Shader::Type);
-       PyType_Ready(&BL_ShapeActionActuator::Type);
-       PyType_Ready(&CListValue::Type);
-       PyType_Ready(&CValue::Type);
-       PyType_Ready(&KX_BlenderMaterial::Type);
-       PyType_Ready(&KX_CDActuator::Type);
-       PyType_Ready(&KX_Camera::Type);
-       PyType_Ready(&KX_CameraActuator::Type);
-       PyType_Ready(&KX_ConstraintActuator::Type);
-       PyType_Ready(&KX_ConstraintWrapper::Type);
-       PyType_Ready(&KX_GameActuator::Type);
-       PyType_Ready(&KX_GameObject::Type);
-       PyType_Ready(&KX_IpoActuator::Type);
-       PyType_Ready(&KX_LightObject::Type);
-       PyType_Ready(&KX_MeshProxy::Type);
-       PyType_Ready(&KX_MouseFocusSensor::Type);
-       PyType_Ready(&KX_NearSensor::Type);
-       PyType_Ready(&KX_NetworkMessageActuator::Type);
-       PyType_Ready(&KX_NetworkMessageSensor::Type);
-       PyType_Ready(&KX_ObjectActuator::Type);
-       PyType_Ready(&KX_ParentActuator::Type);
-       PyType_Ready(&KX_PhysicsObjectWrapper::Type);
-       PyType_Ready(&KX_PolyProxy::Type);
-       PyType_Ready(&KX_PolygonMaterial::Type);
-       PyType_Ready(&KX_RadarSensor::Type);
-       PyType_Ready(&KX_RaySensor::Type);
-       PyType_Ready(&KX_SCA_AddObjectActuator::Type);
-       PyType_Ready(&KX_SCA_DynamicActuator::Type);
-       PyType_Ready(&KX_SCA_EndObjectActuator::Type);
-       PyType_Ready(&KX_SCA_ReplaceMeshActuator::Type);
-       PyType_Ready(&KX_Scene::Type);
-       PyType_Ready(&KX_SceneActuator::Type);
-       PyType_Ready(&KX_SoundActuator::Type);
-       PyType_Ready(&KX_StateActuator::Type);
-       PyType_Ready(&KX_TouchSensor::Type);
-       PyType_Ready(&KX_TrackToActuator::Type);
-       PyType_Ready(&KX_VehicleWrapper::Type);
-       PyType_Ready(&KX_VertexProxy::Type);
-       PyType_Ready(&KX_VisibilityActuator::Type);
-       PyType_Ready(&PyObjectPlus::Type);
-       PyType_Ready(&SCA_2DFilterActuator::Type);
-       PyType_Ready(&SCA_ANDController::Type);
-       PyType_Ready(&SCA_ActuatorSensor::Type);
-       PyType_Ready(&SCA_AlwaysSensor::Type);
-       PyType_Ready(&SCA_DelaySensor::Type);
-       PyType_Ready(&SCA_ILogicBrick::Type);
-       PyType_Ready(&SCA_IObject::Type);
-       PyType_Ready(&SCA_ISensor::Type);
-       PyType_Ready(&SCA_JoystickSensor::Type);
-       PyType_Ready(&SCA_KeyboardSensor::Type);
-       PyType_Ready(&SCA_MouseSensor::Type);
-       PyType_Ready(&SCA_NANDController::Type);
-       PyType_Ready(&SCA_NORController::Type);
-       PyType_Ready(&SCA_ORController::Type);
-       PyType_Ready(&SCA_PropertyActuator::Type);
-       PyType_Ready(&SCA_PropertySensor::Type);
-       PyType_Ready(&SCA_PythonController::Type);
-       PyType_Ready(&SCA_RandomActuator::Type);
-       PyType_Ready(&SCA_RandomSensor::Type);
-       PyType_Ready(&SCA_XNORController::Type);
-       PyType_Ready(&SCA_XORController::Type);
+       PyObject *mod= PyModule_New("GameTypes");
+       PyObject *dict= PyModule_GetDict(mod);
+       PyDict_SetItemString(PySys_GetObject("modules"), "GameTypes", mod);
+       Py_DECREF(mod);
+       
+       PyType_Ready_ADD(dict, &BL_ActionActuator::Type);
+       PyType_Ready_ADD(dict, &BL_Shader::Type);
+       PyType_Ready_ADD(dict, &BL_ShapeActionActuator::Type);
+       PyType_Ready_ADD(dict, &CListValue::Type);
+       PyType_Ready_ADD(dict, &CValue::Type);
+       PyType_Ready_ADD(dict, &KX_BlenderMaterial::Type);
+       PyType_Ready_ADD(dict, &KX_CDActuator::Type);
+       PyType_Ready_ADD(dict, &KX_Camera::Type);
+       PyType_Ready_ADD(dict, &KX_CameraActuator::Type);
+       PyType_Ready_ADD(dict, &KX_ConstraintActuator::Type);
+       PyType_Ready_ADD(dict, &KX_ConstraintWrapper::Type);
+       PyType_Ready_ADD(dict, &KX_GameActuator::Type);
+       PyType_Ready_ADD(dict, &KX_GameObject::Type);
+       PyType_Ready_ADD(dict, &KX_IpoActuator::Type);
+       PyType_Ready_ADD(dict, &KX_LightObject::Type);
+       PyType_Ready_ADD(dict, &KX_MeshProxy::Type);
+       PyType_Ready_ADD(dict, &KX_MouseFocusSensor::Type);
+       PyType_Ready_ADD(dict, &KX_NearSensor::Type);
+       PyType_Ready_ADD(dict, &KX_NetworkMessageActuator::Type);
+       PyType_Ready_ADD(dict, &KX_NetworkMessageSensor::Type);
+       PyType_Ready_ADD(dict, &KX_ObjectActuator::Type);
+       PyType_Ready_ADD(dict, &KX_ParentActuator::Type);
+       PyType_Ready_ADD(dict, &KX_PhysicsObjectWrapper::Type);
+       PyType_Ready_ADD(dict, &KX_PolyProxy::Type);
+       PyType_Ready_ADD(dict, &KX_PolygonMaterial::Type);
+       PyType_Ready_ADD(dict, &KX_RadarSensor::Type);
+       PyType_Ready_ADD(dict, &KX_RaySensor::Type);
+       PyType_Ready_ADD(dict, &KX_SCA_AddObjectActuator::Type);
+       PyType_Ready_ADD(dict, &KX_SCA_DynamicActuator::Type);
+       PyType_Ready_ADD(dict, &KX_SCA_EndObjectActuator::Type);
+       PyType_Ready_ADD(dict, &KX_SCA_ReplaceMeshActuator::Type);
+       PyType_Ready_ADD(dict, &KX_Scene::Type);
+       PyType_Ready_ADD(dict, &KX_SceneActuator::Type);
+       PyType_Ready_ADD(dict, &KX_SoundActuator::Type);
+       PyType_Ready_ADD(dict, &KX_StateActuator::Type);
+       PyType_Ready_ADD(dict, &KX_TouchSensor::Type);
+       PyType_Ready_ADD(dict, &KX_TrackToActuator::Type);
+       PyType_Ready_ADD(dict, &KX_VehicleWrapper::Type);
+       PyType_Ready_ADD(dict, &KX_VertexProxy::Type);
+       PyType_Ready_ADD(dict, &KX_VisibilityActuator::Type);
+       PyType_Ready_ADD(dict, &PyObjectPlus::Type);
+       PyType_Ready_ADD(dict, &SCA_2DFilterActuator::Type);
+       PyType_Ready_ADD(dict, &SCA_ANDController::Type);
+       PyType_Ready_ADD(dict, &SCA_ActuatorSensor::Type);
+       PyType_Ready_ADD(dict, &SCA_AlwaysSensor::Type);
+       PyType_Ready_ADD(dict, &SCA_DelaySensor::Type);
+       PyType_Ready_ADD(dict, &SCA_ILogicBrick::Type);
+       PyType_Ready_ADD(dict, &SCA_IObject::Type);
+       PyType_Ready_ADD(dict, &SCA_ISensor::Type);
+       PyType_Ready_ADD(dict, &SCA_JoystickSensor::Type);
+       PyType_Ready_ADD(dict, &SCA_KeyboardSensor::Type);
+       PyType_Ready_ADD(dict, &SCA_MouseSensor::Type);
+       PyType_Ready_ADD(dict, &SCA_NANDController::Type);
+       PyType_Ready_ADD(dict, &SCA_NORController::Type);
+       PyType_Ready_ADD(dict, &SCA_ORController::Type);
+       PyType_Ready_ADD(dict, &SCA_PropertyActuator::Type);
+       PyType_Ready_ADD(dict, &SCA_PropertySensor::Type);
+       PyType_Ready_ADD(dict, &SCA_PythonController::Type);
+       PyType_Ready_ADD(dict, &SCA_RandomActuator::Type);
+       PyType_Ready_ADD(dict, &SCA_RandomSensor::Type);
+       PyType_Ready_ADD(dict, &SCA_XNORController::Type);
+       PyType_Ready_ADD(dict, &SCA_XORController::Type);
+       
+       
+       
 }
 
 #endif
\ No newline at end of file
index 8c8291ef7914af512065cdd013eb02b10df9bf80..f3e9bbf86b186b769fe5b2abac12a5a30d53c21b 100644 (file)
@@ -79,6 +79,30 @@ PyMethodDef KX_VertexProxy::Methods[] = {
 };
 
 PyAttributeDef KX_VertexProxy::Attributes[] = {
+       
+       KX_PYATTRIBUTE_DUMMY("x"),
+       KX_PYATTRIBUTE_DUMMY("y"),
+       KX_PYATTRIBUTE_DUMMY("z"),
+       
+       KX_PYATTRIBUTE_DUMMY("r"),
+       KX_PYATTRIBUTE_DUMMY("g"),
+       KX_PYATTRIBUTE_DUMMY("b"),
+       KX_PYATTRIBUTE_DUMMY("a"),
+       
+       KX_PYATTRIBUTE_DUMMY("u"),
+       KX_PYATTRIBUTE_DUMMY("v"),
+       
+       KX_PYATTRIBUTE_DUMMY("u2"),
+       KX_PYATTRIBUTE_DUMMY("v2"),
+       
+       KX_PYATTRIBUTE_DUMMY("XYZ"),
+       KX_PYATTRIBUTE_DUMMY("UV"),
+       
+       KX_PYATTRIBUTE_DUMMY("color"),
+       KX_PYATTRIBUTE_DUMMY("colour"),
+       
+       KX_PYATTRIBUTE_DUMMY("normal"),
+       
        { NULL }        //Sentinel
 };
 
diff --git a/source/gameengine/PyDoc/bge_api_validate_py.txt b/source/gameengine/PyDoc/bge_api_validate_py.txt
new file mode 100644 (file)
index 0000000..e003f29
--- /dev/null
@@ -0,0 +1,66 @@
+#~ This program is free software; you can redistribute it and/or modify
+#~ it under the terms of the GNU General Public License as published by
+#~ the Free Software Foundation; version 2 of the License.
+
+#~ This program is distributed in the hope that it will be useful,
+#~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+#~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#~ GNU General Public License for more details.
+
+# This script must run from a logic brick so it has access to the game engine api
+# it assumes the root blender source directory is the current working directory
+# 
+# Currently it only prints missing modules and methods (not attributes)
+
+
+BGE_API_DOC_PATH = 'source/gameengine/PyDoc'
+
+type_members = {}
+
+for type_name in dir(GameTypes):
+       if type_name.startswith('__'):
+               continue
+       
+       type_object = getattr(GameTypes, type_name)
+       
+       members = []
+       type_members[type_object.__name__] = members
+       
+       for member in type_object.__dict__.keys():
+               if member.startswith('__'):
+                       continue
+               
+               # print type_object.__name__ + '.' + k
+               members.append(member)
+
+import sys, os
+
+doc_dir= os.path.join(os.getcwd(), BGE_API_DOC_PATH)
+
+if doc_dir not in sys.path:
+       sys.path.append(doc_dir)
+
+for type_name in sorted(type_members.keys()):
+       members = type_members[type_name]
+       
+       try:
+               mod = __import__(type_name)
+               print "type: %s" % type_name
+       except:
+               print "missing: %s - %s" % (type_name, str(members))
+               continue
+       
+       reload(mod) # incase were editing it
+       
+       try:
+               type_class = getattr(mod, type_name)
+       except:
+               print "missing class: %s.%s - %s" % (type_name, type_name, str(members))
+               continue
+       
+       for member in sorted(members):
+               try:
+                       getattr(type_class, member)
+                       print "\tfound: %s.%s" % (type_name, member)
+               except:
+                       print "\tmissing: %s.%s" % (type_name, member)