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