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