BGE: Add setMistType and setMistIntensity API.
[blender.git] / source / gameengine / Ketsji / KX_PythonInit.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  * Initialize Python thingies.
27  */
28
29 /** \file gameengine/Ketsji/KX_PythonInit.cpp
30  *  \ingroup ketsji
31  */
32
33 #include "glew-mx.h"
34
35 #ifdef _MSC_VER
36 #  pragma warning (disable:4786)
37 #endif
38
39 #ifdef WITH_PYTHON
40 #  ifdef   _POSIX_C_SOURCE
41 #    undef _POSIX_C_SOURCE
42 #  endif
43 #  ifdef   _XOPEN_SOURCE
44 #    undef _XOPEN_SOURCE
45 #  endif
46 #  if defined(__sun) || defined(sun)
47 #    if defined(_XPG4)
48 #      undef _XPG4
49 #    endif
50 #  endif
51 #  include <Python.h>
52
53 extern "C" {
54         #  include "bpy_internal_import.h"  /* from the blender python api, but we want to import text too! */
55         #  include "py_capi_utils.h"
56         #  include "mathutils.h" // 'mathutils' module copied here so the blenderlayer can use.
57         #  include "bgl.h"
58         #  include "blf_py_api.h"
59
60         #  include "marshal.h" /* python header for loading/saving dicts */
61 }
62 #include "AUD_PyInit.h"
63
64 #endif  /* WITH_PYTHON */
65
66 #include "KX_PythonInit.h"
67
68 // directory header for py function getBlendFileList
69 #ifndef WIN32
70 #  include <dirent.h>
71 #  include <stdlib.h>
72 #else
73 #  include <io.h>
74 #  include "BLI_winstuff.h"
75 #endif
76
77 //python physics binding
78 #include "KX_PyConstraintBinding.h"
79
80 #include "KX_KetsjiEngine.h"
81 #include "KX_RadarSensor.h"
82 #include "KX_RaySensor.h"
83 #include "KX_ArmatureSensor.h"
84 #include "KX_SceneActuator.h"
85 #include "KX_GameActuator.h"
86 #include "KX_ParentActuator.h"
87 #include "KX_SCA_DynamicActuator.h"
88 #include "KX_SteeringActuator.h"
89 #include "KX_NavMeshObject.h"
90 #include "KX_MouseActuator.h"
91 #include "KX_TrackToActuator.h"
92
93 #include "SCA_IInputDevice.h"
94 #include "SCA_PropertySensor.h"
95 #include "SCA_RandomActuator.h"
96 #include "SCA_KeyboardSensor.h" /* IsPrintable, ToCharacter */
97 #include "SCA_JoystickManager.h" /* JOYINDEX_MAX */
98 #include "SCA_PythonJoystick.h"
99 #include "SCA_PythonKeyboard.h"
100 #include "SCA_PythonMouse.h"
101 #include "KX_ConstraintActuator.h"
102 #include "KX_IpoActuator.h"
103 #include "KX_SoundActuator.h"
104 #include "KX_StateActuator.h"
105 #include "BL_ActionActuator.h"
106 #include "BL_ArmatureObject.h"
107 #include "RAS_IRasterizer.h"
108 #include "RAS_ICanvas.h"
109 #include "RAS_BucketManager.h"
110 #include "RAS_2DFilterManager.h"
111 #include "MT_Vector3.h"
112 #include "MT_Point3.h"
113 #include "ListValue.h"
114 #include "InputParser.h"
115 #include "KX_Scene.h"
116
117 #include "NG_NetworkScene.h" //Needed for sendMessage()
118
119 #include "BL_Shader.h"
120 #include "BL_Action.h"
121
122 #include "KX_PyMath.h"
123
124 #include "PyObjectPlus.h"
125
126 #include "KX_PythonInitTypes.h" 
127
128 /* we only need this to get a list of libraries from the main struct */
129 #include "DNA_ID.h"
130 #include "DNA_scene_types.h"
131
132 #include "PHY_IPhysicsEnvironment.h"
133
134 extern "C" {
135 #include "BKE_main.h"
136 #include "BKE_global.h"
137 #include "BKE_library.h"
138 #include "BKE_appdir.h"
139 #include "BLI_blenlib.h"
140 #include "GPU_material.h"
141 #include "MEM_guardedalloc.h"
142 }
143
144 /* for converting new scenes */
145 #include "KX_BlenderSceneConverter.h"
146 #include "KX_LibLoadStatus.h"
147 #include "KX_MeshProxy.h" /* for creating a new library of mesh objects */
148 extern "C" {
149         #include "BKE_idcode.h"
150 }
151
152 // 'local' copy of canvas ptr, for window height/width python scripts
153
154 #ifdef WITH_PYTHON
155
156 static RAS_ICanvas* gp_Canvas = NULL;
157 static char gp_GamePythonPath[FILE_MAX] = "";
158 static char gp_GamePythonPathOrig[FILE_MAX] = ""; // not super happy about this, but we need to remember the first loaded file for the global/dict load save
159
160 static SCA_PythonKeyboard* gp_PythonKeyboard = NULL;
161 static SCA_PythonMouse* gp_PythonMouse = NULL;
162 static SCA_PythonJoystick* gp_PythonJoysticks[JOYINDEX_MAX] = {NULL};
163 #endif // WITH_PYTHON
164
165 static KX_Scene*        gp_KetsjiScene = NULL;
166 static KX_KetsjiEngine* gp_KetsjiEngine = NULL;
167 static RAS_IRasterizer* gp_Rasterizer = NULL;
168
169
170 void KX_SetActiveScene(class KX_Scene* scene)
171 {
172         gp_KetsjiScene = scene;
173 }
174
175 class KX_Scene* KX_GetActiveScene()
176 {
177         return gp_KetsjiScene;
178 }
179
180 class KX_KetsjiEngine* KX_GetActiveEngine()
181 {
182         return gp_KetsjiEngine;
183 }
184
185 /* why is this in python? */
186 void    KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
187 {
188         if (gp_Rasterizer)
189                 gp_Rasterizer->DrawDebugLine(from,to,color);
190 }
191
192 void KX_RasterizerDrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
193                                   const MT_Vector3& normal, int nsector)
194 {
195         if (gp_Rasterizer)
196                 gp_Rasterizer->DrawDebugCircle(center, radius, color, normal, nsector);
197 }
198
199 #ifdef WITH_PYTHON
200
201 static PyObject *gp_OrigPythonSysPath= NULL;
202 static PyObject *gp_OrigPythonSysModules= NULL;
203
204 /* Macro for building the keyboard translation */
205 //#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyLong_FromLong(SCA_IInputDevice::KX_##name))
206 //#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, item=PyLong_FromLong(name)); Py_DECREF(item)
207 /* For the defines for types from logic bricks, we do stuff explicitly... */
208 #define KX_MACRO_addTypesToDict(dict, name, value) KX_MACRO_addTypesToDict_fn(dict, #name, value)
209 static void KX_MACRO_addTypesToDict_fn(PyObject *dict, const char *name, long value)
210 {
211         PyObject *item;
212
213         item = PyLong_FromLong(value);
214         PyDict_SetItemString(dict, name, item);
215         Py_DECREF(item);
216 }
217
218
219
220 // temporarily python stuff, will be put in another place later !
221 #include "KX_Python.h"
222 #include "SCA_PythonController.h"
223 // List of methods defined in the module
224
225 static PyObject *ErrorObject;
226
227 PyDoc_STRVAR(gPyGetRandomFloat_doc,
228 "getRandomFloat()\n"
229 "returns a random floating point value in the range [0..1]"
230 );
231 static PyObject *gPyGetRandomFloat(PyObject *)
232 {
233         return PyFloat_FromDouble(MT_random());
234 }
235
236 static PyObject *gPySetGravity(PyObject *, PyObject *value)
237 {
238         MT_Vector3 vec;
239         if (!PyVecTo(value, vec))
240                 return NULL;
241
242         if (gp_KetsjiScene)
243                 gp_KetsjiScene->SetGravity(vec);
244         
245         Py_RETURN_NONE;
246 }
247
248 PyDoc_STRVAR(gPyExpandPath_doc,
249 "expandPath(path)\n"
250 "Converts a blender internal path into a proper file system path.\n"
251 " path - the string path to convert.\n"
252 "Use / as directory separator in path\n"
253 "You can use '//' at the start of the string to define a relative path."
254 "Blender replaces that string by the directory of the current .blend or runtime file to make a full path name.\n"
255 "The function also converts the directory separator to the local file system format."
256 );
257 static PyObject *gPyExpandPath(PyObject *, PyObject *args)
258 {
259         char expanded[FILE_MAX];
260         char* filename;
261         
262         if (!PyArg_ParseTuple(args,"s:ExpandPath",&filename))
263                 return NULL;
264
265         BLI_strncpy(expanded, filename, FILE_MAX);
266         BLI_path_abs(expanded, gp_GamePythonPath);
267         return PyC_UnicodeFromByte(expanded);
268 }
269
270 PyDoc_STRVAR(gPyStartGame_doc,
271 "startGame(blend)\n"
272 "Loads the blend file"
273 );
274 static PyObject *gPyStartGame(PyObject *, PyObject *args)
275 {
276         char* blendfile;
277
278         if (!PyArg_ParseTuple(args, "s:startGame", &blendfile))
279                 return NULL;
280
281         gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME);
282         gp_KetsjiEngine->SetNameNextGame(blendfile);
283
284         Py_RETURN_NONE;
285 }
286
287 PyDoc_STRVAR(gPyEndGame_doc,
288 "endGame()\n"
289 "Ends the current game"
290 );
291 static PyObject *gPyEndGame(PyObject *)
292 {
293         gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME);
294
295         //printf("%s\n", gp_GamePythonPath);
296
297         Py_RETURN_NONE;
298 }
299
300 PyDoc_STRVAR(gPyRestartGame_doc,
301 "restartGame()\n"
302 "Restarts the current game by reloading the .blend file"
303 );
304 static PyObject *gPyRestartGame(PyObject *)
305 {
306         gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME);
307         gp_KetsjiEngine->SetNameNextGame(gp_GamePythonPath);
308
309         Py_RETURN_NONE;
310 }
311
312 PyDoc_STRVAR(gPySaveGlobalDict_doc,
313 "saveGlobalDict()\n"
314 "Saves bge.logic.globalDict to a file"
315 );
316 static PyObject *gPySaveGlobalDict(PyObject *)
317 {
318         char marshal_path[512];
319         char *marshal_buffer = NULL;
320         unsigned int marshal_length;
321         FILE *fp = NULL;
322
323         pathGamePythonConfig(marshal_path);
324         marshal_length = saveGamePythonConfig(&marshal_buffer);
325
326         if (marshal_length && marshal_buffer)
327         {
328                 fp = fopen(marshal_path, "wb");
329
330                 if (fp)
331                 {
332                         if (fwrite(marshal_buffer, 1, marshal_length, fp) != marshal_length)
333                                 printf("Warning: could not write marshal data\n");
334
335                         fclose(fp);
336                 } else {
337                         printf("Warning: could not open marshal file\n");
338                 }
339         } else {
340                 printf("Warning: could not create marshal buffer\n");
341         }
342
343         if (marshal_buffer)
344                 delete [] marshal_buffer;
345
346         Py_RETURN_NONE;
347 }
348
349 PyDoc_STRVAR(gPyLoadGlobalDict_doc,
350 "LoadGlobalDict()\n"
351 "Loads bge.logic.globalDict from a file"
352 );
353 static PyObject *gPyLoadGlobalDict(PyObject *)
354 {
355         char marshal_path[512];
356         char *marshal_buffer = NULL;
357         size_t marshal_length;
358         FILE *fp = NULL;
359         int result;
360
361         pathGamePythonConfig(marshal_path);
362
363         fp = fopen(marshal_path, "rb");
364
365         if (fp) {
366                 // obtain file size:
367                 fseek (fp, 0, SEEK_END);
368                 marshal_length = (size_t)ftell(fp);
369                 rewind(fp);
370
371                 marshal_buffer = (char*)malloc (sizeof(char)*marshal_length);
372
373                 result = fread(marshal_buffer, 1, marshal_length, fp);
374
375                 if (result == marshal_length) {
376                         loadGamePythonConfig(marshal_buffer, marshal_length);
377                 } else {
378                         printf("Warning: could not read all of '%s'\n", marshal_path);
379                 }
380
381                 free(marshal_buffer);
382                 fclose(fp);
383         } else {
384                 printf("Warning: could not open '%s'\n", marshal_path);
385         }
386
387         Py_RETURN_NONE;
388 }
389
390 PyDoc_STRVAR(gPyGetProfileInfo_doc,
391 "getProfileInfo()\n"
392 "returns a dictionary with profiling information"
393 );
394 static PyObject *gPyGetProfileInfo(PyObject *)
395 {
396         return gp_KetsjiEngine->GetPyProfileDict();
397 }
398
399 PyDoc_STRVAR(gPySendMessage_doc,
400 "sendMessage(subject, [body, to, from])\n"
401 "sends a message in same manner as a message actuator"
402 " subject = Subject of the message"
403 " body = Message body"
404 " to = Name of object to send the message to"
405 " from = Name of object to send the string from"
406 );
407 static PyObject *gPySendMessage(PyObject *, PyObject *args)
408 {
409         char* subject;
410         char* body = (char *)"";
411         char* to = (char *)"";
412         char* from = (char *)"";
413
414         if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to, &from))
415                 return NULL;
416
417         gp_KetsjiScene->GetNetworkScene()->SendMessage(to, from, subject, body);
418
419         Py_RETURN_NONE;
420 }
421
422 // this gets a pointer to an array filled with floats
423 static PyObject *gPyGetSpectrum(PyObject *)
424 {
425         PyObject *resultlist = PyList_New(512);
426
427         for (int index = 0; index < 512; index++)
428         {
429                 PyList_SET_ITEM(resultlist, index, PyFloat_FromDouble(0.0));
430         }
431
432         return resultlist;
433 }
434
435 static PyObject *gPySetLogicTicRate(PyObject *, PyObject *args)
436 {
437         float ticrate;
438         if (!PyArg_ParseTuple(args, "f:setLogicTicRate", &ticrate))
439                 return NULL;
440         
441         KX_KetsjiEngine::SetTicRate(ticrate);
442         Py_RETURN_NONE;
443 }
444
445 static PyObject *gPyGetLogicTicRate(PyObject *)
446 {
447         return PyFloat_FromDouble(KX_KetsjiEngine::GetTicRate());
448 }
449
450 static PyObject *gPySetExitKey(PyObject *, PyObject *args)
451 {
452         short exitkey;
453         if (!PyArg_ParseTuple(args, "h:setExitKey", &exitkey))
454                 return NULL;
455         KX_KetsjiEngine::SetExitKey(exitkey);
456         Py_RETURN_NONE;
457 }
458
459 static PyObject *gPyGetExitKey(PyObject *)
460 {
461         return PyLong_FromLong(KX_KetsjiEngine::GetExitKey());
462 }
463
464 static PyObject *gPySetMaxLogicFrame(PyObject *, PyObject *args)
465 {
466         int frame;
467         if (!PyArg_ParseTuple(args, "i:setMaxLogicFrame", &frame))
468                 return NULL;
469         
470         KX_KetsjiEngine::SetMaxLogicFrame(frame);
471         Py_RETURN_NONE;
472 }
473
474 static PyObject *gPyGetMaxLogicFrame(PyObject *)
475 {
476         return PyLong_FromLong(KX_KetsjiEngine::GetMaxLogicFrame());
477 }
478
479 static PyObject *gPySetMaxPhysicsFrame(PyObject *, PyObject *args)
480 {
481         int frame;
482         if (!PyArg_ParseTuple(args, "i:setMaxPhysicsFrame", &frame))
483                 return NULL;
484         
485         KX_KetsjiEngine::SetMaxPhysicsFrame(frame);
486         Py_RETURN_NONE;
487 }
488
489 static PyObject *gPyGetMaxPhysicsFrame(PyObject *)
490 {
491         return PyLong_FromLong(KX_KetsjiEngine::GetMaxPhysicsFrame());
492 }
493
494 static PyObject *gPySetPhysicsTicRate(PyObject *, PyObject *args)
495 {
496         float ticrate;
497         if (!PyArg_ParseTuple(args, "f:setPhysicsTicRate", &ticrate))
498                 return NULL;
499         
500         PHY_GetActiveEnvironment()->SetFixedTimeStep(true,ticrate);
501         Py_RETURN_NONE;
502 }
503 #if 0 // unused
504 static PyObject *gPySetPhysicsDebug(PyObject *, PyObject *args)
505 {
506         int debugMode;
507         if (!PyArg_ParseTuple(args, "i:setPhysicsDebug", &debugMode))
508                 return NULL;
509         
510         PHY_GetActiveEnvironment()->setDebugMode(debugMode);
511         Py_RETURN_NONE;
512 }
513 #endif
514
515
516 static PyObject *gPyGetPhysicsTicRate(PyObject *)
517 {
518         return PyFloat_FromDouble(PHY_GetActiveEnvironment()->GetFixedTimeStep());
519 }
520
521 static PyObject *gPyGetAverageFrameRate(PyObject *)
522 {
523         return PyFloat_FromDouble(KX_KetsjiEngine::GetAverageFrameRate());
524 }
525
526 static PyObject *gPyGetBlendFileList(PyObject *, PyObject *args)
527 {
528         char cpath[sizeof(gp_GamePythonPath)];
529         char *searchpath = NULL;
530         PyObject *list, *value;
531
532         DIR *dp;
533         struct dirent *dirp;
534
535         if (!PyArg_ParseTuple(args, "|s:getBlendFileList", &searchpath))
536                 return NULL;
537
538         list = PyList_New(0);
539         
540         if (searchpath) {
541                 BLI_strncpy(cpath, searchpath, FILE_MAX);
542                 BLI_path_abs(cpath, gp_GamePythonPath);
543         } else {
544                 /* Get the dir only */
545                 BLI_split_dir_part(gp_GamePythonPath, cpath, sizeof(cpath));
546         }
547
548         if ((dp  = opendir(cpath)) == NULL) {
549                 /* todo, show the errno, this shouldnt happen anyway if the blendfile is readable */
550                 fprintf(stderr, "Could not read directory (%s) failed, code %d (%s)\n", cpath, errno, strerror(errno));
551                 return list;
552         }
553         
554         while ((dirp = readdir(dp)) != NULL) {
555                 if (BLI_testextensie(dirp->d_name, ".blend")) {
556                         value = PyC_UnicodeFromByte(dirp->d_name);
557                         PyList_Append(list, value);
558                         Py_DECREF(value);
559                 }
560         }
561         
562         closedir(dp);
563         return list;
564 }
565
566 PyDoc_STRVAR(gPyAddScene_doc,
567 "addScene(name, [overlay])\n"
568 "Adds a scene to the game engine.\n"
569 " name = Name of the scene\n"
570 " overlay = Overlay or underlay"
571 );
572 static PyObject *gPyAddScene(PyObject *, PyObject *args)
573 {
574         char* name;
575         int overlay = 1;
576         
577         if (!PyArg_ParseTuple(args, "s|i:addScene", &name , &overlay))
578                 return NULL;
579         
580         gp_KetsjiEngine->ConvertAndAddScene(name, (overlay != 0));
581
582         Py_RETURN_NONE;
583 }
584
585 PyDoc_STRVAR(gPyGetCurrentScene_doc,
586 "getCurrentScene()\n"
587 "Gets a reference to the current scene."
588 );
589 static PyObject *gPyGetCurrentScene(PyObject *self)
590 {
591         return gp_KetsjiScene->GetProxy();
592 }
593
594 PyDoc_STRVAR(gPyGetSceneList_doc,
595 "getSceneList()\n"
596 "Return a list of converted scenes."
597 );
598 static PyObject *gPyGetSceneList(PyObject *self)
599 {
600         KX_KetsjiEngine* m_engine = KX_GetActiveEngine();
601         PyObject *list;
602         KX_SceneList* scenes = m_engine->CurrentScenes();
603         int numScenes = scenes->size();
604         int i;
605         
606         list = PyList_New(numScenes);
607         
608         for (i=0;i<numScenes;i++)
609         {
610                 KX_Scene* scene = scenes->at(i);
611                 PyList_SET_ITEM(list, i, scene->GetProxy());
612         }
613
614         return list;
615 }
616
617 static PyObject *pyPrintStats(PyObject *,PyObject *,PyObject *)
618 {
619         gp_KetsjiScene->GetSceneConverter()->PrintStats();
620         Py_RETURN_NONE;
621 }
622
623 static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
624 {
625 #define pprint(x) std::cout << x << std::endl;
626         bool count=0;
627         bool support=0;
628         pprint("Supported Extensions...");
629         pprint(" GL_ARB_shader_objects supported?       "<< (GLEW_ARB_shader_objects?"yes.":"no."));
630         count = 1;
631
632         support= GLEW_ARB_vertex_shader;
633         pprint(" GL_ARB_vertex_shader supported?        "<< (support?"yes.":"no."));
634         count = 1;
635         if (support) {
636                 pprint(" ----------Details----------");
637                 int max=0;
638                 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, (GLint*)&max);
639                 pprint("  Max uniform components." << max);
640
641                 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, (GLint*)&max);
642                 pprint("  Max varying floats." << max);
643
644                 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, (GLint*)&max);
645                 pprint("  Max vertex texture units." << max);
646         
647                 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, (GLint*)&max);
648                 pprint("  Max combined texture units." << max);
649                 pprint("");
650         }
651
652         support=GLEW_ARB_fragment_shader;
653         pprint(" GL_ARB_fragment_shader supported?      "<< (support?"yes.":"no."));
654         count = 1;
655         if (support) {
656                 pprint(" ----------Details----------");
657                 int max=0;
658                 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, (GLint*)&max);
659                 pprint("  Max uniform components." << max);
660                 pprint("");
661         }
662
663         support = GLEW_ARB_texture_cube_map;
664         pprint(" GL_ARB_texture_cube_map supported?     "<< (support?"yes.":"no."));
665         count = 1;
666         if (support) {
667                 pprint(" ----------Details----------");
668                 int size=0;
669                 glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, (GLint*)&size);
670                 pprint("  Max cubemap size." << size);
671                 pprint("");
672         }
673
674         support = GLEW_ARB_multitexture;
675         count = 1;
676         pprint(" GL_ARB_multitexture supported?         "<< (support?"yes.":"no."));
677         if (support) {
678                 pprint(" ----------Details----------");
679                 int units=0;
680                 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&units);
681                 pprint("  Max texture units available.  " << units);
682                 pprint("");
683         }
684
685         pprint(" GL_ARB_texture_env_combine supported?  "<< (GLEW_ARB_texture_env_combine?"yes.":"no."));
686         count = 1;
687
688         if (!count)
689                 pprint("No extenstions are used in this build");
690
691         Py_RETURN_NONE;
692 }
693
694 static PyObject *gLibLoad(PyObject *, PyObject *args, PyObject *kwds)
695 {
696         KX_Scene *kx_scene= gp_KetsjiScene;
697         char *path;
698         char *group;
699         Py_buffer py_buffer;
700         py_buffer.buf = NULL;
701         char *err_str= NULL;
702         KX_LibLoadStatus *status = NULL;
703
704         short options=0;
705         int load_actions=0, verbose=0, load_scripts=1, async=0;
706
707         static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", "load_scripts", "async", NULL};
708         
709         if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*iiIi:LibLoad", const_cast<char**>(kwlist),
710                                                                         &path, &group, &py_buffer, &load_actions, &verbose, &load_scripts, &async))
711                 return NULL;
712
713         /* setup options */
714         if (load_actions != 0)
715                 options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_ACTIONS;
716         if (verbose != 0)
717                 options |= KX_BlenderSceneConverter::LIB_LOAD_VERBOSE;
718         if (load_scripts != 0)
719                 options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_SCRIPTS;
720         if (async != 0)
721                 options |= KX_BlenderSceneConverter::LIB_LOAD_ASYNC;
722
723         if (!py_buffer.buf)
724         {
725                 char abs_path[FILE_MAX];
726                 // Make the path absolute
727                 BLI_strncpy(abs_path, path, sizeof(abs_path));
728                 BLI_path_abs(abs_path, gp_GamePythonPath);
729
730                 if ((status=kx_scene->GetSceneConverter()->LinkBlendFilePath(abs_path, group, kx_scene, &err_str, options))) {
731                         return status->GetProxy();
732                 }
733         }
734         else
735         {
736
737                 if ((status=kx_scene->GetSceneConverter()->LinkBlendFileMemory(py_buffer.buf, py_buffer.len, path, group, kx_scene, &err_str, options)))        {
738                         PyBuffer_Release(&py_buffer);
739                         return status->GetProxy();
740                 }
741
742                 PyBuffer_Release(&py_buffer);
743         }
744         
745         if (err_str) {
746                 PyErr_SetString(PyExc_ValueError, err_str);
747                 return NULL;
748         }
749         
750         Py_RETURN_FALSE;
751 }
752
753 static PyObject *gLibNew(PyObject *, PyObject *args)
754 {
755         KX_Scene *kx_scene= gp_KetsjiScene;
756         char *path;
757         char *group;
758         const char *name;
759         PyObject *names;
760         int idcode;
761
762         if (!PyArg_ParseTuple(args,"ssO!:LibNew",&path, &group, &PyList_Type, &names))
763                 return NULL;
764         
765         if (kx_scene->GetSceneConverter()->GetMainDynamicPath(path))
766         {
767                 PyErr_SetString(PyExc_KeyError, "the name of the path given exists");
768                 return NULL;
769         }
770         
771         idcode= BKE_idcode_from_name(group);
772         if (idcode==0) {
773                 PyErr_Format(PyExc_ValueError, "invalid group given \"%s\"", group);
774                 return NULL;
775         }
776         
777         Main *maggie=BKE_main_new();
778         kx_scene->GetSceneConverter()->GetMainDynamic().push_back(maggie);
779         strncpy(maggie->name, path, sizeof(maggie->name)-1);
780         
781         /* Copy the object into main */
782         if (idcode==ID_ME) {
783                 PyObject *ret= PyList_New(0);
784                 PyObject *item;
785                 for (Py_ssize_t i= 0; i < PyList_GET_SIZE(names); i++) {
786                         name= _PyUnicode_AsString(PyList_GET_ITEM(names, i));
787                         if (name) {
788                                 RAS_MeshObject *meshobj= kx_scene->GetSceneConverter()->ConvertMeshSpecial(kx_scene, maggie, name);
789                                 if (meshobj) {
790                                         KX_MeshProxy* meshproxy = new KX_MeshProxy(meshobj);
791                                         item= meshproxy->NewProxy(true);
792                                         PyList_Append(ret, item);
793                                         Py_DECREF(item);
794                                 }
795                         }
796                         else {
797                                 PyErr_Clear(); /* wasnt a string, ignore for now */
798                         }
799                 }
800                 
801                 return ret;
802         }
803         else {
804                 PyErr_Format(PyExc_ValueError, "only \"Mesh\" group currently supported");
805                 return NULL;
806         }
807         
808         Py_RETURN_NONE;
809 }
810
811 static PyObject *gLibFree(PyObject *, PyObject *args)
812 {
813         KX_Scene *kx_scene= gp_KetsjiScene;
814         char *path;
815
816         if (!PyArg_ParseTuple(args,"s:LibFree",&path))
817                 return NULL;
818
819         if (kx_scene->GetSceneConverter()->FreeBlendFile(path))
820         {
821                 Py_RETURN_TRUE;
822         }
823         else {
824                 Py_RETURN_FALSE;
825         }
826 }
827
828 static PyObject *gLibList(PyObject *, PyObject *args)
829 {
830         vector<Main*> &dynMaggie = gp_KetsjiScene->GetSceneConverter()->GetMainDynamic();
831         int i= 0;
832         PyObject *list= PyList_New(dynMaggie.size());
833         
834         for (vector<Main*>::iterator it=dynMaggie.begin(); !(it==dynMaggie.end()); it++)
835         {
836                 PyList_SET_ITEM(list, i++, PyUnicode_FromString( (*it)->name) );
837         }
838         
839         return list;
840 }
841
842 struct PyNextFrameState pynextframestate;
843 static PyObject *gPyNextFrame(PyObject *)
844 {
845         if (pynextframestate.func == NULL) Py_RETURN_NONE;
846         if (pynextframestate.state == NULL) Py_RETURN_NONE; //should never happen; raise exception instead?
847
848         if (pynextframestate.func(pynextframestate.state)) //nonzero = stop
849         { 
850                 Py_RETURN_TRUE;
851         }
852         else // 0 = go on
853         {
854                 Py_RETURN_FALSE;
855         }
856 }
857
858
859 static struct PyMethodDef game_methods[] = {
860         {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (const char *)gPyExpandPath_doc},
861         {"startGame", (PyCFunction)gPyStartGame, METH_VARARGS, (const char *)gPyStartGame_doc},
862         {"endGame", (PyCFunction)gPyEndGame, METH_NOARGS, (const char *)gPyEndGame_doc},
863         {"restartGame", (PyCFunction)gPyRestartGame, METH_NOARGS, (const char *)gPyRestartGame_doc},
864         {"saveGlobalDict", (PyCFunction)gPySaveGlobalDict, METH_NOARGS, (const char *)gPySaveGlobalDict_doc},
865         {"loadGlobalDict", (PyCFunction)gPyLoadGlobalDict, METH_NOARGS, (const char *)gPyLoadGlobalDict_doc},
866         {"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (const char *)gPySendMessage_doc},
867         {"getCurrentController", (PyCFunction) SCA_PythonController::sPyGetCurrentController, METH_NOARGS, SCA_PythonController::sPyGetCurrentController__doc__},
868         {"getCurrentScene", (PyCFunction) gPyGetCurrentScene, METH_NOARGS, gPyGetCurrentScene_doc},
869         {"getSceneList", (PyCFunction) gPyGetSceneList, METH_NOARGS, (const char *)gPyGetSceneList_doc},
870         {"addScene", (PyCFunction)gPyAddScene, METH_VARARGS, (const char *)gPyAddScene_doc},
871         {"getRandomFloat",(PyCFunction) gPyGetRandomFloat, METH_NOARGS, (const char *)gPyGetRandomFloat_doc},
872         {"setGravity",(PyCFunction) gPySetGravity, METH_O, (const char *)"set Gravitation"},
873         {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_NOARGS, (const char *)"get audio spectrum"},
874         {"getMaxLogicFrame", (PyCFunction) gPyGetMaxLogicFrame, METH_NOARGS, (const char *)"Gets the max number of logic frame per render frame"},
875         {"setMaxLogicFrame", (PyCFunction) gPySetMaxLogicFrame, METH_VARARGS, (const char *)"Sets the max number of logic frame per render frame"},
876         {"getMaxPhysicsFrame", (PyCFunction) gPyGetMaxPhysicsFrame, METH_NOARGS, (const char *)"Gets the max number of physics frame per render frame"},
877         {"setMaxPhysicsFrame", (PyCFunction) gPySetMaxPhysicsFrame, METH_VARARGS, (const char *)"Sets the max number of physics farme per render frame"},
878         {"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_NOARGS, (const char *)"Gets the logic tic rate"},
879         {"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, (const char *)"Sets the logic tic rate"},
880         {"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, (const char *)"Gets the physics tic rate"},
881         {"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, (const char *)"Sets the physics tic rate"},
882         {"getExitKey", (PyCFunction) gPyGetExitKey, METH_NOARGS, (const char *)"Gets the key used to exit the game engine"},
883         {"setExitKey", (PyCFunction) gPySetExitKey, METH_VARARGS, (const char *)"Sets the key used to exit the game engine"},
884         {"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (const char *)"Gets the estimated average frame rate"},
885         {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"},
886         {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"},
887         {"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine statistics"},
888         {"NextFrame", (PyCFunction)gPyNextFrame, METH_NOARGS, (const char *)"Render next frame (if Python has control)"},
889         {"getProfileInfo", (PyCFunction)gPyGetProfileInfo, METH_NOARGS, gPyGetProfileInfo_doc},
890         /* library functions */
891         {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""},
892         {"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""},
893         {"LibFree", (PyCFunction)gLibFree, METH_VARARGS, (const char *)""},
894         {"LibList", (PyCFunction)gLibList, METH_VARARGS, (const char *)""},
895         
896         {NULL, (PyCFunction) NULL, 0, NULL }
897 };
898
899 static PyObject *gPyGetWindowHeight(PyObject *, PyObject *args)
900 {
901         return PyLong_FromLong((gp_Canvas ? gp_Canvas->GetHeight() : 0));
902 }
903
904
905
906 static PyObject *gPyGetWindowWidth(PyObject *, PyObject *args)
907 {
908         return PyLong_FromLong((gp_Canvas ? gp_Canvas->GetWidth() : 0));
909 }
910
911
912
913 // temporarility visibility thing, will be moved to rasterizer/renderer later
914 bool gUseVisibilityTemp = false;
915
916 static PyObject *gPyEnableVisibility(PyObject *, PyObject *args)
917 {
918         int visible;
919         if (!PyArg_ParseTuple(args,"i:enableVisibility",&visible))
920                 return NULL;
921         
922         gUseVisibilityTemp = (visible != 0);
923         Py_RETURN_NONE;
924 }
925
926
927
928 static PyObject *gPyShowMouse(PyObject *, PyObject *args)
929 {
930         int visible;
931         if (!PyArg_ParseTuple(args,"i:showMouse",&visible))
932                 return NULL;
933         
934         if (visible)
935         {
936                 if (gp_Canvas)
937                         gp_Canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
938         } else
939         {
940                 if (gp_Canvas)
941                         gp_Canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
942         }
943         
944         Py_RETURN_NONE;
945 }
946
947
948
949 static PyObject *gPySetMousePosition(PyObject *, PyObject *args)
950 {
951         int x,y;
952         if (!PyArg_ParseTuple(args,"ii:setMousePosition",&x,&y))
953                 return NULL;
954         
955         if (gp_Canvas)
956                 gp_Canvas->SetMousePosition(x,y);
957         
958         Py_RETURN_NONE;
959 }
960
961 static PyObject *gPySetEyeSeparation(PyObject *, PyObject *args)
962 {
963         float sep;
964         if (!PyArg_ParseTuple(args, "f:setEyeSeparation", &sep))
965                 return NULL;
966
967         if (!gp_Rasterizer) {
968                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setEyeSeparation(float), Rasterizer not available");
969                 return NULL;
970         }
971         
972         gp_Rasterizer->SetEyeSeparation(sep);
973         
974         Py_RETURN_NONE;
975 }
976
977 static PyObject *gPyGetEyeSeparation(PyObject *)
978 {
979         if (!gp_Rasterizer) {
980                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getEyeSeparation(), Rasterizer not available");
981                 return NULL;
982         }
983         
984         return PyFloat_FromDouble(gp_Rasterizer->GetEyeSeparation());
985 }
986
987 static PyObject *gPySetFocalLength(PyObject *, PyObject *args)
988 {
989         float focus;
990         if (!PyArg_ParseTuple(args, "f:setFocalLength", &focus))
991                 return NULL;
992         
993         if (!gp_Rasterizer) {
994                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setFocalLength(float), Rasterizer not available");
995                 return NULL;
996         }
997
998         gp_Rasterizer->SetFocalLength(focus);
999         
1000         Py_RETURN_NONE;
1001 }
1002
1003 static PyObject *gPyGetFocalLength(PyObject *, PyObject *, PyObject *)
1004 {
1005         if (!gp_Rasterizer) {
1006                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getFocalLength(), Rasterizer not available");
1007                 return NULL;
1008         }
1009         
1010         return PyFloat_FromDouble(gp_Rasterizer->GetFocalLength());
1011         
1012         Py_RETURN_NONE;
1013 }
1014
1015 static PyObject *gPyGetStereoEye(PyObject *, PyObject *, PyObject *)
1016 {
1017         int flag = RAS_IRasterizer::RAS_STEREO_LEFTEYE;
1018
1019         if (!gp_Rasterizer) {
1020                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getStereoEye(), Rasterizer not available");
1021                 return NULL;
1022         }
1023
1024         if (gp_Rasterizer->Stereo())
1025                 flag = gp_Rasterizer->GetEye();
1026
1027         return PyLong_FromLong(flag);
1028 }
1029
1030 static PyObject *gPySetBackgroundColor(PyObject *, PyObject *value)
1031 {
1032         MT_Vector4 vec;
1033         if (!PyVecTo(value, vec))
1034                 return NULL;
1035
1036         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1037         if (!wi->hasWorld()) {
1038                 PyErr_SetString(PyExc_RuntimeError, "bge.render.SetBackgroundColor(color), World not available");
1039                 return NULL;
1040         }
1041
1042         wi->setBackColor((float)vec[0], (float)vec[1], (float)vec[2]);
1043
1044         Py_RETURN_NONE;
1045 }
1046
1047 static PyObject *gPySetMistColor(PyObject *, PyObject *value)
1048 {
1049         MT_Vector3 vec;
1050         if (!PyVecTo(value, vec))
1051                 return NULL;
1052
1053         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1054         if (!wi->hasWorld()) {
1055                 PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistColor(color), World not available");
1056                 return NULL;
1057         }
1058
1059         wi->setMistColor((float)vec[0], (float)vec[1], (float)vec[2]);
1060
1061         Py_RETURN_NONE;
1062 }
1063
1064 static PyObject *gPyDisableMist(PyObject *)
1065 {
1066         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1067         if (!wi->hasWorld()) {
1068                 PyErr_SetString(PyExc_RuntimeError, "bge.render.DisableMist(), World not available");
1069                 return NULL;
1070         }
1071         ShowDeprecationWarning("DisableMist()", "setUseMist(false)");
1072         wi->setUseMist(false);
1073
1074         Py_RETURN_NONE;
1075 }
1076
1077 static PyObject *gPySetUseMist(PyObject *, PyObject *args)
1078 {
1079         int enable;
1080         if (!PyArg_ParseTuple(args,"i:setUseMist",&enable))
1081                 return NULL;
1082
1083         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1084         if (!wi->hasWorld()) {
1085                 PyErr_SetString(PyExc_RuntimeError, "bge.render.setUseMist(enable), World not available");
1086                 return NULL;
1087         }
1088
1089         wi->setUseMist(enable);
1090
1091         Py_RETURN_NONE;
1092 }
1093
1094 static PyObject *gPySetMistType(PyObject *, PyObject *args)
1095 {
1096         short type;
1097
1098         if (!PyArg_ParseTuple(args,"i:setMistType",&type))
1099                 return NULL;
1100
1101         if (type < 0 || type > 2) {
1102                 PyErr_SetString(PyExc_ValueError, "Rasterizer.setMistType(int): Mist type is not known");
1103                 return NULL;
1104         }
1105
1106         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1107         if (!wi->hasWorld()) {
1108                 PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistType(int), World not available");
1109                 return NULL;
1110         }
1111
1112         wi->setMistType(type);
1113
1114         Py_RETURN_NONE;
1115 }
1116
1117 static PyObject *gPySetMistStart(PyObject *, PyObject *args)
1118 {
1119         float miststart;
1120         if (!PyArg_ParseTuple(args,"f:setMistStart",&miststart))
1121                 return NULL;
1122
1123         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1124         if (!wi->hasWorld()) {
1125                 PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistStart(float), World not available");
1126                 return NULL;
1127         }
1128
1129         wi->setMistStart(miststart);
1130
1131         Py_RETURN_NONE;
1132 }
1133
1134 static PyObject *gPySetMistEnd(PyObject *, PyObject *args)
1135 {
1136         float mistdist;
1137         if (!PyArg_ParseTuple(args,"f:setMistEnd",&mistdist))
1138                 return NULL;
1139
1140         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1141         if (!wi->hasWorld()) {
1142                 PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistEnd(float), World not available");
1143                 return NULL;
1144         }
1145
1146         wi->setMistDistance(mistdist);
1147
1148         Py_RETURN_NONE;
1149 }
1150
1151 static PyObject *gPySetMistIntensity(PyObject *, PyObject *args)
1152 {
1153
1154         float intensity;
1155         if (!PyArg_ParseTuple(args,"f:setMistIntensity",&intensity))
1156                 return NULL;
1157
1158         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1159         if (!wi->hasWorld()) {
1160                 PyErr_SetString(PyExc_RuntimeError, "bge.render.setMistIntensity(float), World not available");
1161                 return NULL;
1162         }
1163
1164         wi->setMistIntensity(intensity);
1165
1166         Py_RETURN_NONE;
1167 }
1168
1169 static PyObject *gPySetAmbientColor(PyObject *, PyObject *value)
1170 {
1171         MT_Vector3 vec;
1172         if (!PyVecTo(value, vec))
1173                 return NULL;
1174
1175         KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
1176         if (!wi->hasWorld()) {
1177                 PyErr_SetString(PyExc_RuntimeError, "bge.render.setAmbientColor(color), World not available");
1178                 return NULL;
1179         }
1180
1181         wi->setAmbientColor((float)vec[0], (float)vec[1], (float)vec[2]);
1182
1183         Py_RETURN_NONE;
1184 }
1185
1186 static PyObject *gPyMakeScreenshot(PyObject *, PyObject *args)
1187 {
1188         char* filename;
1189         if (!PyArg_ParseTuple(args,"s:makeScreenshot",&filename))
1190                 return NULL;
1191         
1192         if (gp_Canvas)
1193         {
1194                 gp_Canvas->MakeScreenShot(filename);
1195         }
1196         
1197         Py_RETURN_NONE;
1198 }
1199
1200 static PyObject *gPyEnableMotionBlur(PyObject *, PyObject *args)
1201 {
1202         float motionblurvalue;
1203         if (!PyArg_ParseTuple(args,"f:enableMotionBlur",&motionblurvalue))
1204                 return NULL;
1205         
1206         if (!gp_Rasterizer) {
1207                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.enableMotionBlur(float), Rasterizer not available");
1208                 return NULL;
1209         }
1210         
1211         gp_Rasterizer->EnableMotionBlur(motionblurvalue);
1212         
1213         Py_RETURN_NONE;
1214 }
1215
1216 static PyObject *gPyDisableMotionBlur(PyObject *)
1217 {
1218         if (!gp_Rasterizer) {
1219                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.disableMotionBlur(), Rasterizer not available");
1220                 return NULL;
1221         }
1222         
1223         gp_Rasterizer->DisableMotionBlur();
1224         
1225         Py_RETURN_NONE;
1226 }
1227
1228 static int getGLSLSettingFlag(const char *setting)
1229 {
1230         if (strcmp(setting, "lights") == 0)
1231                 return GAME_GLSL_NO_LIGHTS;
1232         else if (strcmp(setting, "shaders") == 0)
1233                 return GAME_GLSL_NO_SHADERS;
1234         else if (strcmp(setting, "shadows") == 0)
1235                 return GAME_GLSL_NO_SHADOWS;
1236         else if (strcmp(setting, "ramps") == 0)
1237                 return GAME_GLSL_NO_RAMPS;
1238         else if (strcmp(setting, "nodes") == 0)
1239                 return GAME_GLSL_NO_NODES;
1240         else if (strcmp(setting, "extra_textures") == 0)
1241                 return GAME_GLSL_NO_EXTRA_TEX;
1242         else
1243                 return -1;
1244 }
1245
1246 static PyObject *gPySetGLSLMaterialSetting(PyObject *,
1247                                            PyObject *args,
1248                                            PyObject *)
1249 {
1250         GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
1251         char *setting;
1252         int enable, flag, sceneflag;
1253
1254         if (!PyArg_ParseTuple(args,"si:setGLSLMaterialSetting",&setting,&enable))
1255                 return NULL;
1256         
1257         flag = getGLSLSettingFlag(setting);
1258         
1259         if (flag == -1) {
1260                 PyErr_SetString(PyExc_ValueError, "Rasterizer.setGLSLMaterialSetting(string): glsl setting is not known");
1261                 return NULL;
1262         }
1263
1264         sceneflag= gs->glslflag;
1265         
1266         if (enable)
1267                 gs->glslflag &= ~flag;
1268         else
1269                 gs->glslflag |= flag;
1270
1271         /* temporarily store the glsl settings in the scene for the GLSL materials */
1272         GameData *gm= &(gp_KetsjiScene->GetBlenderScene()->gm);
1273         gm->flag = gs->glslflag;
1274
1275         /* display lists and GLSL materials need to be remade */
1276         if (sceneflag != gs->glslflag) {
1277                 GPU_materials_free();
1278                 if (gp_KetsjiEngine) {
1279                         KX_SceneList *scenes = gp_KetsjiEngine->CurrentScenes();
1280                         KX_SceneList::iterator it;
1281
1282                         for (it=scenes->begin(); it!=scenes->end(); it++)
1283                                 if ((*it)->GetBucketManager()) {
1284                                         (*it)->GetBucketManager()->ReleaseDisplayLists();
1285                                         (*it)->GetBucketManager()->ReleaseMaterials();
1286                                 }
1287                 }
1288         }
1289
1290         Py_RETURN_NONE;
1291 }
1292
1293 static PyObject *gPyGetGLSLMaterialSetting(PyObject *,
1294                                            PyObject *args,
1295                                            PyObject *)
1296 {
1297         GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
1298         char *setting;
1299         int enabled = 0, flag;
1300
1301         if (!PyArg_ParseTuple(args,"s:getGLSLMaterialSetting",&setting))
1302                 return NULL;
1303         
1304         flag = getGLSLSettingFlag(setting);
1305         
1306         if (flag == -1) {
1307                 PyErr_SetString(PyExc_ValueError, "Rasterizer.getGLSLMaterialSetting(string): glsl setting is not known");
1308                 return NULL;
1309         }
1310
1311         enabled = ((gs->glslflag & flag) != 0);
1312         return PyLong_FromLong(enabled);
1313 }
1314
1315 #define KX_BLENDER_MULTITEX_MATERIAL    1
1316 #define KX_BLENDER_GLSL_MATERIAL                2
1317
1318 static PyObject *gPySetMaterialType(PyObject *,
1319                                     PyObject *args,
1320                                     PyObject *)
1321 {
1322         GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
1323         int type;
1324
1325         if (!PyArg_ParseTuple(args,"i:setMaterialType",&type))
1326                 return NULL;
1327
1328         if (type == KX_BLENDER_GLSL_MATERIAL)
1329                 gs->matmode= GAME_MAT_GLSL;
1330         else if (type == KX_BLENDER_MULTITEX_MATERIAL)
1331                 gs->matmode= GAME_MAT_MULTITEX;
1332         else {
1333                 PyErr_SetString(PyExc_ValueError, "Rasterizer.setMaterialType(int): material type is not known");
1334                 return NULL;
1335         }
1336
1337         Py_RETURN_NONE;
1338 }
1339
1340 static PyObject *gPyGetMaterialType(PyObject *)
1341 {
1342         GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
1343         int flag;
1344
1345         if (gs->matmode == GAME_MAT_GLSL)
1346                 flag = KX_BLENDER_GLSL_MATERIAL;
1347         else
1348                 flag = KX_BLENDER_MULTITEX_MATERIAL;
1349         
1350         return PyLong_FromLong(flag);
1351 }
1352
1353 static PyObject *gPySetAnisotropicFiltering(PyObject *, PyObject *args)
1354 {
1355         short level;
1356
1357         if (!PyArg_ParseTuple(args, "h:setAnisotropicFiltering", &level))
1358                 return NULL;
1359
1360         if (level != 1 && level != 2 && level != 4 && level != 8 && level != 16) {
1361                 PyErr_SetString(PyExc_ValueError, "Rasterizer.setAnisotropicFiltering(level): Expected value of 1, 2, 4, 8, or 16 for value");
1362                 return NULL;
1363         }
1364
1365         gp_Rasterizer->SetAnisotropicFiltering(level);
1366
1367         Py_RETURN_NONE;
1368 }
1369
1370 static PyObject *gPyGetAnisotropicFiltering(PyObject *, PyObject *args)
1371 {
1372         return PyLong_FromLong(gp_Rasterizer->GetAnisotropicFiltering());
1373 }
1374
1375 static PyObject *gPyDrawLine(PyObject *, PyObject *args)
1376 {
1377         PyObject *ob_from;
1378         PyObject *ob_to;
1379         PyObject *ob_color;
1380
1381         if (!gp_Rasterizer) {
1382                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.drawLine(obFrom, obTo, color): Rasterizer not available");
1383                 return NULL;
1384         }
1385
1386         if (!PyArg_ParseTuple(args,"OOO:drawLine",&ob_from,&ob_to,&ob_color))
1387                 return NULL;
1388
1389         MT_Vector3 from;
1390         MT_Vector3 to;
1391         MT_Vector3 color;
1392         if (!PyVecTo(ob_from, from))
1393                 return NULL;
1394         if (!PyVecTo(ob_to, to))
1395                 return NULL;
1396         if (!PyVecTo(ob_color, color))
1397                 return NULL;
1398
1399         gp_Rasterizer->DrawDebugLine(from,to,color);
1400         
1401         Py_RETURN_NONE;
1402 }
1403
1404 static PyObject *gPySetWindowSize(PyObject *, PyObject *args)
1405 {
1406         int width, height;
1407         if (!PyArg_ParseTuple(args, "ii:resize", &width, &height))
1408                 return NULL;
1409
1410         gp_Canvas->ResizeWindow(width, height);
1411         Py_RETURN_NONE;
1412 }
1413
1414 static PyObject *gPySetFullScreen(PyObject *, PyObject *value)
1415 {
1416         gp_Canvas->SetFullScreen(PyObject_IsTrue(value));
1417         Py_RETURN_NONE;
1418 }
1419
1420 static PyObject *gPyGetFullScreen(PyObject *)
1421 {
1422         return PyBool_FromLong(gp_Canvas->GetFullScreen());
1423 }
1424
1425 static PyObject *gPySetMipmapping(PyObject *, PyObject *args)
1426 {
1427         int val = 0;
1428
1429         if (!PyArg_ParseTuple(args, "i:setMipmapping", &val))
1430                 return NULL;
1431
1432         if (val < 0 || val > RAS_IRasterizer::RAS_MIPMAP_MAX) {
1433                 PyErr_SetString(PyExc_ValueError, "Rasterizer.setMipmapping(val): invalid mipmaping option");
1434                 return NULL;
1435         }
1436
1437         if (!gp_Rasterizer) {
1438                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMipmapping(val): Rasterizer not available");
1439                 return NULL;
1440         }
1441
1442         gp_Rasterizer->SetMipmapping((RAS_IRasterizer::MipmapOption)val);
1443         Py_RETURN_NONE;
1444 }
1445
1446 static PyObject *gPyGetMipmapping(PyObject *)
1447 {
1448         if (!gp_Rasterizer) {
1449                 PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getMipmapping(): Rasterizer not available");
1450                 return NULL;
1451         }
1452         return PyLong_FromLong(gp_Rasterizer->GetMipmapping());
1453 }
1454
1455 static PyObject *gPySetVsync(PyObject *, PyObject *args)
1456 {
1457         int interval;
1458
1459         if (!PyArg_ParseTuple(args, "i:setVsync", &interval))
1460                 return NULL;
1461
1462         if (interval < 0 || interval > VSYNC_ADAPTIVE) {
1463                 PyErr_SetString(PyExc_ValueError, "Rasterizer.setVsync(value): value must be VSYNC_OFF, VSYNC_ON, or VSYNC_ADAPTIVE");
1464                 return NULL;
1465         }
1466
1467         if (interval == VSYNC_ADAPTIVE)
1468                 interval = -1;
1469         gp_Canvas->SetSwapInterval((interval == VSYNC_ON) ? 1 : 0);
1470         Py_RETURN_NONE;
1471 }
1472
1473 static PyObject *gPyGetVsync(PyObject *)
1474 {
1475         int interval = 0;
1476         gp_Canvas->GetSwapInterval(interval);
1477         return PyLong_FromLong(interval);
1478 }
1479
1480 static PyObject *gPyShowFramerate(PyObject *, PyObject *args)
1481 {
1482         int visible;
1483         if (!PyArg_ParseTuple(args,"i:showFramerate",&visible))
1484                 return NULL;
1485
1486         if (visible && gp_KetsjiEngine)
1487                 gp_KetsjiEngine->SetShowFramerate(true);
1488         else
1489                 gp_KetsjiEngine->SetShowFramerate(false);
1490
1491         Py_RETURN_NONE;
1492 }
1493
1494 static PyObject *gPyShowProfile(PyObject *, PyObject *args)
1495 {
1496         int visible;
1497         if (!PyArg_ParseTuple(args,"i:showProfile",&visible))
1498                 return NULL;
1499
1500         if (visible && gp_KetsjiEngine)
1501                 gp_KetsjiEngine->SetShowProfile(true);
1502         else
1503                 gp_KetsjiEngine->SetShowProfile(false);
1504
1505         Py_RETURN_NONE;
1506 }
1507
1508 static PyObject *gPyShowProperties(PyObject *, PyObject *args)
1509 {
1510         int visible;
1511         if (!PyArg_ParseTuple(args,"i:showProperties",&visible))
1512                 return NULL;
1513
1514         if (visible && gp_KetsjiEngine)
1515                 gp_KetsjiEngine->SetShowProperties(true);
1516         else
1517                 gp_KetsjiEngine->SetShowProperties(false);
1518
1519         Py_RETURN_NONE;
1520 }
1521
1522 static PyObject *gPyAutoDebugList(PyObject *, PyObject *args)
1523 {
1524         int add;
1525         if (!PyArg_ParseTuple(args,"i:autoAddProperties",&add))
1526                 return NULL;
1527
1528         if (add && gp_KetsjiEngine)
1529                 gp_KetsjiEngine->SetAutoAddDebugProperties(true);
1530         else
1531                 gp_KetsjiEngine->SetAutoAddDebugProperties(false);
1532
1533         Py_RETURN_NONE;
1534 }
1535
1536 static PyObject *gPyClearDebugList(PyObject *)
1537 {
1538         if (gp_KetsjiScene)
1539                 gp_KetsjiScene->RemoveAllDebugProperties();
1540
1541         Py_RETURN_NONE;
1542 }
1543
1544 PyDoc_STRVAR(Rasterizer_module_documentation,
1545 "This is the Python API for the game engine of Rasterizer"
1546 );
1547
1548 static struct PyMethodDef rasterizer_methods[] = {
1549         {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
1550          METH_VARARGS, "getWindowWidth doc"},
1551         {"getWindowHeight",(PyCFunction) gPyGetWindowHeight,
1552          METH_VARARGS, "getWindowHeight doc"},
1553         {"makeScreenshot",(PyCFunction)gPyMakeScreenshot,
1554          METH_VARARGS, "make Screenshot doc"},
1555         {"enableVisibility",(PyCFunction) gPyEnableVisibility,
1556          METH_VARARGS, "enableVisibility doc"},
1557         {"showMouse",(PyCFunction) gPyShowMouse,
1558          METH_VARARGS, "showMouse(bool visible)"},
1559         {"setMousePosition",(PyCFunction) gPySetMousePosition,
1560          METH_VARARGS, "setMousePosition(int x,int y)"},
1561         {"setBackgroundColor",(PyCFunction)gPySetBackgroundColor,METH_O,"set Background Color (rgb)"},
1562         {"setAmbientColor",(PyCFunction)gPySetAmbientColor,METH_O,"set Ambient Color (rgb)"},
1563         {"disableMist",(PyCFunction)gPyDisableMist,METH_NOARGS,"turn off mist"},
1564         {"setUseMist",(PyCFunction)gPySetUseMist,METH_VARARGS,"enable or disable mist"},
1565         {"setMistColor",(PyCFunction)gPySetMistColor,METH_O,"set Mist Color (rgb)"},
1566         {"setMistType",(PyCFunction)gPySetMistType,METH_VARARGS,"set mist type (short type)"},
1567         {"setMistStart",(PyCFunction)gPySetMistStart,METH_VARARGS,"set Mist Start"},
1568         {"setMistEnd",(PyCFunction)gPySetMistEnd,METH_VARARGS,"set Mist End"},
1569         {"setMistIntensity",(PyCFunction)gPySetMistIntensity,METH_VARARGS,"set mist intensity (float intensity)"},
1570         {"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"},
1571         {"disableMotionBlur",(PyCFunction)gPyDisableMotionBlur,METH_NOARGS,"disable motion blur"},
1572
1573         {"setEyeSeparation", (PyCFunction) gPySetEyeSeparation, METH_VARARGS, "set the eye separation for stereo mode"},
1574         {"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_NOARGS, "get the eye separation for stereo mode"},
1575         {"setFocalLength", (PyCFunction) gPySetFocalLength, METH_VARARGS, "set the focal length for stereo mode"},
1576         {"getFocalLength", (PyCFunction) gPyGetFocalLength, METH_VARARGS, "get the focal length for stereo mode"},
1577         {"getStereoEye", (PyCFunction) gPyGetStereoEye, METH_VARARGS, "get the current stereoscopy eye being rendered"},
1578         {"setMaterialMode",(PyCFunction) gPySetMaterialType,
1579          METH_VARARGS, "set the material mode to use for OpenGL rendering"},
1580         {"getMaterialMode",(PyCFunction) gPyGetMaterialType,
1581          METH_NOARGS, "get the material mode being used for OpenGL rendering"},
1582         {"setGLSLMaterialSetting",(PyCFunction) gPySetGLSLMaterialSetting,
1583          METH_VARARGS, "set the state of a GLSL material setting"},
1584         {"getGLSLMaterialSetting",(PyCFunction) gPyGetGLSLMaterialSetting,
1585          METH_VARARGS, "get the state of a GLSL material setting"},
1586         {"setAnisotropicFiltering", (PyCFunction) gPySetAnisotropicFiltering,
1587          METH_VARARGS, "set the anisotropic filtering level (must be one of 1, 2, 4, 8, 16)"},
1588         {"getAnisotropicFiltering", (PyCFunction) gPyGetAnisotropicFiltering,
1589          METH_VARARGS, "get the anisotropic filtering level"},
1590         {"drawLine", (PyCFunction) gPyDrawLine,
1591          METH_VARARGS, "draw a line on the screen"},
1592         {"setWindowSize", (PyCFunction) gPySetWindowSize, METH_VARARGS, ""},
1593         {"setFullScreen", (PyCFunction) gPySetFullScreen, METH_O, ""},
1594         {"getFullScreen", (PyCFunction) gPyGetFullScreen, METH_NOARGS, ""},
1595         {"setMipmapping", (PyCFunction) gPySetMipmapping, METH_VARARGS, ""},
1596         {"getMipmapping", (PyCFunction) gPyGetMipmapping, METH_NOARGS, ""},
1597         {"setVsync", (PyCFunction) gPySetVsync, METH_VARARGS, ""},
1598         {"getVsync", (PyCFunction) gPyGetVsync, METH_NOARGS, ""},
1599         {"showFramerate",(PyCFunction) gPyShowFramerate, METH_VARARGS, "show or hide the framerate"},
1600         {"showProfile",(PyCFunction) gPyShowProfile, METH_VARARGS, "show or hide the profile"},
1601         {"showProperties",(PyCFunction) gPyShowProperties, METH_VARARGS, "show or hide the debug properties"},
1602         {"autoDebugList",(PyCFunction) gPyAutoDebugList, METH_VARARGS, "enable or disable auto adding debug properties to the debug  list"},
1603         {"clearDebugList",(PyCFunction) gPyClearDebugList, METH_NOARGS, "clears the debug property list"},
1604         { NULL, (PyCFunction) NULL, 0, NULL }
1605 };
1606
1607
1608
1609 PyDoc_STRVAR(GameLogic_module_documentation,
1610 "This is the Python API for the game engine of bge.logic"
1611 );
1612
1613 static struct PyModuleDef GameLogic_module_def = {
1614         {}, /* m_base */
1615         "GameLogic",  /* m_name */
1616         GameLogic_module_documentation,  /* m_doc */
1617         0,  /* m_size */
1618         game_methods,  /* m_methods */
1619         0,  /* m_reload */
1620         0,  /* m_traverse */
1621         0,  /* m_clear */
1622         0,  /* m_free */
1623 };
1624
1625 PyMODINIT_FUNC initGameLogicPythonBinding()
1626 {
1627         PyObject *m;
1628         PyObject *d;
1629         PyObject *item; /* temp PyObject *storage */
1630
1631         gUseVisibilityTemp=false;
1632
1633         PyObjectPlus::ClearDeprecationWarning(); /* Not that nice to call here but makes sure warnings are reset between loading scenes */
1634
1635         m = PyModule_Create(&GameLogic_module_def);
1636         PyDict_SetItemString(PySys_GetObject("modules"), GameLogic_module_def.m_name, m);
1637
1638
1639         // Add some symbolic constants to the module
1640         d = PyModule_GetDict(m);
1641         
1642         // can be overwritten later for gameEngine instances that can load new blend files and re-initialize this module
1643         // for now its safe to make sure it exists for other areas such as the web plugin
1644         
1645         PyDict_SetItemString(d, "globalDict", item=PyDict_New()); Py_DECREF(item);
1646
1647         // Add keyboard and mouse attributes to this module
1648         MT_assert(!gp_PythonKeyboard);
1649         gp_PythonKeyboard = new SCA_PythonKeyboard(gp_KetsjiEngine->GetKeyboardDevice());
1650         PyDict_SetItemString(d, "keyboard", gp_PythonKeyboard->NewProxy(true));
1651
1652         MT_assert(!gp_PythonMouse);
1653         gp_PythonMouse = new SCA_PythonMouse(gp_KetsjiEngine->GetMouseDevice(), gp_Canvas);
1654         PyDict_SetItemString(d, "mouse", gp_PythonMouse->NewProxy(true));
1655
1656         PyObject* joylist = PyList_New(JOYINDEX_MAX);
1657         for (int i=0; i<JOYINDEX_MAX; ++i) {
1658                 SCA_Joystick *joy = SCA_Joystick::GetInstance(i);
1659                 PyObject *item;
1660
1661                 if (joy && joy->Connected()) {
1662                         gp_PythonJoysticks[i] = new SCA_PythonJoystick(joy);
1663                         item = gp_PythonJoysticks[i]->NewProxy(true);
1664                 }
1665                 else {
1666                         if (joy) {
1667                                 joy->ReleaseInstance();
1668                         }
1669                         item = Py_None;
1670                 }
1671
1672                 Py_INCREF(item);
1673                 PyList_SET_ITEM(joylist, i, item);
1674         }
1675         PyDict_SetItemString(d, "joysticks", joylist);
1676
1677         ErrorObject = PyUnicode_FromString("GameLogic.error");
1678         PyDict_SetItemString(d, "error", ErrorObject);
1679         Py_DECREF(ErrorObject);
1680         
1681         // XXXX Add constants here
1682         /* To use logic bricks, we need some sort of constants. Here, we associate */
1683         /* constants and sumbolic names. Add them to dictionary d.                 */
1684
1685         /* 1. true and false: needed for everyone                                  */
1686         KX_MACRO_addTypesToDict(d, KX_TRUE,  SCA_ILogicBrick::KX_TRUE);
1687         KX_MACRO_addTypesToDict(d, KX_FALSE, SCA_ILogicBrick::KX_FALSE);
1688
1689         /* 2. Property sensor                                                      */
1690         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EQUAL,      SCA_PropertySensor::KX_PROPSENSOR_EQUAL);
1691         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_NOTEQUAL,   SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL);
1692         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_INTERVAL,   SCA_PropertySensor::KX_PROPSENSOR_INTERVAL);
1693         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_CHANGED,    SCA_PropertySensor::KX_PROPSENSOR_CHANGED);
1694         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EXPRESSION, SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION);
1695         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_LESSTHAN,   SCA_PropertySensor::KX_PROPSENSOR_LESSTHAN);
1696         KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_GREATERTHAN, SCA_PropertySensor::KX_PROPSENSOR_GREATERTHAN);
1697
1698         /* 3. Constraint actuator                                                  */
1699         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX);
1700         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY);
1701         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ);
1702         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX);
1703         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY);
1704         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ);
1705         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX);
1706         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY);
1707         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ);
1708         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX);
1709         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY);
1710         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ);
1711         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX);
1712         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY);
1713         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ);
1714         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX);
1715         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY);
1716         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ);
1717         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX);
1718         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY);
1719         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ);
1720         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_NORMAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_NORMAL);
1721         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_MATERIAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_MATERIAL);
1722         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_PERMANENT, KX_ConstraintActuator::KX_ACT_CONSTRAINT_PERMANENT);
1723         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DISTANCE, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DISTANCE);
1724         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCAL);
1725         KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DOROTFH, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DOROTFH);
1726
1727         /* 4. Random distribution types                                            */
1728         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_CONST,      SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST);
1729         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_UNIFORM,    SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM);
1730         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_BERNOUILLI, SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI);
1731         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_CONST,       SCA_RandomActuator::KX_RANDOMACT_INT_CONST);
1732         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_UNIFORM,     SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM);
1733         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_POISSON,     SCA_RandomActuator::KX_RANDOMACT_INT_POISSON);
1734         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_CONST,     SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST);
1735         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_UNIFORM,   SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM);
1736         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NORMAL,    SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL);
1737         KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL, SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL);
1738
1739         /* 5. Sound actuator                                                      */
1740         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP,              KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
1741         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND,               KX_SoundActuator::KX_SOUNDACT_PLAYEND);
1742         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP,              KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
1743         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND,               KX_SoundActuator::KX_SOUNDACT_LOOPEND);
1744         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL,     KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
1745         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP,     KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
1746
1747         /* 6. Action actuator                                                                                                      */
1748         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PLAY,        ACT_ACTION_PLAY);
1749         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PINGPONG,    ACT_ACTION_PINGPONG);
1750         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_FLIPPER,     ACT_ACTION_FLIPPER);
1751         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPSTOP,    ACT_ACTION_LOOP_STOP);
1752         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPEND,     ACT_ACTION_LOOP_END);
1753         KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PROPERTY,    ACT_ACTION_FROM_PROP);
1754         
1755         /* 7. GL_BlendFunc */
1756         KX_MACRO_addTypesToDict(d, BL_ZERO, GL_ZERO);
1757         KX_MACRO_addTypesToDict(d, BL_ONE, GL_ONE);
1758         KX_MACRO_addTypesToDict(d, BL_SRC_COLOR, GL_SRC_COLOR);
1759         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
1760         KX_MACRO_addTypesToDict(d, BL_DST_COLOR, GL_DST_COLOR);
1761         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_DST_COLOR);
1762         KX_MACRO_addTypesToDict(d, BL_SRC_ALPHA, GL_SRC_ALPHA);
1763         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1764         KX_MACRO_addTypesToDict(d, BL_DST_ALPHA, GL_DST_ALPHA);
1765         KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
1766         KX_MACRO_addTypesToDict(d, BL_SRC_ALPHA_SATURATE, GL_SRC_ALPHA_SATURATE);
1767
1768
1769         /* 8. UniformTypes */
1770         KX_MACRO_addTypesToDict(d, SHD_TANGENT, BL_Shader::SHD_TANGENT);
1771         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX, BL_Shader::MODELVIEWMATRIX);
1772         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_TRANSPOSE, BL_Shader::MODELVIEWMATRIX_TRANSPOSE);
1773         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_INVERSE, BL_Shader::MODELVIEWMATRIX_INVERSE);
1774         KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_INVERSETRANSPOSE, BL_Shader::MODELVIEWMATRIX_INVERSETRANSPOSE);
1775         KX_MACRO_addTypesToDict(d, MODELMATRIX, BL_Shader::MODELMATRIX);
1776         KX_MACRO_addTypesToDict(d, MODELMATRIX_TRANSPOSE, BL_Shader::MODELMATRIX_TRANSPOSE);
1777         KX_MACRO_addTypesToDict(d, MODELMATRIX_INVERSE, BL_Shader::MODELMATRIX_INVERSE);
1778         KX_MACRO_addTypesToDict(d, MODELMATRIX_INVERSETRANSPOSE, BL_Shader::MODELMATRIX_INVERSETRANSPOSE);
1779         KX_MACRO_addTypesToDict(d, VIEWMATRIX, BL_Shader::VIEWMATRIX);
1780         KX_MACRO_addTypesToDict(d, VIEWMATRIX_TRANSPOSE, BL_Shader::VIEWMATRIX_TRANSPOSE);
1781         KX_MACRO_addTypesToDict(d, VIEWMATRIX_INVERSE, BL_Shader::VIEWMATRIX_INVERSE);
1782         KX_MACRO_addTypesToDict(d, VIEWMATRIX_INVERSETRANSPOSE, BL_Shader::VIEWMATRIX_INVERSETRANSPOSE);
1783         KX_MACRO_addTypesToDict(d, CAM_POS, BL_Shader::CAM_POS);
1784         KX_MACRO_addTypesToDict(d, CONSTANT_TIMER, BL_Shader::CONSTANT_TIMER);
1785
1786         /* 9. state actuator */
1787         KX_MACRO_addTypesToDict(d, KX_STATE1, (1<<0));
1788         KX_MACRO_addTypesToDict(d, KX_STATE2, (1<<1));
1789         KX_MACRO_addTypesToDict(d, KX_STATE3, (1<<2));
1790         KX_MACRO_addTypesToDict(d, KX_STATE4, (1<<3));
1791         KX_MACRO_addTypesToDict(d, KX_STATE5, (1<<4));
1792         KX_MACRO_addTypesToDict(d, KX_STATE6, (1<<5));
1793         KX_MACRO_addTypesToDict(d, KX_STATE7, (1<<6));
1794         KX_MACRO_addTypesToDict(d, KX_STATE8, (1<<7));
1795         KX_MACRO_addTypesToDict(d, KX_STATE9, (1<<8));
1796         KX_MACRO_addTypesToDict(d, KX_STATE10, (1<<9));
1797         KX_MACRO_addTypesToDict(d, KX_STATE11, (1<<10));
1798         KX_MACRO_addTypesToDict(d, KX_STATE12, (1<<11));
1799         KX_MACRO_addTypesToDict(d, KX_STATE13, (1<<12));
1800         KX_MACRO_addTypesToDict(d, KX_STATE14, (1<<13));
1801         KX_MACRO_addTypesToDict(d, KX_STATE15, (1<<14));
1802         KX_MACRO_addTypesToDict(d, KX_STATE16, (1<<15));
1803         KX_MACRO_addTypesToDict(d, KX_STATE17, (1<<16));
1804         KX_MACRO_addTypesToDict(d, KX_STATE18, (1<<17));
1805         KX_MACRO_addTypesToDict(d, KX_STATE19, (1<<18));
1806         KX_MACRO_addTypesToDict(d, KX_STATE20, (1<<19));
1807         KX_MACRO_addTypesToDict(d, KX_STATE21, (1<<20));
1808         KX_MACRO_addTypesToDict(d, KX_STATE22, (1<<21));
1809         KX_MACRO_addTypesToDict(d, KX_STATE23, (1<<22));
1810         KX_MACRO_addTypesToDict(d, KX_STATE24, (1<<23));
1811         KX_MACRO_addTypesToDict(d, KX_STATE25, (1<<24));
1812         KX_MACRO_addTypesToDict(d, KX_STATE26, (1<<25));
1813         KX_MACRO_addTypesToDict(d, KX_STATE27, (1<<26));
1814         KX_MACRO_addTypesToDict(d, KX_STATE28, (1<<27));
1815         KX_MACRO_addTypesToDict(d, KX_STATE29, (1<<28));
1816         KX_MACRO_addTypesToDict(d, KX_STATE30, (1<<29));
1817         
1818         /* All Sensors */
1819         KX_MACRO_addTypesToDict(d, KX_SENSOR_JUST_ACTIVATED, SCA_ISensor::KX_SENSOR_JUST_ACTIVATED);
1820         KX_MACRO_addTypesToDict(d, KX_SENSOR_ACTIVE, SCA_ISensor::KX_SENSOR_ACTIVE);
1821         KX_MACRO_addTypesToDict(d, KX_SENSOR_JUST_DEACTIVATED, SCA_ISensor::KX_SENSOR_JUST_DEACTIVATED);
1822         KX_MACRO_addTypesToDict(d, KX_SENSOR_INACTIVE, SCA_ISensor::KX_SENSOR_INACTIVE);
1823         
1824         /* Radar Sensor */
1825         KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_X, KX_RadarSensor::KX_RADAR_AXIS_POS_X);
1826         KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Y, KX_RadarSensor::KX_RADAR_AXIS_POS_Y);
1827         KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Z, KX_RadarSensor::KX_RADAR_AXIS_POS_Z);
1828         KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_X, KX_RadarSensor::KX_RADAR_AXIS_NEG_X);
1829         KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Y, KX_RadarSensor::KX_RADAR_AXIS_NEG_Y);
1830         KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Z, KX_RadarSensor::KX_RADAR_AXIS_NEG_Z);
1831
1832         /* Ray Sensor */
1833         KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_X, KX_RaySensor::KX_RAY_AXIS_POS_X);
1834         KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_Y, KX_RaySensor::KX_RAY_AXIS_POS_Y);
1835         KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_Z, KX_RaySensor::KX_RAY_AXIS_POS_Z);
1836         KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_X, KX_RaySensor::KX_RAY_AXIS_NEG_X);
1837         KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Y, KX_RaySensor::KX_RAY_AXIS_NEG_Y);
1838         KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Z, KX_RaySensor::KX_RAY_AXIS_NEG_Z);
1839
1840         /* TrackTo Actuator */
1841         KX_MACRO_addTypesToDict(d, KX_TRACK_UPAXIS_POS_X, KX_TrackToActuator::KX_TRACK_UPAXIS_POS_X);
1842         KX_MACRO_addTypesToDict(d, KX_TRACK_UPAXIS_POS_Y, KX_TrackToActuator::KX_TRACK_UPAXIS_POS_Y);
1843         KX_MACRO_addTypesToDict(d, KX_TRACK_UPAXIS_POS_Z, KX_TrackToActuator::KX_TRACK_UPAXIS_POS_Z);
1844         KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_POS_X, KX_TrackToActuator::KX_TRACK_TRAXIS_POS_X);
1845         KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_POS_Y, KX_TrackToActuator::KX_TRACK_TRAXIS_POS_Y);
1846         KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_POS_Z, KX_TrackToActuator::KX_TRACK_TRAXIS_POS_Z);
1847         KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_NEG_X, KX_TrackToActuator::KX_TRACK_TRAXIS_NEG_X);
1848         KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_NEG_Y, KX_TrackToActuator::KX_TRACK_TRAXIS_NEG_Y);
1849         KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_NEG_Z, KX_TrackToActuator::KX_TRACK_TRAXIS_NEG_Z);
1850
1851         /* Dynamic actuator */
1852         KX_MACRO_addTypesToDict(d, KX_DYN_RESTORE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_RESTORE_DYNAMICS);
1853         KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_DISABLE_DYNAMICS);
1854         KX_MACRO_addTypesToDict(d, KX_DYN_ENABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_ENABLE_RIGID_BODY);
1855         KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_DISABLE_RIGID_BODY);
1856         KX_MACRO_addTypesToDict(d, KX_DYN_SET_MASS, KX_SCA_DynamicActuator::KX_DYN_SET_MASS);
1857
1858         /* Input & Mouse Sensor */
1859         KX_MACRO_addTypesToDict(d, KX_INPUT_NONE, SCA_InputEvent::KX_NO_INPUTSTATUS);
1860         KX_MACRO_addTypesToDict(d, KX_INPUT_JUST_ACTIVATED, SCA_InputEvent::KX_JUSTACTIVATED);
1861         KX_MACRO_addTypesToDict(d, KX_INPUT_ACTIVE, SCA_InputEvent::KX_ACTIVE);
1862         KX_MACRO_addTypesToDict(d, KX_INPUT_JUST_RELEASED, SCA_InputEvent::KX_JUSTRELEASED);
1863         
1864         KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_LEFT, SCA_IInputDevice::KX_LEFTMOUSE);
1865         KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_IInputDevice::KX_MIDDLEMOUSE);
1866         KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_IInputDevice::KX_RIGHTMOUSE);
1867
1868         /* 2D Filter Actuator */
1869         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_ENABLED, RAS_2DFilterManager::RAS_2DFILTER_ENABLED);
1870         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_DISABLED, RAS_2DFilterManager::RAS_2DFILTER_DISABLED);
1871         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_NOFILTER, RAS_2DFilterManager::RAS_2DFILTER_NOFILTER);
1872         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_MOTIONBLUR, RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR);
1873         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_BLUR, RAS_2DFilterManager::RAS_2DFILTER_BLUR);
1874         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SHARPEN, RAS_2DFilterManager::RAS_2DFILTER_SHARPEN);
1875         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_DILATION, RAS_2DFilterManager::RAS_2DFILTER_DILATION);
1876         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_EROSION, RAS_2DFilterManager::RAS_2DFILTER_EROSION);
1877         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_LAPLACIAN, RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN);
1878         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SOBEL, RAS_2DFilterManager::RAS_2DFILTER_SOBEL);
1879         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_PREWITT, RAS_2DFilterManager::RAS_2DFILTER_PREWITT);
1880         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_GRAYSCALE, RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE);
1881         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SEPIA, RAS_2DFilterManager::RAS_2DFILTER_SEPIA);
1882         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_INVERT, RAS_2DFilterManager::RAS_2DFILTER_INVERT);
1883         KX_MACRO_addTypesToDict(d, RAS_2DFILTER_CUSTOMFILTER, RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER);
1884
1885         /* Sound Actuator */
1886         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP, KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
1887         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND, KX_SoundActuator::KX_SOUNDACT_PLAYEND);
1888         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP, KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
1889         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND, KX_SoundActuator:: KX_SOUNDACT_LOOPEND);
1890         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
1891         KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
1892
1893         /* State Actuator */
1894         KX_MACRO_addTypesToDict(d, KX_STATE_OP_CPY, KX_StateActuator::OP_CPY);
1895         KX_MACRO_addTypesToDict(d, KX_STATE_OP_SET, KX_StateActuator::OP_SET);
1896         KX_MACRO_addTypesToDict(d, KX_STATE_OP_CLR, KX_StateActuator::OP_CLR);
1897         KX_MACRO_addTypesToDict(d, KX_STATE_OP_NEG, KX_StateActuator::OP_NEG);
1898
1899         /* Game Actuator Modes */
1900         KX_MACRO_addTypesToDict(d, KX_GAME_LOAD, KX_GameActuator::KX_GAME_LOAD);
1901         KX_MACRO_addTypesToDict(d, KX_GAME_START, KX_GameActuator::KX_GAME_START);
1902         KX_MACRO_addTypesToDict(d, KX_GAME_RESTART, KX_GameActuator::KX_GAME_RESTART);
1903         KX_MACRO_addTypesToDict(d, KX_GAME_QUIT, KX_GameActuator::KX_GAME_QUIT);
1904         KX_MACRO_addTypesToDict(d, KX_GAME_SAVECFG, KX_GameActuator::KX_GAME_SAVECFG);
1905         KX_MACRO_addTypesToDict(d, KX_GAME_LOADCFG, KX_GameActuator::KX_GAME_LOADCFG);
1906
1907         /* Scene Actuator Modes */
1908         KX_MACRO_addTypesToDict(d, KX_SCENE_RESTART, KX_SceneActuator::KX_SCENE_RESTART);
1909         KX_MACRO_addTypesToDict(d, KX_SCENE_SET_SCENE, KX_SceneActuator::KX_SCENE_SET_SCENE);
1910         KX_MACRO_addTypesToDict(d, KX_SCENE_SET_CAMERA, KX_SceneActuator::KX_SCENE_SET_CAMERA);
1911         KX_MACRO_addTypesToDict(d, KX_SCENE_ADD_FRONT_SCENE, KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE);
1912         KX_MACRO_addTypesToDict(d, KX_SCENE_ADD_BACK_SCENE, KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE);
1913         KX_MACRO_addTypesToDict(d, KX_SCENE_REMOVE_SCENE, KX_SceneActuator::KX_SCENE_REMOVE_SCENE);
1914         KX_MACRO_addTypesToDict(d, KX_SCENE_SUSPEND, KX_SceneActuator::KX_SCENE_SUSPEND);
1915         KX_MACRO_addTypesToDict(d, KX_SCENE_RESUME, KX_SceneActuator::KX_SCENE_RESUME);
1916
1917         /* Parent Actuator Modes */
1918         KX_MACRO_addTypesToDict(d, KX_PARENT_SET, KX_ParentActuator::KX_PARENT_SET);
1919         KX_MACRO_addTypesToDict(d, KX_PARENT_REMOVE, KX_ParentActuator::KX_PARENT_REMOVE);
1920
1921         /* BL_ArmatureConstraint type */
1922         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_TRACKTO, CONSTRAINT_TYPE_TRACKTO);
1923         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_KINEMATIC);
1924         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_ROTLIKE, CONSTRAINT_TYPE_ROTLIKE);
1925         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_LOCLIKE, CONSTRAINT_TYPE_LOCLIKE);
1926         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_MINMAX, CONSTRAINT_TYPE_MINMAX);
1927         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_SIZELIKE, CONSTRAINT_TYPE_SIZELIKE);
1928         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_LOCKTRACK, CONSTRAINT_TYPE_LOCKTRACK);
1929         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_STRETCHTO, CONSTRAINT_TYPE_STRETCHTO);
1930         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_CLAMPTO, CONSTRAINT_TYPE_CLAMPTO);
1931         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_TRANSFORM, CONSTRAINT_TYPE_TRANSFORM);
1932         KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_DISTLIMIT, CONSTRAINT_TYPE_DISTLIMIT);
1933         /* BL_ArmatureConstraint ik_type */
1934         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_COPYPOSE, CONSTRAINT_IK_COPYPOSE);
1935         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_DISTANCE, CONSTRAINT_IK_DISTANCE);
1936         /* BL_ArmatureConstraint ik_mode */
1937         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_INSIDE, LIMITDIST_INSIDE);
1938         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_OUTSIDE, LIMITDIST_OUTSIDE);
1939         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_ONSURFACE, LIMITDIST_ONSURFACE);
1940         /* BL_ArmatureConstraint ik_flag */
1941         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_TIP, CONSTRAINT_IK_TIP);
1942         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_ROT, CONSTRAINT_IK_ROT);
1943         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_STRETCH, CONSTRAINT_IK_STRETCH);
1944         KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_POS, CONSTRAINT_IK_POS);
1945         /* KX_ArmatureSensor type */
1946         KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_STATE_CHANGED, SENS_ARM_STATE_CHANGED);
1947         KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_LIN_ERROR_BELOW, SENS_ARM_LIN_ERROR_BELOW);
1948         KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_LIN_ERROR_ABOVE, SENS_ARM_LIN_ERROR_ABOVE);
1949         KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_ROT_ERROR_BELOW, SENS_ARM_ROT_ERROR_BELOW);
1950         KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_ROT_ERROR_ABOVE, SENS_ARM_ROT_ERROR_ABOVE);
1951
1952         /* BL_ArmatureActuator type */
1953         KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_RUN, ACT_ARM_RUN);
1954         KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_ENABLE, ACT_ARM_ENABLE);
1955         KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_DISABLE, ACT_ARM_DISABLE);
1956         KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_SETTARGET, ACT_ARM_SETTARGET);
1957         KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_SETWEIGHT, ACT_ARM_SETWEIGHT);
1958         KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_SETINFLUENCE, ACT_ARM_SETINFLUENCE);
1959
1960         /* BL_Armature Channel rotation_mode */
1961         KX_MACRO_addTypesToDict(d, ROT_MODE_QUAT, ROT_MODE_QUAT);
1962         KX_MACRO_addTypesToDict(d, ROT_MODE_XYZ, ROT_MODE_XYZ);
1963         KX_MACRO_addTypesToDict(d, ROT_MODE_XZY, ROT_MODE_XZY);
1964         KX_MACRO_addTypesToDict(d, ROT_MODE_YXZ, ROT_MODE_YXZ);
1965         KX_MACRO_addTypesToDict(d, ROT_MODE_YZX, ROT_MODE_YZX);
1966         KX_MACRO_addTypesToDict(d, ROT_MODE_ZXY, ROT_MODE_ZXY);
1967         KX_MACRO_addTypesToDict(d, ROT_MODE_ZYX, ROT_MODE_ZYX);
1968
1969         /* Steering actuator */
1970         KX_MACRO_addTypesToDict(d, KX_STEERING_SEEK, KX_SteeringActuator::KX_STEERING_SEEK);
1971         KX_MACRO_addTypesToDict(d, KX_STEERING_FLEE, KX_SteeringActuator::KX_STEERING_FLEE);
1972         KX_MACRO_addTypesToDict(d, KX_STEERING_PATHFOLLOWING, KX_SteeringActuator::KX_STEERING_PATHFOLLOWING);
1973
1974         /* KX_NavMeshObject render mode */
1975         KX_MACRO_addTypesToDict(d, RM_WALLS, KX_NavMeshObject::RM_WALLS);
1976         KX_MACRO_addTypesToDict(d, RM_POLYS, KX_NavMeshObject::RM_POLYS);
1977         KX_MACRO_addTypesToDict(d, RM_TRIS, KX_NavMeshObject::RM_TRIS);
1978
1979         /* BL_Action play modes */
1980         KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_PLAY, BL_Action::ACT_MODE_PLAY);
1981         KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_LOOP, BL_Action::ACT_MODE_LOOP);
1982         KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_PING_PONG, BL_Action::ACT_MODE_PING_PONG);
1983
1984         /* BL_Action blend modes */
1985         KX_MACRO_addTypesToDict(d, KX_ACTION_BLEND_BLEND, BL_Action::ACT_BLEND_BLEND);
1986         KX_MACRO_addTypesToDict(d, KX_ACTION_BLEND_ADD, BL_Action::ACT_BLEND_ADD);
1987
1988         /* Mouse Actuator object axis*/
1989         KX_MACRO_addTypesToDict(d, KX_ACT_MOUSE_OBJECT_AXIS_X, KX_MouseActuator::KX_ACT_MOUSE_OBJECT_AXIS_X);
1990         KX_MACRO_addTypesToDict(d, KX_ACT_MOUSE_OBJECT_AXIS_Y, KX_MouseActuator::KX_ACT_MOUSE_OBJECT_AXIS_Y);
1991         KX_MACRO_addTypesToDict(d, KX_ACT_MOUSE_OBJECT_AXIS_Z, KX_MouseActuator::KX_ACT_MOUSE_OBJECT_AXIS_Z);
1992
1993
1994         // Check for errors
1995         if (PyErr_Occurred())
1996         {
1997                 Py_FatalError("can't initialize module bge.logic");
1998         }
1999
2000         return m;
2001 }
2002
2003 /* Explanation of 
2004  * 
2005  * - backupPySysObjects()               : stores sys.path in gp_OrigPythonSysPath
2006  * - initPySysObjects(main)     : initializes the blendfile and library paths
2007  * - restorePySysObjects()              : restores sys.path from gp_OrigPythonSysPath
2008  * 
2009  * These exist so the current blend dir "//" can always be used to import modules from.
2010  * the reason we need a few functions for this is that python is not only used by the game engine
2011  * so we cant just add to sys.path all the time, it would leave pythons state in a mess.
2012  * It would also be incorrect since loading blend files for new levels etc would always add to sys.path
2013  * 
2014  * To play nice with blenders python, the sys.path is backed up and the current blendfile along
2015  * with all its lib paths are added to the sys path.
2016  * When loading a new blendfile, the original sys.path is restored and the new paths are added over the top.
2017  */
2018
2019 /**
2020  * So we can have external modules mixed with our blend files.
2021  */
2022 static void backupPySysObjects(void)
2023 {
2024         PyObject *sys_path= PySys_GetObject("path"); /* should never fail */
2025         PyObject *sys_mods= PySys_GetObject("modules"); /* should never fail */
2026         
2027         /* paths */
2028         Py_XDECREF(gp_OrigPythonSysPath); /* just in case its set */
2029         gp_OrigPythonSysPath = PyList_GetSlice(sys_path, 0, INT_MAX); /* copy the list */
2030         
2031         /* modules */
2032         Py_XDECREF(gp_OrigPythonSysModules); /* just in case its set */
2033         gp_OrigPythonSysModules = PyDict_Copy(sys_mods); /* copy the list */
2034         
2035 }
2036
2037 /* for initPySysObjects only,
2038  * takes a blend path and adds a scripts dir from it
2039  *
2040  * "/home/me/foo.blend" -> "/home/me/scripts"
2041  */
2042 static void initPySysObjects__append(PyObject *sys_path, const char *filename)
2043 {
2044         PyObject *item;
2045         char expanded[FILE_MAX];
2046         
2047         BLI_split_dir_part(filename, expanded, sizeof(expanded)); /* get the dir part of filename only */
2048         BLI_path_abs(expanded, gp_GamePythonPath); /* filename from lib->filename is (always?) absolute, so this may not be needed but it wont hurt */
2049         BLI_cleanup_file(gp_GamePythonPath, expanded); /* Don't use BLI_cleanup_dir because it adds a slash - BREAKS WIN32 ONLY */
2050         item = PyC_UnicodeFromByte(expanded);
2051         
2052 //      printf("SysPath - '%s', '%s', '%s'\n", expanded, filename, gp_GamePythonPath);
2053         
2054         if (PySequence_Index(sys_path, item) == -1) {
2055                 PyErr_Clear(); /* PySequence_Index sets a ValueError */
2056                 PyList_Insert(sys_path, 0, item);
2057         }
2058         
2059         Py_DECREF(item);
2060 }
2061 static void initPySysObjects(Main *maggie)
2062 {
2063         PyObject *sys_path= PySys_GetObject("path"); /* should never fail */
2064         
2065         if (gp_OrigPythonSysPath==NULL) {
2066                 /* backup */
2067                 backupPySysObjects();
2068         }
2069         else {
2070                 /* get the original sys path when the BGE started */
2071                 PyList_SetSlice(sys_path, 0, INT_MAX, gp_OrigPythonSysPath);
2072         }
2073         
2074         Library *lib= (Library *)maggie->library.first;
2075         
2076         while (lib) {
2077                 /* lib->name wont work in some cases (on win32),
2078                  * even when expanding with gp_GamePythonPath, using lib->filename is less trouble */
2079                 initPySysObjects__append(sys_path, lib->filepath);
2080                 lib= (Library *)lib->id.next;
2081         }
2082         
2083         initPySysObjects__append(sys_path, gp_GamePythonPath);
2084         
2085 //      fprintf(stderr, "\nNew Path: %d ", PyList_GET_SIZE(sys_path));
2086 //      PyObject_Print(sys_path, stderr, 0);
2087 }
2088
2089 static void restorePySysObjects(void)
2090 {
2091         if (gp_OrigPythonSysPath==NULL)
2092                 return;
2093         
2094         PyObject *sys_path= PySys_GetObject("path"); /* should never fail */
2095         PyObject *sys_mods= PySys_GetObject("modules"); /* should never fail */
2096
2097         /* paths */
2098         PyList_SetSlice(sys_path, 0, INT_MAX, gp_OrigPythonSysPath);
2099         Py_DECREF(gp_OrigPythonSysPath);
2100         gp_OrigPythonSysPath= NULL;
2101         
2102         /* modules */
2103         PyDict_Clear(sys_mods);
2104         PyDict_Update(sys_mods, gp_OrigPythonSysModules);
2105         Py_DECREF(gp_OrigPythonSysModules);
2106         gp_OrigPythonSysModules= NULL;
2107         
2108         
2109 //      fprintf(stderr, "\nRestore Path: %d ", PyList_GET_SIZE(sys_path));
2110 //      PyObject_Print(sys_path, stderr, 0);
2111 }
2112
2113 void addImportMain(struct Main *maggie)
2114 {
2115         bpy_import_main_extra_add(maggie);
2116 }
2117
2118 void removeImportMain(struct Main *maggie)
2119 {
2120         bpy_import_main_extra_remove(maggie);
2121 }
2122
2123
2124 PyDoc_STRVAR(BGE_module_documentation,
2125         "This module contains submodules for the Blender Game Engine.\n"
2126 );
2127
2128 static struct PyModuleDef BGE_module_def = {
2129         PyModuleDef_HEAD_INIT,
2130         "bge",  /* m_name */
2131         BGE_module_documentation,  /* m_doc */
2132         0,  /* m_size */
2133         NULL,  /* m_methods */
2134         NULL,  /* m_reload */
2135         NULL,  /* m_traverse */
2136         NULL,  /* m_clear */
2137         NULL,  /* m_free */
2138 };
2139
2140 PyMODINIT_FUNC initBGE(void)
2141 {
2142         PyObject *mod;
2143         PyObject *submodule;
2144         PyObject *sys_modules = PyThreadState_GET()->interp->modules;
2145
2146         mod = PyModule_Create(&BGE_module_def);
2147
2148         PyModule_AddObject(mod, "constraints", (submodule = initConstraintPythonBinding()));
2149         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
2150         Py_INCREF(submodule);
2151
2152         PyModule_AddObject(mod, "events", (submodule = initGameKeysPythonBinding()));
2153         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
2154         Py_INCREF(submodule);
2155
2156         PyModule_AddObject(mod, "logic", (submodule = initGameLogicPythonBinding()));
2157         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
2158         Py_INCREF(submodule);
2159
2160         PyModule_AddObject(mod, "render", (submodule = initRasterizerPythonBinding()));
2161         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
2162         Py_INCREF(submodule);
2163
2164         PyModule_AddObject(mod, "texture", (submodule = initVideoTexturePythonBinding()));
2165         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
2166         Py_INCREF(submodule);
2167
2168         PyModule_AddObject(mod, "types", (submodule = initGameTypesPythonBinding()));
2169         PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule);
2170         Py_INCREF(submodule);
2171
2172         return mod;
2173 }
2174
2175
2176 /* minimal required blender modules to run blenderplayer */
2177 static struct _inittab bge_internal_modules[] = {
2178         {"mathutils", PyInit_mathutils},
2179         {"bgl", BPyInit_bgl},
2180         {"blf", BPyInit_blf},
2181         {"aud", AUD_initPython},
2182         {NULL, NULL}
2183 };
2184
2185 /**
2186  * Python is not initialized.
2187  * see bpy_interface.c's BPY_python_start() which shares the same functionality in blender.
2188  */
2189 PyObject *initGamePlayerPythonScripting(Main *maggie, int argc, char** argv)
2190 {
2191         /* Yet another gotcha in the py api
2192          * Cant run PySys_SetArgv more than once because this adds the
2193          * binary dir to the sys.path each time.
2194          * Id have thought python being totally restarted would make this ok but
2195          * somehow it remembers the sys.path - Campbell
2196          */
2197         static bool first_time = true;
2198         const char * const py_path_bundle = BKE_appdir_folder_id(BLENDER_SYSTEM_PYTHON, NULL);
2199
2200         /* not essential but nice to set our name */
2201         static wchar_t program_path_wchar[FILE_MAX]; /* python holds a reference */
2202         BLI_strncpy_wchar_from_utf8(program_path_wchar, BKE_appdir_program_path(), ARRAY_SIZE(program_path_wchar));
2203         Py_SetProgramName(program_path_wchar);
2204
2205         /* Update, Py3.3 resolves attempting to parse non-existing header */
2206         #if 0
2207         /* Python 3.2 now looks for '2.xx/python/include/python3.2d/pyconfig.h' to
2208          * parse from the 'sysconfig' module which is used by 'site',
2209          * so for now disable site. alternatively we could copy the file. */
2210         if (py_path_bundle != NULL) {
2211                 Py_NoSiteFlag = 1; /* inhibits the automatic importing of 'site' */
2212         }
2213         #endif
2214
2215         Py_FrozenFlag = 1;
2216
2217         /* must run before python initializes */
2218         PyImport_ExtendInittab(bge_internal_modules);
2219
2220         /* find local python installation */
2221         PyC_SetHomePath(py_path_bundle);
2222
2223         Py_Initialize();
2224         
2225         if (argv && first_time) { /* browser plugins don't currently set this */
2226                 // Until python support ascii again, we use our own.
2227                 // PySys_SetArgv(argc, argv);
2228                 int i;
2229                 PyObject *py_argv= PyList_New(argc);
2230
2231                 for (i=0; i<argc; i++)
2232                         PyList_SET_ITEM(py_argv, i, PyC_UnicodeFromByte(argv[i]));
2233
2234                 PySys_SetObject("argv", py_argv);
2235                 Py_DECREF(py_argv);
2236         }
2237
2238         /* Initialize thread support (also acquires lock) */
2239         PyEval_InitThreads();
2240
2241         bpy_import_init(PyEval_GetBuiltins());
2242
2243         bpy_import_main_set(maggie);
2244
2245         initPySysObjects(maggie);
2246
2247         /* mathutils types are used by the BGE even if we don't import them */
2248         {
2249                 PyObject *mod = PyImport_ImportModuleLevel("mathutils", NULL, NULL, NULL, 0);
2250                 Py_DECREF(mod);
2251         }
2252
2253 #ifdef WITH_AUDASPACE
2254         /* accessing a SoundActuator's sound results in a crash if aud is not initialized... */
2255         {
2256                 PyObject *mod = PyImport_ImportModuleLevel("aud", NULL, NULL, NULL, 0);
2257                 Py_DECREF(mod);
2258         }
2259 #endif
2260
2261         PyDict_SetItemString(PyImport_GetModuleDict(), "bge", initBGE());
2262
2263         first_time = false;
2264         
2265         PyObjectPlus::ClearDeprecationWarning();
2266
2267         return PyC_DefaultNameSpace(NULL);
2268 }
2269
2270 void exitGamePlayerPythonScripting()
2271 {
2272         /* Clean up the Python mouse and keyboard */
2273         delete gp_PythonKeyboard;
2274         gp_PythonKeyboard = NULL;
2275
2276         delete gp_PythonMouse;
2277         gp_PythonMouse = NULL;
2278
2279         for (int i=0; i<JOYINDEX_MAX; ++i) {
2280                 if (gp_PythonJoysticks[i]) {
2281                         delete gp_PythonJoysticks[i];
2282                         gp_PythonJoysticks[i] = NULL;
2283                 }
2284         }
2285
2286         /* since python restarts we cant let the python backup of the sys.path hang around in a global pointer */
2287         restorePySysObjects(); /* get back the original sys.path and clear the backup */
2288         
2289         Py_Finalize();
2290         bpy_import_main_set(NULL);
2291         PyObjectPlus::ClearDeprecationWarning();
2292 }
2293
2294
2295
2296 /**
2297  * Python is already initialized.
2298  */
2299 PyObject *initGamePythonScripting(Main *maggie)
2300 {
2301         /* no need to Py_SetProgramName, it was already taken care of in BPY_python_start */
2302
2303         bpy_import_main_set(maggie);
2304
2305         initPySysObjects(maggie);
2306
2307 #ifdef WITH_AUDASPACE
2308         /* accessing a SoundActuator's sound results in a crash if aud is not initialized... */
2309         {
2310                 PyObject *mod= PyImport_ImportModuleLevel("aud", NULL, NULL, NULL, 0);
2311                 Py_DECREF(mod);
2312         }
2313 #endif
2314
2315         PyDict_SetItemString(PyImport_GetModuleDict(), "bge", initBGE());
2316
2317         PyObjectPlus::NullDeprecationWarning();
2318
2319         return PyC_DefaultNameSpace(NULL);
2320 }
2321
2322 void exitGamePythonScripting()
2323 {
2324         /* Clean up the Python mouse and keyboard */
2325         delete gp_PythonKeyboard;
2326         gp_PythonKeyboard = NULL;
2327
2328         delete gp_PythonMouse;
2329         gp_PythonMouse = NULL;
2330
2331         for (int i=0; i<JOYINDEX_MAX; ++i) {
2332                 if (gp_PythonJoysticks[i]) {
2333                         delete gp_PythonJoysticks[i];
2334                         gp_PythonJoysticks[i] = NULL;
2335                 }
2336         }
2337
2338         restorePySysObjects(); /* get back the original sys.path and clear the backup */
2339         bpy_import_main_set(NULL);
2340         PyObjectPlus::ClearDeprecationWarning();
2341 }
2342
2343 /* similar to the above functions except it sets up the namespace
2344  * and other more general things */
2345 void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene *startscene, Main *blenderdata,
2346                      PyObject *pyGlobalDict, PyObject **gameLogic, PyObject **gameLogic_keys, int argc, char** argv)
2347 {
2348         PyObject *modules, *dictionaryobject;
2349
2350         gp_Canvas = ketsjiengine->GetCanvas();
2351         gp_Rasterizer = ketsjiengine->GetRasterizer();
2352         gp_KetsjiEngine = ketsjiengine;
2353         gp_KetsjiScene = startscene;
2354
2355         if (argv) /* player only */
2356                 dictionaryobject= initGamePlayerPythonScripting(blenderdata, argc, argv);
2357         else
2358                 dictionaryobject= initGamePythonScripting(blenderdata);
2359
2360         ketsjiengine->SetPyNamespace(dictionaryobject);
2361
2362         modules = PyImport_GetModuleDict();
2363
2364         *gameLogic = PyDict_GetItemString(modules, "GameLogic");
2365         /* is set in initGameLogicPythonBinding so only set here if we want it to persist between scenes */
2366         if (pyGlobalDict)
2367                 PyDict_SetItemString(PyModule_GetDict(*gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
2368
2369         *gameLogic_keys = PyDict_Keys(PyModule_GetDict(*gameLogic));
2370 }
2371
2372 static struct PyModuleDef Rasterizer_module_def = {
2373         PyModuleDef_HEAD_INIT,
2374         "Rasterizer",  /* m_name */
2375         Rasterizer_module_documentation,  /* m_doc */
2376         0,  /* m_size */
2377         rasterizer_methods,  /* m_methods */
2378         0,  /* m_reload */
2379         0,  /* m_traverse */
2380         0,  /* m_clear */
2381         0,  /* m_free */
2382 };
2383
2384 PyMODINIT_FUNC initRasterizerPythonBinding()
2385 {
2386         PyObject *m;
2387         PyObject *d;
2388
2389         m = PyModule_Create(&Rasterizer_module_def);
2390         PyDict_SetItemString(PySys_GetObject("modules"), Rasterizer_module_def.m_name, m);
2391
2392
2393         // Add some symbolic constants to the module
2394         d = PyModule_GetDict(m);
2395         ErrorObject = PyUnicode_FromString("Rasterizer.error");
2396         PyDict_SetItemString(d, "error", ErrorObject);
2397         Py_DECREF(ErrorObject);
2398
2399         /* needed for get/setMaterialType */
2400         KX_MACRO_addTypesToDict(d, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL);
2401         KX_MACRO_addTypesToDict(d, KX_BLENDER_GLSL_MATERIAL, KX_BLENDER_GLSL_MATERIAL);
2402
2403         KX_MACRO_addTypesToDict(d, RAS_MIPMAP_NONE, RAS_IRasterizer::RAS_MIPMAP_NONE);
2404         KX_MACRO_addTypesToDict(d, RAS_MIPMAP_NEAREST, RAS_IRasterizer::RAS_MIPMAP_NEAREST);
2405         KX_MACRO_addTypesToDict(d, RAS_MIPMAP_LINEAR, RAS_IRasterizer::RAS_MIPMAP_LINEAR);
2406
2407         /* for get/setVsync */
2408         KX_MACRO_addTypesToDict(d, VSYNC_OFF, VSYNC_OFF);
2409         KX_MACRO_addTypesToDict(d, VSYNC_ON, VSYNC_ON);
2410         KX_MACRO_addTypesToDict(d, VSYNC_ADAPTIVE, VSYNC_ADAPTIVE);
2411
2412         /* stereoscopy */
2413         KX_MACRO_addTypesToDict(d, LEFT_EYE, RAS_IRasterizer::RAS_STEREO_LEFTEYE);
2414         KX_MACRO_addTypesToDict(d, RIGHT_EYE, RAS_IRasterizer::RAS_STEREO_RIGHTEYE);
2415
2416         /* KX_WorldInfo mist types */
2417         KX_MACRO_addTypesToDict(d, KX_MIST_QUADRATIC, KX_WorldInfo::KX_MIST_QUADRATIC);
2418         KX_MACRO_addTypesToDict(d, KX_MIST_LINEAR, KX_WorldInfo::KX_MIST_LINEAR);
2419         KX_MACRO_addTypesToDict(d, KX_MIST_INV_QUADRATIC, KX_WorldInfo::KX_MIST_INV_QUADRATIC);
2420
2421         // XXXX Add constants here
2422
2423         // Check for errors
2424         if (PyErr_Occurred())
2425         {
2426                 Py_FatalError("can't initialize module Rasterizer");
2427         }
2428
2429         return m;
2430 }
2431
2432
2433
2434 /* ------------------------------------------------------------------------- */
2435 /* GameKeys: symbolic constants for key mapping                              */
2436 /* ------------------------------------------------------------------------- */
2437
2438 PyDoc_STRVAR(GameKeys_module_documentation,
2439 "This modules provides defines for key-codes"
2440 );
2441
2442 PyDoc_STRVAR(gPyEventToString_doc,
2443 "EventToString(event)\n"
2444 "Take a valid event from the GameKeys module or Keyboard Sensor and return a name"
2445 );
2446
2447 static PyObject *gPyEventToString(PyObject *, PyObject *value)
2448 {
2449         PyObject *mod, *dict, *key, *val, *ret = NULL;
2450         Py_ssize_t pos = 0;
2451         
2452         mod = PyImport_ImportModule( "GameKeys" );
2453         if (!mod)
2454                 return NULL;
2455         
2456         dict = PyModule_GetDict(mod);
2457         
2458         while (PyDict_Next(dict, &pos, &key, &val)) {
2459                 if (PyObject_RichCompareBool(value, val, Py_EQ)) {
2460                         ret = key;
2461                         break;
2462                 }
2463         }
2464         
2465         PyErr_Clear(); // in case there was an error clearing
2466         Py_DECREF(mod);
2467         if (!ret)       PyErr_SetString(PyExc_ValueError, "GameKeys.EventToString(int): expected a valid int keyboard event");
2468         else            Py_INCREF(ret);
2469         
2470         return ret;
2471 }
2472
2473
2474 PyDoc_STRVAR(gPyEventToCharacter_doc,
2475 "EventToCharacter(event, is_shift)\n"
2476 "Take a valid event from the GameKeys module or Keyboard Sensor and return a character"
2477 );
2478
2479 static PyObject *gPyEventToCharacter(PyObject *, PyObject *args)
2480 {
2481         int event, shift;
2482         if (!PyArg_ParseTuple(args,"ii:EventToCharacter", &event, &shift))
2483                 return NULL;
2484         
2485         if (IsPrintable(event)) {
2486                 char ch[2] = {'\0', '\0'};
2487                 ch[0] = ToCharacter(event, (bool)shift);
2488                 return PyUnicode_FromString(ch);
2489         }
2490         else {
2491                 return PyUnicode_FromString("");
2492         }
2493 }
2494
2495
2496 static struct PyMethodDef gamekeys_methods[] = {
2497         {"EventToCharacter", (PyCFunction)gPyEventToCharacter, METH_VARARGS, (const char *)gPyEventToCharacter_doc},
2498         {"EventToString", (PyCFunction)gPyEventToString, METH_O, (const char *)gPyEventToString_doc},
2499         { NULL, (PyCFunction) NULL, 0, NULL }
2500 };
2501
2502 static struct PyModuleDef GameKeys_module_def = {
2503         PyModuleDef_HEAD_INIT,
2504         "GameKeys",  /* m_name */
2505         GameKeys_module_documentation,  /* m_doc */
2506         0,  /* m_size */
2507         gamekeys_methods,  /* m_methods */
2508         0,  /* m_reload */
2509         0,  /* m_traverse */
2510         0,  /* m_clear */
2511         0,  /* m_free */
2512 };
2513
2514 PyMODINIT_FUNC initGameKeysPythonBinding()
2515 {
2516         PyObject *m;
2517         PyObject *d;
2518
2519         m = PyModule_Create(&GameKeys_module_def);
2520         PyDict_SetItemString(PySys_GetObject("modules"), GameKeys_module_def.m_name, m);
2521
2522         // Add some symbolic constants to the module
2523         d = PyModule_GetDict(m);
2524
2525         // XXXX Add constants here
2526
2527         KX_MACRO_addTypesToDict(d, AKEY, SCA_IInputDevice::KX_AKEY);
2528         KX_MACRO_addTypesToDict(d, BKEY, SCA_IInputDevice::KX_BKEY);
2529         KX_MACRO_addTypesToDict(d, CKEY, SCA_IInputDevice::KX_CKEY);
2530         KX_MACRO_addTypesToDict(d, DKEY, SCA_IInputDevice::KX_DKEY);
2531         KX_MACRO_addTypesToDict(d, EKEY, SCA_IInputDevice::KX_EKEY);
2532         KX_MACRO_addTypesToDict(d, FKEY, SCA_IInputDevice::KX_FKEY);
2533         KX_MACRO_addTypesToDict(d, GKEY, SCA_IInputDevice::KX_GKEY);
2534         KX_MACRO_addTypesToDict(d, HKEY, SCA_IInputDevice::KX_HKEY);
2535         KX_MACRO_addTypesToDict(d, IKEY, SCA_IInputDevice::KX_IKEY);
2536         KX_MACRO_addTypesToDict(d, JKEY, SCA_IInputDevice::KX_JKEY);
2537         KX_MACRO_addTypesToDict(d, KKEY, SCA_IInputDevice::KX_KKEY);
2538         KX_MACRO_addTypesToDict(d, LKEY, SCA_IInputDevice::KX_LKEY);
2539         KX_MACRO_addTypesToDict(d, MKEY, SCA_IInputDevice::KX_MKEY);
2540         KX_MACRO_addTypesToDict(d, NKEY, SCA_IInputDevice::KX_NKEY);
2541         KX_MACRO_addTypesToDict(d, OKEY, SCA_IInputDevice::KX_OKEY);
2542         KX_MACRO_addTypesToDict(d, PKEY, SCA_IInputDevice::KX_PKEY);
2543         KX_MACRO_addTypesToDict(d, QKEY, SCA_IInputDevice::KX_QKEY);
2544         KX_MACRO_addTypesToDict(d, RKEY, SCA_IInputDevice::KX_RKEY);
2545         KX_MACRO_addTypesToDict(d, SKEY, SCA_IInputDevice::KX_SKEY);
2546         KX_MACRO_addTypesToDict(d, TKEY, SCA_IInputDevice::KX_TKEY);
2547         KX_MACRO_addTypesToDict(d, UKEY, SCA_IInputDevice::KX_UKEY);
2548         KX_MACRO_addTypesToDict(d, VKEY, SCA_IInputDevice::KX_VKEY);
2549         KX_MACRO_addTypesToDict(d, WKEY, SCA_IInputDevice::KX_WKEY);
2550         KX_MACRO_addTypesToDict(d, XKEY, SCA_IInputDevice::KX_XKEY);
2551         KX_MACRO_addTypesToDict(d, YKEY, SCA_IInputDevice::KX_YKEY);
2552         KX_MACRO_addTypesToDict(d, ZKEY, SCA_IInputDevice::KX_ZKEY);
2553         
2554         KX_MACRO_addTypesToDict(d, ZEROKEY, SCA_IInputDevice::KX_ZEROKEY);
2555         KX_MACRO_addTypesToDict(d, ONEKEY, SCA_IInputDevice::KX_ONEKEY);
2556         KX_MACRO_addTypesToDict(d, TWOKEY, SCA_IInputDevice::KX_TWOKEY);
2557         KX_MACRO_addTypesToDict(d, THREEKEY, SCA_IInputDevice::KX_THREEKEY);
2558         KX_MACRO_addTypesToDict(d, FOURKEY, SCA_IInputDevice::KX_FOURKEY);
2559         KX_MACRO_addTypesToDict(d, FIVEKEY, SCA_IInputDevice::KX_FIVEKEY);
2560         KX_MACRO_addTypesToDict(d, SIXKEY, SCA_IInputDevice::KX_SIXKEY);
2561         KX_MACRO_addTypesToDict(d, SEVENKEY, SCA_IInputDevice::KX_SEVENKEY);
2562         KX_MACRO_addTypesToDict(d, EIGHTKEY, SCA_IInputDevice::KX_EIGHTKEY);
2563         KX_MACRO_addTypesToDict(d, NINEKEY, SCA_IInputDevice::KX_NINEKEY);
2564                 
2565         KX_MACRO_addTypesToDict(d, CAPSLOCKKEY, SCA_IInputDevice::KX_CAPSLOCKKEY);
2566                 
2567         KX_MACRO_addTypesToDict(d, LEFTCTRLKEY, SCA_IInputDevice::KX_LEFTCTRLKEY);
2568         KX_MACRO_addTypesToDict(d, LEFTALTKEY, SCA_IInputDevice::KX_LEFTALTKEY);
2569         KX_MACRO_addTypesToDict(d, RIGHTALTKEY, SCA_IInputDevice::KX_RIGHTALTKEY);
2570         KX_MACRO_addTypesToDict(d, RIGHTCTRLKEY, SCA_IInputDevice::KX_RIGHTCTRLKEY);
2571         KX_MACRO_addTypesToDict(d, RIGHTSHIFTKEY, SCA_IInputDevice::KX_RIGHTSHIFTKEY);
2572         KX_MACRO_addTypesToDict(d, LEFTSHIFTKEY, SCA_IInputDevice::KX_LEFTSHIFTKEY);
2573                 
2574         KX_MACRO_addTypesToDict(d, ESCKEY, SCA_IInputDevice::KX_ESCKEY);
2575         KX_MACRO_addTypesToDict(d, TABKEY, SCA_IInputDevice::KX_TABKEY);
2576         KX_MACRO_addTypesToDict(d, RETKEY, SCA_IInputDevice::KX_RETKEY);
2577         KX_MACRO_addTypesToDict(d, ENTERKEY, SCA_IInputDevice::KX_RETKEY);
2578         KX_MACRO_addTypesToDict(d, SPACEKEY, SCA_IInputDevice::KX_SPACEKEY);
2579         KX_MACRO_addTypesToDict(d, LINEFEEDKEY, SCA_IInputDevice::KX_LINEFEEDKEY);
2580         KX_MACRO_addTypesToDict(d, BACKSPACEKEY, SCA_IInputDevice::KX_BACKSPACEKEY);
2581         KX_MACRO_addTypesToDict(d, DELKEY, SCA_IInputDevice::KX_DELKEY);
2582         KX_MACRO_addTypesToDict(d, SEMICOLONKEY, SCA_IInputDevice::KX_SEMICOLONKEY);
2583         KX_MACRO_addTypesToDict(d, PERIODKEY, SCA_IInputDevice::KX_PERIODKEY);
2584         KX_MACRO_addTypesToDict(d, COMMAKEY, SCA_IInputDevice::KX_COMMAKEY);
2585         KX_MACRO_addTypesToDict(d, QUOTEKEY, SCA_IInputDevice::KX_QUOTEKEY);
2586         KX_MACRO_addTypesToDict(d, ACCENTGRAVEKEY, SCA_IInputDevice::KX_ACCENTGRAVEKEY);
2587         KX_MACRO_addTypesToDict(d, MINUSKEY, SCA_IInputDevice::KX_MINUSKEY);
2588         KX_MACRO_addTypesToDict(d, SLASHKEY, SCA_IInputDevice::KX_SLASHKEY);
2589         KX_MACRO_addTypesToDict(d, BACKSLASHKEY, SCA_IInputDevice::KX_BACKSLASHKEY);
2590         KX_MACRO_addTypesToDict(d, EQUALKEY, SCA_IInputDevice::KX_EQUALKEY);
2591         KX_MACRO_addTypesToDict(d, LEFTBRACKETKEY, SCA_IInputDevice::KX_LEFTBRACKETKEY);
2592         KX_MACRO_addTypesToDict(d, RIGHTBRACKETKEY, SCA_IInputDevice::KX_RIGHTBRACKETKEY);
2593                 
2594         KX_MACRO_addTypesToDict(d, LEFTARROWKEY, SCA_IInputDevice::KX_LEFTARROWKEY);
2595         KX_MACRO_addTypesToDict(d, DOWNARROWKEY, SCA_IInputDevice::KX_DOWNARROWKEY);
2596         KX_MACRO_addTypesToDict(d, RIGHTARROWKEY, SCA_IInputDevice::KX_RIGHTARROWKEY);
2597         KX_MACRO_addTypesToDict(d, UPARROWKEY, SCA_IInputDevice::KX_UPARROWKEY);
2598         
2599         KX_MACRO_addTypesToDict(d, PAD2 , SCA_IInputDevice::KX_PAD2);
2600         KX_MACRO_addTypesToDict(d, PAD4 , SCA_IInputDevice::KX_PAD4);
2601         KX_MACRO_addTypesToDict(d, PAD6 , SCA_IInputDevice::KX_PAD6);
2602         KX_MACRO_addTypesToDict(d, PAD8 , SCA_IInputDevice::KX_PAD8);
2603                 
2604         KX_MACRO_addTypesToDict(d, PAD1 , SCA_IInputDevice::KX_PAD1);
2605         KX_MACRO_addTypesToDict(d, PAD3 , SCA_IInputDevice::KX_PAD3);
2606         KX_MACRO_addTypesToDict(d, PAD5 , SCA_IInputDevice::KX_PAD5);
2607         KX_MACRO_addTypesToDict(d, PAD7 , SCA_IInputDevice::KX_PAD7);
2608         KX_MACRO_addTypesToDict(d, PAD9 , SCA_IInputDevice::KX_PAD9);
2609                 
2610         KX_MACRO_addTypesToDict(d, PADPERIOD, SCA_IInputDevice::KX_PADPERIOD);
2611         KX_MACRO_addTypesToDict(d, PADSLASHKEY, SCA_IInputDevice::KX_PADSLASHKEY);
2612         KX_MACRO_addTypesToDict(d, PADASTERKEY, SCA_IInputDevice::KX_PADASTERKEY);
2613                 
2614                 
2615         KX_MACRO_addTypesToDict(d, PAD0, SCA_IInputDevice::KX_PAD0);
2616         KX_MACRO_addTypesToDict(d, PADMINUS, SCA_IInputDevice::KX_PADMINUS);
2617         KX_MACRO_addTypesToDict(d, PADENTER, SCA_IInputDevice::KX_PADENTER);
2618         KX_MACRO_addTypesToDict(d, PADPLUSKEY, SCA_IInputDevice::KX_PADPLUSKEY);
2619                 
2620                 
2621         KX_MACRO_addTypesToDict(d, F1KEY,  SCA_IInputDevice::KX_F1KEY);
2622         KX_MACRO_addTypesToDict(d, F2KEY,  SCA_IInputDevice::KX_F2KEY);
2623         KX_MACRO_addTypesToDict(d, F3KEY,  SCA_IInputDevice::KX_F3KEY);
2624         KX_MACRO_addTypesToDict(d, F4KEY,  SCA_IInputDevice::KX_F4KEY);
2625         KX_MACRO_addTypesToDict(d, F5KEY,  SCA_IInputDevice::KX_F5KEY);
2626         KX_MACRO_addTypesToDict(d, F6KEY,  SCA_IInputDevice::KX_F6KEY);
2627         KX_MACRO_addTypesToDict(d, F7KEY,  SCA_IInputDevice::KX_F7KEY);
2628         KX_MACRO_addTypesToDict(d, F8KEY,  SCA_IInputDevice::KX_F8KEY);
2629         KX_MACRO_addTypesToDict(d, F9KEY,  SCA_IInputDevice::KX_F9KEY);
2630         KX_MACRO_addTypesToDict(d, F10KEY, SCA_IInputDevice::KX_F10KEY);
2631         KX_MACRO_addTypesToDict(d, F11KEY, SCA_IInputDevice::KX_F11KEY);
2632         KX_MACRO_addTypesToDict(d, F12KEY, SCA_IInputDevice::KX_F12KEY);
2633         KX_MACRO_addTypesToDict(d, F13KEY, SCA_IInputDevice::KX_F13KEY);
2634         KX_MACRO_addTypesToDict(d, F14KEY, SCA_IInputDevice::KX_F14KEY);
2635         KX_MACRO_addTypesToDict(d, F15KEY, SCA_IInputDevice::KX_F15KEY);
2636         KX_MACRO_addTypesToDict(d, F16KEY, SCA_IInputDevice::KX_F16KEY);
2637         KX_MACRO_addTypesToDict(d, F17KEY, SCA_IInputDevice::KX_F17KEY);
2638         KX_MACRO_addTypesToDict(d, F18KEY, SCA_IInputDevice::KX_F18KEY);
2639         KX_MACRO_addTypesToDict(d, F19KEY, SCA_IInputDevice::KX_F19KEY);
2640
2641         KX_MACRO_addTypesToDict(d, OSKEY, SCA_IInputDevice::KX_OSKEY);
2642                 
2643         KX_MACRO_addTypesToDict(d, PAUSEKEY,  SCA_IInputDevice::KX_PAUSEKEY);
2644         KX_MACRO_addTypesToDict(d, INSERTKEY, SCA_IInputDevice::KX_INSERTKEY);
2645         KX_MACRO_addTypesToDict(d, HOMEKEY,   SCA_IInputDevice::KX_HOMEKEY);
2646         KX_MACRO_addTypesToDict(d, PAGEUPKEY, SCA_IInputDevice::KX_PAGEUPKEY);
2647         KX_MACRO_addTypesToDict(d, PAGEDOWNKEY, SCA_IInputDevice::KX_PAGEDOWNKEY);
2648         KX_MACRO_addTypesToDict(d, ENDKEY, SCA_IInputDevice::KX_ENDKEY);
2649
2650         // MOUSE
2651         KX_MACRO_addTypesToDict(d, LEFTMOUSE, SCA_IInputDevice::KX_LEFTMOUSE);
2652         KX_MACRO_addTypesToDict(d, MIDDLEMOUSE, SCA_IInputDevice::KX_MIDDLEMOUSE);
2653         KX_MACRO_addTypesToDict(d, RIGHTMOUSE, SCA_IInputDevice::KX_RIGHTMOUSE);
2654         KX_MACRO_addTypesToDict(d, WHEELUPMOUSE, SCA_IInputDevice::KX_WHEELUPMOUSE);
2655         KX_MACRO_addTypesToDict(d, WHEELDOWNMOUSE, SCA_IInputDevice::KX_WHEELDOWNMOUSE);
2656         KX_MACRO_addTypesToDict(d, MOUSEX, SCA_IInputDevice::KX_MOUSEX);
2657         KX_MACRO_addTypesToDict(d, MOUSEY, SCA_IInputDevice::KX_MOUSEY);
2658
2659         // Check for errors
2660         if (PyErr_Occurred())
2661         {
2662                 Py_FatalError("can't initialize module GameKeys");
2663         }
2664
2665         return m;
2666 }
2667
2668 // utility function for loading and saving the globalDict
2669 int saveGamePythonConfig( char **marshal_buffer)
2670 {
2671         int marshal_length = 0;
2672         PyObject *gameLogic = PyImport_ImportModule("GameLogic");
2673         if (gameLogic) {
2674                 PyObject *pyGlobalDict = PyDict_GetItemString(PyModule_GetDict(gameLogic), "globalDict"); // Same as importing the module
2675                 if (pyGlobalDict) {
2676 #ifdef Py_MARSHAL_VERSION
2677                         PyObject *pyGlobalDictMarshal = PyMarshal_WriteObjectToString(  pyGlobalDict, 2); // Py_MARSHAL_VERSION == 2 as of Py2.5
2678 #else
2679                         PyObject *pyGlobalDictMarshal = PyMarshal_WriteObjectToString(  pyGlobalDict );
2680 #endif
2681                         if (pyGlobalDictMarshal) {
2682                                 // for testing only
2683                                 // PyObject_Print(pyGlobalDictMarshal, stderr, 0);
2684                                 char *marshal_cstring;
2685                                 
2686                                 marshal_cstring = PyBytes_AsString(pyGlobalDictMarshal); // py3 uses byte arrays
2687                                 marshal_length= PyBytes_Size(pyGlobalDictMarshal);
2688                                 *marshal_buffer = new char[marshal_length + 1];
2689                                 memcpy(*marshal_buffer, marshal_cstring, marshal_length);
2690                                 Py_DECREF(pyGlobalDictMarshal);
2691                         } else {
2692                                 printf("Error, bge.logic.globalDict could not be marshal'd\n");
2693                         }
2694                 } else {
2695                         printf("Error, bge.logic.globalDict was removed\n");
2696                 }
2697                 Py_DECREF(gameLogic);
2698         } else {
2699                 PyErr_Clear();
2700                 printf("Error, bge.logic failed to import bge.logic.globalDict will be lost\n");
2701         }
2702         return marshal_length;
2703 }
2704
2705 int loadGamePythonConfig(char *marshal_buffer, int marshal_length)
2706 {
2707         /* Restore the dict */
2708         if (marshal_buffer) {
2709                 PyObject *gameLogic = PyImport_ImportModule("GameLogic");
2710
2711                 if (gameLogic) {
2712                         PyObject *pyGlobalDict = PyMarshal_ReadObjectFromString(marshal_buffer, marshal_length);
2713                         if (pyGlobalDict) {
2714                                 PyObject *pyGlobalDict_orig = PyDict_GetItemString(PyModule_GetDict(gameLogic), "globalDict"); // Same as importing the module.
2715                                 if (pyGlobalDict_orig) {
2716                                         PyDict_Clear(pyGlobalDict_orig);
2717                                         PyDict_Update(pyGlobalDict_orig, pyGlobalDict);
2718                                 } else {
2719                                         /* this should not happen, but cant find the original globalDict, just assign it then */
2720                                         PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
2721                                 }
2722                                 Py_DECREF(gameLogic);
2723                                 Py_DECREF(pyGlobalDict);
2724                                 return 1;
2725                         } else {
2726                                 Py_DECREF(gameLogic);
2727                                 PyErr_Clear();
2728                                 printf("Error could not marshall string\n");
2729                         }
2730                 }
2731                 else {
2732                         PyErr_Clear();
2733                         printf("Error, bge.logic failed to import bge.logic.globalDict will be lost\n");
2734                 }
2735         }
2736         return 0;
2737 }
2738
2739 void pathGamePythonConfig(char *path)
2740 {
2741         int len = strlen(gp_GamePythonPathOrig); // Always use the first loaded blend filename
2742         
2743         BLI_strncpy(path, gp_GamePythonPathOrig, sizeof(gp_GamePythonPathOrig));
2744
2745         /* replace extension */
2746         if (BLI_testextensie(path, ".blend")) {
2747                 strcpy(path+(len-6), ".bgeconf");
2748         } else {
2749                 strcpy(path+len, ".bgeconf");
2750         }
2751 }
2752
2753 void setGamePythonPath(const char *path)
2754 {
2755         BLI_strncpy(gp_GamePythonPath, path, sizeof(gp_GamePythonPath));
2756         BLI_cleanup_file(NULL, gp_GamePythonPath); /* not absolutely needed but makes resolving path problems less confusing later */
2757         
2758         if (gp_GamePythonPathOrig[0] == '\0')
2759                 BLI_strncpy(gp_GamePythonPathOrig, path, sizeof(gp_GamePythonPathOrig));
2760 }
2761
2762 // we need this so while blender is open (not blenderplayer)
2763 // loading new blendfiles will reset this on starting the
2764 // engine but loading blend files within the BGE wont overwrite gp_GamePythonPathOrig
2765 void resetGamePythonPath()
2766 {
2767         gp_GamePythonPathOrig[0] = '\0';
2768 }
2769
2770 #endif // WITH_PYTHON