Hopefully a working merge with trunk (could be one error left in raytrace.c - will...
[blender.git] / source / gameengine / Ketsji / KX_PythonInitTypes.cpp
1 /**
2  * $Id: KX_PythonInitTypes.cpp 19794 2009-04-19 17:29:07Z campbellbarton $
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_CDActuator.h"
40 #include "KX_CameraActuator.h"
41 #include "KX_ConstraintActuator.h"
42 #include "KX_ConstraintWrapper.h"
43 #include "KX_GameActuator.h"
44 #include "KX_Light.h"
45 #include "KX_MeshProxy.h"
46 #include "KX_MouseFocusSensor.h"
47 #include "KX_NetworkMessageActuator.h"
48 #include "KX_NetworkMessageSensor.h"
49 #include "KX_ObjectActuator.h"
50 #include "KX_ParentActuator.h"
51 #include "KX_PhysicsObjectWrapper.h"
52 #include "KX_PolyProxy.h"
53 #include "KX_PolygonMaterial.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
88
89 void initPyObjectPlusType(PyTypeObject **parents)
90 {
91         int i;
92
93         for (i=0; parents[i]; i++) {
94                 if(PyType_Ready(parents[i]) < 0) {
95                         /* This is very very unlikely */
96                         printf("Error, pytype could not initialize, Blender may crash \"%s\"\n", parents[i]->tp_name);
97                         return;
98                 }
99
100 #if 0
101                 PyObject_Print(reinterpret_cast<PyObject *>parents[i], stderr, 0);
102                 fprintf(stderr, "\n");
103                 PyObject_Print(parents[i]->tp_dict, stderr, 0);
104                 fprintf(stderr, "\n\n");
105 #endif
106
107         }
108
109          PyObject *dict= NULL;
110
111          while(i) {
112                  i--;
113
114                  if (dict) {
115                         PyDict_Update(parents[i]->tp_dict, dict);
116                  }
117                  dict= parents[i]->tp_dict;
118
119 #if 1
120                 PyObject_Print(reinterpret_cast<PyObject *>(parents[i]), stderr, 0);
121                 fprintf(stderr, "\n");
122                 PyObject_Print(parents[i]->tp_dict, stderr, 0);
123                 fprintf(stderr, "\n\n");
124 #endif
125
126         }
127 }
128
129
130
131
132 static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes)
133 {
134         PyAttributeDef *attr;
135         PyObject *item;
136         
137         PyType_Ready(tp);
138         PyDict_SetItemString(dict, tp->tp_name, reinterpret_cast<PyObject *>(tp));
139         
140         /* store attr defs in the tp_dict for to avoid string lookups */
141         for(attr= attributes; attr->m_name; attr++) {
142                 item= PyCObject_FromVoidPtr(attr, NULL);
143                 PyDict_SetItemString(tp->tp_dict, attr->m_name, item);
144                 Py_DECREF(item);
145         }
146         
147 }
148
149
150 #define PyType_Ready_Attr(d, n)   PyType_Ready_ADD(d, &n::Type, n::Attributes)
151
152 void initPyTypes(void)
153 {
154         
155 /*
156         initPyObjectPlusType(BL_ActionActuator::Parents);
157         .....
158 */
159
160         /* For now just do PyType_Ready */
161         PyObject *mod= PyModule_New("GameTypes");
162         PyObject *dict= PyModule_GetDict(mod);
163         PyDict_SetItemString(PySys_GetObject((char *)"modules"), (char *)"GameTypes", mod);
164         Py_DECREF(mod);
165         
166         PyType_Ready_Attr(dict, BL_ActionActuator);
167         PyType_Ready_Attr(dict, BL_Shader);
168         PyType_Ready_Attr(dict, BL_ShapeActionActuator);
169         PyType_Ready_Attr(dict, CListValue);
170         PyType_Ready_Attr(dict, CValue);
171         PyType_Ready_Attr(dict, KX_BlenderMaterial);
172         PyType_Ready_Attr(dict, KX_CDActuator);
173         PyType_Ready_Attr(dict, KX_Camera);
174         PyType_Ready_Attr(dict, KX_CameraActuator);
175         PyType_Ready_Attr(dict, KX_ConstraintActuator);
176         PyType_Ready_Attr(dict, KX_ConstraintWrapper);
177         PyType_Ready_Attr(dict, KX_GameActuator);
178         PyType_Ready_Attr(dict, KX_GameObject);
179         PyType_Ready_Attr(dict, KX_IpoActuator);
180         PyType_Ready_Attr(dict, KX_LightObject);
181         PyType_Ready_Attr(dict, KX_MeshProxy);
182         PyType_Ready_Attr(dict, KX_MouseFocusSensor);
183         PyType_Ready_Attr(dict, KX_NearSensor);
184         PyType_Ready_Attr(dict, KX_NetworkMessageActuator);
185         PyType_Ready_Attr(dict, KX_NetworkMessageSensor);
186         PyType_Ready_Attr(dict, KX_ObjectActuator);
187         PyType_Ready_Attr(dict, KX_ParentActuator);
188         PyType_Ready_Attr(dict, KX_PhysicsObjectWrapper);
189         PyType_Ready_Attr(dict, KX_PolyProxy);
190         PyType_Ready_Attr(dict, KX_PolygonMaterial);
191         PyType_Ready_Attr(dict, KX_RadarSensor);
192         PyType_Ready_Attr(dict, KX_RaySensor);
193         PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator);
194         PyType_Ready_Attr(dict, KX_SCA_DynamicActuator);
195         PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator);
196         PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator);
197         PyType_Ready_Attr(dict, KX_Scene);
198         PyType_Ready_Attr(dict, KX_SceneActuator);
199         PyType_Ready_Attr(dict, KX_SoundActuator);
200         PyType_Ready_Attr(dict, KX_StateActuator);
201         PyType_Ready_Attr(dict, KX_TouchSensor);
202         PyType_Ready_Attr(dict, KX_TrackToActuator);
203         PyType_Ready_Attr(dict, KX_VehicleWrapper);
204         PyType_Ready_Attr(dict, KX_VertexProxy);
205         PyType_Ready_Attr(dict, KX_VisibilityActuator);
206         PyType_Ready_Attr(dict, PyObjectPlus);
207         PyType_Ready_Attr(dict, SCA_2DFilterActuator);
208         PyType_Ready_Attr(dict, SCA_ANDController);
209         PyType_Ready_Attr(dict, SCA_ActuatorSensor);
210         PyType_Ready_Attr(dict, SCA_AlwaysSensor);
211         PyType_Ready_Attr(dict, SCA_DelaySensor);
212         PyType_Ready_Attr(dict, SCA_ILogicBrick);
213         PyType_Ready_Attr(dict, SCA_IObject);
214         PyType_Ready_Attr(dict, SCA_ISensor);
215         PyType_Ready_Attr(dict, SCA_JoystickSensor);
216         PyType_Ready_Attr(dict, SCA_KeyboardSensor);
217         PyType_Ready_Attr(dict, SCA_MouseSensor);
218         PyType_Ready_Attr(dict, SCA_NANDController);
219         PyType_Ready_Attr(dict, SCA_NORController);
220         PyType_Ready_Attr(dict, SCA_ORController);
221         PyType_Ready_Attr(dict, SCA_PropertyActuator);
222         PyType_Ready_Attr(dict, SCA_PropertySensor);
223         PyType_Ready_Attr(dict, SCA_PythonController);
224         PyType_Ready_Attr(dict, SCA_RandomActuator);
225         PyType_Ready_Attr(dict, SCA_RandomSensor);
226         PyType_Ready_Attr(dict, SCA_XNORController);
227         PyType_Ready_Attr(dict, SCA_XORController);
228         
229         
230         
231 }
232
233 #endif