Merge with -r 22620:23107.
[blender.git] / source / gameengine / Ketsji / KX_PythonInitTypes.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): Campbell Barton
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30
31
32 #ifndef _adr_py_init_types_h_                           // only process once,
33 #define _adr_py_init_types_h_                           // even if multiply included
34
35 /* Only for Class::Parents */
36 #include "BL_BlenderShader.h"
37 #include "BL_ShapeActionActuator.h"
38 #include "KX_BlenderMaterial.h"
39 #include "KX_CameraActuator.h"
40 #include "KX_ConstraintActuator.h"
41 #include "KX_ConstraintWrapper.h"
42 #include "KX_GameActuator.h"
43 #include "KX_Light.h"
44 #include "KX_MeshProxy.h"
45 #include "KX_MouseFocusSensor.h"
46 #include "KX_NetworkMessageActuator.h"
47 #include "KX_NetworkMessageSensor.h"
48 #include "KX_ObjectActuator.h"
49 #include "KX_ParentActuator.h"
50 #include "KX_PhysicsObjectWrapper.h"
51 #include "KX_PolyProxy.h"
52 #include "KX_PolygonMaterial.h"
53 #include "KX_PythonSeq.h"
54 #include "KX_SCA_AddObjectActuator.h"
55 #include "KX_SCA_EndObjectActuator.h"
56 #include "KX_SCA_ReplaceMeshActuator.h"
57 #include "KX_SceneActuator.h"
58 #include "KX_StateActuator.h"
59 #include "KX_TrackToActuator.h"
60 #include "KX_VehicleWrapper.h"
61 #include "KX_VertexProxy.h"
62 #include "SCA_2DFilterActuator.h"
63 #include "SCA_ANDController.h"
64 #include "SCA_ActuatorSensor.h"
65 #include "SCA_AlwaysSensor.h"
66 #include "SCA_DelaySensor.h"
67 #include "SCA_JoystickSensor.h"
68 #include "SCA_KeyboardSensor.h"
69 #include "SCA_MouseSensor.h"
70 #include "SCA_NANDController.h"
71 #include "SCA_NORController.h"
72 #include "SCA_ORController.h"
73 #include "SCA_RandomSensor.h"
74 #include "SCA_XNORController.h"
75 #include "SCA_XORController.h"
76 #include "KX_IpoActuator.h"
77 #include "KX_NearSensor.h"
78 #include "KX_RadarSensor.h"
79 #include "KX_RaySensor.h"
80 #include "KX_SCA_DynamicActuator.h"
81 #include "KX_SoundActuator.h"
82 #include "KX_TouchSensor.h"
83 #include "KX_VisibilityActuator.h"
84 #include "SCA_PropertySensor.h"
85 #include "SCA_PythonController.h"
86 #include "SCA_RandomActuator.h"
87 #include "SCA_IController.h"
88
89 static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes, int init_getset)
90 {
91         PyAttributeDef *attr;
92
93         if(init_getset) {
94                 /* we need to do this for all types before calling PyType_Ready
95                  * since they will call the parents PyType_Ready and those might not have initialized vars yet */
96
97                 //if(tp->tp_base==NULL)
98                 //      printf("Debug: No Parents - '%s'\n" , tp->tp_name);
99
100                 if(tp->tp_getset==NULL && attributes->m_name) {
101                         PyGetSetDef *attr_getset;
102                         int attr_tot= 0;
103
104                         for(attr= attributes; attr->m_name; attr++, attr_tot++) {};
105
106                         tp->tp_getset = attr_getset = reinterpret_cast<PyGetSetDef *>(PyMem_Malloc((attr_tot+1) * sizeof(PyGetSetDef))); // XXX - Todo, free
107
108
109                         for(attr= attributes; attr->m_name; attr++, attr_getset++) {
110                                 attr_getset->name= (char *)attr->m_name;
111                                 attr_getset->doc= NULL;
112
113                                 attr_getset->get= reinterpret_cast<getter>(PyObjectPlus::py_get_attrdef);
114
115                                 if(attr->m_access==KX_PYATTRIBUTE_RO)
116                                         attr_getset->set= NULL;
117                                 else
118                                         attr_getset->set= reinterpret_cast<setter>(PyObjectPlus::py_set_attrdef);
119
120                                 attr_getset->closure= reinterpret_cast<void *>(attr);
121                         }
122
123                         memset(attr_getset, 0, sizeof(PyGetSetDef));
124                 }
125         } else {
126                 PyType_Ready(tp);
127                 PyDict_SetItemString(dict, tp->tp_name, reinterpret_cast<PyObject *>(tp));
128         }
129         
130 }
131
132
133 #define PyType_Ready_Attr(d, n, i)   PyType_Ready_ADD(d, &n::Type, n::Attributes, i)
134
135 void initPyTypes(void)
136 {
137         
138 /*
139         initPyObjectPlusType(BL_ActionActuator::Parents);
140         .....
141 */
142
143         /* For now just do PyType_Ready */
144         PyObject *mod= PyModule_New("GameTypes");
145         PyObject *dict= PyModule_GetDict(mod);
146         PyDict_SetItemString(PySys_GetObject((char *)"modules"), (char *)"GameTypes", mod);
147         Py_DECREF(mod);
148         
149         
150         for(int init_getset= 1; init_getset > -1; init_getset--) { /* run twice, once to init the getsets another to run PyType_Ready */
151                 PyType_Ready_Attr(dict, BL_ActionActuator, init_getset);
152                 PyType_Ready_Attr(dict, BL_Shader, init_getset);
153                 PyType_Ready_Attr(dict, BL_ShapeActionActuator, init_getset);
154                 PyType_Ready_Attr(dict, CListValue, init_getset);
155                 PyType_Ready_Attr(dict, CValue, init_getset);
156                 PyType_Ready_Attr(dict, KX_BlenderMaterial, init_getset);
157                 PyType_Ready_Attr(dict, KX_Camera, init_getset);
158                 PyType_Ready_Attr(dict, KX_CameraActuator, init_getset);
159                 PyType_Ready_Attr(dict, KX_ConstraintActuator, init_getset);
160                 PyType_Ready_Attr(dict, KX_ConstraintWrapper, init_getset);
161                 PyType_Ready_Attr(dict, KX_GameActuator, init_getset);
162                 PyType_Ready_Attr(dict, KX_GameObject, init_getset);
163                 PyType_Ready_Attr(dict, KX_IpoActuator, init_getset);
164                 PyType_Ready_Attr(dict, KX_LightObject, init_getset);
165                 PyType_Ready_Attr(dict, KX_MeshProxy, init_getset);
166                 PyType_Ready_Attr(dict, KX_MouseFocusSensor, init_getset);
167                 PyType_Ready_Attr(dict, KX_NearSensor, init_getset);
168                 PyType_Ready_Attr(dict, KX_NetworkMessageActuator, init_getset);
169                 PyType_Ready_Attr(dict, KX_NetworkMessageSensor, init_getset);
170                 PyType_Ready_Attr(dict, KX_ObjectActuator, init_getset);
171                 PyType_Ready_Attr(dict, KX_ParentActuator, init_getset);
172                 PyType_Ready_Attr(dict, KX_PhysicsObjectWrapper, init_getset);
173                 PyType_Ready_Attr(dict, KX_PolyProxy, init_getset);
174                 PyType_Ready_Attr(dict, KX_PolygonMaterial, init_getset);
175                 PyType_Ready_Attr(dict, KX_RadarSensor, init_getset);
176                 PyType_Ready_Attr(dict, KX_RaySensor, init_getset);
177                 PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator, init_getset);
178                 PyType_Ready_Attr(dict, KX_SCA_DynamicActuator, init_getset);
179                 PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator, init_getset);
180                 PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator, init_getset);
181                 PyType_Ready_Attr(dict, KX_Scene, init_getset);
182                 PyType_Ready_Attr(dict, KX_SceneActuator, init_getset);
183                 PyType_Ready_Attr(dict, KX_SoundActuator, init_getset);
184                 PyType_Ready_Attr(dict, KX_StateActuator, init_getset);
185                 PyType_Ready_Attr(dict, KX_TouchSensor, init_getset);
186                 PyType_Ready_Attr(dict, KX_TrackToActuator, init_getset);
187                 PyType_Ready_Attr(dict, KX_VehicleWrapper, init_getset);
188                 PyType_Ready_Attr(dict, KX_VertexProxy, init_getset);
189                 PyType_Ready_Attr(dict, KX_VisibilityActuator, init_getset);
190                 PyType_Ready_Attr(dict, PyObjectPlus, init_getset);
191                 PyType_Ready_Attr(dict, SCA_2DFilterActuator, init_getset);
192                 PyType_Ready_Attr(dict, SCA_ANDController, init_getset);
193                 PyType_Ready_Attr(dict, SCA_ActuatorSensor, init_getset);
194                 PyType_Ready_Attr(dict, SCA_AlwaysSensor, init_getset);
195                 PyType_Ready_Attr(dict, SCA_DelaySensor, init_getset);
196                 PyType_Ready_Attr(dict, SCA_ILogicBrick, init_getset);
197                 PyType_Ready_Attr(dict, SCA_IObject, init_getset);
198                 PyType_Ready_Attr(dict, SCA_ISensor, init_getset);
199                 PyType_Ready_Attr(dict, SCA_JoystickSensor, init_getset);
200                 PyType_Ready_Attr(dict, SCA_KeyboardSensor, init_getset);
201                 PyType_Ready_Attr(dict, SCA_MouseSensor, init_getset);
202                 PyType_Ready_Attr(dict, SCA_NANDController, init_getset);
203                 PyType_Ready_Attr(dict, SCA_NORController, init_getset);
204                 PyType_Ready_Attr(dict, SCA_ORController, init_getset);
205                 PyType_Ready_Attr(dict, SCA_PropertyActuator, init_getset);
206                 PyType_Ready_Attr(dict, SCA_PropertySensor, init_getset);
207                 PyType_Ready_Attr(dict, SCA_PythonController, init_getset);
208                 PyType_Ready_Attr(dict, SCA_RandomActuator, init_getset);
209                 PyType_Ready_Attr(dict, SCA_RandomSensor, init_getset);
210                 PyType_Ready_Attr(dict, SCA_XNORController, init_getset);
211                 PyType_Ready_Attr(dict, SCA_XORController, init_getset);
212                 PyType_Ready_Attr(dict, SCA_IController, init_getset);
213         }
214
215
216         /* Normal python type */
217         PyType_Ready(&KX_PythonSeq_Type);
218
219 #ifdef USE_MATHUTILS
220         /* Init mathutils callbacks */
221         KX_GameObject_Mathutils_Callback_Init();
222         KX_ObjectActuator_Mathutils_Callback_Init();
223 #endif
224 }
225
226 #endif