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