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