Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): Campbell Barton 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00035 #ifndef _adr_py_init_types_h_ // only process once, 00036 #define _adr_py_init_types_h_ // even if multiply included 00037 00038 #ifdef WITH_PYTHON 00039 00040 /* Only for Class::Parents */ 00041 #include "BL_BlenderShader.h" 00042 #include "BL_ShapeActionActuator.h" 00043 #include "BL_ArmatureActuator.h" 00044 #include "BL_ArmatureConstraint.h" 00045 #include "BL_ArmatureObject.h" 00046 #include "BL_ArmatureChannel.h" 00047 #include "KX_BlenderMaterial.h" 00048 #include "KX_CameraActuator.h" 00049 #include "KX_ConstraintActuator.h" 00050 #include "KX_ConstraintWrapper.h" 00051 #include "KX_GameActuator.h" 00052 #include "KX_Light.h" 00053 #include "KX_FontObject.h" 00054 #include "KX_MeshProxy.h" 00055 #include "KX_MouseFocusSensor.h" 00056 #include "KX_NetworkMessageActuator.h" 00057 #include "KX_NetworkMessageSensor.h" 00058 #include "KX_ObjectActuator.h" 00059 #include "KX_ParentActuator.h" 00060 #include "KX_PhysicsObjectWrapper.h" 00061 #include "KX_PolyProxy.h" 00062 #include "KX_PolygonMaterial.h" 00063 #include "KX_PythonSeq.h" 00064 #include "KX_SCA_AddObjectActuator.h" 00065 #include "KX_SCA_EndObjectActuator.h" 00066 #include "KX_SCA_ReplaceMeshActuator.h" 00067 #include "KX_SceneActuator.h" 00068 #include "KX_StateActuator.h" 00069 #include "KX_SteeringActuator.h" 00070 #include "KX_TrackToActuator.h" 00071 #include "KX_VehicleWrapper.h" 00072 #include "KX_VertexProxy.h" 00073 #include "SCA_2DFilterActuator.h" 00074 #include "SCA_ANDController.h" 00075 #include "SCA_ActuatorSensor.h" 00076 #include "SCA_AlwaysSensor.h" 00077 #include "SCA_DelaySensor.h" 00078 #include "SCA_JoystickSensor.h" 00079 #include "SCA_KeyboardSensor.h" 00080 #include "SCA_MouseSensor.h" 00081 #include "SCA_NANDController.h" 00082 #include "SCA_NORController.h" 00083 #include "SCA_ORController.h" 00084 #include "SCA_RandomSensor.h" 00085 #include "SCA_XNORController.h" 00086 #include "SCA_XORController.h" 00087 #include "SCA_PythonKeyboard.h" 00088 #include "SCA_PythonMouse.h" 00089 #include "KX_IpoActuator.h" 00090 #include "KX_NearSensor.h" 00091 #include "KX_RadarSensor.h" 00092 #include "KX_RaySensor.h" 00093 #include "KX_SCA_DynamicActuator.h" 00094 #include "KX_SoundActuator.h" 00095 #include "KX_TouchSensor.h" 00096 #include "KX_VisibilityActuator.h" 00097 #include "SCA_PropertySensor.h" 00098 #include "SCA_PythonController.h" 00099 #include "SCA_RandomActuator.h" 00100 #include "SCA_IController.h" 00101 #include "KX_NavMeshObject.h" 00102 00103 static void PyType_Attr_Set(PyGetSetDef *attr_getset, PyAttributeDef *attr) 00104 { 00105 attr_getset->name= (char *)attr->m_name; 00106 attr_getset->doc= NULL; 00107 00108 attr_getset->get= reinterpret_cast<getter>(PyObjectPlus::py_get_attrdef); 00109 00110 if(attr->m_access==KX_PYATTRIBUTE_RO) 00111 attr_getset->set= NULL; 00112 else 00113 attr_getset->set= reinterpret_cast<setter>(PyObjectPlus::py_set_attrdef); 00114 00115 attr_getset->closure= reinterpret_cast<void *>(attr); 00116 } 00117 00118 static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes, PyAttributeDef *attributesPtr, int init_getset) 00119 { 00120 PyAttributeDef *attr; 00121 00122 if(init_getset) { 00123 /* we need to do this for all types before calling PyType_Ready 00124 * since they will call the parents PyType_Ready and those might not have initialized vars yet */ 00125 00126 //if(tp->tp_base==NULL) 00127 // printf("Debug: No Parents - '%s'\n" , tp->tp_name); 00128 00129 if(tp->tp_getset==NULL && ((attributes && attributes->m_name) || (attributesPtr && attributesPtr->m_name))) { 00130 PyGetSetDef *attr_getset; 00131 int attr_tot= 0; 00132 00133 if (attributes) { 00134 for(attr= attributes; attr->m_name; attr++, attr_tot++) 00135 attr->m_usePtr = false; 00136 } 00137 if (attributesPtr) { 00138 for(attr= attributesPtr; attr->m_name; attr++, attr_tot++) 00139 attr->m_usePtr = true; 00140 } 00141 00142 tp->tp_getset = attr_getset = reinterpret_cast<PyGetSetDef *>(PyMem_Malloc((attr_tot+1) * sizeof(PyGetSetDef))); // XXX - Todo, free 00143 00144 if (attributes) { 00145 for(attr= attributes; attr->m_name; attr++, attr_getset++) { 00146 PyType_Attr_Set(attr_getset, attr); 00147 } 00148 } 00149 if (attributesPtr) { 00150 for(attr= attributesPtr; attr->m_name; attr++, attr_getset++) { 00151 PyType_Attr_Set(attr_getset, attr); 00152 } 00153 } 00154 memset(attr_getset, 0, sizeof(PyGetSetDef)); 00155 } 00156 } else { 00157 PyType_Ready(tp); 00158 PyDict_SetItemString(dict, tp->tp_name, reinterpret_cast<PyObject *>(tp)); 00159 } 00160 00161 } 00162 00163 00164 #define PyType_Ready_Attr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, NULL, i) 00165 #define PyType_Ready_AttrPtr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, n::AttributesPtr, i) 00166 00167 void initPyTypes(void) 00168 { 00169 00170 /* 00171 initPyObjectPlusType(BL_ActionActuator::Parents); 00172 ..... 00173 */ 00174 00175 /* For now just do PyType_Ready */ 00176 PyObject *mod= PyModule_New("GameTypes"); 00177 PyObject *dict= PyModule_GetDict(mod); 00178 PyDict_SetItemString(PySys_GetObject((char *)"modules"), (char *)"GameTypes", mod); 00179 Py_DECREF(mod); 00180 00181 00182 for(int init_getset= 1; init_getset > -1; init_getset--) { /* run twice, once to init the getsets another to run PyType_Ready */ 00183 PyType_Ready_Attr(dict, BL_ActionActuator, init_getset); 00184 PyType_Ready_Attr(dict, BL_Shader, init_getset); 00185 PyType_Ready_Attr(dict, BL_ShapeActionActuator, init_getset); 00186 PyType_Ready_Attr(dict, BL_ArmatureObject, init_getset); 00187 PyType_Ready_Attr(dict, BL_ArmatureActuator, init_getset); 00188 PyType_Ready_Attr(dict, BL_ArmatureConstraint, init_getset); 00189 PyType_Ready_AttrPtr(dict, BL_ArmatureBone, init_getset); 00190 PyType_Ready_AttrPtr(dict, BL_ArmatureChannel, init_getset); 00191 PyType_Ready_Attr(dict, CListValue, init_getset); 00192 PyType_Ready_Attr(dict, CValue, init_getset); 00193 PyType_Ready_Attr(dict, KX_BlenderMaterial, init_getset); 00194 PyType_Ready_Attr(dict, KX_Camera, init_getset); 00195 PyType_Ready_Attr(dict, KX_CameraActuator, init_getset); 00196 PyType_Ready_Attr(dict, KX_ConstraintActuator, init_getset); 00197 PyType_Ready_Attr(dict, KX_ConstraintWrapper, init_getset); 00198 PyType_Ready_Attr(dict, KX_GameActuator, init_getset); 00199 PyType_Ready_Attr(dict, KX_GameObject, init_getset); 00200 PyType_Ready_Attr(dict, KX_IpoActuator, init_getset); 00201 PyType_Ready_Attr(dict, KX_LightObject, init_getset); 00202 PyType_Ready_Attr(dict, KX_FontObject, init_getset); 00203 PyType_Ready_Attr(dict, KX_MeshProxy, init_getset); 00204 PyType_Ready_Attr(dict, KX_MouseFocusSensor, init_getset); 00205 PyType_Ready_Attr(dict, KX_NearSensor, init_getset); 00206 PyType_Ready_Attr(dict, KX_NetworkMessageActuator, init_getset); 00207 PyType_Ready_Attr(dict, KX_NetworkMessageSensor, init_getset); 00208 PyType_Ready_Attr(dict, KX_ObjectActuator, init_getset); 00209 PyType_Ready_Attr(dict, KX_ParentActuator, init_getset); 00210 PyType_Ready_Attr(dict, KX_PhysicsObjectWrapper, init_getset); 00211 PyType_Ready_Attr(dict, KX_PolyProxy, init_getset); 00212 PyType_Ready_Attr(dict, KX_PolygonMaterial, init_getset); 00213 PyType_Ready_Attr(dict, KX_RadarSensor, init_getset); 00214 PyType_Ready_Attr(dict, KX_RaySensor, init_getset); 00215 PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator, init_getset); 00216 PyType_Ready_Attr(dict, KX_SCA_DynamicActuator, init_getset); 00217 PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator, init_getset); 00218 PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator, init_getset); 00219 PyType_Ready_Attr(dict, KX_Scene, init_getset); 00220 PyType_Ready_Attr(dict, KX_NavMeshObject, init_getset); 00221 PyType_Ready_Attr(dict, KX_SceneActuator, init_getset); 00222 PyType_Ready_Attr(dict, KX_SoundActuator, init_getset); 00223 PyType_Ready_Attr(dict, KX_StateActuator, init_getset); 00224 PyType_Ready_Attr(dict, KX_SteeringActuator, init_getset); 00225 PyType_Ready_Attr(dict, KX_TouchSensor, init_getset); 00226 PyType_Ready_Attr(dict, KX_TrackToActuator, init_getset); 00227 PyType_Ready_Attr(dict, KX_VehicleWrapper, init_getset); 00228 PyType_Ready_Attr(dict, KX_VertexProxy, init_getset); 00229 PyType_Ready_Attr(dict, KX_VisibilityActuator, init_getset); 00230 PyType_Ready_Attr(dict, PyObjectPlus, init_getset); 00231 PyType_Ready_Attr(dict, SCA_2DFilterActuator, init_getset); 00232 PyType_Ready_Attr(dict, SCA_ANDController, init_getset); 00233 PyType_Ready_Attr(dict, SCA_ActuatorSensor, init_getset); 00234 PyType_Ready_Attr(dict, SCA_AlwaysSensor, init_getset); 00235 PyType_Ready_Attr(dict, SCA_DelaySensor, init_getset); 00236 PyType_Ready_Attr(dict, SCA_ILogicBrick, init_getset); 00237 PyType_Ready_Attr(dict, SCA_IObject, init_getset); 00238 PyType_Ready_Attr(dict, SCA_ISensor, init_getset); 00239 PyType_Ready_Attr(dict, SCA_JoystickSensor, init_getset); 00240 PyType_Ready_Attr(dict, SCA_KeyboardSensor, init_getset); 00241 PyType_Ready_Attr(dict, SCA_MouseSensor, init_getset); 00242 PyType_Ready_Attr(dict, SCA_NANDController, init_getset); 00243 PyType_Ready_Attr(dict, SCA_NORController, init_getset); 00244 PyType_Ready_Attr(dict, SCA_ORController, init_getset); 00245 PyType_Ready_Attr(dict, SCA_PropertyActuator, init_getset); 00246 PyType_Ready_Attr(dict, SCA_PropertySensor, init_getset); 00247 PyType_Ready_Attr(dict, SCA_PythonController, init_getset); 00248 PyType_Ready_Attr(dict, SCA_RandomActuator, init_getset); 00249 PyType_Ready_Attr(dict, SCA_RandomSensor, init_getset); 00250 PyType_Ready_Attr(dict, SCA_XNORController, init_getset); 00251 PyType_Ready_Attr(dict, SCA_XORController, init_getset); 00252 PyType_Ready_Attr(dict, SCA_IController, init_getset); 00253 PyType_Ready_Attr(dict, SCA_PythonKeyboard, init_getset); 00254 PyType_Ready_Attr(dict, SCA_PythonMouse, init_getset); 00255 } 00256 00257 00258 /* Normal python type */ 00259 PyType_Ready(&KX_PythonSeq_Type); 00260 00261 #ifdef USE_MATHUTILS 00262 /* Init mathutils callbacks */ 00263 KX_GameObject_Mathutils_Callback_Init(); 00264 KX_ObjectActuator_Mathutils_Callback_Init(); 00265 #endif 00266 } 00267 00268 #endif // WITH_PYTHON 00269 00270 #endif