This patch spawns from this game engine issue:
[blender-staging.git] / source / gameengine / Ketsji / KX_PythonInit.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  * Initialize Python thingies.
32  */
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #ifdef WIN32
39 #include <windows.h>
40 #endif // WIN32
41 #ifdef __APPLE__
42 #define GL_GLEXT_LEGACY 1
43 #include <OpenGL/gl.h>
44 #include <OpenGL/glu.h>
45 #else
46 #include <GL/gl.h>
47 /* #if defined(__sun__) && !defined(__sparc__)
48 #include <mesa/glu.h>
49 #else */
50 #include <GL/glu.h>
51 /* #endif */
52 #endif
53
54 #include <stdlib.h>
55
56 #ifdef WIN32
57 #pragma warning (disable : 4786)
58 #endif //WIN32
59
60 #include "KX_PythonInit.h"
61 //python physics binding
62 #include "KX_PyConstraintBinding.h"
63
64 #include "KX_KetsjiEngine.h"
65
66 #include "SCA_IInputDevice.h"
67 #include "SCA_PropertySensor.h"
68 #include "SCA_RandomActuator.h"
69 #include "KX_ConstraintActuator.h"
70 #include "KX_IpoActuator.h"
71 #include "KX_SoundActuator.h"
72 #include "BL_ActionActuator.h"
73 #include "RAS_IRasterizer.h"
74 #include "RAS_ICanvas.h"
75 #include "MT_Vector3.h"
76 #include "MT_Point3.h"
77 #include "ListValue.h"
78 #include "KX_Scene.h"
79 #include "SND_DeviceManager.h"
80
81 #include "RAS_OpenGLRasterizer/RAS_GLExtensionManager.h"
82 #include "BL_Shader.h"
83
84 #include "KX_PyMath.h"
85
86 #include "PHY_IPhysicsEnvironment.h"
87 // FIXME: Enable for access to blender python modules.  This is disabled because
88 // python has dependencies on a lot of other modules and is a pain to link.
89 //#define USE_BLENDER_PYTHON
90 #ifdef USE_BLENDER_PYTHON
91 //#include "BPY_extern.h"
92 #endif 
93
94 static void setSandbox(TPythonSecurityLevel level);
95
96
97 // 'local' copy of canvas ptr, for window height/width python scripts
98 static RAS_ICanvas* gp_Canvas = NULL;
99 static KX_Scene*        gp_KetsjiScene = NULL;
100 static RAS_IRasterizer* gp_Rasterizer = NULL;
101
102 void    KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
103 {
104         if (gp_Rasterizer)
105                 gp_Rasterizer->DrawDebugLine(from,to,color);
106 }
107
108 /* Macro for building the keyboard translation */
109 //#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyInt_FromLong(SCA_IInputDevice::KX_##name))
110 #define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyInt_FromLong(name))
111 /* For the defines for types from logic bricks, we do stuff explicitly... */
112 #define KX_MACRO_addTypesToDict(dict, name, name2) PyDict_SetItemString(dict, #name, PyInt_FromLong(name2))
113
114
115 // temporarily python stuff, will be put in another place later !
116 #include "KX_Python.h"
117 #include "SCA_PythonController.h"
118 // List of methods defined in the module
119
120 static PyObject* ErrorObject;
121 STR_String gPyGetRandomFloat_doc="getRandomFloat returns a random floating point value in the range [0..1)";
122
123 static PyObject* gPyGetRandomFloat(PyObject*,
124                                         PyObject*, 
125                                         PyObject*)
126 {
127         return PyFloat_FromDouble(MT_random());
128 }
129
130 static PyObject* gPySetGravity(PyObject*,
131                                                                                  PyObject* args, 
132                                                                                  PyObject*)
133 {
134         MT_Vector3 vec = MT_Vector3(0., 0., 0.);
135         if (PyVecArgTo(args, vec))
136         {
137                 if (gp_KetsjiScene)
138                         gp_KetsjiScene->SetGravity(vec);
139                 
140                 Py_Return;
141         }
142         
143         return NULL;
144 }
145
146
147 static bool usedsp = false;
148
149 // this gets a pointer to an array filled with floats
150 static PyObject* gPyGetSpectrum(PyObject*,
151                                                                 PyObject* args, 
152                                                                 PyObject*)
153 {
154         SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
155
156         PyObject* resultlist = PyList_New(512);
157
158         if (audiodevice)
159         {
160                 if (!usedsp)
161                 {
162                         audiodevice->StartUsingDSP();
163                         usedsp = true;
164                 }
165                         
166                 float* spectrum = audiodevice->GetSpectrum();
167
168                 for (int index = 0; index < 512; index++)
169                 {
170                         PyList_SetItem(resultlist, index, PyFloat_FromDouble(spectrum[index]));
171                 }
172         }
173
174         return resultlist;
175 }
176
177
178
179 static PyObject* gPyStartDSP(PyObject*,
180                                                 PyObject* args, 
181                                                 PyObject*)
182 {
183         SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
184
185         if (audiodevice)
186         {
187                 if (!usedsp)
188                 {
189                         audiodevice->StartUsingDSP();
190                         usedsp = true;
191                         Py_Return;
192                 }
193         }
194         return NULL;
195 }
196
197
198
199 static PyObject* gPyStopDSP(PyObject*,
200                                            PyObject* args, 
201                                            PyObject*)
202 {
203         SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
204
205         if (audiodevice)
206         {
207                 if (usedsp)
208                 {
209                         audiodevice->StopUsingDSP();
210                         usedsp = false;
211                         Py_Return;
212                 }
213         }
214         return NULL;
215 }
216
217 static PyObject* gPySetLogicTicRate(PyObject*,
218                                         PyObject* args,
219                                         PyObject*)
220 {
221         float ticrate;
222         if (PyArg_ParseTuple(args, "f", &ticrate))
223         {
224                 KX_KetsjiEngine::SetTicRate(ticrate);
225                 Py_Return;
226         }
227         
228         return NULL;
229 }
230
231 static PyObject* gPyGetLogicTicRate(PyObject*, PyObject*, PyObject*)
232 {
233         return PyFloat_FromDouble(KX_KetsjiEngine::GetTicRate());
234 }
235
236 static PyObject* gPySetPhysicsTicRate(PyObject*,
237                                         PyObject* args,
238                                         PyObject*)
239 {
240         float ticrate;
241         if (PyArg_ParseTuple(args, "f", &ticrate))
242         {
243
244                 PHY_GetActiveEnvironment()->setFixedTimeStep(true,ticrate);
245                 Py_Return;
246         }
247         
248         return NULL;
249 }
250
251 static PyObject* gPySetPhysicsDebug(PyObject*,
252                                         PyObject* args,
253                                         PyObject*)
254 {
255         int debugMode;
256         if (PyArg_ParseTuple(args, "i", &debugMode))
257         {
258                 PHY_GetActiveEnvironment()->setDebugMode(debugMode);
259                 Py_Return;
260         }
261         
262         return NULL;
263 }
264
265
266
267 static PyObject* gPyGetPhysicsTicRate(PyObject*, PyObject*, PyObject*)
268 {
269         return PyFloat_FromDouble(PHY_GetActiveEnvironment()->getFixedTimeStep());
270 }
271
272 static STR_String gPyGetCurrentScene_doc =  
273 "getCurrentScene()\n"
274 "Gets a reference to the current scene.\n";
275 static PyObject* gPyGetCurrentScene(PyObject* self,
276                                            PyObject* args, 
277                                            PyObject* kwds)
278 {
279         Py_INCREF(gp_KetsjiScene);
280         return (PyObject*) gp_KetsjiScene;
281 }
282
283 static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
284 {
285 #define pprint(x) std::cout << x << std::endl;
286         bgl::BL_EXTInfo ext = bgl::RAS_EXT_support;
287         bool count=0;
288         bool support=0;
289         pprint("Supported Extensions...");
290 #ifdef GL_ARB_shader_objects
291         pprint(" GL_ARB_shader_objects supported?       "<< (ext._ARB_shader_objects?"yes.":"no."));
292         count = 1;
293 #endif
294
295 #ifdef GL_ARB_vertex_shader
296         support= ext._ARB_vertex_shader;
297         pprint(" GL_ARB_vertex_shader supported?        "<< (support?"yes.":"no."));
298         count = 1;
299         if(support){
300                 pprint(" ----------Details----------");
301                 int max=0;
302                 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, (GLint*)&max);
303                 pprint("  Max uniform components." << max);
304
305                 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, (GLint*)&max);
306                 pprint("  Max varying floats." << max);
307
308                 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, (GLint*)&max);
309                 pprint("  Max vertex texture units." << max);
310         
311                 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, (GLint*)&max);
312                 pprint("  Max combined texture units." << max);
313                 pprint("");
314         }
315 #endif
316 #ifdef GL_ARB_fragment_shader
317         support=ext._ARB_fragment_shader;
318         pprint(" GL_ARB_fragment_shader supported?      "<< (support?"yes.":"no."));
319         count = 1;
320         if(support){
321                 pprint(" ----------Details----------");
322                 int max=0;
323                 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, (GLint*)&max);
324                 pprint("  Max uniform components." << max);
325                 pprint("");
326         }
327 #endif
328 #ifdef GL_ARB_texture_cube_map
329         support = ext._ARB_texture_cube_map;
330         pprint(" GL_ARB_texture_cube_map supported?     "<< (support?"yes.":"no."));
331         count = 1;
332         if(support){
333                 pprint(" ----------Details----------");
334                 int size=0;
335                 glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, (GLint*)&size);
336                 pprint("  Max cubemap size." << size);
337                 pprint("");
338         }
339 #endif
340 #if defined(GL_ARB_multitexture) && defined(WITH_GLEXT)
341         if (!getenv("WITHOUT_GLEXT")) {
342                 support = ext._ARB_multitexture;
343                 count = 1;
344                 pprint(" GL_ARB_multitexture supported?         "<< (support?"yes.":"no."));
345                 if(support){
346                         pprint(" ----------Details----------");
347                         int units=0;
348                         glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&units);
349                         pprint("  Max texture units available.  " << units);
350                         pprint("");
351                 }
352         }
353 #endif
354 #ifdef GL_ARB_texture_env_combine
355         pprint(" GL_ARB_texture_env_combine supported?  "<< (ext._ARB_texture_env_combine?"yes.":"no."));
356         count = 1;
357 #endif
358         if(!count)
359                 pprint("No extenstions are used in this build");
360
361         Py_INCREF(Py_None);
362         return Py_None;
363 }
364
365
366 static struct PyMethodDef game_methods[] = {
367         {"getCurrentController",
368         (PyCFunction) SCA_PythonController::sPyGetCurrentController,
369         METH_VARARGS, SCA_PythonController::sPyGetCurrentController__doc__},
370         {"getCurrentScene", (PyCFunction) gPyGetCurrentScene,
371         METH_VARARGS, gPyGetCurrentScene_doc.Ptr()},
372         {"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator,
373         METH_VARARGS, SCA_PythonController::sPyAddActiveActuator__doc__},
374         {"getRandomFloat",(PyCFunction) gPyGetRandomFloat,
375         METH_VARARGS,gPyGetRandomFloat_doc.Ptr()},
376         {"setGravity",(PyCFunction) gPySetGravity, METH_VARARGS,"set Gravitation"},
377         {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_VARARGS,"get audio spectrum"},
378         {"stopDSP",(PyCFunction) gPyStopDSP, METH_VARARGS,"stop using the audio dsp (for performance reasons)"},
379         {"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_VARARGS, "Gets the logic tic rate"},
380         {"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, "Sets the logic tic rate"},
381         {"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_VARARGS, "Gets the physics tic rate"},
382         {"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, "Sets the physics tic rate"},
383         {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, "Prints GL Extension Info"},
384         {NULL, (PyCFunction) NULL, 0, NULL }
385 };
386
387
388 static PyObject* gPyGetWindowHeight(PyObject*, 
389                                                                                  PyObject* args, 
390                                                                                  PyObject*)
391 {
392         int height = (gp_Canvas ? gp_Canvas->GetHeight() : 0);
393
394                 PyObject* heightval = PyInt_FromLong(height);
395                 return heightval;
396 }
397
398
399
400 static PyObject* gPyGetWindowWidth(PyObject*, 
401                                                                                  PyObject* args, 
402                                                                                  PyObject*)
403 {
404                 
405
406         int width = (gp_Canvas ? gp_Canvas->GetWidth() : 0);
407         
408                 PyObject* widthval = PyInt_FromLong(width);
409                 return widthval;
410 }
411
412
413
414 // temporarility visibility thing, will be moved to rasterizer/renderer later
415 bool gUseVisibilityTemp = false;
416
417 static PyObject* gPyEnableVisibility(PyObject*, 
418                                                                                  PyObject* args, 
419                                                                                  PyObject*)
420 {
421         int visible;
422         if (PyArg_ParseTuple(args,"i",&visible))
423         {
424             gUseVisibilityTemp = (visible != 0);
425         }
426         else
427         {
428           Py_Return;         
429         }
430    Py_Return;
431 }
432
433
434
435 static PyObject* gPyShowMouse(PyObject*, 
436                                                                                  PyObject* args, 
437                                                                                  PyObject*)
438 {
439         int visible;
440         if (PyArg_ParseTuple(args,"i",&visible))
441         {
442             if (visible)
443                 {
444                         if (gp_Canvas)
445                                 gp_Canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
446                 } else
447                 {
448                         if (gp_Canvas)
449                                 gp_Canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
450                 }
451         }
452         
453    Py_Return;
454 }
455
456
457
458 static PyObject* gPySetMousePosition(PyObject*, 
459                                                                                  PyObject* args, 
460                                                                                  PyObject*)
461 {
462         int x,y;
463         if (PyArg_ParseTuple(args,"ii",&x,&y))
464         {
465             if (gp_Canvas)
466                         gp_Canvas->SetMousePosition(x,y);
467         }
468         
469    Py_Return;
470 }
471
472 static PyObject* gPySetEyeSeparation(PyObject*,
473                                                 PyObject* args,
474                                                 PyObject*)
475 {
476         float sep;
477         if (PyArg_ParseTuple(args, "f", &sep))
478         {
479                 if (gp_Rasterizer)
480                         gp_Rasterizer->SetEyeSeparation(sep);
481                         
482                 Py_Return;
483         }
484         
485         return NULL;
486 }
487
488 static PyObject* gPyGetEyeSeparation(PyObject*, PyObject*, PyObject*)
489 {
490         if (gp_Rasterizer)
491                 return PyFloat_FromDouble(gp_Rasterizer->GetEyeSeparation());
492         
493         return NULL;
494 }
495
496 static PyObject* gPySetFocalLength(PyObject*,
497                                         PyObject* args,
498                                         PyObject*)
499 {
500         float focus;
501         if (PyArg_ParseTuple(args, "f", &focus))
502         {
503                 if (gp_Rasterizer)
504                         gp_Rasterizer->SetFocalLength(focus);
505                 Py_Return;
506         }
507         
508         return NULL;
509 }
510
511 static PyObject* gPyGetFocalLength(PyObject*, PyObject*, PyObject*)
512 {
513         if (gp_Rasterizer)
514                 return PyFloat_FromDouble(gp_Rasterizer->GetFocalLength());
515         return NULL;
516 }
517
518 static PyObject* gPySetBackgroundColor(PyObject*, 
519                                                                                  PyObject* args, 
520                                                                                  PyObject*)
521 {
522         
523         MT_Vector4 vec = MT_Vector4(0., 0., 0.3, 0.);
524         if (PyVecArgTo(args, vec))
525         {
526                 if (gp_Canvas)
527                 {
528                         gp_Rasterizer->SetBackColor(vec[0], vec[1], vec[2], vec[3]);
529                 }
530                 Py_Return;
531         }
532         
533         return NULL;
534 }
535
536
537
538 static PyObject* gPySetMistColor(PyObject*, 
539                                                                                  PyObject* args, 
540                                                                                  PyObject*)
541 {
542         
543         MT_Vector3 vec = MT_Vector3(0., 0., 0.);
544         if (PyVecArgTo(args, vec))
545         {
546                 if (gp_Rasterizer)
547                 {
548                         gp_Rasterizer->SetFogColor(vec[0], vec[1], vec[2]);
549                 }
550                 Py_Return;
551         }
552         
553         return NULL;
554 }
555
556
557
558 static PyObject* gPySetMistStart(PyObject*, 
559                                                                                  PyObject* args, 
560                                                                                  PyObject*)
561 {
562
563         float miststart;
564         if (PyArg_ParseTuple(args,"f",&miststart))
565         {
566                 if (gp_Rasterizer)
567                 {
568                         gp_Rasterizer->SetFogStart(miststart);
569                 }
570         }
571    Py_Return;
572 }
573
574
575
576 static PyObject* gPySetMistEnd(PyObject*, 
577                                                                                  PyObject* args, 
578                                                                                  PyObject*)
579 {
580
581         float mistend;
582         if (PyArg_ParseTuple(args,"f",&mistend))
583         {
584                 if (gp_Rasterizer)
585                 {
586                         gp_Rasterizer->SetFogEnd(mistend);
587                 }
588         }
589    Py_Return;
590 }
591
592
593 static PyObject* gPySetAmbientColor(PyObject*, 
594                                                                                  PyObject* args, 
595                                                                                  PyObject*)
596 {
597         
598         MT_Vector3 vec = MT_Vector3(0., 0., 0.);
599         if (PyVecArgTo(args, vec))
600         {
601                 if (gp_Rasterizer)
602                 {
603                         gp_Rasterizer->SetAmbientColor(vec[0], vec[1], vec[2]);
604                 }
605                 Py_Return;
606         }
607         
608         return NULL;
609 }
610
611
612
613
614 static PyObject* gPyMakeScreenshot(PyObject*,
615                                                                         PyObject* args,
616                                                                         PyObject*)
617 {
618         char* filename;
619         if (PyArg_ParseTuple(args,"s",&filename))
620         {
621                 if (gp_Canvas)
622                 {
623                         gp_Canvas->MakeScreenShot(filename);
624                 }
625         }
626         Py_Return;
627 }
628
629 static PyObject* gPyEnableMotionBlur(PyObject*,
630                                                                         PyObject* args,
631                                                                         PyObject*)
632 {
633         float motionblurvalue;
634         if (PyArg_ParseTuple(args,"f",&motionblurvalue))
635         {
636                 if(gp_Rasterizer)
637                 {
638                         gp_Rasterizer->EnableMotionBlur(motionblurvalue);
639                 }
640         }
641         Py_Return;
642 }
643
644 static PyObject* gPyDisableMotionBlur(PyObject*,
645                                                                         PyObject* args,
646                                                                         PyObject*)
647 {
648         if(gp_Rasterizer)
649         {
650                 gp_Rasterizer->DisableMotionBlur();
651         }
652         Py_Return;
653 }
654
655 STR_String      gPyGetWindowHeight__doc__="getWindowHeight doc";
656 STR_String      gPyGetWindowWidth__doc__="getWindowWidth doc";
657 STR_String      gPyEnableVisibility__doc__="enableVisibility doc";
658 STR_String      gPyMakeScreenshot__doc__="make Screenshot doc";
659 STR_String      gPyShowMouse__doc__="showMouse(bool visible)";
660 STR_String      gPySetMousePosition__doc__="setMousePosition(int x,int y)";
661
662 static struct PyMethodDef rasterizer_methods[] = {
663   {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
664    METH_VARARGS, gPyGetWindowWidth__doc__.Ptr()},
665    {"getWindowHeight",(PyCFunction) gPyGetWindowHeight,
666    METH_VARARGS, gPyGetWindowHeight__doc__.Ptr()},
667   {"makeScreenshot",(PyCFunction)gPyMakeScreenshot,
668         METH_VARARGS, gPyMakeScreenshot__doc__.Ptr()},
669    {"enableVisibility",(PyCFunction) gPyEnableVisibility,
670    METH_VARARGS, gPyEnableVisibility__doc__.Ptr()},
671         {"showMouse",(PyCFunction) gPyShowMouse,
672    METH_VARARGS, gPyShowMouse__doc__.Ptr()},
673    {"setMousePosition",(PyCFunction) gPySetMousePosition,
674    METH_VARARGS, gPySetMousePosition__doc__.Ptr()},
675   {"setBackgroundColor",(PyCFunction)gPySetBackgroundColor,METH_VARARGS,"set Background Color (rgb)"},
676         {"setAmbientColor",(PyCFunction)gPySetAmbientColor,METH_VARARGS,"set Ambient Color (rgb)"},
677  {"setMistColor",(PyCFunction)gPySetMistColor,METH_VARARGS,"set Mist Color (rgb)"},
678   {"setMistStart",(PyCFunction)gPySetMistStart,METH_VARARGS,"set Mist Start(rgb)"},
679   {"setMistEnd",(PyCFunction)gPySetMistEnd,METH_VARARGS,"set Mist End(rgb)"},
680   {"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"},
681   {"disableMotionBlur",(PyCFunction)gPyDisableMotionBlur,METH_VARARGS,"disable motion blur"},
682
683   
684   {"setEyeSeparation", (PyCFunction) gPySetEyeSeparation, METH_VARARGS, "set the eye separation for stereo mode"},
685   {"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_VARARGS, "get the eye separation for stereo mode"},
686   {"setFocalLength", (PyCFunction) gPySetFocalLength, METH_VARARGS, "set the focal length for stereo mode"},
687   {"getFocalLength", (PyCFunction) gPyGetFocalLength, METH_VARARGS, "get the focal length for stereo mode"},
688   { NULL, (PyCFunction) NULL, 0, NULL }
689 };
690
691
692
693 // Initialization function for the module (*must* be called initGameLogic)
694
695 static char GameLogic_module_documentation[] =
696 "This is the Python API for the game engine of GameLogic"
697 ;
698
699 static char Rasterizer_module_documentation[] =
700 "This is the Python API for the game engine of Rasterizer"
701 ;
702
703
704
705 PyObject* initGameLogic(KX_Scene* scene) // quick hack to get gravity hook
706 {
707         PyObject* m;
708         PyObject* d;
709
710         gp_KetsjiScene = scene;
711
712         gUseVisibilityTemp=false;
713
714         // Create the module and add the functions
715         m = Py_InitModule4("GameLogic", game_methods,
716                                            GameLogic_module_documentation,
717                                            (PyObject*)NULL,PYTHON_API_VERSION);
718
719         // Add some symbolic constants to the module
720         d = PyModule_GetDict(m);
721
722         ErrorObject = PyString_FromString("GameLogic.error");
723         PyDict_SetItemString(d, "error", ErrorObject);
724
725         // XXXX Add constants here
726         /* To use logic bricks, we need some sort of constants. Here, we associate */
727         /* constants and sumbolic names. Add them to dictionary d.                 */
728
729         /* 1. true and false: needed for everyone                                  */
730         KX_MACRO_addTypesToDict(d, KX_TRUE,  SCA_ILogicBrick::KX_TRUE);
731         KX_MACRO_addTypesToDict(d, KX_FALSE, SCA_ILogicBrick::KX_FALSE);
732
733         /* 2. Property sensor                                                      */
734         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EQUAL,      SCA_PropertySensor::KX_PROPSENSOR_EQUAL);
735         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_NOTEQUAL,   SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL);
736         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_INTERVAL,   SCA_PropertySensor::KX_PROPSENSOR_INTERVAL);
737         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_CHANGED,    SCA_PropertySensor::KX_PROPSENSOR_CHANGED);
738         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EXPRESSION, SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION);
739
740         /* 3. Constraint actuator                                                  */
741         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX);
742         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY);
743         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ);
744         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX);
745         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY);
746         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ);
747
748         /* 4. Ipo actuator, simple part                                            */
749         KX_MACRO_addTypesToDict(d, KX_IPOACT_PLAY,     KX_IpoActuator::KX_ACT_IPO_PLAY);
750         KX_MACRO_addTypesToDict(d, KX_IPOACT_PINGPONG, KX_IpoActuator::KX_ACT_IPO_PINGPONG);
751         KX_MACRO_addTypesToDict(d, KX_IPOACT_FLIPPER,  KX_IpoActuator::KX_ACT_IPO_FLIPPER);
752         KX_MACRO_addTypesToDict(d, KX_IPOACT_LOOPSTOP, KX_IpoActuator::KX_ACT_IPO_LOOPSTOP);
753         KX_MACRO_addTypesToDict(d, KX_IPOACT_LOOPEND,  KX_IpoActuator::KX_ACT_IPO_LOOPEND);
754
755         /* 5. Random distribution types                                            */
756         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_CONST,      SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST);
757         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_UNIFORM,    SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM);
758         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_BERNOUILLI, SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI);
759         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_CONST,       SCA_RandomActuator::KX_RANDOMACT_INT_CONST);
760         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_UNIFORM,     SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM);
761         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_POISSON,     SCA_RandomActuator::KX_RANDOMACT_INT_POISSON);
762         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_CONST,     SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST);
763         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_UNIFORM,   SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM);
764         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NORMAL,    SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL);
765         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL, SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL);
766
767         /* 6. Sound actuator                                                      */
768         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP,              KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
769         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND,               KX_SoundActuator::KX_SOUNDACT_PLAYEND);
770         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP,              KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
771         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND,               KX_SoundActuator::KX_SOUNDACT_LOOPEND);
772         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL,     KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
773         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP,     KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
774
775         /* 7. Action actuator                                                                                                      */
776         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PLAY,     BL_ActionActuator::KX_ACT_ACTION_PLAY);
777         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_FLIPPER,     BL_ActionActuator::KX_ACT_ACTION_FLIPPER);
778         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPSTOP,     BL_ActionActuator::KX_ACT_ACTION_LOOPSTOP);
779         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPEND,     BL_ActionActuator::KX_ACT_ACTION_LOOPEND);
780         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PROPERTY,     BL_ActionActuator::KX_ACT_ACTION_PROPERTY);
781         
782         /*8. GL_BlendFunc */
783         KX_MACRO_addTypesToDict(d, BL_ZERO, GL_ZERO);
784         KX_MACRO_addTypesToDict(d, BL_ONE, GL_ONE);
785         KX_MACRO_addTypesToDict(d, BL_SRC_COLOR, GL_SRC_COLOR);
786         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
787         KX_MACRO_addTypesToDict(d, BL_DST_COLOR, GL_DST_COLOR);
788         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_DST_COLOR);
789         KX_MACRO_addTypesToDict(d, BL_SRC_ALPHA, GL_SRC_ALPHA);
790         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
791         KX_MACRO_addTypesToDict(d, BL_DST_ALPHA, GL_DST_ALPHA);
792         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
793         KX_MACRO_addTypesToDict(d, BL_SRC_ALPHA_SATURATE, GL_SRC_ALPHA_SATURATE);
794
795
796         /* 9. UniformTypes */
797         KX_MACRO_addTypesToDict(d, SHD_TANGENT, BL_Shader::SHD_TANGENT);
798         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX, BL_Shader::MODELVIEWMATRIX);
799         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_TRANSPOSE, BL_Shader::MODELVIEWMATRIX_TRANSPOSE);
800         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_INVERSE, BL_Shader::MODELVIEWMATRIX_INVERSE);
801         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_INVERSETRANSPOSE, BL_Shader::MODELVIEWMATRIX_INVERSETRANSPOSE);
802         KX_MACRO_addTypesToDict(d, MODELMATRIX, BL_Shader::MODELMATRIX);
803         KX_MACRO_addTypesToDict(d, MODELMATRIX_TRANSPOSE, BL_Shader::MODELMATRIX_TRANSPOSE);
804         KX_MACRO_addTypesToDict(d, MODELMATRIX_INVERSE, BL_Shader::MODELMATRIX_INVERSE);
805         KX_MACRO_addTypesToDict(d, MODELMATRIX_INVERSETRANSPOSE, BL_Shader::MODELMATRIX_INVERSETRANSPOSE);
806         KX_MACRO_addTypesToDict(d, VIEWMATRIX, BL_Shader::VIEWMATRIX);
807         KX_MACRO_addTypesToDict(d, VIEWMATRIX_TRANSPOSE, BL_Shader::VIEWMATRIX_TRANSPOSE);
808         KX_MACRO_addTypesToDict(d, VIEWMATRIX_INVERSE, BL_Shader::VIEWMATRIX_INVERSE);
809         KX_MACRO_addTypesToDict(d, VIEWMATRIX_INVERSETRANSPOSE, BL_Shader::VIEWMATRIX_INVERSETRANSPOSE);
810         KX_MACRO_addTypesToDict(d, CAM_POS, BL_Shader::CAM_POS);
811         KX_MACRO_addTypesToDict(d, CONSTANT_TIMER, BL_Shader::CONSTANT_TIMER);
812
813         // Check for errors
814         if (PyErr_Occurred())
815     {
816                 Py_FatalError("can't initialize module GameLogic");
817     }
818
819         return d;
820 }
821
822 void dictionaryClearByHand(PyObject *dict)
823 {
824         // Clears the dictionary by hand:
825         // This prevents, extra references to global variables
826         // inside the GameLogic dictionary when the python interpreter is finalized.
827         // which allows the scene to safely delete them :)
828         // see: (space.c)->start_game
829         if(dict) PyDict_Clear(dict);
830 }
831
832
833 // Python Sandbox code
834 // override builtin functions import() and open()
835
836
837 PyObject *KXpy_open(PyObject *self, PyObject *args)
838 {
839         PyErr_SetString(PyExc_RuntimeError, "Sandbox: open() function disabled!\nGame Scripts should not use this function.");
840         return NULL;
841 }
842
843
844
845 PyObject *KXpy_import(PyObject *self, PyObject *args)
846 {
847         char *name;
848         PyObject *globals = NULL;
849         PyObject *locals = NULL;
850         PyObject *fromlist = NULL;
851         PyObject *l, *m, *n;
852
853         if (!PyArg_ParseTuple(args, "s|OOO:m_import",
854                 &name, &globals, &locals, &fromlist))
855             return NULL;
856
857         /* check for builtin modules */
858         m = PyImport_AddModule("sys");
859         l = PyObject_GetAttrString(m, "builtin_module_names");
860         n = PyString_FromString(name);
861         
862         if (PySequence_Contains(l, n)) {
863                 return PyImport_ImportModuleEx(name, globals, locals, fromlist);
864         }
865
866         /* quick hack for GamePython modules 
867                 TODO: register builtin modules properly by ExtendInittab */
868         if (!strcmp(name, "GameLogic") || !strcmp(name, "GameKeys") || !strcmp(name, "PhysicsConstraints") ||
869                 !strcmp(name, "Rasterizer")) {
870                 return PyImport_ImportModuleEx(name, globals, locals, fromlist);
871         }
872                 
873         PyErr_Format(PyExc_ImportError,
874                  "Import of external Module %.20s not allowed.", name);
875         return NULL;
876
877 }
878
879
880
881 static PyMethodDef meth_open[] = {
882         { "open", KXpy_open, METH_VARARGS,
883                 "(disabled)"}
884 };
885
886
887 static PyMethodDef meth_import[] = {
888         { "import", KXpy_import, METH_VARARGS,
889                 "our own import"}
890 };
891
892
893
894 //static PyObject *g_oldopen = 0;
895 //static PyObject *g_oldimport = 0;
896 //static int g_security = 0;
897
898
899 void setSandbox(TPythonSecurityLevel level)
900 {
901     PyObject *m = PyImport_AddModule("__builtin__");
902     PyObject *d = PyModule_GetDict(m);
903         PyObject *meth = PyCFunction_New(meth_open, NULL);
904
905         switch (level) {
906         case psl_Highest:
907                 //if (!g_security) {
908                         //g_oldopen = PyDict_GetItemString(d, "open");
909                         PyDict_SetItemString(d, "open", meth);
910                         meth = PyCFunction_New(meth_import, NULL);
911                         PyDict_SetItemString(d, "__import__", meth);
912                         //g_security = level;
913                 //}
914                 break;
915         /*
916         case psl_Lowest:
917                 if (g_security) {
918                         PyDict_SetItemString(d, "open", g_oldopen);
919                         PyDict_SetItemString(d, "__import__", g_oldimport);
920                         g_security = level;
921                 }
922         */
923         default:
924                 break;
925         }
926 }
927
928 /**
929  * Python is not initialised.
930  */
931 PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level)
932 {
933         STR_String pname = progname;
934         Py_SetProgramName(pname.Ptr());
935         Py_NoSiteFlag=1;
936         Py_FrozenFlag=1;
937         Py_Initialize();
938
939         //importBlenderModules()
940         
941         setSandbox(level);
942
943         PyObject* moduleobj = PyImport_AddModule("__main__");
944         return PyModule_GetDict(moduleobj);
945 }
946
947 void exitGamePlayerPythonScripting()
948 {
949         Py_Finalize();
950 }
951
952 /**
953  * Python is already initialized.
954  */
955 PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level)
956 {
957         STR_String pname = progname;
958         Py_SetProgramName(pname.Ptr());
959         Py_NoSiteFlag=1;
960         Py_FrozenFlag=1;
961
962         setSandbox(level);
963
964         PyObject* moduleobj = PyImport_AddModule("__main__");
965         return PyModule_GetDict(moduleobj);
966 }
967
968
969
970 void exitGamePythonScripting()
971 {
972 }
973
974
975
976 PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas)
977 {
978         gp_Canvas = canvas;
979         gp_Rasterizer = rasty;
980
981
982   PyObject* m;
983   PyObject* d;
984
985   // Create the module and add the functions
986   m = Py_InitModule4("Rasterizer", rasterizer_methods,
987                      Rasterizer_module_documentation,
988                      (PyObject*)NULL,PYTHON_API_VERSION);
989
990   // Add some symbolic constants to the module
991   d = PyModule_GetDict(m);
992   ErrorObject = PyString_FromString("Rasterizer.error");
993   PyDict_SetItemString(d, "error", ErrorObject);
994
995   // XXXX Add constants here
996
997   // Check for errors
998   if (PyErr_Occurred())
999     {
1000       Py_FatalError("can't initialize module Rasterizer");
1001     }
1002
1003   return d;
1004 }
1005
1006
1007
1008 /* ------------------------------------------------------------------------- */
1009 /* GameKeys: symbolic constants for key mapping                              */
1010 /* ------------------------------------------------------------------------- */
1011
1012 static char GameKeys_module_documentation[] =
1013 "This modules provides defines for key-codes"
1014 ;
1015
1016
1017
1018 static struct PyMethodDef gamekeys_methods[] = {
1019         { NULL, (PyCFunction) NULL, 0, NULL }
1020 };
1021
1022
1023
1024 PyObject* initGameKeys()
1025 {
1026         PyObject* m;
1027         PyObject* d;
1028
1029         // Create the module and add the functions
1030         m = Py_InitModule4("GameKeys", gamekeys_methods,
1031                                            GameKeys_module_documentation,
1032                                            (PyObject*)NULL,PYTHON_API_VERSION);
1033
1034         // Add some symbolic constants to the module
1035         d = PyModule_GetDict(m);
1036
1037         // XXXX Add constants here
1038
1039         KX_MACRO_addTypesToDict(d, AKEY, SCA_IInputDevice::KX_AKEY);
1040         KX_MACRO_addTypesToDict(d, BKEY, SCA_IInputDevice::KX_BKEY);
1041         KX_MACRO_addTypesToDict(d, CKEY, SCA_IInputDevice::KX_CKEY);
1042         KX_MACRO_addTypesToDict(d, DKEY, SCA_IInputDevice::KX_DKEY);
1043         KX_MACRO_addTypesToDict(d, EKEY, SCA_IInputDevice::KX_EKEY);
1044         KX_MACRO_addTypesToDict(d, FKEY, SCA_IInputDevice::KX_FKEY);
1045         KX_MACRO_addTypesToDict(d, GKEY, SCA_IInputDevice::KX_GKEY);
1046         KX_MACRO_addTypesToDict(d, HKEY, SCA_IInputDevice::KX_HKEY);
1047         KX_MACRO_addTypesToDict(d, IKEY, SCA_IInputDevice::KX_IKEY);
1048         KX_MACRO_addTypesToDict(d, JKEY, SCA_IInputDevice::KX_JKEY);
1049         KX_MACRO_addTypesToDict(d, KKEY, SCA_IInputDevice::KX_KKEY);
1050         KX_MACRO_addTypesToDict(d, LKEY, SCA_IInputDevice::KX_LKEY);
1051         KX_MACRO_addTypesToDict(d, MKEY, SCA_IInputDevice::KX_MKEY);
1052         KX_MACRO_addTypesToDict(d, NKEY, SCA_IInputDevice::KX_NKEY);
1053         KX_MACRO_addTypesToDict(d, OKEY, SCA_IInputDevice::KX_OKEY);
1054         KX_MACRO_addTypesToDict(d, PKEY, SCA_IInputDevice::KX_PKEY);
1055         KX_MACRO_addTypesToDict(d, QKEY, SCA_IInputDevice::KX_QKEY);
1056         KX_MACRO_addTypesToDict(d, RKEY, SCA_IInputDevice::KX_RKEY);
1057         KX_MACRO_addTypesToDict(d, SKEY, SCA_IInputDevice::KX_SKEY);
1058         KX_MACRO_addTypesToDict(d, TKEY, SCA_IInputDevice::KX_TKEY);
1059         KX_MACRO_addTypesToDict(d, UKEY, SCA_IInputDevice::KX_UKEY);
1060         KX_MACRO_addTypesToDict(d, VKEY, SCA_IInputDevice::KX_VKEY);
1061         KX_MACRO_addTypesToDict(d, WKEY, SCA_IInputDevice::KX_WKEY);
1062         KX_MACRO_addTypesToDict(d, XKEY, SCA_IInputDevice::KX_XKEY);
1063         KX_MACRO_addTypesToDict(d, YKEY, SCA_IInputDevice::KX_YKEY);
1064         KX_MACRO_addTypesToDict(d, ZKEY, SCA_IInputDevice::KX_ZKEY);
1065         
1066         KX_MACRO_addTypesToDict(d, ZEROKEY, SCA_IInputDevice::KX_ZEROKEY);              
1067         KX_MACRO_addTypesToDict(d, ONEKEY, SCA_IInputDevice::KX_ONEKEY);                
1068         KX_MACRO_addTypesToDict(d, TWOKEY, SCA_IInputDevice::KX_TWOKEY);                
1069         KX_MACRO_addTypesToDict(d, THREEKEY, SCA_IInputDevice::KX_THREEKEY);
1070         KX_MACRO_addTypesToDict(d, FOURKEY, SCA_IInputDevice::KX_FOURKEY);              
1071         KX_MACRO_addTypesToDict(d, FIVEKEY, SCA_IInputDevice::KX_FIVEKEY);              
1072         KX_MACRO_addTypesToDict(d, SIXKEY, SCA_IInputDevice::KX_SIXKEY);                
1073         KX_MACRO_addTypesToDict(d, SEVENKEY, SCA_IInputDevice::KX_SEVENKEY);
1074         KX_MACRO_addTypesToDict(d, EIGHTKEY, SCA_IInputDevice::KX_EIGHTKEY);
1075         KX_MACRO_addTypesToDict(d, NINEKEY, SCA_IInputDevice::KX_NINEKEY);              
1076                 
1077         KX_MACRO_addTypesToDict(d, CAPSLOCKKEY, SCA_IInputDevice::KX_CAPSLOCKKEY);
1078                 
1079         KX_MACRO_addTypesToDict(d, LEFTCTRLKEY, SCA_IInputDevice::KX_LEFTCTRLKEY);      
1080         KX_MACRO_addTypesToDict(d, LEFTALTKEY, SCA_IInputDevice::KX_LEFTALTKEY);                
1081         KX_MACRO_addTypesToDict(d, RIGHTALTKEY, SCA_IInputDevice::KX_RIGHTALTKEY);      
1082         KX_MACRO_addTypesToDict(d, RIGHTCTRLKEY, SCA_IInputDevice::KX_RIGHTCTRLKEY);    
1083         KX_MACRO_addTypesToDict(d, RIGHTSHIFTKEY, SCA_IInputDevice::KX_RIGHTSHIFTKEY);  
1084         KX_MACRO_addTypesToDict(d, LEFTSHIFTKEY, SCA_IInputDevice::KX_LEFTSHIFTKEY);
1085                 
1086         KX_MACRO_addTypesToDict(d, ESCKEY, SCA_IInputDevice::KX_ESCKEY);
1087         KX_MACRO_addTypesToDict(d, TABKEY, SCA_IInputDevice::KX_TABKEY);
1088         KX_MACRO_addTypesToDict(d, RETKEY, SCA_IInputDevice::KX_RETKEY);
1089         KX_MACRO_addTypesToDict(d, SPACEKEY, SCA_IInputDevice::KX_SPACEKEY);
1090         KX_MACRO_addTypesToDict(d, LINEFEEDKEY, SCA_IInputDevice::KX_LINEFEEDKEY);              
1091         KX_MACRO_addTypesToDict(d, BACKSPACEKEY, SCA_IInputDevice::KX_BACKSPACEKEY);
1092         KX_MACRO_addTypesToDict(d, DELKEY, SCA_IInputDevice::KX_DELKEY);
1093         KX_MACRO_addTypesToDict(d, SEMICOLONKEY, SCA_IInputDevice::KX_SEMICOLONKEY);
1094         KX_MACRO_addTypesToDict(d, PERIODKEY, SCA_IInputDevice::KX_PERIODKEY);          
1095         KX_MACRO_addTypesToDict(d, COMMAKEY, SCA_IInputDevice::KX_COMMAKEY);            
1096         KX_MACRO_addTypesToDict(d, QUOTEKEY, SCA_IInputDevice::KX_QUOTEKEY);            
1097         KX_MACRO_addTypesToDict(d, ACCENTGRAVEKEY, SCA_IInputDevice::KX_ACCENTGRAVEKEY);        
1098         KX_MACRO_addTypesToDict(d, MINUSKEY, SCA_IInputDevice::KX_MINUSKEY);            
1099         KX_MACRO_addTypesToDict(d, SLASHKEY, SCA_IInputDevice::KX_SLASHKEY);            
1100         KX_MACRO_addTypesToDict(d, BACKSLASHKEY, SCA_IInputDevice::KX_BACKSLASHKEY);
1101         KX_MACRO_addTypesToDict(d, EQUALKEY, SCA_IInputDevice::KX_EQUALKEY);            
1102         KX_MACRO_addTypesToDict(d, LEFTBRACKETKEY, SCA_IInputDevice::KX_LEFTBRACKETKEY);        
1103         KX_MACRO_addTypesToDict(d, RIGHTBRACKETKEY, SCA_IInputDevice::KX_RIGHTBRACKETKEY);      
1104                 
1105         KX_MACRO_addTypesToDict(d, LEFTARROWKEY, SCA_IInputDevice::KX_LEFTARROWKEY);
1106         KX_MACRO_addTypesToDict(d, DOWNARROWKEY, SCA_IInputDevice::KX_DOWNARROWKEY);
1107         KX_MACRO_addTypesToDict(d, RIGHTARROWKEY, SCA_IInputDevice::KX_RIGHTARROWKEY);  
1108         KX_MACRO_addTypesToDict(d, UPARROWKEY, SCA_IInputDevice::KX_UPARROWKEY);                
1109         
1110         KX_MACRO_addTypesToDict(d, PAD2 , SCA_IInputDevice::KX_PAD2);
1111         KX_MACRO_addTypesToDict(d, PAD4 , SCA_IInputDevice::KX_PAD4);
1112         KX_MACRO_addTypesToDict(d, PAD6 , SCA_IInputDevice::KX_PAD6);
1113         KX_MACRO_addTypesToDict(d, PAD8 , SCA_IInputDevice::KX_PAD8);
1114                 
1115         KX_MACRO_addTypesToDict(d, PAD1 , SCA_IInputDevice::KX_PAD1);
1116         KX_MACRO_addTypesToDict(d, PAD3 , SCA_IInputDevice::KX_PAD3);
1117         KX_MACRO_addTypesToDict(d, PAD5 , SCA_IInputDevice::KX_PAD5);
1118         KX_MACRO_addTypesToDict(d, PAD7 , SCA_IInputDevice::KX_PAD7);
1119         KX_MACRO_addTypesToDict(d, PAD9 , SCA_IInputDevice::KX_PAD9);
1120                 
1121         KX_MACRO_addTypesToDict(d, PADPERIOD, SCA_IInputDevice::KX_PADPERIOD);
1122         KX_MACRO_addTypesToDict(d, PADSLASHKEY, SCA_IInputDevice::KX_PADSLASHKEY);
1123         KX_MACRO_addTypesToDict(d, PADASTERKEY, SCA_IInputDevice::KX_PADASTERKEY);
1124                 
1125                 
1126         KX_MACRO_addTypesToDict(d, PAD0, SCA_IInputDevice::KX_PAD0);
1127         KX_MACRO_addTypesToDict(d, PADMINUS, SCA_IInputDevice::KX_PADMINUS);
1128         KX_MACRO_addTypesToDict(d, PADENTER, SCA_IInputDevice::KX_PADENTER);
1129         KX_MACRO_addTypesToDict(d, PADPLUSKEY, SCA_IInputDevice::KX_PADPLUSKEY);
1130                 
1131                 
1132         KX_MACRO_addTypesToDict(d, F1KEY , SCA_IInputDevice::KX_F1KEY);
1133         KX_MACRO_addTypesToDict(d, F2KEY , SCA_IInputDevice::KX_F2KEY);
1134         KX_MACRO_addTypesToDict(d, F3KEY , SCA_IInputDevice::KX_F3KEY);
1135         KX_MACRO_addTypesToDict(d, F4KEY , SCA_IInputDevice::KX_F4KEY);
1136         KX_MACRO_addTypesToDict(d, F5KEY , SCA_IInputDevice::KX_F5KEY);
1137         KX_MACRO_addTypesToDict(d, F6KEY , SCA_IInputDevice::KX_F6KEY);
1138         KX_MACRO_addTypesToDict(d, F7KEY , SCA_IInputDevice::KX_F7KEY);
1139         KX_MACRO_addTypesToDict(d, F8KEY , SCA_IInputDevice::KX_F8KEY);
1140         KX_MACRO_addTypesToDict(d, F9KEY , SCA_IInputDevice::KX_F9KEY);
1141         KX_MACRO_addTypesToDict(d, F10KEY, SCA_IInputDevice::KX_F10KEY);
1142         KX_MACRO_addTypesToDict(d, F11KEY, SCA_IInputDevice::KX_F11KEY);
1143         KX_MACRO_addTypesToDict(d, F12KEY, SCA_IInputDevice::KX_F12KEY);
1144                 
1145         KX_MACRO_addTypesToDict(d, PAUSEKEY, SCA_IInputDevice::KX_PAUSEKEY);
1146         KX_MACRO_addTypesToDict(d, INSERTKEY, SCA_IInputDevice::KX_INSERTKEY);
1147         KX_MACRO_addTypesToDict(d, HOMEKEY , SCA_IInputDevice::KX_HOMEKEY);
1148         KX_MACRO_addTypesToDict(d, PAGEUPKEY, SCA_IInputDevice::KX_PAGEUPKEY);
1149         KX_MACRO_addTypesToDict(d, PAGEDOWNKEY, SCA_IInputDevice::KX_PAGEDOWNKEY);
1150         KX_MACRO_addTypesToDict(d, ENDKEY, SCA_IInputDevice::KX_ENDKEY);
1151
1152
1153         // Check for errors
1154         if (PyErr_Occurred())
1155     {
1156                 Py_FatalError("can't initialize module GameKeys");
1157     }
1158
1159         return d;
1160 }
1161
1162 void PHY_SetActiveScene(class KX_Scene* scene)
1163 {
1164         gp_KetsjiScene = scene;
1165 }
1166
1167 class KX_Scene* PHY_GetActiveScene()
1168 {
1169         return gp_KetsjiScene;
1170 }