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