doxygen: prevent GPL license block from being parsed as doxygen comment.
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #ifdef WITH_PYTHON
36
37 /* Only for Class::Parents */
38 #include "BL_BlenderShader.h"
39 #include "BL_ShapeActionActuator.h"
40 #include "BL_ArmatureActuator.h"
41 #include "BL_ArmatureConstraint.h"
42 #include "BL_ArmatureObject.h"
43 #include "BL_ArmatureChannel.h"
44 #include "KX_BlenderMaterial.h"
45 #include "KX_CameraActuator.h"
46 #include "KX_ConstraintActuator.h"
47 #include "KX_ConstraintWrapper.h"
48 #include "KX_GameActuator.h"
49 #include "KX_Light.h"
50 #include "KX_FontObject.h"
51 #include "KX_MeshProxy.h"
52 #include "KX_MouseFocusSensor.h"
53 #include "KX_NetworkMessageActuator.h"
54 #include "KX_NetworkMessageSensor.h"
55 #include "KX_ObjectActuator.h"
56 #include "KX_ParentActuator.h"
57 #include "KX_PhysicsObjectWrapper.h"
58 #include "KX_PolyProxy.h"
59 #include "KX_PolygonMaterial.h"
60 #include "KX_PythonSeq.h"
61 #include "KX_SCA_AddObjectActuator.h"
62 #include "KX_SCA_EndObjectActuator.h"
63 #include "KX_SCA_ReplaceMeshActuator.h"
64 #include "KX_SceneActuator.h"
65 #include "KX_StateActuator.h"
66 #include "KX_TrackToActuator.h"
67 #include "KX_VehicleWrapper.h"
68 #include "KX_VertexProxy.h"
69 #include "SCA_2DFilterActuator.h"
70 #include "SCA_ANDController.h"
71 #include "SCA_ActuatorSensor.h"
72 #include "SCA_AlwaysSensor.h"
73 #include "SCA_DelaySensor.h"
74 #include "SCA_JoystickSensor.h"
75 #include "SCA_KeyboardSensor.h"
76 #include "SCA_MouseSensor.h"
77 #include "SCA_NANDController.h"
78 #include "SCA_NORController.h"
79 #include "SCA_ORController.h"
80 #include "SCA_RandomSensor.h"
81 #include "SCA_XNORController.h"
82 #include "SCA_XORController.h"
83 #include "SCA_PythonKeyboard.h"
84 #include "SCA_PythonMouse.h"
85 #include "KX_IpoActuator.h"
86 #include "KX_NearSensor.h"
87 #include "KX_RadarSensor.h"
88 #include "KX_RaySensor.h"
89 #include "KX_SCA_DynamicActuator.h"
90 #include "KX_SoundActuator.h"
91 #include "KX_TouchSensor.h"
92 #include "KX_VisibilityActuator.h"
93 #include "SCA_PropertySensor.h"
94 #include "SCA_PythonController.h"
95 #include "SCA_RandomActuator.h"
96 #include "SCA_IController.h"
97
98 static void PyType_Attr_Set(PyGetSetDef *attr_getset, PyAttributeDef *attr)
99 {
100         attr_getset->name= (char *)attr->m_name;
101         attr_getset->doc= NULL;
102
103         attr_getset->get= reinterpret_cast<getter>(PyObjectPlus::py_get_attrdef);
104
105         if(attr->m_access==KX_PYATTRIBUTE_RO)
106                 attr_getset->set= NULL;
107         else
108                 attr_getset->set= reinterpret_cast<setter>(PyObjectPlus::py_set_attrdef);
109
110         attr_getset->closure= reinterpret_cast<void *>(attr);
111 }
112
113 static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes, PyAttributeDef *attributesPtr, int init_getset)
114 {
115         PyAttributeDef *attr;
116
117         if(init_getset) {
118                 /* we need to do this for all types before calling PyType_Ready
119                  * since they will call the parents PyType_Ready and those might not have initialized vars yet */
120
121                 //if(tp->tp_base==NULL)
122                 //      printf("Debug: No Parents - '%s'\n" , tp->tp_name);
123
124                 if(tp->tp_getset==NULL && ((attributes && attributes->m_name) || (attributesPtr && attributesPtr->m_name))) {
125                         PyGetSetDef *attr_getset;
126                         int attr_tot= 0;
127
128                         if (attributes) {
129                                 for(attr= attributes; attr->m_name; attr++, attr_tot++)
130                                         attr->m_usePtr = false;
131                         }
132                         if (attributesPtr) {
133                                 for(attr= attributesPtr; attr->m_name; attr++, attr_tot++)
134                                         attr->m_usePtr = true;
135                         }
136
137                         tp->tp_getset = attr_getset = reinterpret_cast<PyGetSetDef *>(PyMem_Malloc((attr_tot+1) * sizeof(PyGetSetDef))); // XXX - Todo, free
138
139                         if (attributes) {
140                                 for(attr= attributes; attr->m_name; attr++, attr_getset++) {
141                                         PyType_Attr_Set(attr_getset, attr);
142                                 }
143                         }
144                         if (attributesPtr) {
145                                 for(attr= attributesPtr; attr->m_name; attr++, attr_getset++) {
146                                         PyType_Attr_Set(attr_getset, attr);
147                                 }
148                         }
149                         memset(attr_getset, 0, sizeof(PyGetSetDef));
150                 }
151         } else {
152                 PyType_Ready(tp);
153                 PyDict_SetItemString(dict, tp->tp_name, reinterpret_cast<PyObject *>(tp));
154         }
155         
156 }
157
158
159 #define PyType_Ready_Attr(d, n, i)   PyType_Ready_ADD(d, &n::Type, n::Attributes, NULL, i)
160 #define PyType_Ready_AttrPtr(d, n, i)   PyType_Ready_ADD(d, &n::Type, n::Attributes, n::AttributesPtr, i)
161
162 void initPyTypes(void)
163 {
164         
165 /*
166         initPyObjectPlusType(BL_ActionActuator::Parents);
167         .....
168 */
169
170         /* For now just do PyType_Ready */
171         PyObject *mod= PyModule_New("GameTypes");
172         PyObject *dict= PyModule_GetDict(mod);
173         PyDict_SetItemString(PySys_GetObject((char *)"modules"), (char *)"GameTypes", mod);
174         Py_DECREF(mod);
175         
176         
177         for(int init_getset= 1; init_getset > -1; init_getset--) { /* run twice, once to init the getsets another to run PyType_Ready */
178                 PyType_Ready_Attr(dict, BL_ActionActuator, init_getset);
179                 PyType_Ready_Attr(dict, BL_Shader, init_getset);
180                 PyType_Ready_Attr(dict, BL_ShapeActionActuator, init_getset);
181                 PyType_Ready_Attr(dict, BL_ArmatureObject, init_getset);
182                 PyType_Ready_Attr(dict, BL_ArmatureActuator, init_getset);
183                 PyType_Ready_Attr(dict, BL_ArmatureConstraint, init_getset);
184                 PyType_Ready_AttrPtr(dict, BL_ArmatureBone, init_getset);
185                 PyType_Ready_AttrPtr(dict, BL_ArmatureChannel, init_getset);
186                 PyType_Ready_Attr(dict, CListValue, init_getset);
187                 PyType_Ready_Attr(dict, CValue, init_getset);
188                 PyType_Ready_Attr(dict, KX_BlenderMaterial, init_getset);
189                 PyType_Ready_Attr(dict, KX_Camera, init_getset);
190                 PyType_Ready_Attr(dict, KX_CameraActuator, init_getset);
191                 PyType_Ready_Attr(dict, KX_ConstraintActuator, init_getset);
192                 PyType_Ready_Attr(dict, KX_ConstraintWrapper, init_getset);
193                 PyType_Ready_Attr(dict, KX_GameActuator, init_getset);
194                 PyType_Ready_Attr(dict, KX_GameObject, init_getset);
195                 PyType_Ready_Attr(dict, KX_IpoActuator, init_getset);
196                 PyType_Ready_Attr(dict, KX_LightObject, init_getset);
197                 PyType_Ready_Attr(dict, KX_FontObject, init_getset);
198                 PyType_Ready_Attr(dict, KX_MeshProxy, init_getset);
199                 PyType_Ready_Attr(dict, KX_MouseFocusSensor, init_getset);
200                 PyType_Ready_Attr(dict, KX_NearSensor, init_getset);
201                 PyType_Ready_Attr(dict, KX_NetworkMessageActuator, init_getset);
202                 PyType_Ready_Attr(dict, KX_NetworkMessageSensor, init_getset);
203                 PyType_Ready_Attr(dict, KX_ObjectActuator, init_getset);
204                 PyType_Ready_Attr(dict, KX_ParentActuator, init_getset);
205                 PyType_Ready_Attr(dict, KX_PhysicsObjectWrapper, init_getset);
206                 PyType_Ready_Attr(dict, KX_PolyProxy, init_getset);
207                 PyType_Ready_Attr(dict, KX_PolygonMaterial, init_getset);
208                 PyType_Ready_Attr(dict, KX_RadarSensor, init_getset);
209                 PyType_Ready_Attr(dict, KX_RaySensor, init_getset);
210                 PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator, init_getset);
211                 PyType_Ready_Attr(dict, KX_SCA_DynamicActuator, init_getset);
212                 PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator, init_getset);
213                 PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator, init_getset);
214                 PyType_Ready_Attr(dict, KX_Scene, init_getset);
215                 PyType_Ready_Attr(dict, KX_SceneActuator, init_getset);
216                 PyType_Ready_Attr(dict, KX_SoundActuator, init_getset);
217                 PyType_Ready_Attr(dict, KX_StateActuator, init_getset);
218                 PyType_Ready_Attr(dict, KX_TouchSensor, init_getset);
219                 PyType_Ready_Attr(dict, KX_TrackToActuator, init_getset);
220                 PyType_Ready_Attr(dict, KX_VehicleWrapper, init_getset);
221                 PyType_Ready_Attr(dict, KX_VertexProxy, init_getset);
222                 PyType_Ready_Attr(dict, KX_VisibilityActuator, init_getset);
223                 PyType_Ready_Attr(dict, PyObjectPlus, init_getset);
224                 PyType_Ready_Attr(dict, SCA_2DFilterActuator, init_getset);
225                 PyType_Ready_Attr(dict, SCA_ANDController, init_getset);
226                 PyType_Ready_Attr(dict, SCA_ActuatorSensor, init_getset);
227                 PyType_Ready_Attr(dict, SCA_AlwaysSensor, init_getset);
228                 PyType_Ready_Attr(dict, SCA_DelaySensor, init_getset);
229                 PyType_Ready_Attr(dict, SCA_ILogicBrick, init_getset);
230                 PyType_Ready_Attr(dict, SCA_IObject, init_getset);
231                 PyType_Ready_Attr(dict, SCA_ISensor, init_getset);
232                 PyType_Ready_Attr(dict, SCA_JoystickSensor, init_getset);
233                 PyType_Ready_Attr(dict, SCA_KeyboardSensor, init_getset);
234                 PyType_Ready_Attr(dict, SCA_MouseSensor, init_getset);
235                 PyType_Ready_Attr(dict, SCA_NANDController, init_getset);
236                 PyType_Ready_Attr(dict, SCA_NORController, init_getset);
237                 PyType_Ready_Attr(dict, SCA_ORController, init_getset);
238                 PyType_Ready_Attr(dict, SCA_PropertyActuator, init_getset);
239                 PyType_Ready_Attr(dict, SCA_PropertySensor, init_getset);
240                 PyType_Ready_Attr(dict, SCA_PythonController, init_getset);
241                 PyType_Ready_Attr(dict, SCA_RandomActuator, init_getset);
242                 PyType_Ready_Attr(dict, SCA_RandomSensor, init_getset);
243                 PyType_Ready_Attr(dict, SCA_XNORController, init_getset);
244                 PyType_Ready_Attr(dict, SCA_XORController, init_getset);
245                 PyType_Ready_Attr(dict, SCA_IController, init_getset);
246                 PyType_Ready_Attr(dict, SCA_PythonKeyboard, init_getset);
247                 PyType_Ready_Attr(dict, SCA_PythonMouse, init_getset);
248         }
249
250
251         /* Normal python type */
252         PyType_Ready(&KX_PythonSeq_Type);
253
254 #ifdef USE_MATHUTILS
255         /* Init mathutils callbacks */
256         KX_GameObject_Mathutils_Callback_Init();
257         KX_ObjectActuator_Mathutils_Callback_Init();
258 #endif
259 }
260
261 #endif // WITH_PYTHON
262
263 #endif