fix for bug #18898: GE perspective 3D View not working properly (missing LENS)
[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_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_PythonSeq.h"
55 #include "KX_SCA_AddObjectActuator.h"
56 #include "KX_SCA_EndObjectActuator.h"
57 #include "KX_SCA_ReplaceMeshActuator.h"
58 #include "KX_SceneActuator.h"
59 #include "KX_StateActuator.h"
60 #include "KX_TrackToActuator.h"
61 #include "KX_VehicleWrapper.h"
62 #include "KX_VertexProxy.h"
63 #include "SCA_2DFilterActuator.h"
64 #include "SCA_ANDController.h"
65 #include "SCA_ActuatorSensor.h"
66 #include "SCA_AlwaysSensor.h"
67 #include "SCA_DelaySensor.h"
68 #include "SCA_JoystickSensor.h"
69 #include "SCA_KeyboardSensor.h"
70 #include "SCA_MouseSensor.h"
71 #include "SCA_NANDController.h"
72 #include "SCA_NORController.h"
73 #include "SCA_ORController.h"
74 #include "SCA_RandomSensor.h"
75 #include "SCA_XNORController.h"
76 #include "SCA_XORController.h"
77 #include "KX_IpoActuator.h"
78 #include "KX_NearSensor.h"
79 #include "KX_RadarSensor.h"
80 #include "KX_RaySensor.h"
81 #include "KX_SCA_DynamicActuator.h"
82 #include "KX_SoundActuator.h"
83 #include "KX_TouchSensor.h"
84 #include "KX_VisibilityActuator.h"
85 #include "SCA_PropertySensor.h"
86 #include "SCA_PythonController.h"
87 #include "SCA_RandomActuator.h"
88 #include "SCA_IController.h"
89
90
91 void initPyObjectPlusType(PyTypeObject **parents)
92 {
93         int i;
94
95         for (i=0; parents[i]; i++) {
96                 if(PyType_Ready(parents[i]) < 0) {
97                         /* This is very very unlikely */
98                         printf("Error, pytype could not initialize, Blender may crash \"%s\"\n", parents[i]->tp_name);
99                         return;
100                 }
101
102 #if 0
103                 PyObject_Print(reinterpret_cast<PyObject *>parents[i], stderr, 0);
104                 fprintf(stderr, "\n");
105                 PyObject_Print(parents[i]->tp_dict, stderr, 0);
106                 fprintf(stderr, "\n\n");
107 #endif
108
109         }
110
111          PyObject *dict= NULL;
112
113          while(i) {
114                  i--;
115
116                  if (dict) {
117                         PyDict_Update(parents[i]->tp_dict, dict);
118                  }
119                  dict= parents[i]->tp_dict;
120
121 #if 1
122                 PyObject_Print(reinterpret_cast<PyObject *>(parents[i]), stderr, 0);
123                 fprintf(stderr, "\n");
124                 PyObject_Print(parents[i]->tp_dict, stderr, 0);
125                 fprintf(stderr, "\n\n");
126 #endif
127
128         }
129 }
130
131
132
133
134 static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes)
135 {
136         PyAttributeDef *attr;
137         PyObject *item;
138         
139         PyType_Ready(tp);
140         PyDict_SetItemString(dict, tp->tp_name, reinterpret_cast<PyObject *>(tp));
141         
142         /* store attr defs in the tp_dict for to avoid string lookups */
143         for(attr= attributes; attr->m_name; attr++) {
144                 item= PyCObject_FromVoidPtr(attr, NULL);
145                 PyDict_SetItemString(tp->tp_dict, attr->m_name, item);
146                 Py_DECREF(item);
147         }
148         
149 }
150
151
152 #define PyType_Ready_Attr(d, n)   PyType_Ready_ADD(d, &n::Type, n::Attributes)
153
154 void initPyTypes(void)
155 {
156         
157 /*
158         initPyObjectPlusType(BL_ActionActuator::Parents);
159         .....
160 */
161
162         /* For now just do PyType_Ready */
163         PyObject *mod= PyModule_New("GameTypes");
164         PyObject *dict= PyModule_GetDict(mod);
165         PyDict_SetItemString(PySys_GetObject((char *)"modules"), (char *)"GameTypes", mod);
166         Py_DECREF(mod);
167         
168         PyType_Ready_Attr(dict, BL_ActionActuator);
169         PyType_Ready_Attr(dict, BL_Shader);
170         PyType_Ready_Attr(dict, BL_ShapeActionActuator);
171         PyType_Ready_Attr(dict, CListValue);
172         PyType_Ready_Attr(dict, CValue);
173         PyType_Ready_Attr(dict, KX_BlenderMaterial);
174         PyType_Ready_Attr(dict, KX_CDActuator);
175         PyType_Ready_Attr(dict, KX_Camera);
176         PyType_Ready_Attr(dict, KX_CameraActuator);
177         PyType_Ready_Attr(dict, KX_ConstraintActuator);
178         PyType_Ready_Attr(dict, KX_ConstraintWrapper);
179         PyType_Ready_Attr(dict, KX_GameActuator);
180         PyType_Ready_Attr(dict, KX_GameObject);
181         PyType_Ready_Attr(dict, KX_IpoActuator);
182         PyType_Ready_Attr(dict, KX_LightObject);
183         PyType_Ready_Attr(dict, KX_MeshProxy);
184         PyType_Ready_Attr(dict, KX_MouseFocusSensor);
185         PyType_Ready_Attr(dict, KX_NearSensor);
186         PyType_Ready_Attr(dict, KX_NetworkMessageActuator);
187         PyType_Ready_Attr(dict, KX_NetworkMessageSensor);
188         PyType_Ready_Attr(dict, KX_ObjectActuator);
189         PyType_Ready_Attr(dict, KX_ParentActuator);
190         PyType_Ready_Attr(dict, KX_PhysicsObjectWrapper);
191         PyType_Ready_Attr(dict, KX_PolyProxy);
192         PyType_Ready_Attr(dict, KX_PolygonMaterial);
193         PyType_Ready_Attr(dict, KX_RadarSensor);
194         PyType_Ready_Attr(dict, KX_RaySensor);
195         PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator);
196         PyType_Ready_Attr(dict, KX_SCA_DynamicActuator);
197         PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator);
198         PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator);
199         PyType_Ready_Attr(dict, KX_Scene);
200         PyType_Ready_Attr(dict, KX_SceneActuator);
201         PyType_Ready_Attr(dict, KX_SoundActuator);
202         PyType_Ready_Attr(dict, KX_StateActuator);
203         PyType_Ready_Attr(dict, KX_TouchSensor);
204         PyType_Ready_Attr(dict, KX_TrackToActuator);
205         PyType_Ready_Attr(dict, KX_VehicleWrapper);
206         PyType_Ready_Attr(dict, KX_VertexProxy);
207         PyType_Ready_Attr(dict, KX_VisibilityActuator);
208         PyType_Ready_Attr(dict, PyObjectPlus);
209         PyType_Ready_Attr(dict, SCA_2DFilterActuator);
210         PyType_Ready_Attr(dict, SCA_ANDController);
211         PyType_Ready_Attr(dict, SCA_ActuatorSensor);
212         PyType_Ready_Attr(dict, SCA_AlwaysSensor);
213         PyType_Ready_Attr(dict, SCA_DelaySensor);
214         PyType_Ready_Attr(dict, SCA_ILogicBrick);
215         PyType_Ready_Attr(dict, SCA_IObject);
216         PyType_Ready_Attr(dict, SCA_ISensor);
217         PyType_Ready_Attr(dict, SCA_JoystickSensor);
218         PyType_Ready_Attr(dict, SCA_KeyboardSensor);
219         PyType_Ready_Attr(dict, SCA_MouseSensor);
220         PyType_Ready_Attr(dict, SCA_NANDController);
221         PyType_Ready_Attr(dict, SCA_NORController);
222         PyType_Ready_Attr(dict, SCA_ORController);
223         PyType_Ready_Attr(dict, SCA_PropertyActuator);
224         PyType_Ready_Attr(dict, SCA_PropertySensor);
225         PyType_Ready_Attr(dict, SCA_PythonController);
226         PyType_Ready_Attr(dict, SCA_RandomActuator);
227         PyType_Ready_Attr(dict, SCA_RandomSensor);
228         PyType_Ready_Attr(dict, SCA_XNORController);
229         PyType_Ready_Attr(dict, SCA_XORController);
230         PyType_Ready_Attr(dict, SCA_IController);
231         
232         /* Normal python type */
233         PyType_Ready(&KX_PythonSeq_Type);
234 }
235
236 #endif