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