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