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:
authorCampbell Barton <ideasman42@gmail.com>2009-04-06 17:27:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-06 17:27:28 +0400
commit46a440c7a5393177dbc74cef466d1eb5643e068d (patch)
tree0928a660f178f192ee37c8f2483a0c5fd69189e0
parent960fa534b7690796d463f062edf572ceae88457d (diff)
BGE Python API
- 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
-rw-r--r--source/gameengine/GameLogic/SCA_MouseSensor.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_Light.cpp16
-rw-r--r--source/gameengine/Ketsji/KX_MouseFocusSensor.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_PolyProxy.cpp11
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp6
-rw-r--r--source/gameengine/Ketsji/KX_PythonInitTypes.cpp140
-rw-r--r--source/gameengine/Ketsji/KX_VertexProxy.cpp24
-rw-r--r--source/gameengine/PyDoc/bge_api_validate_py.txt66
8 files changed, 198 insertions, 71 deletions
diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
index c5f6fdabbe8..3cd32391ce2 100644
--- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
@@ -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))
{
diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp
index 6f9d8b0211b..7b5b77ccacf 100644
--- a/source/gameengine/Ketsji/KX_Light.cpp
+++ b/source/gameengine/Ketsji/KX_Light.cpp
@@ -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,
diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
index 72a0381e8dc..4afc6d6f1b8 100644
--- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
+++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
@@ -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);
diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp
index 6f74c3ed3f9..39eb6225864 100644
--- a/source/gameengine/Ketsji/KX_PolyProxy.cpp
+++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp
@@ -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
};
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 9929e66c3a4..9a6565d7627 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -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())
diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
index 8eeed5d853b..29a7a5f85f2 100644
--- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
@@ -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
diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp
index 8c8291ef791..f3e9bbf86b1 100644
--- a/source/gameengine/Ketsji/KX_VertexProxy.cpp
+++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp
@@ -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
index 00000000000..e003f29831b
--- /dev/null
+++ b/source/gameengine/PyDoc/bge_api_validate_py.txt
@@ -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)