Improved OpenGL Shader Language support for game engine. The python interface is...
[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
622
623 STR_String      gPyGetWindowHeight__doc__="getWindowHeight doc";
624 STR_String      gPyGetWindowWidth__doc__="getWindowWidth doc";
625 STR_String      gPyEnableVisibility__doc__="enableVisibility doc";
626 STR_String      gPyMakeScreenshot__doc__="make Screenshot doc";
627 STR_String      gPyShowMouse__doc__="showMouse(bool visible)";
628 STR_String      gPySetMousePosition__doc__="setMousePosition(int x,int y)";
629
630 static struct PyMethodDef rasterizer_methods[] = {
631   {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
632    METH_VARARGS, gPyGetWindowWidth__doc__.Ptr()},
633    {"getWindowHeight",(PyCFunction) gPyGetWindowHeight,
634    METH_VARARGS, gPyGetWindowHeight__doc__.Ptr()},
635   {"makeScreenshot",(PyCFunction)gPyMakeScreenshot,
636         METH_VARARGS, gPyMakeScreenshot__doc__.Ptr()},
637    {"enableVisibility",(PyCFunction) gPyEnableVisibility,
638    METH_VARARGS, gPyEnableVisibility__doc__.Ptr()},
639         {"showMouse",(PyCFunction) gPyShowMouse,
640    METH_VARARGS, gPyShowMouse__doc__.Ptr()},
641    {"setMousePosition",(PyCFunction) gPySetMousePosition,
642    METH_VARARGS, gPySetMousePosition__doc__.Ptr()},
643   {"setBackgroundColor",(PyCFunction)gPySetBackgroundColor,METH_VARARGS,"set Background Color (rgb)"},
644         {"setAmbientColor",(PyCFunction)gPySetAmbientColor,METH_VARARGS,"set Ambient Color (rgb)"},
645  {"setMistColor",(PyCFunction)gPySetMistColor,METH_VARARGS,"set Mist Color (rgb)"},
646   {"setMistStart",(PyCFunction)gPySetMistStart,METH_VARARGS,"set Mist Start(rgb)"},
647   {"setMistEnd",(PyCFunction)gPySetMistEnd,METH_VARARGS,"set Mist End(rgb)"},
648   
649   {"setEyeSeparation", (PyCFunction) gPySetEyeSeparation, METH_VARARGS, "set the eye separation for stereo mode"},
650   {"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_VARARGS, "get the eye separation for stereo mode"},
651   {"setFocalLength", (PyCFunction) gPySetFocalLength, METH_VARARGS, "set the focal length for stereo mode"},
652   {"getFocalLength", (PyCFunction) gPyGetFocalLength, METH_VARARGS, "get the focal length for stereo mode"},
653   { NULL, (PyCFunction) NULL, 0, NULL }
654 };
655
656
657
658 // Initialization function for the module (*must* be called initGameLogic)
659
660 static char GameLogic_module_documentation[] =
661 "This is the Python API for the game engine of GameLogic"
662 ;
663
664 static char Rasterizer_module_documentation[] =
665 "This is the Python API for the game engine of Rasterizer"
666 ;
667
668
669
670 PyObject* initGameLogic(KX_Scene* scene) // quick hack to get gravity hook
671 {
672         PyObject* m;
673         PyObject* d;
674
675         gp_KetsjiScene = scene;
676
677         gUseVisibilityTemp=false;
678
679         // Create the module and add the functions
680         m = Py_InitModule4("GameLogic", game_methods,
681                                            GameLogic_module_documentation,
682                                            (PyObject*)NULL,PYTHON_API_VERSION);
683
684         // Add some symbolic constants to the module
685         d = PyModule_GetDict(m);
686
687         ErrorObject = PyString_FromString("GameLogic.error");
688         PyDict_SetItemString(d, "error", ErrorObject);
689
690         // XXXX Add constants here
691         /* To use logic bricks, we need some sort of constants. Here, we associate */
692         /* constants and sumbolic names. Add them to dictionary d.                 */
693
694         /* 1. true and false: needed for everyone                                  */
695         KX_MACRO_addTypesToDict(d, KX_TRUE,  SCA_ILogicBrick::KX_TRUE);
696         KX_MACRO_addTypesToDict(d, KX_FALSE, SCA_ILogicBrick::KX_FALSE);
697
698         /* 2. Property sensor                                                      */
699         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EQUAL,      SCA_PropertySensor::KX_PROPSENSOR_EQUAL);
700         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_NOTEQUAL,   SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL);
701         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_INTERVAL,   SCA_PropertySensor::KX_PROPSENSOR_INTERVAL);
702         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_CHANGED,    SCA_PropertySensor::KX_PROPSENSOR_CHANGED);
703         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EXPRESSION, SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION);
704
705         /* 3. Constraint actuator                                                  */
706         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX);
707         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY);
708         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ);
709         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX);
710         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY);
711         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ);
712
713         /* 4. Ipo actuator, simple part                                            */
714         KX_MACRO_addTypesToDict(d, KX_IPOACT_PLAY,     KX_IpoActuator::KX_ACT_IPO_PLAY);
715         KX_MACRO_addTypesToDict(d, KX_IPOACT_PINGPONG, KX_IpoActuator::KX_ACT_IPO_PINGPONG);
716         KX_MACRO_addTypesToDict(d, KX_IPOACT_FLIPPER,  KX_IpoActuator::KX_ACT_IPO_FLIPPER);
717         KX_MACRO_addTypesToDict(d, KX_IPOACT_LOOPSTOP, KX_IpoActuator::KX_ACT_IPO_LOOPSTOP);
718         KX_MACRO_addTypesToDict(d, KX_IPOACT_LOOPEND,  KX_IpoActuator::KX_ACT_IPO_LOOPEND);
719
720         /* 5. Random distribution types                                            */
721         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_CONST,      SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST);
722         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_UNIFORM,    SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM);
723         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_BERNOUILLI, SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI);
724         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_CONST,       SCA_RandomActuator::KX_RANDOMACT_INT_CONST);
725         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_UNIFORM,     SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM);
726         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_POISSON,     SCA_RandomActuator::KX_RANDOMACT_INT_POISSON);
727         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_CONST,     SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST);
728         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_UNIFORM,   SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM);
729         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NORMAL,    SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL);
730         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL, SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL);
731
732         /* 6. Sound actuator                                                      */
733         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP,              KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
734         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND,               KX_SoundActuator::KX_SOUNDACT_PLAYEND);
735         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP,              KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
736         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND,               KX_SoundActuator::KX_SOUNDACT_LOOPEND);
737         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL,     KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
738         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP,     KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
739
740         /* 7. Action actuator                                                                                                      */
741         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PLAY,     BL_ActionActuator::KX_ACT_ACTION_PLAY);
742         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_FLIPPER,     BL_ActionActuator::KX_ACT_ACTION_FLIPPER);
743         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPSTOP,     BL_ActionActuator::KX_ACT_ACTION_LOOPSTOP);
744         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPEND,     BL_ActionActuator::KX_ACT_ACTION_LOOPEND);
745         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PROPERTY,     BL_ActionActuator::KX_ACT_ACTION_PROPERTY);
746         
747         /*8. GL_BlendFunc */
748         KX_MACRO_addTypesToDict(d, BL_ZERO, GL_ZERO);
749         KX_MACRO_addTypesToDict(d, BL_ONE, GL_ONE);
750         KX_MACRO_addTypesToDict(d, BL_SRC_COLOR, GL_SRC_COLOR);
751         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
752         KX_MACRO_addTypesToDict(d, BL_DST_COLOR, GL_DST_COLOR);
753         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_DST_COLOR);
754         KX_MACRO_addTypesToDict(d, BL_SRC_ALPHA, GL_SRC_ALPHA);
755         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
756         KX_MACRO_addTypesToDict(d, BL_DST_ALPHA, GL_DST_ALPHA);
757         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
758         KX_MACRO_addTypesToDict(d, BL_SRC_ALPHA_SATURATE, GL_SRC_ALPHA_SATURATE);
759
760
761         /* 9. UniformTypes */
762         KX_MACRO_addTypesToDict(d, SHD_TANGENT, BL_Shader::SHD_TANGENT);
763         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX, BL_Shader::MODELVIEWMATRIX);
764         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_TRANSPOSE, BL_Shader::MODELVIEWMATRIX_TRANSPOSE);
765         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_INVERSE, BL_Shader::MODELVIEWMATRIX_INVERSE);
766         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_INVERSETRANSPOSE, BL_Shader::MODELVIEWMATRIX_INVERSETRANSPOSE);
767         KX_MACRO_addTypesToDict(d, MODELMATRIX, BL_Shader::MODELMATRIX);
768         KX_MACRO_addTypesToDict(d, MODELMATRIX_TRANSPOSE, BL_Shader::MODELMATRIX_TRANSPOSE);
769         KX_MACRO_addTypesToDict(d, MODELMATRIX_INVERSE, BL_Shader::MODELMATRIX_INVERSE);
770         KX_MACRO_addTypesToDict(d, MODELMATRIX_INVERSETRANSPOSE, BL_Shader::MODELMATRIX_INVERSETRANSPOSE);
771         KX_MACRO_addTypesToDict(d, VIEWMATRIX, BL_Shader::VIEWMATRIX);
772         KX_MACRO_addTypesToDict(d, VIEWMATRIX_TRANSPOSE, BL_Shader::VIEWMATRIX_TRANSPOSE);
773         KX_MACRO_addTypesToDict(d, VIEWMATRIX_INVERSE, BL_Shader::VIEWMATRIX_INVERSE);
774         KX_MACRO_addTypesToDict(d, VIEWMATRIX_INVERSETRANSPOSE, BL_Shader::VIEWMATRIX_INVERSETRANSPOSE);
775         KX_MACRO_addTypesToDict(d, CAM_POS, BL_Shader::CAM_POS);
776
777         // Check for errors
778         if (PyErr_Occurred())
779     {
780                 Py_FatalError("can't initialize module GameLogic");
781     }
782
783         return d;
784 }
785
786
787
788 // Python Sandbox code
789 // override builtin functions import() and open()
790
791
792 PyObject *KXpy_open(PyObject *self, PyObject *args)
793 {
794         PyErr_SetString(PyExc_RuntimeError, "Sandbox: open() function disabled!\nGame Scripts should not use this function.");
795         return NULL;
796 }
797
798
799
800 PyObject *KXpy_import(PyObject *self, PyObject *args)
801 {
802         char *name;
803         PyObject *globals = NULL;
804         PyObject *locals = NULL;
805         PyObject *fromlist = NULL;
806         PyObject *l, *m, *n;
807
808         if (!PyArg_ParseTuple(args, "s|OOO:m_import",
809                 &name, &globals, &locals, &fromlist))
810             return NULL;
811
812         /* check for builtin modules */
813         m = PyImport_AddModule("sys");
814         l = PyObject_GetAttrString(m, "builtin_module_names");
815         n = PyString_FromString(name);
816         
817         if (PySequence_Contains(l, n)) {
818                 return PyImport_ImportModuleEx(name, globals, locals, fromlist);
819         }
820
821         /* quick hack for GamePython modules 
822                 TODO: register builtin modules properly by ExtendInittab */
823         if (!strcmp(name, "GameLogic") || !strcmp(name, "GameKeys") ||
824                 !strcmp(name, "Rasterizer")) {
825                 return PyImport_ImportModuleEx(name, globals, locals, fromlist);
826         }
827                 
828         PyErr_Format(PyExc_ImportError,
829                  "Import of external Module %.20s not allowed.", name);
830         return NULL;
831
832 }
833
834
835
836 static PyMethodDef meth_open[] = {
837         { "open", KXpy_open, METH_VARARGS,
838                 "(disabled)"}
839 };
840
841
842 static PyMethodDef meth_import[] = {
843         { "import", KXpy_import, METH_VARARGS,
844                 "our own import"}
845 };
846
847
848
849 //static PyObject *g_oldopen = 0;
850 //static PyObject *g_oldimport = 0;
851 //static int g_security = 0;
852
853
854 void setSandbox(TPythonSecurityLevel level)
855 {
856     PyObject *m = PyImport_AddModule("__builtin__");
857     PyObject *d = PyModule_GetDict(m);
858         PyObject *meth = PyCFunction_New(meth_open, NULL);
859
860         switch (level) {
861         case psl_Highest:
862                 //if (!g_security) {
863                         //g_oldopen = PyDict_GetItemString(d, "open");
864                         PyDict_SetItemString(d, "open", meth);
865                         meth = PyCFunction_New(meth_import, NULL);
866                         PyDict_SetItemString(d, "__import__", meth);
867                         //g_security = level;
868                 //}
869                 break;
870         /*
871         case psl_Lowest:
872                 if (g_security) {
873                         PyDict_SetItemString(d, "open", g_oldopen);
874                         PyDict_SetItemString(d, "__import__", g_oldimport);
875                         g_security = level;
876                 }
877         */
878         default:
879                 break;
880         }
881 }
882
883 /**
884  * Python is not initialised.
885  */
886 PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecurityLevel level)
887 {
888         STR_String pname = progname;
889         Py_SetProgramName(pname.Ptr());
890         Py_NoSiteFlag=1;
891         Py_FrozenFlag=1;
892         Py_Initialize();
893
894         //importBlenderModules()
895         
896         setSandbox(level);
897
898         PyObject* moduleobj = PyImport_AddModule("__main__");
899         return PyModule_GetDict(moduleobj);
900 }
901
902 void exitGamePlayerPythonScripting()
903 {
904         Py_Finalize();
905 }
906
907 /**
908  * Python is already initialized.
909  */
910 PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level)
911 {
912         STR_String pname = progname;
913         Py_SetProgramName(pname.Ptr());
914         Py_NoSiteFlag=1;
915         Py_FrozenFlag=1;
916
917         setSandbox(level);
918
919         PyObject* moduleobj = PyImport_AddModule("__main__");
920         return PyModule_GetDict(moduleobj);
921 }
922
923
924
925 void exitGamePythonScripting()
926 {
927 }
928
929
930
931 PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas)
932 {
933         gp_Canvas = canvas;
934         gp_Rasterizer = rasty;
935
936
937   PyObject* m;
938   PyObject* d;
939
940   // Create the module and add the functions
941   m = Py_InitModule4("Rasterizer", rasterizer_methods,
942                      Rasterizer_module_documentation,
943                      (PyObject*)NULL,PYTHON_API_VERSION);
944
945   // Add some symbolic constants to the module
946   d = PyModule_GetDict(m);
947   ErrorObject = PyString_FromString("Rasterizer.error");
948   PyDict_SetItemString(d, "error", ErrorObject);
949
950   // XXXX Add constants here
951
952   // Check for errors
953   if (PyErr_Occurred())
954     {
955       Py_FatalError("can't initialize module Rasterizer");
956     }
957
958   return d;
959 }
960
961
962
963 /* ------------------------------------------------------------------------- */
964 /* GameKeys: symbolic constants for key mapping                              */
965 /* ------------------------------------------------------------------------- */
966
967 static char GameKeys_module_documentation[] =
968 "This modules provides defines for key-codes"
969 ;
970
971
972
973 static struct PyMethodDef gamekeys_methods[] = {
974         { NULL, (PyCFunction) NULL, 0, NULL }
975 };
976
977
978
979 PyObject* initGameKeys()
980 {
981         PyObject* m;
982         PyObject* d;
983
984         // Create the module and add the functions
985         m = Py_InitModule4("GameKeys", gamekeys_methods,
986                                            GameKeys_module_documentation,
987                                            (PyObject*)NULL,PYTHON_API_VERSION);
988
989         // Add some symbolic constants to the module
990         d = PyModule_GetDict(m);
991
992         // XXXX Add constants here
993
994         KX_MACRO_addTypesToDict(d, AKEY, SCA_IInputDevice::KX_AKEY);
995         KX_MACRO_addTypesToDict(d, BKEY, SCA_IInputDevice::KX_BKEY);
996         KX_MACRO_addTypesToDict(d, CKEY, SCA_IInputDevice::KX_CKEY);
997         KX_MACRO_addTypesToDict(d, DKEY, SCA_IInputDevice::KX_DKEY);
998         KX_MACRO_addTypesToDict(d, EKEY, SCA_IInputDevice::KX_EKEY);
999         KX_MACRO_addTypesToDict(d, FKEY, SCA_IInputDevice::KX_FKEY);
1000         KX_MACRO_addTypesToDict(d, GKEY, SCA_IInputDevice::KX_GKEY);
1001         KX_MACRO_addTypesToDict(d, HKEY, SCA_IInputDevice::KX_HKEY);
1002         KX_MACRO_addTypesToDict(d, IKEY, SCA_IInputDevice::KX_IKEY);
1003         KX_MACRO_addTypesToDict(d, JKEY, SCA_IInputDevice::KX_JKEY);
1004         KX_MACRO_addTypesToDict(d, KKEY, SCA_IInputDevice::KX_KKEY);
1005         KX_MACRO_addTypesToDict(d, LKEY, SCA_IInputDevice::KX_LKEY);
1006         KX_MACRO_addTypesToDict(d, MKEY, SCA_IInputDevice::KX_MKEY);
1007         KX_MACRO_addTypesToDict(d, NKEY, SCA_IInputDevice::KX_NKEY);
1008         KX_MACRO_addTypesToDict(d, OKEY, SCA_IInputDevice::KX_OKEY);
1009         KX_MACRO_addTypesToDict(d, PKEY, SCA_IInputDevice::KX_PKEY);
1010         KX_MACRO_addTypesToDict(d, QKEY, SCA_IInputDevice::KX_QKEY);
1011         KX_MACRO_addTypesToDict(d, RKEY, SCA_IInputDevice::KX_RKEY);
1012         KX_MACRO_addTypesToDict(d, SKEY, SCA_IInputDevice::KX_SKEY);
1013         KX_MACRO_addTypesToDict(d, TKEY, SCA_IInputDevice::KX_TKEY);
1014         KX_MACRO_addTypesToDict(d, UKEY, SCA_IInputDevice::KX_UKEY);
1015         KX_MACRO_addTypesToDict(d, VKEY, SCA_IInputDevice::KX_VKEY);
1016         KX_MACRO_addTypesToDict(d, WKEY, SCA_IInputDevice::KX_WKEY);
1017         KX_MACRO_addTypesToDict(d, XKEY, SCA_IInputDevice::KX_XKEY);
1018         KX_MACRO_addTypesToDict(d, YKEY, SCA_IInputDevice::KX_YKEY);
1019         KX_MACRO_addTypesToDict(d, ZKEY, SCA_IInputDevice::KX_ZKEY);
1020         
1021         KX_MACRO_addTypesToDict(d, ZEROKEY, SCA_IInputDevice::KX_ZEROKEY);              
1022         KX_MACRO_addTypesToDict(d, ONEKEY, SCA_IInputDevice::KX_ONEKEY);                
1023         KX_MACRO_addTypesToDict(d, TWOKEY, SCA_IInputDevice::KX_TWOKEY);                
1024         KX_MACRO_addTypesToDict(d, THREEKEY, SCA_IInputDevice::KX_THREEKEY);
1025         KX_MACRO_addTypesToDict(d, FOURKEY, SCA_IInputDevice::KX_FOURKEY);              
1026         KX_MACRO_addTypesToDict(d, FIVEKEY, SCA_IInputDevice::KX_FIVEKEY);              
1027         KX_MACRO_addTypesToDict(d, SIXKEY, SCA_IInputDevice::KX_SIXKEY);                
1028         KX_MACRO_addTypesToDict(d, SEVENKEY, SCA_IInputDevice::KX_SEVENKEY);
1029         KX_MACRO_addTypesToDict(d, EIGHTKEY, SCA_IInputDevice::KX_EIGHTKEY);
1030         KX_MACRO_addTypesToDict(d, NINEKEY, SCA_IInputDevice::KX_NINEKEY);              
1031                 
1032         KX_MACRO_addTypesToDict(d, CAPSLOCKKEY, SCA_IInputDevice::KX_CAPSLOCKKEY);
1033                 
1034         KX_MACRO_addTypesToDict(d, LEFTCTRLKEY, SCA_IInputDevice::KX_LEFTCTRLKEY);      
1035         KX_MACRO_addTypesToDict(d, LEFTALTKEY, SCA_IInputDevice::KX_LEFTALTKEY);                
1036         KX_MACRO_addTypesToDict(d, RIGHTALTKEY, SCA_IInputDevice::KX_RIGHTALTKEY);      
1037         KX_MACRO_addTypesToDict(d, RIGHTCTRLKEY, SCA_IInputDevice::KX_RIGHTCTRLKEY);    
1038         KX_MACRO_addTypesToDict(d, RIGHTSHIFTKEY, SCA_IInputDevice::KX_RIGHTSHIFTKEY);  
1039         KX_MACRO_addTypesToDict(d, LEFTSHIFTKEY, SCA_IInputDevice::KX_LEFTSHIFTKEY);
1040                 
1041         KX_MACRO_addTypesToDict(d, ESCKEY, SCA_IInputDevice::KX_ESCKEY);
1042         KX_MACRO_addTypesToDict(d, TABKEY, SCA_IInputDevice::KX_TABKEY);
1043         KX_MACRO_addTypesToDict(d, RETKEY, SCA_IInputDevice::KX_RETKEY);
1044         KX_MACRO_addTypesToDict(d, SPACEKEY, SCA_IInputDevice::KX_SPACEKEY);
1045         KX_MACRO_addTypesToDict(d, LINEFEEDKEY, SCA_IInputDevice::KX_LINEFEEDKEY);              
1046         KX_MACRO_addTypesToDict(d, BACKSPACEKEY, SCA_IInputDevice::KX_BACKSPACEKEY);
1047         KX_MACRO_addTypesToDict(d, DELKEY, SCA_IInputDevice::KX_DELKEY);
1048         KX_MACRO_addTypesToDict(d, SEMICOLONKEY, SCA_IInputDevice::KX_SEMICOLONKEY);
1049         KX_MACRO_addTypesToDict(d, PERIODKEY, SCA_IInputDevice::KX_PERIODKEY);          
1050         KX_MACRO_addTypesToDict(d, COMMAKEY, SCA_IInputDevice::KX_COMMAKEY);            
1051         KX_MACRO_addTypesToDict(d, QUOTEKEY, SCA_IInputDevice::KX_QUOTEKEY);            
1052         KX_MACRO_addTypesToDict(d, ACCENTGRAVEKEY, SCA_IInputDevice::KX_ACCENTGRAVEKEY);        
1053         KX_MACRO_addTypesToDict(d, MINUSKEY, SCA_IInputDevice::KX_MINUSKEY);            
1054         KX_MACRO_addTypesToDict(d, SLASHKEY, SCA_IInputDevice::KX_SLASHKEY);            
1055         KX_MACRO_addTypesToDict(d, BACKSLASHKEY, SCA_IInputDevice::KX_BACKSLASHKEY);
1056         KX_MACRO_addTypesToDict(d, EQUALKEY, SCA_IInputDevice::KX_EQUALKEY);            
1057         KX_MACRO_addTypesToDict(d, LEFTBRACKETKEY, SCA_IInputDevice::KX_LEFTBRACKETKEY);        
1058         KX_MACRO_addTypesToDict(d, RIGHTBRACKETKEY, SCA_IInputDevice::KX_RIGHTBRACKETKEY);      
1059                 
1060         KX_MACRO_addTypesToDict(d, LEFTARROWKEY, SCA_IInputDevice::KX_LEFTARROWKEY);
1061         KX_MACRO_addTypesToDict(d, DOWNARROWKEY, SCA_IInputDevice::KX_DOWNARROWKEY);
1062         KX_MACRO_addTypesToDict(d, RIGHTARROWKEY, SCA_IInputDevice::KX_RIGHTARROWKEY);  
1063         KX_MACRO_addTypesToDict(d, UPARROWKEY, SCA_IInputDevice::KX_UPARROWKEY);                
1064         
1065         KX_MACRO_addTypesToDict(d, PAD2 , SCA_IInputDevice::KX_PAD2);
1066         KX_MACRO_addTypesToDict(d, PAD4 , SCA_IInputDevice::KX_PAD4);
1067         KX_MACRO_addTypesToDict(d, PAD6 , SCA_IInputDevice::KX_PAD6);
1068         KX_MACRO_addTypesToDict(d, PAD8 , SCA_IInputDevice::KX_PAD8);
1069                 
1070         KX_MACRO_addTypesToDict(d, PAD1 , SCA_IInputDevice::KX_PAD1);
1071         KX_MACRO_addTypesToDict(d, PAD3 , SCA_IInputDevice::KX_PAD3);
1072         KX_MACRO_addTypesToDict(d, PAD5 , SCA_IInputDevice::KX_PAD5);
1073         KX_MACRO_addTypesToDict(d, PAD7 , SCA_IInputDevice::KX_PAD7);
1074         KX_MACRO_addTypesToDict(d, PAD9 , SCA_IInputDevice::KX_PAD9);
1075                 
1076         KX_MACRO_addTypesToDict(d, PADPERIOD, SCA_IInputDevice::KX_PADPERIOD);
1077         KX_MACRO_addTypesToDict(d, PADSLASHKEY, SCA_IInputDevice::KX_PADSLASHKEY);
1078         KX_MACRO_addTypesToDict(d, PADASTERKEY, SCA_IInputDevice::KX_PADASTERKEY);
1079                 
1080                 
1081         KX_MACRO_addTypesToDict(d, PAD0, SCA_IInputDevice::KX_PAD0);
1082         KX_MACRO_addTypesToDict(d, PADMINUS, SCA_IInputDevice::KX_PADMINUS);
1083         KX_MACRO_addTypesToDict(d, PADENTER, SCA_IInputDevice::KX_PADENTER);
1084         KX_MACRO_addTypesToDict(d, PADPLUSKEY, SCA_IInputDevice::KX_PADPLUSKEY);
1085                 
1086                 
1087         KX_MACRO_addTypesToDict(d, F1KEY , SCA_IInputDevice::KX_F1KEY);
1088         KX_MACRO_addTypesToDict(d, F2KEY , SCA_IInputDevice::KX_F2KEY);
1089         KX_MACRO_addTypesToDict(d, F3KEY , SCA_IInputDevice::KX_F3KEY);
1090         KX_MACRO_addTypesToDict(d, F4KEY , SCA_IInputDevice::KX_F4KEY);
1091         KX_MACRO_addTypesToDict(d, F5KEY , SCA_IInputDevice::KX_F5KEY);
1092         KX_MACRO_addTypesToDict(d, F6KEY , SCA_IInputDevice::KX_F6KEY);
1093         KX_MACRO_addTypesToDict(d, F7KEY , SCA_IInputDevice::KX_F7KEY);
1094         KX_MACRO_addTypesToDict(d, F8KEY , SCA_IInputDevice::KX_F8KEY);
1095         KX_MACRO_addTypesToDict(d, F9KEY , SCA_IInputDevice::KX_F9KEY);
1096         KX_MACRO_addTypesToDict(d, F10KEY, SCA_IInputDevice::KX_F10KEY);
1097         KX_MACRO_addTypesToDict(d, F11KEY, SCA_IInputDevice::KX_F11KEY);
1098         KX_MACRO_addTypesToDict(d, F12KEY, SCA_IInputDevice::KX_F12KEY);
1099                 
1100         KX_MACRO_addTypesToDict(d, PAUSEKEY, SCA_IInputDevice::KX_PAUSEKEY);
1101         KX_MACRO_addTypesToDict(d, INSERTKEY, SCA_IInputDevice::KX_INSERTKEY);
1102         KX_MACRO_addTypesToDict(d, HOMEKEY , SCA_IInputDevice::KX_HOMEKEY);
1103         KX_MACRO_addTypesToDict(d, PAGEUPKEY, SCA_IInputDevice::KX_PAGEUPKEY);
1104         KX_MACRO_addTypesToDict(d, PAGEDOWNKEY, SCA_IInputDevice::KX_PAGEDOWNKEY);
1105         KX_MACRO_addTypesToDict(d, ENDKEY, SCA_IInputDevice::KX_ENDKEY);
1106
1107
1108         // Check for errors
1109         if (PyErr_Occurred())
1110     {
1111                 Py_FatalError("can't initialize module GameKeys");
1112     }
1113
1114         return d;
1115 }
1116
1117 void PHY_SetActiveScene(class KX_Scene* scene)
1118 {
1119         gp_KetsjiScene = scene;
1120 }