2011-02-23 10:52:22 +00:00
/*
2008-01-07 19:13:47 +00:00
* * * * * * BEGIN GPL LICENSE BLOCK * * * * *
2002-10-12 11:37:38 +00:00
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
2008-01-07 19:13:47 +00:00
* of the License , or ( at your option ) any later version .
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
2010-02-12 13:34:04 +00:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright ( C ) 2001 - 2002 by NaN Holding BV .
* All rights reserved .
*
* The Original Code is : all of this file .
*
* Contributor ( s ) : none yet .
*
2008-01-07 19:13:47 +00:00
* * * * * * END GPL LICENSE BLOCK * * * * *
2002-10-12 11:37:38 +00:00
* Initialize Python thingies .
*/
2011-02-25 13:35:59 +00:00
/** \file gameengine/Ketsji/KX_PythonInit.cpp
* \ ingroup ketsji
*/
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
# include "GL/glew.h"
2002-11-25 15:29:57 +00:00
2012-10-15 02:15:07 +00:00
# ifdef _MSC_VER
# pragma warning (disable:4786)
2010-10-27 06:05:22 +00:00
# endif
2012-10-15 02:15:07 +00:00
# ifdef WITH_PYTHON
# ifdef _POSIX_C_SOURCE
# undef _POSIX_C_SOURCE
# endif
# ifdef _XOPEN_SOURCE
# undef _XOPEN_SOURCE
# endif
# if defined(__sun) || defined(sun)
# if defined(_XPG4)
# undef _XPG4
# endif
# endif
# include <Python.h>
2009-09-29 21:42:40 +00:00
2009-06-17 20:33:34 +00:00
extern " C " {
2012-10-15 02:15:07 +00:00
# include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */
# include "py_capi_utils.h"
# include "mathutils.h" // 'mathutils' module copied here so the blenderlayer can use.
# include "bgl.h"
# include "blf_py_api.h"
2009-09-29 21:42:40 +00:00
2012-10-15 02:15:07 +00:00
# include "marshal.h" /* python header for loading/saving dicts */
2009-06-17 20:33:34 +00:00
}
2010-08-16 20:05:59 +00:00
# include "AUD_PyInit.h"
2010-07-09 12:35:40 +00:00
2012-10-15 02:15:07 +00:00
# endif /* WITH_PYTHON */
2009-06-17 20:33:34 +00:00
2002-10-12 11:37:38 +00:00
# include "KX_PythonInit.h"
2009-11-15 23:58:56 +00:00
// directory header for py function getBlendFileList
# ifndef WIN32
2012-10-15 02:15:07 +00:00
# include <dirent.h>
# include <stdlib.h>
2009-11-15 23:58:56 +00:00
# else
2012-10-15 02:15:07 +00:00
# include <io.h>
# include "BLI_winstuff.h"
2009-11-15 23:58:56 +00:00
# endif
2005-03-25 10:33:39 +00:00
//python physics binding
# include "KX_PyConstraintBinding.h"
2002-10-12 11:37:38 +00:00
2004-10-16 11:41:50 +00:00
# include "KX_KetsjiEngine.h"
2009-02-28 21:00:27 +00:00
# include "KX_RadarSensor.h"
2009-04-20 15:06:46 +00:00
# include "KX_RaySensor.h"
2009-09-24 21:22:24 +00:00
# include "KX_ArmatureSensor.h"
2009-06-08 20:08:19 +00:00
# include "KX_SceneActuator.h"
# include "KX_GameActuator.h"
# include "KX_ParentActuator.h"
2009-04-20 15:06:46 +00:00
# include "KX_SCA_DynamicActuator.h"
2010-07-21 09:16:27 +00:00
# include "KX_SteeringActuator.h"
# include "KX_NavMeshObject.h"
2004-10-16 11:41:50 +00:00
2002-10-12 11:37:38 +00:00
# include "SCA_IInputDevice.h"
# include "SCA_PropertySensor.h"
# include "SCA_RandomActuator.h"
2009-04-20 15:06:46 +00:00
# include "SCA_KeyboardSensor.h" /* IsPrintable, ToCharacter */
2012-12-21 02:28:59 +00:00
# include "SCA_JoystickManager.h" /* JOYINDEX_MAX */
# include "SCA_PythonJoystick.h"
2010-04-17 06:52:14 +00:00
# include "SCA_PythonKeyboard.h"
# include "SCA_PythonMouse.h"
2002-10-12 11:37:38 +00:00
# include "KX_ConstraintActuator.h"
# include "KX_IpoActuator.h"
2004-07-17 05:28:23 +00:00
# include "KX_SoundActuator.h"
2009-04-20 15:06:46 +00:00
# include "KX_StateActuator.h"
2004-07-17 05:28:23 +00:00
# include "BL_ActionActuator.h"
2009-09-24 21:22:24 +00:00
# include "BL_ArmatureObject.h"
2002-10-12 11:37:38 +00:00
# include "RAS_IRasterizer.h"
# include "RAS_ICanvas.h"
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
# include "RAS_BucketManager.h"
2009-04-20 15:06:46 +00:00
# include "RAS_2DFilterManager.h"
2002-10-12 11:37:38 +00:00
# include "MT_Vector3.h"
# include "MT_Point3.h"
# include "ListValue.h"
2009-06-16 07:16:51 +00:00
# include "InputParser.h"
2002-10-12 11:37:38 +00:00
# include "KX_Scene.h"
2009-11-15 23:58:56 +00:00
# include "NG_NetworkScene.h" //Needed for sendMessage()
2006-02-13 05:45:32 +00:00
# include "BL_Shader.h"
2011-07-08 07:32:45 +00:00
# include "BL_Action.h"
2006-01-06 03:46:54 +00:00
2004-05-16 12:53:54 +00:00
# include "KX_PyMath.h"
2009-04-20 15:06:46 +00:00
# include "PyObjectPlus.h"
2008-09-06 02:46:11 +00:00
2009-04-20 15:06:46 +00:00
# include "KX_PythonInitTypes.h"
2008-09-06 02:46:11 +00:00
2009-06-08 20:08:19 +00:00
/* we only need this to get a list of libraries from the main struct */
# include "DNA_ID.h"
2009-08-18 15:27:48 +00:00
# include "DNA_scene_types.h"
2009-06-08 20:08:19 +00:00
2005-07-29 18:14:41 +00:00
# include "PHY_IPhysicsEnvironment.h"
2009-06-08 20:08:19 +00:00
# include "BKE_main.h"
2008-05-11 18:45:30 +00:00
# include "BKE_global.h"
# include "BLI_blenlib.h"
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
# include "GPU_material.h"
2009-11-15 23:58:56 +00:00
# include "MEM_guardedalloc.h"
/* for converting new scenes */
# include "KX_BlenderSceneConverter.h"
2012-12-22 05:38:32 +00:00
# include "KX_LibLoadStatus.h"
2009-11-15 23:58:56 +00:00
# include "KX_MeshProxy.h" /* for creating a new library of mesh objects */
extern " C " {
2010-08-10 15:14:19 +00:00
# include "BKE_idcode.h"
2009-11-15 23:58:56 +00:00
}
2009-09-06 13:20:05 +00:00
# include "NG_NetworkScene.h" //Needed for sendMessage()
2002-10-12 11:37:38 +00:00
// 'local' copy of canvas ptr, for window height/width python scripts
2010-06-06 01:15:44 +00:00
2010-10-31 04:11:39 +00:00
# ifdef WITH_PYTHON
2010-06-06 01:15:44 +00:00
2002-10-12 11:37:38 +00:00
static RAS_ICanvas * gp_Canvas = NULL ;
2011-11-26 04:07:38 +00:00
static char gp_GamePythonPath [ FILE_MAX ] = " " ;
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
2010-06-06 01:15:44 +00:00
2010-10-10 20:59:30 +00:00
static SCA_PythonKeyboard * gp_PythonKeyboard = NULL ;
static SCA_PythonMouse * gp_PythonMouse = NULL ;
2012-12-21 02:28:59 +00:00
static SCA_PythonJoystick * gp_PythonJoysticks [ JOYINDEX_MAX ] = { NULL } ;
2010-10-31 04:11:39 +00:00
# endif // WITH_PYTHON
2010-06-06 01:15:44 +00:00
2002-10-12 11:37:38 +00:00
static KX_Scene * gp_KetsjiScene = NULL ;
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
static KX_KetsjiEngine * gp_KetsjiEngine = NULL ;
2002-10-12 11:37:38 +00:00
static RAS_IRasterizer * gp_Rasterizer = NULL ;
2009-09-29 21:42:40 +00:00
void KX_SetActiveScene ( class KX_Scene * scene )
{
gp_KetsjiScene = scene ;
}
class KX_Scene * KX_GetActiveScene ( )
{
return gp_KetsjiScene ;
}
class KX_KetsjiEngine * KX_GetActiveEngine ( )
{
return gp_KetsjiEngine ;
}
/* why is this in python? */
2005-07-27 09:30:53 +00:00
void KX_RasterizerDrawDebugLine ( const MT_Vector3 & from , const MT_Vector3 & to , const MT_Vector3 & color )
{
if ( gp_Rasterizer )
gp_Rasterizer - > DrawDebugLine ( from , to , color ) ;
}
2012-10-29 02:11:40 +00:00
void KX_RasterizerDrawDebugCircle ( const MT_Vector3 & center , const MT_Scalar radius , const MT_Vector3 & color ,
const MT_Vector3 & normal , int nsector )
2010-06-10 00:25:04 +00:00
{
if ( gp_Rasterizer )
gp_Rasterizer - > DrawDebugCircle ( center , radius , color , normal , nsector ) ;
}
2010-10-31 04:11:39 +00:00
# ifdef WITH_PYTHON
2009-09-29 21:42:40 +00:00
static PyObject * gp_OrigPythonSysPath = NULL ;
static PyObject * gp_OrigPythonSysModules = NULL ;
2002-10-12 11:37:38 +00:00
/* Macro for building the keyboard translation */
2012-11-21 02:28:36 +00:00
//#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyLong_FromLong(SCA_IInputDevice::KX_##name))
2013-01-11 03:21:24 +00:00
//#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, item=PyLong_FromLong(name)); Py_DECREF(item)
2002-10-12 11:37:38 +00:00
/* For the defines for types from logic bricks, we do stuff explicitly... */
2012-11-21 02:28:36 +00:00
# define KX_MACRO_addTypesToDict(dict, name, name2) PyDict_SetItemString(dict, #name, item=PyLong_FromLong(name2)); Py_DECREF(item)
2002-10-12 11:37:38 +00:00
// temporarily python stuff, will be put in another place later !
# include "KX_Python.h"
# include "SCA_PythonController.h"
// List of methods defined in the module
2012-09-16 04:58:18 +00:00
static PyObject * ErrorObject ;
2009-08-19 10:26:43 +00:00
static const char * gPyGetRandomFloat_doc = " getRandomFloat returns a random floating point value in the range [0..1] " ;
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetRandomFloat ( PyObject * )
2002-10-12 11:37:38 +00:00
{
return PyFloat_FromDouble ( MT_random ( ) ) ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetGravity ( PyObject * , PyObject * value )
2002-10-12 11:37:38 +00:00
{
2009-02-23 06:41:10 +00:00
MT_Vector3 vec ;
if ( ! PyVecTo ( value , vec ) )
2008-09-05 02:53:12 +00:00
return NULL ;
if ( gp_KetsjiScene )
gp_KetsjiScene - > SetGravity ( vec ) ;
2002-10-12 11:37:38 +00:00
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2008-05-11 18:45:30 +00:00
static char gPyExpandPath_doc [ ] =
" (path) - Converts a blender internal path into a proper file system path. \n \
path - the string path to convert . \ n \ n \
Use / as directory separator in path \ n \
You can use ' / / ' at the start of the string to define a relative path ; \ n \
2013-08-13 07:48:07 +00:00
Blender replaces that string by the directory of the current . blend or runtime \ n \
file to make a full path name . \ n \
2008-05-11 18:45:30 +00:00
The function also converts the directory separator to the local file system format . " ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyExpandPath ( PyObject * , PyObject * args )
2008-05-11 18:45:30 +00:00
{
2011-11-26 04:07:38 +00:00
char expanded [ FILE_MAX ] ;
2008-05-11 18:45:30 +00:00
char * filename ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " s:ExpandPath " , & filename ) )
2008-09-05 02:53:12 +00:00
return NULL ;
2011-11-26 04:07:38 +00:00
BLI_strncpy ( expanded , filename , FILE_MAX ) ;
2010-03-09 17:36:23 +00:00
BLI_path_abs ( expanded , gp_GamePythonPath ) ;
2011-01-06 05:04:07 +00:00
return PyUnicode_DecodeFSDefault ( expanded ) ;
2002-10-12 11:37:38 +00:00
}
2009-10-29 21:59:31 +00:00
static char gPyStartGame_doc [ ] =
" startGame(blend) \n \
Loads the blend file " ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyStartGame ( PyObject * , PyObject * args )
2009-10-29 21:59:31 +00:00
{
char * blendfile ;
if ( ! PyArg_ParseTuple ( args , " s:startGame " , & blendfile ) )
return NULL ;
gp_KetsjiEngine - > RequestExit ( KX_EXIT_REQUEST_START_OTHER_GAME ) ;
gp_KetsjiEngine - > SetNameNextGame ( blendfile ) ;
Py_RETURN_NONE ;
}
static char gPyEndGame_doc [ ] =
" endGame() \n \
Ends the current game " ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyEndGame ( PyObject * )
2009-10-29 21:59:31 +00:00
{
gp_KetsjiEngine - > RequestExit ( KX_EXIT_REQUEST_QUIT_GAME ) ;
//printf("%s\n", gp_GamePythonPath);
Py_RETURN_NONE ;
}
static char gPyRestartGame_doc [ ] =
" restartGame() \n \
Restarts the current game by reloading the . blend file " ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyRestartGame ( PyObject * )
2009-10-29 21:59:31 +00:00
{
gp_KetsjiEngine - > RequestExit ( KX_EXIT_REQUEST_RESTART_GAME ) ;
gp_KetsjiEngine - > SetNameNextGame ( gp_GamePythonPath ) ;
Py_RETURN_NONE ;
}
static char gPySaveGlobalDict_doc [ ] =
2010-08-11 12:14:16 +00:00
" saveGlobalDict() \n "
" Saves bge.logic.globalDict to a file " ;
2009-10-29 21:59:31 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPySaveGlobalDict ( PyObject * )
2009-10-29 21:59:31 +00:00
{
char marshal_path [ 512 ] ;
char * marshal_buffer = NULL ;
unsigned int marshal_length ;
FILE * fp = NULL ;
pathGamePythonConfig ( marshal_path ) ;
marshal_length = saveGamePythonConfig ( & marshal_buffer ) ;
if ( marshal_length & & marshal_buffer )
{
fp = fopen ( marshal_path , " wb " ) ;
if ( fp )
{
if ( fwrite ( marshal_buffer , 1 , marshal_length , fp ) ! = marshal_length )
printf ( " Warning: could not write marshal data \n " ) ;
fclose ( fp ) ;
} else {
printf ( " Warning: could not open marshal file \n " ) ;
}
} else {
printf ( " Warning: could not create marshal buffer \n " ) ;
}
if ( marshal_buffer )
delete [ ] marshal_buffer ;
Py_RETURN_NONE ;
}
static char gPyLoadGlobalDict_doc [ ] =
2010-08-11 12:14:16 +00:00
" LoadGlobalDict() \n "
" Loads bge.logic.globalDict from a file " ;
2009-10-29 21:59:31 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPyLoadGlobalDict ( PyObject * )
2009-10-29 21:59:31 +00:00
{
char marshal_path [ 512 ] ;
char * marshal_buffer = NULL ;
2011-07-06 10:19:04 +00:00
size_t marshal_length ;
2009-10-29 21:59:31 +00:00
FILE * fp = NULL ;
int result ;
pathGamePythonConfig ( marshal_path ) ;
fp = fopen ( marshal_path , " rb " ) ;
if ( fp ) {
// obtain file size:
fseek ( fp , 0 , SEEK_END ) ;
2011-07-06 10:19:04 +00:00
marshal_length = ( size_t ) ftell ( fp ) ;
2009-10-29 21:59:31 +00:00
rewind ( fp ) ;
marshal_buffer = ( char * ) malloc ( sizeof ( char ) * marshal_length ) ;
result = fread ( marshal_buffer , 1 , marshal_length , fp ) ;
if ( result = = marshal_length ) {
loadGamePythonConfig ( marshal_buffer , marshal_length ) ;
} else {
printf ( " Warning: could not read all of '%s' \n " , marshal_path ) ;
}
free ( marshal_buffer ) ;
fclose ( fp ) ;
} else {
printf ( " Warning: could not open '%s' \n " , marshal_path ) ;
}
Py_RETURN_NONE ;
}
2013-03-19 04:51:37 +00:00
static char gPyGetProfileInfo_doc [ ] =
" getProfileInfo() \n "
" returns a dictionary with profiling information " ;
static PyObject * gPyGetProfileInfo ( PyObject * )
{
return gp_KetsjiEngine - > GetPyProfileDict ( ) ;
}
2009-04-20 15:06:46 +00:00
static char gPySendMessage_doc [ ] =
" sendMessage(subject, [body, to, from]) \n \
sends a message in same manner as a message actuator \
subject = Subject of the message \
body = Message body \
to = Name of object to send the message to \
2010-01-30 18:23:13 +00:00
from = Name of object to send the string from " ;
2009-04-20 15:06:46 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPySendMessage ( PyObject * , PyObject * args )
2009-04-20 15:06:46 +00:00
{
char * subject ;
char * body = ( char * ) " " ;
char * to = ( char * ) " " ;
char * from = ( char * ) " " ;
if ( ! PyArg_ParseTuple ( args , " s|sss:sendMessage " , & subject , & body , & to , & from ) )
return NULL ;
gp_KetsjiScene - > GetNetworkScene ( ) - > SendMessage ( to , from , subject , body ) ;
Py_RETURN_NONE ;
}
2002-10-12 11:37:38 +00:00
// this gets a pointer to an array filled with floats
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetSpectrum ( PyObject * )
2002-10-12 11:37:38 +00:00
{
2012-09-16 04:58:18 +00:00
PyObject * resultlist = PyList_New ( 512 ) ;
2002-10-12 11:37:38 +00:00
2011-09-01 02:12:53 +00:00
for ( int index = 0 ; index < 512 ; index + + )
{
PyList_SET_ITEM ( resultlist , index , PyFloat_FromDouble ( 0.0 ) ) ;
}
2002-10-12 11:37:38 +00:00
return resultlist ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetLogicTicRate ( PyObject * , PyObject * args )
2004-10-16 11:41:50 +00:00
{
float ticrate ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " f:setLogicTicRate " , & ticrate ) )
2008-09-05 02:53:12 +00:00
return NULL ;
2004-10-16 11:41:50 +00:00
2008-09-05 02:53:12 +00:00
KX_KetsjiEngine : : SetTicRate ( ticrate ) ;
Py_RETURN_NONE ;
2004-10-16 11:41:50 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetLogicTicRate ( PyObject * )
2004-10-16 11:41:50 +00:00
{
return PyFloat_FromDouble ( KX_KetsjiEngine : : GetTicRate ( ) ) ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetExitKey ( PyObject * , PyObject * args )
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
{
short exitkey ;
if ( ! PyArg_ParseTuple ( args , " h:setExitKey " , & exitkey ) )
return NULL ;
KX_KetsjiEngine : : SetExitKey ( exitkey ) ;
Py_RETURN_NONE ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetExitKey ( PyObject * )
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
{
2012-11-21 02:28:36 +00:00
return PyLong_FromLong ( KX_KetsjiEngine : : GetExitKey ( ) ) ;
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetMaxLogicFrame ( PyObject * , PyObject * args )
2009-06-08 20:08:19 +00:00
{
int frame ;
if ( ! PyArg_ParseTuple ( args , " i:setMaxLogicFrame " , & frame ) )
return NULL ;
KX_KetsjiEngine : : SetMaxLogicFrame ( frame ) ;
Py_RETURN_NONE ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetMaxLogicFrame ( PyObject * )
2009-06-08 20:08:19 +00:00
{
2012-11-21 02:28:36 +00:00
return PyLong_FromLong ( KX_KetsjiEngine : : GetMaxLogicFrame ( ) ) ;
2009-06-08 20:08:19 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetMaxPhysicsFrame ( PyObject * , PyObject * args )
2009-06-08 20:08:19 +00:00
{
int frame ;
if ( ! PyArg_ParseTuple ( args , " i:setMaxPhysicsFrame " , & frame ) )
return NULL ;
KX_KetsjiEngine : : SetMaxPhysicsFrame ( frame ) ;
Py_RETURN_NONE ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetMaxPhysicsFrame ( PyObject * )
2009-06-08 20:08:19 +00:00
{
2012-11-21 02:28:36 +00:00
return PyLong_FromLong ( KX_KetsjiEngine : : GetMaxPhysicsFrame ( ) ) ;
2009-06-08 20:08:19 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetPhysicsTicRate ( PyObject * , PyObject * args )
2004-10-16 11:41:50 +00:00
{
float ticrate ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " f:setPhysicsTicRate " , & ticrate ) )
2008-09-05 02:53:12 +00:00
return NULL ;
2004-10-16 11:41:50 +00:00
BGE: Cleaning up the BGE's physics code and removing KX_IPhysicsController and KX_BulletPhysicsController. Instead, we just use PHY_IPhysicsController, which removes a lot of duplicate code.
This is a squashed commit of the following:
BGE Physics Cleanup: Fix crashes with LibLoading and replication. Also fixing some memory leaks.
BGE Physics Cleanup: Removing KX_IPhysicsController and KX_BulletPhysicsController.
BGE Physics Cleanup: Moving the replication code outside of KX_BlenderBulletController and switching KX_ConvertPhysicsObjects to create a CcdPhysicsController instead of a KX_BlenderBulletController.
BGE Physics Cleanup: Getting rid of an unsued KX_BulletPhysicsController.h include in KX_Scene.cpp.
BGE Physics Cleanup: Removing unused KX_IPhysicsController and KX_BulletPhysicsController includes.
BGE Physics Cleanup: Removing m_pPhysicsController1 and GetPhysicsController1() from KX_GameObject.
BGE Physics Cleanup: Remove SetRigidBody() from KX_IPhysicsController and remove GetName() from CcdPhysicsController.
BGE Physics Cleanup: Moving Add/RemoveCompoundChild() from KX_IPhysicsController to PHY_IPhysicsController.
BGE Physics Cleanup: Removing GetLocalInertia() from KX_IPhysicsController.
BGE Physics Cleanup: Making BlenderBulletCharacterController derive from PHY_ICharacter and removing CharacterWrapper from CcdPhysicsEnvironment.cpp. Also removing the character functions from KX_IPhysicsController.
BGE Physics Cleanup: Removing GetOrientation(), SetOrientation(), SetPosition(), SetScaling(), and GetRadius() from KX_IPhysicsController.
BGE Physics Cleanup: Removing GetReactionForce() since all implementations returned (0, 0, 0). The Python interface for KX_GameObject still has reaction force code, but it still also returns (0, 0, 0). This can probably be removed as well, but removing it can break scripts, so I'll leave it for now.
BGE Physics Cleanup: Removing Get/SetLinVelocityMin() and Get/SetLinVelocityMax() from KX_IPhysicsController.
BGE Physics Cleanup: Removing SetMargin(), RelativeTranslate(), and RelativeRotate() from KX_IPhysicsController.
BGE Physics Cleanup: Using constant references for function arguments in PHY_IPhysicsController where appropriate.
BGE Physics Cleanup: Removing ApplyImpulse() from KX_IPhysicsController.
BGE Physics Cleanup: Removing ResolveCombinedVelocities() from KX_IPhysicsController.
BGE Physics Cleanup: Accidently removed a return when cleaning up KX_GameObject::PyGetVelocity().
BGE Physics Cleanup: Remove GetLinearVelocity(), GetAngularVelocity() and GetVelocity() from KX_IPhysicsController. The corresponding PHY_IPhysicsController functions now also take Moto types instead of scalars to match the KX_IPhysicsController interface.
BGE Physics Cleanup: Moving SuspendDynamics, RestoreDynamics, SetMass, GetMass, and SetTransform from KX_IPhysicsController to PHY_IPhysicsController.
BGE Physics Cleanup: PHY_IPhysicsEnvironment and derived classes now use the same naming scheme as PHY_IController.
BGE Physics Cleanup: PHY_IMotionState and derived classes now use the same naming convention as PHY_IController.
BGE Phsyics Cleanup: Making PHY_IController and its derived classes follow a consistent naming scheme for member functions. They now all start with capital letters (e.g., setWorldOrientation becomes SetWorldOrientation).
BGE Physics Cleanup: Getting rid of KX_GameObject::SuspendDynamics() and KX_GameObject::RestoreDynamics(). Instead, use the functions from the physics controller.
BGE: Some first steps in trying to cleanup the KX_IPhysicsController mess. KX_GameObject now has a GetPhysicsController() and a GetPhysicsController1(). The former returns a PHY_IPhysicsController* while the latter returns a KX_IPhysicsController. The goal is to get everything using GetPhysicsController() instead of GetPhysicsController1().
2013-11-04 19:22:47 +00:00
PHY_GetActiveEnvironment ( ) - > SetFixedTimeStep ( true , ticrate ) ;
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
2004-10-16 11:41:50 +00:00
}
2009-02-25 03:26:02 +00:00
#if 0 // unused
2012-09-16 04:58:18 +00:00
static PyObject * gPySetPhysicsDebug ( PyObject * , PyObject * args )
2005-07-29 18:14:41 +00:00
{
int debugMode ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " i:setPhysicsDebug " , & debugMode ) )
2008-09-05 02:53:12 +00:00
return NULL ;
2005-07-29 18:14:41 +00:00
2008-09-05 02:53:12 +00:00
PHY_GetActiveEnvironment ( ) - > setDebugMode ( debugMode ) ;
Py_RETURN_NONE ;
2005-07-29 18:14:41 +00:00
}
2009-02-25 03:26:02 +00:00
# endif
2005-07-29 18:14:41 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetPhysicsTicRate ( PyObject * )
2004-10-16 11:41:50 +00:00
{
BGE: Cleaning up the BGE's physics code and removing KX_IPhysicsController and KX_BulletPhysicsController. Instead, we just use PHY_IPhysicsController, which removes a lot of duplicate code.
This is a squashed commit of the following:
BGE Physics Cleanup: Fix crashes with LibLoading and replication. Also fixing some memory leaks.
BGE Physics Cleanup: Removing KX_IPhysicsController and KX_BulletPhysicsController.
BGE Physics Cleanup: Moving the replication code outside of KX_BlenderBulletController and switching KX_ConvertPhysicsObjects to create a CcdPhysicsController instead of a KX_BlenderBulletController.
BGE Physics Cleanup: Getting rid of an unsued KX_BulletPhysicsController.h include in KX_Scene.cpp.
BGE Physics Cleanup: Removing unused KX_IPhysicsController and KX_BulletPhysicsController includes.
BGE Physics Cleanup: Removing m_pPhysicsController1 and GetPhysicsController1() from KX_GameObject.
BGE Physics Cleanup: Remove SetRigidBody() from KX_IPhysicsController and remove GetName() from CcdPhysicsController.
BGE Physics Cleanup: Moving Add/RemoveCompoundChild() from KX_IPhysicsController to PHY_IPhysicsController.
BGE Physics Cleanup: Removing GetLocalInertia() from KX_IPhysicsController.
BGE Physics Cleanup: Making BlenderBulletCharacterController derive from PHY_ICharacter and removing CharacterWrapper from CcdPhysicsEnvironment.cpp. Also removing the character functions from KX_IPhysicsController.
BGE Physics Cleanup: Removing GetOrientation(), SetOrientation(), SetPosition(), SetScaling(), and GetRadius() from KX_IPhysicsController.
BGE Physics Cleanup: Removing GetReactionForce() since all implementations returned (0, 0, 0). The Python interface for KX_GameObject still has reaction force code, but it still also returns (0, 0, 0). This can probably be removed as well, but removing it can break scripts, so I'll leave it for now.
BGE Physics Cleanup: Removing Get/SetLinVelocityMin() and Get/SetLinVelocityMax() from KX_IPhysicsController.
BGE Physics Cleanup: Removing SetMargin(), RelativeTranslate(), and RelativeRotate() from KX_IPhysicsController.
BGE Physics Cleanup: Using constant references for function arguments in PHY_IPhysicsController where appropriate.
BGE Physics Cleanup: Removing ApplyImpulse() from KX_IPhysicsController.
BGE Physics Cleanup: Removing ResolveCombinedVelocities() from KX_IPhysicsController.
BGE Physics Cleanup: Accidently removed a return when cleaning up KX_GameObject::PyGetVelocity().
BGE Physics Cleanup: Remove GetLinearVelocity(), GetAngularVelocity() and GetVelocity() from KX_IPhysicsController. The corresponding PHY_IPhysicsController functions now also take Moto types instead of scalars to match the KX_IPhysicsController interface.
BGE Physics Cleanup: Moving SuspendDynamics, RestoreDynamics, SetMass, GetMass, and SetTransform from KX_IPhysicsController to PHY_IPhysicsController.
BGE Physics Cleanup: PHY_IPhysicsEnvironment and derived classes now use the same naming scheme as PHY_IController.
BGE Physics Cleanup: PHY_IMotionState and derived classes now use the same naming convention as PHY_IController.
BGE Phsyics Cleanup: Making PHY_IController and its derived classes follow a consistent naming scheme for member functions. They now all start with capital letters (e.g., setWorldOrientation becomes SetWorldOrientation).
BGE Physics Cleanup: Getting rid of KX_GameObject::SuspendDynamics() and KX_GameObject::RestoreDynamics(). Instead, use the functions from the physics controller.
BGE: Some first steps in trying to cleanup the KX_IPhysicsController mess. KX_GameObject now has a GetPhysicsController() and a GetPhysicsController1(). The former returns a PHY_IPhysicsController* while the latter returns a KX_IPhysicsController. The goal is to get everything using GetPhysicsController() instead of GetPhysicsController1().
2013-11-04 19:22:47 +00:00
return PyFloat_FromDouble ( PHY_GetActiveEnvironment ( ) - > GetFixedTimeStep ( ) ) ;
2004-10-16 11:41:50 +00:00
}
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetAverageFrameRate ( PyObject * )
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
{
return PyFloat_FromDouble ( KX_KetsjiEngine : : GetAverageFrameRate ( ) ) ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetBlendFileList ( PyObject * , PyObject * args )
2008-08-22 06:02:01 +00:00
{
2008-10-11 00:56:49 +00:00
char cpath [ sizeof ( gp_GamePythonPath ) ] ;
2008-08-22 06:02:01 +00:00
char * searchpath = NULL ;
2012-09-16 04:58:18 +00:00
PyObject * list , * value ;
2011-09-01 02:12:53 +00:00
DIR * dp ;
struct dirent * dirp ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " |s:getBlendFileList " , & searchpath ) )
2008-08-22 06:02:01 +00:00
return NULL ;
2011-09-01 02:12:53 +00:00
2008-08-22 06:02:01 +00:00
list = PyList_New ( 0 ) ;
if ( searchpath ) {
2011-11-26 04:07:38 +00:00
BLI_strncpy ( cpath , searchpath , FILE_MAX ) ;
2010-03-09 17:36:23 +00:00
BLI_path_abs ( cpath , gp_GamePythonPath ) ;
2008-08-22 06:02:01 +00:00
} else {
/* Get the dir only */
2011-10-21 02:13:36 +00:00
BLI_split_dir_part ( gp_GamePythonPath , cpath , sizeof ( cpath ) ) ;
2008-08-22 06:02:01 +00:00
}
2011-09-01 02:12:53 +00:00
2012-03-24 07:52:14 +00:00
if ( ( dp = opendir ( cpath ) ) = = NULL ) {
2008-08-22 06:02:01 +00:00
/* todo, show the errno, this shouldnt happen anyway if the blendfile is readable */
2014-01-13 03:53:41 +00:00
fprintf ( stderr , " Could not read directory (%s) failed, code %d (%s) \n " , cpath , errno , strerror ( errno ) ) ;
2008-08-22 06:02:01 +00:00
return list ;
2011-09-01 02:12:53 +00:00
}
2008-08-22 06:02:01 +00:00
2011-09-01 02:12:53 +00:00
while ( ( dirp = readdir ( dp ) ) ! = NULL ) {
2008-08-22 06:02:01 +00:00
if ( BLI_testextensie ( dirp - > d_name , " .blend " ) ) {
2011-01-06 05:04:07 +00:00
value = PyUnicode_DecodeFSDefault ( dirp - > d_name ) ;
2008-09-03 23:51:55 +00:00
PyList_Append ( list , value ) ;
Py_DECREF ( value ) ;
2008-08-22 06:02:01 +00:00
}
2011-09-01 02:12:53 +00:00
}
2008-08-22 06:02:01 +00:00
2011-09-01 02:12:53 +00:00
closedir ( dp ) ;
return list ;
2008-08-22 06:02:01 +00:00
}
2010-01-30 18:23:13 +00:00
static char gPyAddScene_doc [ ] =
" addScene(name, [overlay]) \n \
adds a scene to the game engine \ n \
name = Name of the scene \ n \
overlay = Overlay or underlay " ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyAddScene ( PyObject * , PyObject * args )
2010-01-30 18:23:13 +00:00
{
char * name ;
int overlay = 1 ;
if ( ! PyArg_ParseTuple ( args , " s|i:addScene " , & name , & overlay ) )
return NULL ;
gp_KetsjiEngine - > ConvertAndAddScene ( name , ( overlay ! = 0 ) ) ;
Py_RETURN_NONE ;
}
2009-08-19 10:26:43 +00:00
static const char * gPyGetCurrentScene_doc =
2004-06-07 11:03:12 +00:00
" getCurrentScene() \n "
" Gets a reference to the current scene. \n " ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetCurrentScene ( PyObject * self )
2004-06-07 11:03:12 +00:00
{
2009-04-20 15:06:46 +00:00
return gp_KetsjiScene - > GetProxy ( ) ;
2004-06-07 11:03:12 +00:00
}
2006-01-06 03:46:54 +00:00
2009-08-19 10:26:43 +00:00
static const char * gPyGetSceneList_doc =
2009-02-27 23:53:09 +00:00
" getSceneList() \n "
" Return a list of converted scenes. \n " ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetSceneList ( PyObject * self )
2009-02-27 23:53:09 +00:00
{
KX_KetsjiEngine * m_engine = KX_GetActiveEngine ( ) ;
2012-09-16 04:58:18 +00:00
PyObject * list ;
2009-02-27 23:53:09 +00:00
KX_SceneList * scenes = m_engine - > CurrentScenes ( ) ;
int numScenes = scenes - > size ( ) ;
int i ;
list = PyList_New ( numScenes ) ;
for ( i = 0 ; i < numScenes ; i + + )
{
KX_Scene * scene = scenes - > at ( i ) ;
2009-04-20 15:06:46 +00:00
PyList_SET_ITEM ( list , i , scene - > GetProxy ( ) ) ;
2009-02-27 23:53:09 +00:00
}
2009-11-15 23:58:56 +00:00
2009-04-20 15:06:46 +00:00
return list ;
2009-02-27 23:53:09 +00:00
}
2009-11-15 23:58:56 +00:00
static PyObject * pyPrintStats ( PyObject * , PyObject * , PyObject * )
{
gp_KetsjiScene - > GetSceneConverter ( ) - > PrintStats ( ) ;
Py_RETURN_NONE ;
}
2006-01-06 03:46:54 +00:00
static PyObject * pyPrintExt ( PyObject * , PyObject * , PyObject * )
{
# define pprint(x) std::cout << x << std::endl;
bool count = 0 ;
2006-01-15 11:34:55 +00:00
bool support = 0 ;
2006-01-06 03:46:54 +00:00
pprint ( " Supported Extensions... " ) ;
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
pprint ( " GL_ARB_shader_objects supported? " < < ( GLEW_ARB_shader_objects ? " yes. " : " no. " ) ) ;
2006-01-06 03:46:54 +00:00
count = 1 ;
2006-01-15 11:34:55 +00:00
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
support = GLEW_ARB_vertex_shader ;
2006-01-15 11:34:55 +00:00
pprint ( " GL_ARB_vertex_shader supported? " < < ( support ? " yes. " : " no. " ) ) ;
2006-01-06 03:46:54 +00:00
count = 1 ;
2012-03-28 05:03:24 +00:00
if ( support ) {
2006-01-15 11:34:55 +00:00
pprint ( " ----------Details---------- " ) ;
int max = 0 ;
glGetIntegerv ( GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB , ( GLint * ) & max ) ;
pprint ( " Max uniform components. " < < max ) ;
glGetIntegerv ( GL_MAX_VARYING_FLOATS_ARB , ( GLint * ) & max ) ;
pprint ( " Max varying floats. " < < max ) ;
glGetIntegerv ( GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB , ( GLint * ) & max ) ;
pprint ( " Max vertex texture units. " < < max ) ;
glGetIntegerv ( GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB , ( GLint * ) & max ) ;
pprint ( " Max combined texture units. " < < max ) ;
pprint ( " " ) ;
}
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
support = GLEW_ARB_fragment_shader ;
2006-01-15 11:34:55 +00:00
pprint ( " GL_ARB_fragment_shader supported? " < < ( support ? " yes. " : " no. " ) ) ;
2006-01-06 03:46:54 +00:00
count = 1 ;
2012-03-28 05:03:24 +00:00
if ( support ) {
2006-01-15 11:34:55 +00:00
pprint ( " ----------Details---------- " ) ;
int max = 0 ;
glGetIntegerv ( GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB , ( GLint * ) & max ) ;
pprint ( " Max uniform components. " < < max ) ;
pprint ( " " ) ;
}
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
support = GLEW_ARB_texture_cube_map ;
2006-01-15 11:34:55 +00:00
pprint ( " GL_ARB_texture_cube_map supported? " < < ( support ? " yes. " : " no. " ) ) ;
2006-01-06 03:46:54 +00:00
count = 1 ;
2012-03-28 05:03:24 +00:00
if ( support ) {
2006-01-15 11:34:55 +00:00
pprint ( " ----------Details---------- " ) ;
int size = 0 ;
glGetIntegerv ( GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB , ( GLint * ) & size ) ;
pprint ( " Max cubemap size. " < < size ) ;
pprint ( " " ) ;
}
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
support = GLEW_ARB_multitexture ;
2006-01-06 03:46:54 +00:00
count = 1 ;
2006-01-15 11:34:55 +00:00
pprint ( " GL_ARB_multitexture supported? " < < ( support ? " yes. " : " no. " ) ) ;
2012-03-28 05:03:24 +00:00
if ( support ) {
2006-01-15 11:34:55 +00:00
pprint ( " ----------Details---------- " ) ;
int units = 0 ;
glGetIntegerv ( GL_MAX_TEXTURE_UNITS_ARB , ( GLint * ) & units ) ;
pprint ( " Max texture units available. " < < units ) ;
pprint ( " " ) ;
}
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
pprint ( " GL_ARB_texture_env_combine supported? " < < ( GLEW_ARB_texture_env_combine ? " yes. " : " no. " ) ) ;
2006-01-06 03:46:54 +00:00
count = 1 ;
Merge of apricot branch game engine changes into trunk, excluding GLSL.
GLEW
====
Added the GLEW opengl extension library into extern/, always compiled
into Blender now. This is much nicer than doing this kind of extension
management manually, and will be used in the game engine, for GLSL, and
other opengl extensions.
* According to the GLEW website it works on Windows, Linux, Mac OS X,
FreeBSD, Irix, and Solaris. There might still be platform specific
issues due to this commit, so let me know and I'll look into it.
* This means also that all extensions will now always be compiled in,
regardless of the glext.h on the platform where compilation happens.
Game Engine
===========
Refactoring of the use of opengl extensions and other drawing code
in the game engine, and cleaning up some hacks related to GLSL
integration. These changes will be merged into trunk too after this.
The game engine graphics demos & apricot level survived my tests,
but this could use some good testing of course.
For users: please test with the options "Generate Display Lists" and
"Vertex Arrays" enabled, these should be the fastest and are supposed
to be "unreliable", but if that's the case that's probably due to bugs
that can be fixed.
* The game engine now also uses GLEW for extensions, replacing the
custom opengl extensions code that was there. Removes a lot of
#ifdef's, but the runtime checks stay of course.
* Removed the WITHOUT_GLEXT environment variable. This was added to
work around a specific bug and only disabled multitexturing anyway.
It might also have caused a slowdown since it was retrieving the
environment variable for every vertex in immediate mode (bug #13680).
* Refactored the code to allow drawing skinned meshes with vertex
arrays too, removing some specific immediate mode drawing functions
for this that only did extra normal calculation. Now it always splits
vertices of flat faces instead.
* Refactored normal recalculation with some minor optimizations,
required for the above change.
* Removed some outdated code behind the __NLA_OLDDEFORM #ifdef.
* Fixed various bugs in setting of multitexture coordinates and vertex
attributes for vertex arrays. These were not being enabled/disabled
correct according to the opengl spec, leading to crashes. Also tangent
attributes used an immediate mode call for vertex arrays, which can't
work.
* Fixed use of uninitialized variable in RAS_TexVert.
* Exporting skinned meshes was doing O(n^2) lookups for vertices and
deform weights, now uses same trick as regular meshes.
2008-06-17 10:27:34 +00:00
2012-03-24 07:52:14 +00:00
if ( ! count )
2006-01-06 03:46:54 +00:00
pprint ( " No extenstions are used in this build " ) ;
2008-08-14 03:23:36 +00:00
Py_RETURN_NONE ;
2006-01-06 03:46:54 +00:00
}
2004-06-07 11:03:12 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gLibLoad ( PyObject * , PyObject * args , PyObject * kwds )
2009-11-15 23:58:56 +00:00
{
KX_Scene * kx_scene = gp_KetsjiScene ;
char * path ;
char * group ;
2010-08-28 02:07:55 +00:00
Py_buffer py_buffer ;
py_buffer . buf = NULL ;
2009-11-15 23:58:56 +00:00
char * err_str = NULL ;
2012-12-22 05:38:32 +00:00
KX_LibLoadStatus * status = NULL ;
2011-03-22 02:39:08 +00:00
short options = 0 ;
2012-12-22 05:38:32 +00:00
int load_actions = 0 , verbose = 0 , load_scripts = 1 , async = 0 ;
2011-03-22 02:39:08 +00:00
2012-12-22 05:38:32 +00:00
static const char * kwlist [ ] = { " path " , " group " , " buffer " , " load_actions " , " verbose " , " load_scripts " , " async " , NULL } ;
2009-11-15 23:58:56 +00:00
2012-12-22 05:38:32 +00:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwds , " ss|y*iiIi:LibLoad " , const_cast < char * * > ( kwlist ) ,
& path , & group , & py_buffer , & load_actions , & verbose , & load_scripts , & async ) )
2009-11-15 23:58:56 +00:00
return NULL ;
2011-03-22 02:39:08 +00:00
/* setup options */
if ( load_actions ! = 0 )
options | = KX_BlenderSceneConverter : : LIB_LOAD_LOAD_ACTIONS ;
if ( verbose ! = 0 )
options | = KX_BlenderSceneConverter : : LIB_LOAD_VERBOSE ;
2012-07-22 22:58:12 +00:00
if ( load_scripts ! = 0 )
options | = KX_BlenderSceneConverter : : LIB_LOAD_LOAD_SCRIPTS ;
2012-12-22 05:38:32 +00:00
if ( async ! = 0 )
options | = KX_BlenderSceneConverter : : LIB_LOAD_ASYNC ;
2011-03-22 02:39:08 +00:00
2010-08-28 02:07:55 +00:00
if ( ! py_buffer . buf )
{
2011-03-21 12:40:06 +00:00
char abs_path [ FILE_MAX ] ;
2011-03-21 09:29:28 +00:00
// Make the path absolute
BLI_strncpy ( abs_path , path , sizeof ( abs_path ) ) ;
BLI_path_abs ( abs_path , gp_GamePythonPath ) ;
2012-12-22 05:38:32 +00:00
if ( ( status = kx_scene - > GetSceneConverter ( ) - > LinkBlendFilePath ( abs_path , group , kx_scene , & err_str , options ) ) ) {
return status - > GetProxy ( ) ;
2010-08-28 02:07:55 +00:00
}
}
else
{
2012-12-22 05:38:32 +00:00
if ( ( status = kx_scene - > GetSceneConverter ( ) - > LinkBlendFileMemory ( py_buffer . buf , py_buffer . len , path , group , kx_scene , & err_str , options ) ) ) {
2010-08-28 02:07:55 +00:00
PyBuffer_Release ( & py_buffer ) ;
2012-12-22 05:38:32 +00:00
return status - > GetProxy ( ) ;
2010-08-28 02:07:55 +00:00
}
PyBuffer_Release ( & py_buffer ) ;
2009-11-15 23:58:56 +00:00
}
2012-03-24 07:52:14 +00:00
if ( err_str ) {
2009-11-15 23:58:56 +00:00
PyErr_SetString ( PyExc_ValueError , err_str ) ;
return NULL ;
}
Py_RETURN_FALSE ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gLibNew ( PyObject * , PyObject * args )
2009-11-15 23:58:56 +00:00
{
KX_Scene * kx_scene = gp_KetsjiScene ;
char * path ;
char * group ;
2011-11-03 14:09:18 +00:00
const char * name ;
2009-11-15 23:58:56 +00:00
PyObject * names ;
int idcode ;
if ( ! PyArg_ParseTuple ( args , " ssO!:LibNew " , & path , & group , & PyList_Type , & names ) )
return NULL ;
2012-03-24 07:52:14 +00:00
if ( kx_scene - > GetSceneConverter ( ) - > GetMainDynamicPath ( path ) )
2009-11-15 23:58:56 +00:00
{
PyErr_SetString ( PyExc_KeyError , " the name of the path given exists " ) ;
return NULL ;
}
2010-08-10 15:14:19 +00:00
idcode = BKE_idcode_from_name ( group ) ;
2012-03-24 07:52:14 +00:00
if ( idcode = = 0 ) {
2009-11-15 23:58:56 +00:00
PyErr_Format ( PyExc_ValueError , " invalid group given \" %s \" " , group ) ;
return NULL ;
}
Main * maggie = ( Main * ) MEM_callocN ( sizeof ( Main ) , " BgeMain " ) ;
kx_scene - > GetSceneConverter ( ) - > GetMainDynamic ( ) . push_back ( maggie ) ;
strncpy ( maggie - > name , path , sizeof ( maggie - > name ) - 1 ) ;
/* Copy the object into main */
2012-03-24 07:52:14 +00:00
if ( idcode = = ID_ME ) {
2009-11-15 23:58:56 +00:00
PyObject * ret = PyList_New ( 0 ) ;
PyObject * item ;
2012-03-24 07:52:14 +00:00
for ( Py_ssize_t i = 0 ; i < PyList_GET_SIZE ( names ) ; i + + ) {
2009-11-15 23:58:56 +00:00
name = _PyUnicode_AsString ( PyList_GET_ITEM ( names , i ) ) ;
2012-03-24 07:52:14 +00:00
if ( name ) {
2009-11-15 23:58:56 +00:00
RAS_MeshObject * meshobj = kx_scene - > GetSceneConverter ( ) - > ConvertMeshSpecial ( kx_scene , maggie , name ) ;
2012-03-24 07:52:14 +00:00
if ( meshobj ) {
2009-11-15 23:58:56 +00:00
KX_MeshProxy * meshproxy = new KX_MeshProxy ( meshobj ) ;
item = meshproxy - > NewProxy ( true ) ;
PyList_Append ( ret , item ) ;
Py_DECREF ( item ) ;
}
}
else {
PyErr_Clear ( ) ; /* wasnt a string, ignore for now */
}
}
return ret ;
}
else {
PyErr_Format ( PyExc_ValueError , " only \" Mesh \" group currently supported " ) ;
return NULL ;
}
Py_RETURN_NONE ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gLibFree ( PyObject * , PyObject * args )
2009-11-15 23:58:56 +00:00
{
KX_Scene * kx_scene = gp_KetsjiScene ;
char * path ;
if ( ! PyArg_ParseTuple ( args , " s:LibFree " , & path ) )
return NULL ;
if ( kx_scene - > GetSceneConverter ( ) - > FreeBlendFile ( path ) )
{
Py_RETURN_TRUE ;
}
else {
Py_RETURN_FALSE ;
}
}
2012-09-16 04:58:18 +00:00
static PyObject * gLibList ( PyObject * , PyObject * args )
2009-11-15 23:58:56 +00:00
{
vector < Main * > & dynMaggie = gp_KetsjiScene - > GetSceneConverter ( ) - > GetMainDynamic ( ) ;
int i = 0 ;
PyObject * list = PyList_New ( dynMaggie . size ( ) ) ;
for ( vector < Main * > : : iterator it = dynMaggie . begin ( ) ; ! ( it = = dynMaggie . end ( ) ) ; it + + )
{
PyList_SET_ITEM ( list , i + + , PyUnicode_FromString ( ( * it ) - > name ) ) ;
}
return list ;
}
2002-10-12 11:37:38 +00:00
2012-09-01 21:23:05 +00:00
struct PyNextFrameState pynextframestate ;
static PyObject * gPyNextFrame ( PyObject * )
{
if ( pynextframestate . func = = NULL ) Py_RETURN_NONE ;
if ( pynextframestate . state = = NULL ) Py_RETURN_NONE ; //should never happen; raise exception instead?
if ( pynextframestate . func ( pynextframestate . state ) ) //nonzero = stop
{
Py_RETURN_TRUE ;
}
else // 0 = go on
{
Py_RETURN_FALSE ;
}
}
2002-10-12 11:37:38 +00:00
static struct PyMethodDef game_methods [ ] = {
2009-08-10 00:07:34 +00:00
{ " expandPath " , ( PyCFunction ) gPyExpandPath , METH_VARARGS , ( const char * ) gPyExpandPath_doc } ,
2009-10-29 21:59:31 +00:00
{ " startGame " , ( PyCFunction ) gPyStartGame , METH_VARARGS , ( const char * ) gPyStartGame_doc } ,
{ " endGame " , ( PyCFunction ) gPyEndGame , METH_NOARGS , ( const char * ) gPyEndGame_doc } ,
{ " restartGame " , ( PyCFunction ) gPyRestartGame , METH_NOARGS , ( const char * ) gPyRestartGame_doc } ,
{ " saveGlobalDict " , ( PyCFunction ) gPySaveGlobalDict , METH_NOARGS , ( const char * ) gPySaveGlobalDict_doc } ,
{ " loadGlobalDict " , ( PyCFunction ) gPyLoadGlobalDict , METH_NOARGS , ( const char * ) gPyLoadGlobalDict_doc } ,
2009-08-10 00:07:34 +00:00
{ " sendMessage " , ( PyCFunction ) gPySendMessage , METH_VARARGS , ( const char * ) gPySendMessage_doc } ,
2010-01-30 18:23:13 +00:00
{ " getCurrentController " , ( PyCFunction ) SCA_PythonController : : sPyGetCurrentController , METH_NOARGS , SCA_PythonController : : sPyGetCurrentController__doc__ } ,
{ " getCurrentScene " , ( PyCFunction ) gPyGetCurrentScene , METH_NOARGS , gPyGetCurrentScene_doc } ,
{ " getSceneList " , ( PyCFunction ) gPyGetSceneList , METH_NOARGS , ( const char * ) gPyGetSceneList_doc } ,
{ " addScene " , ( PyCFunction ) gPyAddScene , METH_VARARGS , ( const char * ) gPyAddScene_doc } ,
{ " getRandomFloat " , ( PyCFunction ) gPyGetRandomFloat , METH_NOARGS , ( const char * ) gPyGetRandomFloat_doc } ,
2009-08-10 00:07:34 +00:00
{ " setGravity " , ( PyCFunction ) gPySetGravity , METH_O , ( const char * ) " set Gravitation " } ,
{ " getSpectrum " , ( PyCFunction ) gPyGetSpectrum , METH_NOARGS , ( const char * ) " get audio spectrum " } ,
{ " getMaxLogicFrame " , ( PyCFunction ) gPyGetMaxLogicFrame , METH_NOARGS , ( const char * ) " Gets the max number of logic frame per render frame " } ,
{ " setMaxLogicFrame " , ( PyCFunction ) gPySetMaxLogicFrame , METH_VARARGS , ( const char * ) " Sets the max number of logic frame per render frame " } ,
{ " getMaxPhysicsFrame " , ( PyCFunction ) gPyGetMaxPhysicsFrame , METH_NOARGS , ( const char * ) " Gets the max number of physics frame per render frame " } ,
{ " setMaxPhysicsFrame " , ( PyCFunction ) gPySetMaxPhysicsFrame , METH_VARARGS , ( const char * ) " Sets the max number of physics farme per render frame " } ,
{ " getLogicTicRate " , ( PyCFunction ) gPyGetLogicTicRate , METH_NOARGS , ( const char * ) " Gets the logic tic rate " } ,
{ " setLogicTicRate " , ( PyCFunction ) gPySetLogicTicRate , METH_VARARGS , ( const char * ) " Sets the logic tic rate " } ,
{ " getPhysicsTicRate " , ( PyCFunction ) gPyGetPhysicsTicRate , METH_NOARGS , ( const char * ) " Gets the physics tic rate " } ,
{ " setPhysicsTicRate " , ( PyCFunction ) gPySetPhysicsTicRate , METH_VARARGS , ( const char * ) " Sets the physics tic rate " } ,
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
{ " getExitKey " , ( PyCFunction ) gPyGetExitKey , METH_NOARGS , ( const char * ) " Gets the key used to exit the game engine " } ,
{ " setExitKey " , ( PyCFunction ) gPySetExitKey , METH_VARARGS , ( const char * ) " Sets the key used to exit the game engine " } ,
2009-08-10 00:07:34 +00:00
{ " getAverageFrameRate " , ( PyCFunction ) gPyGetAverageFrameRate , METH_NOARGS , ( const char * ) " Gets the estimated average frame rate " } ,
{ " getBlendFileList " , ( PyCFunction ) gPyGetBlendFileList , METH_VARARGS , ( const char * ) " Gets a list of blend files in the same directory as the current blend file " } ,
{ " PrintGLInfo " , ( PyCFunction ) pyPrintExt , METH_NOARGS , ( const char * ) " Prints GL Extension Info " } ,
2011-11-04 04:27:46 +00:00
{ " PrintMemInfo " , ( PyCFunction ) pyPrintStats , METH_NOARGS , ( const char * ) " Print engine statistics " } ,
2012-09-01 21:23:05 +00:00
{ " NextFrame " , ( PyCFunction ) gPyNextFrame , METH_NOARGS , ( const char * ) " Render next frame (if Python has control) " } ,
2013-03-19 04:51:37 +00:00
{ " getProfileInfo " , ( PyCFunction ) gPyGetProfileInfo , METH_NOARGS , gPyGetProfileInfo_doc } ,
2009-11-15 23:58:56 +00:00
/* library functions */
2011-03-22 02:39:08 +00:00
{ " LibLoad " , ( PyCFunction ) gLibLoad , METH_VARARGS | METH_KEYWORDS , ( const char * ) " " } ,
2009-11-15 23:58:56 +00:00
{ " LibNew " , ( PyCFunction ) gLibNew , METH_VARARGS , ( const char * ) " " } ,
{ " LibFree " , ( PyCFunction ) gLibFree , METH_VARARGS , ( const char * ) " " } ,
{ " LibList " , ( PyCFunction ) gLibList , METH_VARARGS , ( const char * ) " " } ,
2002-10-12 11:37:38 +00:00
{ NULL , ( PyCFunction ) NULL , 0 , NULL }
} ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetWindowHeight ( PyObject * , PyObject * args )
2002-10-12 11:37:38 +00:00
{
2012-11-21 02:28:36 +00:00
return PyLong_FromLong ( ( gp_Canvas ? gp_Canvas - > GetHeight ( ) : 0 ) ) ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetWindowWidth ( PyObject * , PyObject * args )
2002-10-12 11:37:38 +00:00
{
2012-11-21 02:28:36 +00:00
return PyLong_FromLong ( ( gp_Canvas ? gp_Canvas - > GetWidth ( ) : 0 ) ) ;
2002-10-12 11:37:38 +00:00
}
// temporarility visibility thing, will be moved to rasterizer/renderer later
bool gUseVisibilityTemp = false ;
2012-09-16 04:58:18 +00:00
static PyObject * gPyEnableVisibility ( PyObject * , PyObject * args )
2002-10-12 11:37:38 +00:00
{
int visible ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " i:enableVisibility " , & visible ) )
2008-07-01 16:43:46 +00:00
return NULL ;
2008-09-05 02:53:12 +00:00
gUseVisibilityTemp = ( visible ! = 0 ) ;
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyShowMouse ( PyObject * , PyObject * args )
2002-10-12 11:37:38 +00:00
{
int visible ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " i:showMouse " , & visible ) )
2008-07-01 16:43:46 +00:00
return NULL ;
2008-09-05 02:53:12 +00:00
if ( visible )
2002-10-12 11:37:38 +00:00
{
2008-09-05 02:53:12 +00:00
if ( gp_Canvas )
gp_Canvas - > SetMouseState ( RAS_ICanvas : : MOUSE_NORMAL ) ;
} else
{
if ( gp_Canvas )
gp_Canvas - > SetMouseState ( RAS_ICanvas : : MOUSE_INVISIBLE ) ;
2002-10-12 11:37:38 +00:00
}
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetMousePosition ( PyObject * , PyObject * args )
2002-10-12 11:37:38 +00:00
{
int x , y ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " ii:setMousePosition " , & x , & y ) )
2008-07-01 16:43:46 +00:00
return NULL ;
2002-10-12 11:37:38 +00:00
2008-09-05 02:53:12 +00:00
if ( gp_Canvas )
gp_Canvas - > SetMousePosition ( x , y ) ;
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetEyeSeparation ( PyObject * , PyObject * args )
2004-10-24 11:03:18 +00:00
{
float sep ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " f:setEyeSeparation " , & sep ) )
2008-09-05 02:53:12 +00:00
return NULL ;
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.setEyeSeparation(float), Rasterizer not available " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
2004-10-24 11:03:18 +00:00
}
2008-09-05 02:53:12 +00:00
gp_Rasterizer - > SetEyeSeparation ( sep ) ;
Py_RETURN_NONE ;
2004-10-24 11:03:18 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetEyeSeparation ( PyObject * )
2004-10-24 11:03:18 +00:00
{
2008-09-05 02:53:12 +00:00
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.getEyeSeparation(), Rasterizer not available " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
}
2004-10-24 11:03:18 +00:00
2008-09-05 02:53:12 +00:00
return PyFloat_FromDouble ( gp_Rasterizer - > GetEyeSeparation ( ) ) ;
2004-10-24 11:03:18 +00:00
}
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPySetFocalLength ( PyObject * , PyObject * args )
2004-10-24 11:03:18 +00:00
{
float focus ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " f:setFocalLength " , & focus ) )
2008-09-05 02:53:12 +00:00
return NULL ;
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.setFocalLength(float), Rasterizer not available " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
2004-10-24 11:03:18 +00:00
}
2008-09-05 02:53:12 +00:00
gp_Rasterizer - > SetFocalLength ( focus ) ;
2004-10-24 11:03:18 +00:00
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
2004-10-24 11:03:18 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetFocalLength ( PyObject * , PyObject * , PyObject * )
2004-10-24 11:03:18 +00:00
{
2008-09-05 02:53:12 +00:00
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.getFocalLength(), Rasterizer not available " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
}
return PyFloat_FromDouble ( gp_Rasterizer - > GetFocalLength ( ) ) ;
Py_RETURN_NONE ;
2004-10-24 11:03:18 +00:00
}
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPySetBackgroundColor ( PyObject * , PyObject * value )
2002-10-12 11:37:38 +00:00
{
2009-02-23 06:41:10 +00:00
MT_Vector4 vec ;
if ( ! PyVecTo ( value , vec ) )
2008-09-05 02:53:12 +00:00
return NULL ;
if ( gp_Canvas )
2002-10-12 11:37:38 +00:00
{
2011-04-10 09:37:04 +00:00
gp_Rasterizer - > SetBackColor ( ( float ) vec [ 0 ] , ( float ) vec [ 1 ] , ( float ) vec [ 2 ] , ( float ) vec [ 3 ] ) ;
2002-10-12 11:37:38 +00:00
}
2011-01-18 22:27:18 +00:00
KX_WorldInfo * wi = gp_KetsjiScene - > GetWorldInfo ( ) ;
if ( wi - > hasWorld ( ) )
2011-04-10 09:37:04 +00:00
wi - > setBackColor ( ( float ) vec [ 0 ] , ( float ) vec [ 1 ] , ( float ) vec [ 2 ] ) ;
2011-01-18 22:27:18 +00:00
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetMistColor ( PyObject * , PyObject * value )
2002-10-12 11:37:38 +00:00
{
2009-02-23 06:41:10 +00:00
MT_Vector3 vec ;
if ( ! PyVecTo ( value , vec ) )
2008-09-05 02:53:12 +00:00
return NULL ;
2004-07-17 05:28:23 +00:00
2008-09-05 02:53:12 +00:00
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.setMistColor(color), Rasterizer not available " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
2012-09-16 04:58:18 +00:00
}
2011-04-10 09:37:04 +00:00
gp_Rasterizer - > SetFogColor ( ( float ) vec [ 0 ] , ( float ) vec [ 1 ] , ( float ) vec [ 2 ] ) ;
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyDisableMist ( PyObject * )
2009-06-08 20:08:19 +00:00
{
if ( ! gp_Rasterizer ) {
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.setMistColor(color), Rasterizer not available " ) ;
return NULL ;
2012-09-16 04:58:18 +00:00
}
2009-06-08 20:08:19 +00:00
gp_Rasterizer - > DisableFog ( ) ;
Py_RETURN_NONE ;
}
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPySetMistStart ( PyObject * , PyObject * args )
2002-10-12 11:37:38 +00:00
{
float miststart ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " f:setMistStart " , & miststart ) )
2008-09-05 02:53:12 +00:00
return NULL ;
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.setMistStart(float), Rasterizer not available " ) ;
2008-07-01 16:43:46 +00:00
return NULL ;
2002-10-12 11:37:38 +00:00
}
2008-09-05 02:53:12 +00:00
gp_Rasterizer - > SetFogStart ( miststart ) ;
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetMistEnd ( PyObject * , PyObject * args )
2002-10-12 11:37:38 +00:00
{
float mistend ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " f:setMistEnd " , & mistend ) )
2008-09-05 02:53:12 +00:00
return NULL ;
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.setMistEnd(float), Rasterizer not available " ) ;
2008-07-01 16:43:46 +00:00
return NULL ;
2002-10-12 11:37:38 +00:00
}
2008-09-05 02:53:12 +00:00
gp_Rasterizer - > SetFogEnd ( mistend ) ;
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetAmbientColor ( PyObject * , PyObject * value )
2006-01-06 03:46:54 +00:00
{
2009-02-23 06:41:10 +00:00
MT_Vector3 vec ;
if ( ! PyVecTo ( value , vec ) )
2008-09-05 02:53:12 +00:00
return NULL ;
2006-01-06 03:46:54 +00:00
2008-09-05 02:53:12 +00:00
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.setAmbientColor(color), Rasterizer not available " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
2012-09-16 04:58:18 +00:00
}
2011-04-10 09:37:04 +00:00
gp_Rasterizer - > SetAmbientColor ( ( float ) vec [ 0 ] , ( float ) vec [ 1 ] , ( float ) vec [ 2 ] ) ;
2006-01-06 03:46:54 +00:00
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
2006-01-06 03:46:54 +00:00
}
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPyMakeScreenshot ( PyObject * , PyObject * args )
2002-10-12 11:37:38 +00:00
{
char * filename ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " s:makeScreenshot " , & filename ) )
2008-07-01 16:43:46 +00:00
return NULL ;
2008-09-05 02:53:12 +00:00
if ( gp_Canvas )
2002-10-12 11:37:38 +00:00
{
2008-09-05 02:53:12 +00:00
gp_Canvas - > MakeScreenShot ( filename ) ;
2002-10-12 11:37:38 +00:00
}
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyEnableMotionBlur ( PyObject * , PyObject * args )
2007-09-29 18:51:01 +00:00
{
float motionblurvalue ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " f:enableMotionBlur " , & motionblurvalue ) )
2008-09-05 02:53:12 +00:00
return NULL ;
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.enableMotionBlur(float), Rasterizer not available " ) ;
2008-07-01 16:43:46 +00:00
return NULL ;
}
2008-09-05 02:53:12 +00:00
gp_Rasterizer - > EnableMotionBlur ( motionblurvalue ) ;
Py_RETURN_NONE ;
2007-09-29 18:51:01 +00:00
}
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPyDisableMotionBlur ( PyObject * )
2007-09-29 18:51:01 +00:00
{
2008-09-05 02:53:12 +00:00
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.disableMotionBlur(), Rasterizer not available " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
2007-09-29 18:51:01 +00:00
}
2008-09-05 02:53:12 +00:00
gp_Rasterizer - > DisableMotionBlur ( ) ;
Py_RETURN_NONE ;
2007-09-29 18:51:01 +00:00
}
2002-10-12 11:37:38 +00:00
2011-10-27 14:41:26 +00:00
static int getGLSLSettingFlag ( const char * setting )
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
{
2012-03-24 07:52:14 +00:00
if ( strcmp ( setting , " lights " ) = = 0 )
2009-08-18 15:27:48 +00:00
return GAME_GLSL_NO_LIGHTS ;
2012-03-24 07:52:14 +00:00
else if ( strcmp ( setting , " shaders " ) = = 0 )
2009-08-18 15:27:48 +00:00
return GAME_GLSL_NO_SHADERS ;
2012-03-24 07:52:14 +00:00
else if ( strcmp ( setting , " shadows " ) = = 0 )
2009-08-18 15:27:48 +00:00
return GAME_GLSL_NO_SHADOWS ;
2012-03-24 07:52:14 +00:00
else if ( strcmp ( setting , " ramps " ) = = 0 )
2009-08-18 15:27:48 +00:00
return GAME_GLSL_NO_RAMPS ;
2012-03-24 07:52:14 +00:00
else if ( strcmp ( setting , " nodes " ) = = 0 )
2009-08-18 15:27:48 +00:00
return GAME_GLSL_NO_NODES ;
2012-03-24 07:52:14 +00:00
else if ( strcmp ( setting , " extra_textures " ) = = 0 )
2009-08-18 15:27:48 +00:00
return GAME_GLSL_NO_EXTRA_TEX ;
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
else
return - 1 ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetGLSLMaterialSetting ( PyObject * ,
PyObject * args ,
PyObject * )
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
{
2011-09-11 05:54:07 +00:00
GlobalSettings * gs = gp_KetsjiEngine - > GetGlobalSettings ( ) ;
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
char * setting ;
2009-08-18 15:27:48 +00:00
int enable , flag , sceneflag ;
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " si:setGLSLMaterialSetting " , & setting , & enable ) )
2008-09-05 02:53:12 +00:00
return NULL ;
flag = getGLSLSettingFlag ( setting ) ;
2012-06-27 05:59:41 +00:00
if ( flag = = - 1 ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_ValueError , " Rasterizer.setGLSLMaterialSetting(string): glsl setting is not known " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
}
2008-09-13 19:19:51 +00:00
2011-09-11 05:54:07 +00:00
sceneflag = gs - > glslflag ;
2008-09-05 02:53:12 +00:00
if ( enable )
2011-09-11 05:54:07 +00:00
gs - > glslflag & = ~ flag ;
2008-09-05 02:53:12 +00:00
else
2011-09-11 05:54:07 +00:00
gs - > glslflag | = flag ;
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
2013-05-08 21:43:35 +00:00
/* temporarily store the glsl settings in the scene for the GLSL materials */
GameData * gm = & ( gp_KetsjiScene - > GetBlenderScene ( ) - > gm ) ;
gm - > flag = gs - > glslflag ;
2008-09-05 02:53:12 +00:00
/* display lists and GLSL materials need to be remade */
2012-03-24 07:52:14 +00:00
if ( sceneflag ! = gs - > glslflag ) {
2009-06-08 20:08:19 +00:00
GPU_materials_free ( ) ;
2012-03-24 07:52:14 +00:00
if ( gp_KetsjiEngine ) {
2008-09-13 19:19:51 +00:00
KX_SceneList * scenes = gp_KetsjiEngine - > CurrentScenes ( ) ;
KX_SceneList : : iterator it ;
2012-03-24 07:52:14 +00:00
for ( it = scenes - > begin ( ) ; it ! = scenes - > end ( ) ; it + + )
if ( ( * it ) - > GetBucketManager ( ) ) {
2008-09-13 19:19:51 +00:00
( * it ) - > GetBucketManager ( ) - > ReleaseDisplayLists ( ) ;
2009-06-08 20:08:19 +00:00
( * it ) - > GetBucketManager ( ) - > ReleaseMaterials ( ) ;
}
2007-09-29 18:51:01 +00:00
}
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
}
2008-09-05 02:53:12 +00:00
Py_RETURN_NONE ;
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetGLSLMaterialSetting ( PyObject * ,
PyObject * args ,
PyObject * )
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
{
2011-09-11 05:54:07 +00:00
GlobalSettings * gs = gp_KetsjiEngine - > GetGlobalSettings ( ) ;
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
char * setting ;
int enabled = 0 , flag ;
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " s:getGLSLMaterialSetting " , & setting ) )
2008-09-05 02:53:12 +00:00
return NULL ;
flag = getGLSLSettingFlag ( setting ) ;
2012-06-27 05:59:41 +00:00
if ( flag = = - 1 ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_ValueError , " Rasterizer.getGLSLMaterialSetting(string): glsl setting is not known " ) ;
2008-09-05 02:53:12 +00:00
return NULL ;
2007-09-29 18:51:01 +00:00
}
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
2011-09-11 05:54:07 +00:00
enabled = ( ( gs - > glslflag & flag ) ! = 0 ) ;
2012-11-21 02:28:36 +00:00
return PyLong_FromLong ( enabled ) ;
2007-09-29 18:51:01 +00:00
}
2002-10-12 11:37:38 +00:00
2008-09-13 19:19:51 +00:00
# define KX_BLENDER_MULTITEX_MATERIAL 1
# define KX_BLENDER_GLSL_MATERIAL 2
2012-09-16 04:58:18 +00:00
static PyObject * gPySetMaterialType ( PyObject * ,
PyObject * args ,
PyObject * )
2007-09-29 18:51:01 +00:00
{
2011-09-11 05:54:07 +00:00
GlobalSettings * gs = gp_KetsjiEngine - > GetGlobalSettings ( ) ;
2009-08-18 15:27:48 +00:00
int type ;
2008-09-13 19:19:51 +00:00
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " i:setMaterialType " , & type ) )
2008-09-13 19:19:51 +00:00
return NULL ;
2012-03-24 07:52:14 +00:00
if ( type = = KX_BLENDER_GLSL_MATERIAL )
2011-09-11 05:54:07 +00:00
gs - > matmode = GAME_MAT_GLSL ;
2012-03-24 07:52:14 +00:00
else if ( type = = KX_BLENDER_MULTITEX_MATERIAL )
2011-09-11 05:54:07 +00:00
gs - > matmode = GAME_MAT_MULTITEX ;
2008-09-13 19:19:51 +00:00
else {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_ValueError , " Rasterizer.setMaterialType(int): material type is not known " ) ;
2008-09-13 19:19:51 +00:00
return NULL ;
2007-09-29 18:51:01 +00:00
}
2008-09-13 19:19:51 +00:00
Py_RETURN_NONE ;
2007-09-29 18:51:01 +00:00
}
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetMaterialType ( PyObject * )
2008-09-13 19:19:51 +00:00
{
2011-09-11 05:54:07 +00:00
GlobalSettings * gs = gp_KetsjiEngine - > GetGlobalSettings ( ) ;
2008-09-13 19:19:51 +00:00
int flag ;
2012-03-24 07:52:14 +00:00
if ( gs - > matmode = = GAME_MAT_GLSL )
2008-09-13 19:19:51 +00:00
flag = KX_BLENDER_GLSL_MATERIAL ;
else
2013-11-04 19:21:50 +00:00
flag = KX_BLENDER_MULTITEX_MATERIAL ;
2008-09-13 19:19:51 +00:00
2012-11-21 02:28:36 +00:00
return PyLong_FromLong ( flag ) ;
2008-09-13 19:19:51 +00:00
}
2012-09-16 04:58:18 +00:00
static PyObject * gPySetAnisotropicFiltering ( PyObject * , PyObject * args )
2011-08-31 05:51:51 +00:00
{
short level ;
if ( ! PyArg_ParseTuple ( args , " h:setAnisotropicFiltering " , & level ) )
return NULL ;
if ( level ! = 1 & & level ! = 2 & & level ! = 4 & & level ! = 8 & & level ! = 16 ) {
PyErr_SetString ( PyExc_ValueError , " Rasterizer.setAnisotropicFiltering(level): Expected value of 1, 2, 4, 8, or 16 for value " ) ;
return NULL ;
}
gp_Rasterizer - > SetAnisotropicFiltering ( level ) ;
Py_RETURN_NONE ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyGetAnisotropicFiltering ( PyObject * , PyObject * args )
2011-08-31 05:51:51 +00:00
{
return PyLong_FromLong ( gp_Rasterizer - > GetAnisotropicFiltering ( ) ) ;
}
2012-09-16 04:58:18 +00:00
static PyObject * gPyDrawLine ( PyObject * , PyObject * args )
2008-09-24 22:58:49 +00:00
{
2012-09-16 04:58:18 +00:00
PyObject * ob_from ;
PyObject * ob_to ;
PyObject * ob_color ;
2008-09-24 22:58:49 +00:00
if ( ! gp_Rasterizer ) {
2009-04-20 15:06:46 +00:00
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.drawLine(obFrom, obTo, color): Rasterizer not available " ) ;
2008-09-24 22:58:49 +00:00
return NULL ;
}
2009-04-20 15:06:46 +00:00
if ( ! PyArg_ParseTuple ( args , " OOO:drawLine " , & ob_from , & ob_to , & ob_color ) )
2008-09-24 22:58:49 +00:00
return NULL ;
2009-02-23 06:41:10 +00:00
MT_Vector3 from ;
MT_Vector3 to ;
MT_Vector3 color ;
2008-09-24 22:58:49 +00:00
if ( ! PyVecTo ( ob_from , from ) )
return NULL ;
if ( ! PyVecTo ( ob_to , to ) )
return NULL ;
if ( ! PyVecTo ( ob_color , color ) )
return NULL ;
gp_Rasterizer - > DrawDebugLine ( from , to , color ) ;
Py_RETURN_NONE ;
}
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPySetWindowSize ( PyObject * , PyObject * args )
2012-01-22 20:25:25 +00:00
{
int width , height ;
if ( ! PyArg_ParseTuple ( args , " ii:resize " , & width , & height ) )
return NULL ;
gp_Canvas - > ResizeWindow ( width , height ) ;
Py_RETURN_NONE ;
}
2013-04-13 21:09:02 +00:00
static PyObject * gPySetFullScreen ( PyObject * , PyObject * value )
{
gp_Canvas - > SetFullScreen ( PyObject_IsTrue ( value ) ) ;
Py_RETURN_NONE ;
}
static PyObject * gPyGetFullScreen ( PyObject * )
{
return PyBool_FromLong ( gp_Canvas - > GetFullScreen ( ) ) ;
}
2013-04-14 00:40:24 +00:00
static PyObject * gPySetMipmapping ( PyObject * , PyObject * args )
{
int val = 0 ;
if ( ! PyArg_ParseTuple ( args , " i:setMipmapping " , & val ) )
return NULL ;
if ( val < 0 | | val > RAS_IRasterizer : : RAS_MIPMAP_MAX ) {
PyErr_SetString ( PyExc_ValueError , " Rasterizer.setMipmapping(val): invalid mipmaping option " ) ;
return NULL ;
}
if ( ! gp_Rasterizer ) {
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.setMipmapping(val): Rasterizer not available " ) ;
return NULL ;
}
gp_Rasterizer - > SetMipmapping ( ( RAS_IRasterizer : : MipmapOption ) val ) ;
Py_RETURN_NONE ;
}
static PyObject * gPyGetMipmapping ( PyObject * )
{
if ( ! gp_Rasterizer ) {
PyErr_SetString ( PyExc_RuntimeError , " Rasterizer.getMipmapping(): Rasterizer not available " ) ;
return NULL ;
}
return PyLong_FromLong ( gp_Rasterizer - > GetMipmapping ( ) ) ;
}
2013-07-29 22:31:32 +00:00
static PyObject * gPySetVsync ( PyObject * , PyObject * args )
{
int interval ;
if ( ! PyArg_ParseTuple ( args , " i:setVsync " , & interval ) )
return NULL ;
2013-08-17 02:06:45 +00:00
if ( interval < 0 | | interval > VSYNC_ADAPTIVE ) {
2013-07-29 22:31:32 +00:00
PyErr_SetString ( PyExc_ValueError , " Rasterizer.setVsync(value): value must be VSYNC_OFF, VSYNC_ON, or VSYNC_ADAPTIVE " ) ;
return NULL ;
}
if ( interval = = VSYNC_ADAPTIVE )
interval = - 1 ;
2013-08-26 08:14:52 +00:00
gp_Canvas - > SetSwapInterval ( ( interval = = VSYNC_ON ) ? 1 : 0 ) ;
2013-07-29 22:31:32 +00:00
Py_RETURN_NONE ;
}
static PyObject * gPyGetVsync ( PyObject * )
{
return PyLong_FromLong ( gp_Canvas - > GetSwapInterval ( ) ) ;
}
2002-10-12 11:37:38 +00:00
static struct PyMethodDef rasterizer_methods [ ] = {
2012-11-03 15:35:03 +00:00
{ " getWindowWidth " , ( PyCFunction ) gPyGetWindowWidth ,
METH_VARARGS , " getWindowWidth doc " } ,
{ " getWindowHeight " , ( PyCFunction ) gPyGetWindowHeight ,
METH_VARARGS , " getWindowHeight doc " } ,
{ " makeScreenshot " , ( PyCFunction ) gPyMakeScreenshot ,
METH_VARARGS , " make Screenshot doc " } ,
{ " enableVisibility " , ( PyCFunction ) gPyEnableVisibility ,
METH_VARARGS , " enableVisibility doc " } ,
2002-10-12 11:37:38 +00:00
{ " showMouse " , ( PyCFunction ) gPyShowMouse ,
2012-11-03 15:35:03 +00:00
METH_VARARGS , " showMouse(bool visible) " } ,
{ " setMousePosition " , ( PyCFunction ) gPySetMousePosition ,
METH_VARARGS , " setMousePosition(int x,int y) " } ,
{ " setBackgroundColor " , ( PyCFunction ) gPySetBackgroundColor , METH_O , " set Background Color (rgb) " } ,
2009-02-23 06:41:10 +00:00
{ " setAmbientColor " , ( PyCFunction ) gPySetAmbientColor , METH_O , " set Ambient Color (rgb) " } ,
2012-11-03 15:35:03 +00:00
{ " disableMist " , ( PyCFunction ) gPyDisableMist , METH_NOARGS , " turn off mist " } ,
{ " setMistColor " , ( PyCFunction ) gPySetMistColor , METH_O , " set Mist Color (rgb) " } ,
{ " setMistStart " , ( PyCFunction ) gPySetMistStart , METH_VARARGS , " set Mist Start(rgb) " } ,
{ " setMistEnd " , ( PyCFunction ) gPySetMistEnd , METH_VARARGS , " set Mist End(rgb) " } ,
{ " enableMotionBlur " , ( PyCFunction ) gPyEnableMotionBlur , METH_VARARGS , " enable motion blur " } ,
{ " disableMotionBlur " , ( PyCFunction ) gPyDisableMotionBlur , METH_NOARGS , " disable motion blur " } ,
{ " setEyeSeparation " , ( PyCFunction ) gPySetEyeSeparation , METH_VARARGS , " set the eye separation for stereo mode " } ,
{ " getEyeSeparation " , ( PyCFunction ) gPyGetEyeSeparation , METH_NOARGS , " get the eye separation for stereo mode " } ,
{ " setFocalLength " , ( PyCFunction ) gPySetFocalLength , METH_VARARGS , " set the focal length for stereo mode " } ,
{ " getFocalLength " , ( PyCFunction ) gPyGetFocalLength , METH_VARARGS , " get the focal length for stereo mode " } ,
{ " setMaterialMode " , ( PyCFunction ) gPySetMaterialType ,
METH_VARARGS , " set the material mode to use for OpenGL rendering " } ,
{ " getMaterialMode " , ( PyCFunction ) gPyGetMaterialType ,
METH_NOARGS , " get the material mode being used for OpenGL rendering " } ,
{ " setGLSLMaterialSetting " , ( PyCFunction ) gPySetGLSLMaterialSetting ,
METH_VARARGS , " set the state of a GLSL material setting " } ,
{ " getGLSLMaterialSetting " , ( PyCFunction ) gPyGetGLSLMaterialSetting ,
METH_VARARGS , " get the state of a GLSL material setting " } ,
{ " setAnisotropicFiltering " , ( PyCFunction ) gPySetAnisotropicFiltering ,
METH_VARARGS , " set the anisotropic filtering level (must be one of 1, 2, 4, 8, 16) " } ,
{ " getAnisotropicFiltering " , ( PyCFunction ) gPyGetAnisotropicFiltering ,
METH_VARARGS , " get the anisotropic filtering level " } ,
{ " drawLine " , ( PyCFunction ) gPyDrawLine ,
METH_VARARGS , " draw a line on the screen " } ,
{ " setWindowSize " , ( PyCFunction ) gPySetWindowSize , METH_VARARGS , " " } ,
2013-04-13 21:09:02 +00:00
{ " setFullScreen " , ( PyCFunction ) gPySetFullScreen , METH_O , " " } ,
{ " getFullScreen " , ( PyCFunction ) gPyGetFullScreen , METH_NOARGS , " " } ,
2013-04-14 00:40:24 +00:00
{ " setMipmapping " , ( PyCFunction ) gPySetMipmapping , METH_VARARGS , " " } ,
{ " getMipmapping " , ( PyCFunction ) gPyGetMipmapping , METH_NOARGS , " " } ,
2013-07-29 22:31:32 +00:00
{ " setVsync " , ( PyCFunction ) gPySetVsync , METH_VARARGS , " " } ,
{ " getVsync " , ( PyCFunction ) gPyGetVsync , METH_NOARGS , " " } ,
2012-11-03 15:35:03 +00:00
{ NULL , ( PyCFunction ) NULL , 0 , NULL }
2002-10-12 11:37:38 +00:00
} ;
// Initialization function for the module (*must* be called initGameLogic)
static char GameLogic_module_documentation [ ] =
2010-08-11 12:14:16 +00:00
" This is the Python API for the game engine of bge.logic "
2002-10-12 11:37:38 +00:00
;
static char Rasterizer_module_documentation [ ] =
" This is the Python API for the game engine of Rasterizer "
;
2009-06-08 20:08:19 +00:00
static struct PyModuleDef GameLogic_module_def = {
{ } , /* m_base */
" GameLogic " , /* m_name */
GameLogic_module_documentation , /* m_doc */
0 , /* m_size */
game_methods , /* m_methods */
0 , /* m_reload */
0 , /* m_traverse */
0 , /* m_clear */
0 , /* m_free */
} ;
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
PyObject * initGameLogic ( KX_KetsjiEngine * engine , KX_Scene * scene ) // quick hack to get gravity hook
2002-10-12 11:37:38 +00:00
{
2012-09-16 04:58:18 +00:00
PyObject * m ;
PyObject * d ;
PyObject * item ; /* temp PyObject *storage */
2009-04-20 15:06:46 +00:00
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
gp_KetsjiEngine = engine ;
2002-10-12 11:37:38 +00:00
gp_KetsjiScene = scene ;
gUseVisibilityTemp = false ;
2009-06-08 20:08:19 +00:00
PyObjectPlus : : ClearDeprecationWarning ( ) ; /* Not that nice to call here but makes sure warnings are reset between loading scenes */
/* Use existing module where possible
* be careful not to init any runtime vars after this */
m = PyImport_ImportModule ( " GameLogic " ) ;
2012-03-24 07:52:14 +00:00
if ( m ) {
2009-06-08 20:08:19 +00:00
Py_DECREF ( m ) ;
return m ;
}
else {
PyErr_Clear ( ) ;
2012-09-16 04:58:18 +00:00
// Create the module and add the functions
2009-06-08 20:08:19 +00:00
m = PyModule_Create ( & GameLogic_module_def ) ;
2009-06-16 07:16:51 +00:00
PyDict_SetItemString ( PySys_GetObject ( " modules " ) , GameLogic_module_def . m_name , m ) ;
2009-06-08 20:08:19 +00:00
}
2002-10-12 11:37:38 +00:00
// Add some symbolic constants to the module
d = PyModule_GetDict ( m ) ;
2008-08-19 11:53:24 +00:00
// can be overwritten later for gameEngine instances that can load new blend files and re-initialize this module
// for now its safe to make sure it exists for other areas such as the web plugin
2009-04-20 15:06:46 +00:00
PyDict_SetItemString ( d , " globalDict " , item = PyDict_New ( ) ) ; Py_DECREF ( item ) ;
2002-10-12 11:37:38 +00:00
2010-04-17 06:52:14 +00:00
// Add keyboard and mouse attributes to this module
2010-10-09 01:31:20 +00:00
MT_assert ( ! gp_PythonKeyboard ) ;
gp_PythonKeyboard = new SCA_PythonKeyboard ( gp_KetsjiEngine - > GetKeyboardDevice ( ) ) ;
PyDict_SetItemString ( d , " keyboard " , gp_PythonKeyboard - > NewProxy ( true ) ) ;
2010-04-17 06:52:14 +00:00
2010-10-09 01:31:20 +00:00
MT_assert ( ! gp_PythonMouse ) ;
gp_PythonMouse = new SCA_PythonMouse ( gp_KetsjiEngine - > GetMouseDevice ( ) , gp_Canvas ) ;
PyDict_SetItemString ( d , " mouse " , gp_PythonMouse - > NewProxy ( true ) ) ;
2010-04-17 06:52:14 +00:00
2012-12-21 02:28:59 +00:00
PyObject * joylist = PyList_New ( JOYINDEX_MAX ) ;
for ( int i = 0 ; i < JOYINDEX_MAX ; + + i ) {
2013-01-12 05:44:08 +00:00
SCA_Joystick * joy = SCA_Joystick : : GetInstance ( i ) ;
2012-12-21 02:28:59 +00:00
if ( joy & & joy - > Connected ( ) ) {
gp_PythonJoysticks [ i ] = new SCA_PythonJoystick ( joy ) ;
PyObject * tmp = gp_PythonJoysticks [ i ] - > NewProxy ( true ) ;
Py_INCREF ( tmp ) ;
PyList_SET_ITEM ( joylist , i , tmp ) ;
} else {
2013-01-12 05:44:08 +00:00
joy - > ReleaseInstance ( ) ;
2012-12-21 02:28:59 +00:00
Py_INCREF ( Py_None ) ;
PyList_SET_ITEM ( joylist , i , Py_None ) ;
}
}
PyDict_SetItemString ( d , " joysticks " , joylist ) ;
2009-06-29 02:25:54 +00:00
ErrorObject = PyUnicode_FromString ( " GameLogic.error " ) ;
2002-10-12 11:37:38 +00:00
PyDict_SetItemString ( d , " error " , ErrorObject ) ;
2009-04-20 15:06:46 +00:00
Py_DECREF ( ErrorObject ) ;
2008-08-05 09:35:46 +00:00
2002-10-12 11:37:38 +00:00
// XXXX Add constants here
/* To use logic bricks, we need some sort of constants. Here, we associate */
/* constants and sumbolic names. Add them to dictionary d. */
/* 1. true and false: needed for everyone */
KX_MACRO_addTypesToDict ( d , KX_TRUE , SCA_ILogicBrick : : KX_TRUE ) ;
KX_MACRO_addTypesToDict ( d , KX_FALSE , SCA_ILogicBrick : : KX_FALSE ) ;
/* 2. Property sensor */
KX_MACRO_addTypesToDict ( d , KX_PROPSENSOR_EQUAL , SCA_PropertySensor : : KX_PROPSENSOR_EQUAL ) ;
KX_MACRO_addTypesToDict ( d , KX_PROPSENSOR_NOTEQUAL , SCA_PropertySensor : : KX_PROPSENSOR_NOTEQUAL ) ;
KX_MACRO_addTypesToDict ( d , KX_PROPSENSOR_INTERVAL , SCA_PropertySensor : : KX_PROPSENSOR_INTERVAL ) ;
KX_MACRO_addTypesToDict ( d , KX_PROPSENSOR_CHANGED , SCA_PropertySensor : : KX_PROPSENSOR_CHANGED ) ;
KX_MACRO_addTypesToDict ( d , KX_PROPSENSOR_EXPRESSION , SCA_PropertySensor : : KX_PROPSENSOR_EXPRESSION ) ;
/* 3. Constraint actuator */
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_LOCX , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_LOCX ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_LOCY , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_LOCY ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_LOCZ , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_LOCZ ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_ROTX , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_ROTX ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_ROTY , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_ROTY ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_ROTZ , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_ROTZ ) ;
2008-07-23 21:37:37 +00:00
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_DIRPX , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_DIRPX ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_DIRPY , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_DIRPY ) ;
2010-06-02 21:28:17 +00:00
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_DIRPZ , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_DIRPZ ) ;
2008-07-23 21:37:37 +00:00
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_DIRNX , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_DIRNX ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_DIRNY , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_DIRNY ) ;
2010-06-02 21:28:17 +00:00
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_DIRNZ , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_DIRNZ ) ;
2008-07-23 21:37:37 +00:00
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_ORIX , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_ORIX ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_ORIY , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_ORIY ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_ORIZ , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_ORIZ ) ;
2010-07-21 09:46:24 +00:00
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_FHPX , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_FHPX ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_FHPY , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_FHPY ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_FHPZ , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_FHPZ ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_FHNX , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_FHNX ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_FHNY , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_FHNY ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_FHNZ , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_FHNZ ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_NORMAL , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_NORMAL ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_MATERIAL , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_MATERIAL ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_PERMANENT , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_PERMANENT ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_DISTANCE , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_DISTANCE ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_LOCAL , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_LOCAL ) ;
KX_MACRO_addTypesToDict ( d , KX_CONSTRAINTACT_DOROTFH , KX_ConstraintActuator : : KX_ACT_CONSTRAINT_DOROTFH ) ;
2002-10-12 11:37:38 +00:00
2012-01-30 06:47:01 +00:00
/* 4. Random distribution types */
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_BOOL_CONST , SCA_RandomActuator : : KX_RANDOMACT_BOOL_CONST ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_BOOL_UNIFORM , SCA_RandomActuator : : KX_RANDOMACT_BOOL_UNIFORM ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_BOOL_BERNOUILLI , SCA_RandomActuator : : KX_RANDOMACT_BOOL_BERNOUILLI ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_INT_CONST , SCA_RandomActuator : : KX_RANDOMACT_INT_CONST ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_INT_UNIFORM , SCA_RandomActuator : : KX_RANDOMACT_INT_UNIFORM ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_INT_POISSON , SCA_RandomActuator : : KX_RANDOMACT_INT_POISSON ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_FLOAT_CONST , SCA_RandomActuator : : KX_RANDOMACT_FLOAT_CONST ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_FLOAT_UNIFORM , SCA_RandomActuator : : KX_RANDOMACT_FLOAT_UNIFORM ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_FLOAT_NORMAL , SCA_RandomActuator : : KX_RANDOMACT_FLOAT_NORMAL ) ;
KX_MACRO_addTypesToDict ( d , KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL , SCA_RandomActuator : : KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL ) ;
2012-01-30 06:47:01 +00:00
/* 5. Sound actuator */
2004-07-17 05:28:23 +00:00
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_PLAYSTOP , KX_SoundActuator : : KX_SOUNDACT_PLAYSTOP ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_PLAYEND , KX_SoundActuator : : KX_SOUNDACT_PLAYEND ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_LOOPSTOP , KX_SoundActuator : : KX_SOUNDACT_LOOPSTOP ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_LOOPEND , KX_SoundActuator : : KX_SOUNDACT_LOOPEND ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_LOOPBIDIRECTIONAL , KX_SoundActuator : : KX_SOUNDACT_LOOPBIDIRECTIONAL ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP , KX_SoundActuator : : KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP ) ;
2012-01-30 06:47:01 +00:00
/* 6. Action actuator */
2009-01-26 08:34:40 +00:00
KX_MACRO_addTypesToDict ( d , KX_ACTIONACT_PLAY , ACT_ACTION_PLAY ) ;
2011-02-16 19:53:39 +00:00
KX_MACRO_addTypesToDict ( d , KX_ACTIONACT_PINGPONG , ACT_ACTION_PINGPONG ) ;
2009-01-26 08:34:40 +00:00
KX_MACRO_addTypesToDict ( d , KX_ACTIONACT_FLIPPER , ACT_ACTION_FLIPPER ) ;
KX_MACRO_addTypesToDict ( d , KX_ACTIONACT_LOOPSTOP , ACT_ACTION_LOOP_STOP ) ;
KX_MACRO_addTypesToDict ( d , KX_ACTIONACT_LOOPEND , ACT_ACTION_LOOP_END ) ;
KX_MACRO_addTypesToDict ( d , KX_ACTIONACT_PROPERTY , ACT_ACTION_FROM_PROP ) ;
2004-07-17 05:28:23 +00:00
2012-01-30 06:47:01 +00:00
/* 7. GL_BlendFunc */
2006-01-15 11:34:55 +00:00
KX_MACRO_addTypesToDict ( d , BL_ZERO , GL_ZERO ) ;
KX_MACRO_addTypesToDict ( d , BL_ONE , GL_ONE ) ;
KX_MACRO_addTypesToDict ( d , BL_SRC_COLOR , GL_SRC_COLOR ) ;
KX_MACRO_addTypesToDict ( d , BL_ONE_MINUS_SRC_COLOR , GL_ONE_MINUS_SRC_COLOR ) ;
KX_MACRO_addTypesToDict ( d , BL_DST_COLOR , GL_DST_COLOR ) ;
KX_MACRO_addTypesToDict ( d , BL_ONE_MINUS_DST_COLOR , GL_ONE_MINUS_DST_COLOR ) ;
KX_MACRO_addTypesToDict ( d , BL_SRC_ALPHA , GL_SRC_ALPHA ) ;
KX_MACRO_addTypesToDict ( d , BL_ONE_MINUS_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA ) ;
KX_MACRO_addTypesToDict ( d , BL_DST_ALPHA , GL_DST_ALPHA ) ;
KX_MACRO_addTypesToDict ( d , BL_ONE_MINUS_DST_ALPHA , GL_ONE_MINUS_DST_ALPHA ) ;
KX_MACRO_addTypesToDict ( d , BL_SRC_ALPHA_SATURATE , GL_SRC_ALPHA_SATURATE ) ;
2006-02-13 05:45:32 +00:00
2012-01-30 06:47:01 +00:00
/* 8. UniformTypes */
2006-02-13 05:45:32 +00:00
KX_MACRO_addTypesToDict ( d , SHD_TANGENT , BL_Shader : : SHD_TANGENT ) ;
KX_MACRO_addTypesToDict ( d , MODELVIEWMATRIX , BL_Shader : : MODELVIEWMATRIX ) ;
KX_MACRO_addTypesToDict ( d , MODELVIEWMATRIX_TRANSPOSE , BL_Shader : : MODELVIEWMATRIX_TRANSPOSE ) ;
KX_MACRO_addTypesToDict ( d , MODELVIEWMATRIX_INVERSE , BL_Shader : : MODELVIEWMATRIX_INVERSE ) ;
KX_MACRO_addTypesToDict ( d , MODELVIEWMATRIX_INVERSETRANSPOSE , BL_Shader : : MODELVIEWMATRIX_INVERSETRANSPOSE ) ;
KX_MACRO_addTypesToDict ( d , MODELMATRIX , BL_Shader : : MODELMATRIX ) ;
KX_MACRO_addTypesToDict ( d , MODELMATRIX_TRANSPOSE , BL_Shader : : MODELMATRIX_TRANSPOSE ) ;
KX_MACRO_addTypesToDict ( d , MODELMATRIX_INVERSE , BL_Shader : : MODELMATRIX_INVERSE ) ;
KX_MACRO_addTypesToDict ( d , MODELMATRIX_INVERSETRANSPOSE , BL_Shader : : MODELMATRIX_INVERSETRANSPOSE ) ;
KX_MACRO_addTypesToDict ( d , VIEWMATRIX , BL_Shader : : VIEWMATRIX ) ;
KX_MACRO_addTypesToDict ( d , VIEWMATRIX_TRANSPOSE , BL_Shader : : VIEWMATRIX_TRANSPOSE ) ;
KX_MACRO_addTypesToDict ( d , VIEWMATRIX_INVERSE , BL_Shader : : VIEWMATRIX_INVERSE ) ;
KX_MACRO_addTypesToDict ( d , VIEWMATRIX_INVERSETRANSPOSE , BL_Shader : : VIEWMATRIX_INVERSETRANSPOSE ) ;
KX_MACRO_addTypesToDict ( d , CAM_POS , BL_Shader : : CAM_POS ) ;
2006-04-02 21:04:20 +00:00
KX_MACRO_addTypesToDict ( d , CONSTANT_TIMER , BL_Shader : : CONSTANT_TIMER ) ;
2006-02-13 05:45:32 +00:00
2012-01-30 06:47:01 +00:00
/* 9. state actuator */
2008-09-22 19:54:30 +00:00
KX_MACRO_addTypesToDict ( d , KX_STATE1 , ( 1 < < 0 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE2 , ( 1 < < 1 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE3 , ( 1 < < 2 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE4 , ( 1 < < 3 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE5 , ( 1 < < 4 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE6 , ( 1 < < 5 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE7 , ( 1 < < 6 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE8 , ( 1 < < 7 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE9 , ( 1 < < 8 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE10 , ( 1 < < 9 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE11 , ( 1 < < 10 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE12 , ( 1 < < 11 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE13 , ( 1 < < 12 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE14 , ( 1 < < 13 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE15 , ( 1 < < 14 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE16 , ( 1 < < 15 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE17 , ( 1 < < 16 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE18 , ( 1 < < 17 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE19 , ( 1 < < 18 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE20 , ( 1 < < 19 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE21 , ( 1 < < 20 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE22 , ( 1 < < 21 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE23 , ( 1 < < 22 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE24 , ( 1 < < 23 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE25 , ( 1 < < 24 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE26 , ( 1 < < 25 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE27 , ( 1 < < 26 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE28 , ( 1 < < 27 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE29 , ( 1 < < 28 ) ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE30 , ( 1 < < 29 ) ) ;
2010-01-30 18:53:33 +00:00
/* All Sensors */
KX_MACRO_addTypesToDict ( d , KX_SENSOR_JUST_ACTIVATED , SCA_ISensor : : KX_SENSOR_JUST_ACTIVATED ) ;
KX_MACRO_addTypesToDict ( d , KX_SENSOR_ACTIVE , SCA_ISensor : : KX_SENSOR_ACTIVE ) ;
KX_MACRO_addTypesToDict ( d , KX_SENSOR_JUST_DEACTIVATED , SCA_ISensor : : KX_SENSOR_JUST_DEACTIVATED ) ;
KX_MACRO_addTypesToDict ( d , KX_SENSOR_INACTIVE , SCA_ISensor : : KX_SENSOR_INACTIVE ) ;
2009-02-28 21:00:27 +00:00
/* Radar Sensor */
KX_MACRO_addTypesToDict ( d , KX_RADAR_AXIS_POS_X , KX_RadarSensor : : KX_RADAR_AXIS_POS_X ) ;
KX_MACRO_addTypesToDict ( d , KX_RADAR_AXIS_POS_Y , KX_RadarSensor : : KX_RADAR_AXIS_POS_Y ) ;
KX_MACRO_addTypesToDict ( d , KX_RADAR_AXIS_POS_Z , KX_RadarSensor : : KX_RADAR_AXIS_POS_Z ) ;
2013-08-20 13:13:30 +00:00
KX_MACRO_addTypesToDict ( d , KX_RADAR_AXIS_NEG_X , KX_RadarSensor : : KX_RADAR_AXIS_NEG_X ) ;
KX_MACRO_addTypesToDict ( d , KX_RADAR_AXIS_NEG_Y , KX_RadarSensor : : KX_RADAR_AXIS_NEG_Y ) ;
2009-02-28 21:00:27 +00:00
KX_MACRO_addTypesToDict ( d , KX_RADAR_AXIS_NEG_Z , KX_RadarSensor : : KX_RADAR_AXIS_NEG_Z ) ;
2009-04-20 15:06:46 +00:00
/* Ray Sensor */
KX_MACRO_addTypesToDict ( d , KX_RAY_AXIS_POS_X , KX_RaySensor : : KX_RAY_AXIS_POS_X ) ;
KX_MACRO_addTypesToDict ( d , KX_RAY_AXIS_POS_Y , KX_RaySensor : : KX_RAY_AXIS_POS_Y ) ;
KX_MACRO_addTypesToDict ( d , KX_RAY_AXIS_POS_Z , KX_RaySensor : : KX_RAY_AXIS_POS_Z ) ;
2013-08-20 13:13:30 +00:00
KX_MACRO_addTypesToDict ( d , KX_RAY_AXIS_NEG_X , KX_RaySensor : : KX_RAY_AXIS_NEG_X ) ;
KX_MACRO_addTypesToDict ( d , KX_RAY_AXIS_NEG_Y , KX_RaySensor : : KX_RAY_AXIS_NEG_Y ) ;
2009-04-20 15:06:46 +00:00
KX_MACRO_addTypesToDict ( d , KX_RAY_AXIS_NEG_Z , KX_RaySensor : : KX_RAY_AXIS_NEG_Z ) ;
/* Dynamic actuator */
KX_MACRO_addTypesToDict ( d , KX_DYN_RESTORE_DYNAMICS , KX_SCA_DynamicActuator : : KX_DYN_RESTORE_DYNAMICS ) ;
KX_MACRO_addTypesToDict ( d , KX_DYN_DISABLE_DYNAMICS , KX_SCA_DynamicActuator : : KX_DYN_DISABLE_DYNAMICS ) ;
KX_MACRO_addTypesToDict ( d , KX_DYN_ENABLE_RIGID_BODY , KX_SCA_DynamicActuator : : KX_DYN_ENABLE_RIGID_BODY ) ;
KX_MACRO_addTypesToDict ( d , KX_DYN_DISABLE_RIGID_BODY , KX_SCA_DynamicActuator : : KX_DYN_DISABLE_RIGID_BODY ) ;
KX_MACRO_addTypesToDict ( d , KX_DYN_SET_MASS , KX_SCA_DynamicActuator : : KX_DYN_SET_MASS ) ;
/* Input & Mouse Sensor */
KX_MACRO_addTypesToDict ( d , KX_INPUT_NONE , SCA_InputEvent : : KX_NO_INPUTSTATUS ) ;
KX_MACRO_addTypesToDict ( d , KX_INPUT_JUST_ACTIVATED , SCA_InputEvent : : KX_JUSTACTIVATED ) ;
KX_MACRO_addTypesToDict ( d , KX_INPUT_ACTIVE , SCA_InputEvent : : KX_ACTIVE ) ;
KX_MACRO_addTypesToDict ( d , KX_INPUT_JUST_RELEASED , SCA_InputEvent : : KX_JUSTRELEASED ) ;
KX_MACRO_addTypesToDict ( d , KX_MOUSE_BUT_LEFT , SCA_IInputDevice : : KX_LEFTMOUSE ) ;
KX_MACRO_addTypesToDict ( d , KX_MOUSE_BUT_MIDDLE , SCA_IInputDevice : : KX_MIDDLEMOUSE ) ;
KX_MACRO_addTypesToDict ( d , KX_MOUSE_BUT_RIGHT , SCA_IInputDevice : : KX_RIGHTMOUSE ) ;
2010-06-02 17:38:38 +00:00
/* 2D Filter Actuator */
2009-04-20 15:06:46 +00:00
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_ENABLED , RAS_2DFilterManager : : RAS_2DFILTER_ENABLED ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_DISABLED , RAS_2DFilterManager : : RAS_2DFILTER_DISABLED ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_NOFILTER , RAS_2DFilterManager : : RAS_2DFILTER_NOFILTER ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_MOTIONBLUR , RAS_2DFilterManager : : RAS_2DFILTER_MOTIONBLUR ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_BLUR , RAS_2DFilterManager : : RAS_2DFILTER_BLUR ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_SHARPEN , RAS_2DFilterManager : : RAS_2DFILTER_SHARPEN ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_DILATION , RAS_2DFilterManager : : RAS_2DFILTER_DILATION ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_EROSION , RAS_2DFilterManager : : RAS_2DFILTER_EROSION ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_LAPLACIAN , RAS_2DFilterManager : : RAS_2DFILTER_LAPLACIAN ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_SOBEL , RAS_2DFilterManager : : RAS_2DFILTER_SOBEL ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_PREWITT , RAS_2DFilterManager : : RAS_2DFILTER_PREWITT ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_GRAYSCALE , RAS_2DFilterManager : : RAS_2DFILTER_GRAYSCALE ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_SEPIA , RAS_2DFilterManager : : RAS_2DFILTER_SEPIA ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_INVERT , RAS_2DFilterManager : : RAS_2DFILTER_INVERT ) ;
KX_MACRO_addTypesToDict ( d , RAS_2DFILTER_CUSTOMFILTER , RAS_2DFilterManager : : RAS_2DFILTER_CUSTOMFILTER ) ;
2010-06-02 17:38:38 +00:00
/* Sound Actuator */
2009-04-20 15:06:46 +00:00
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_PLAYSTOP , KX_SoundActuator : : KX_SOUNDACT_PLAYSTOP ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_PLAYEND , KX_SoundActuator : : KX_SOUNDACT_PLAYEND ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_LOOPSTOP , KX_SoundActuator : : KX_SOUNDACT_LOOPSTOP ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_LOOPEND , KX_SoundActuator : : KX_SOUNDACT_LOOPEND ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_LOOPBIDIRECTIONAL , KX_SoundActuator : : KX_SOUNDACT_LOOPBIDIRECTIONAL ) ;
KX_MACRO_addTypesToDict ( d , KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP , KX_SoundActuator : : KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP ) ;
2010-06-02 17:38:38 +00:00
/* State Actuator */
2009-04-20 15:06:46 +00:00
KX_MACRO_addTypesToDict ( d , KX_STATE_OP_CPY , KX_StateActuator : : OP_CPY ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE_OP_SET , KX_StateActuator : : OP_SET ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE_OP_CLR , KX_StateActuator : : OP_CLR ) ;
KX_MACRO_addTypesToDict ( d , KX_STATE_OP_NEG , KX_StateActuator : : OP_NEG ) ;
2009-06-08 20:08:19 +00:00
/* Game Actuator Modes */
KX_MACRO_addTypesToDict ( d , KX_GAME_LOAD , KX_GameActuator : : KX_GAME_LOAD ) ;
KX_MACRO_addTypesToDict ( d , KX_GAME_START , KX_GameActuator : : KX_GAME_START ) ;
KX_MACRO_addTypesToDict ( d , KX_GAME_RESTART , KX_GameActuator : : KX_GAME_RESTART ) ;
KX_MACRO_addTypesToDict ( d , KX_GAME_QUIT , KX_GameActuator : : KX_GAME_QUIT ) ;
KX_MACRO_addTypesToDict ( d , KX_GAME_SAVECFG , KX_GameActuator : : KX_GAME_SAVECFG ) ;
KX_MACRO_addTypesToDict ( d , KX_GAME_LOADCFG , KX_GameActuator : : KX_GAME_LOADCFG ) ;
/* Scene Actuator Modes */
KX_MACRO_addTypesToDict ( d , KX_SCENE_RESTART , KX_SceneActuator : : KX_SCENE_RESTART ) ;
KX_MACRO_addTypesToDict ( d , KX_SCENE_SET_SCENE , KX_SceneActuator : : KX_SCENE_SET_SCENE ) ;
KX_MACRO_addTypesToDict ( d , KX_SCENE_SET_CAMERA , KX_SceneActuator : : KX_SCENE_SET_CAMERA ) ;
KX_MACRO_addTypesToDict ( d , KX_SCENE_ADD_FRONT_SCENE , KX_SceneActuator : : KX_SCENE_ADD_FRONT_SCENE ) ;
KX_MACRO_addTypesToDict ( d , KX_SCENE_ADD_BACK_SCENE , KX_SceneActuator : : KX_SCENE_ADD_BACK_SCENE ) ;
KX_MACRO_addTypesToDict ( d , KX_SCENE_REMOVE_SCENE , KX_SceneActuator : : KX_SCENE_REMOVE_SCENE ) ;
KX_MACRO_addTypesToDict ( d , KX_SCENE_SUSPEND , KX_SceneActuator : : KX_SCENE_SUSPEND ) ;
KX_MACRO_addTypesToDict ( d , KX_SCENE_RESUME , KX_SceneActuator : : KX_SCENE_RESUME ) ;
/* Parent Actuator Modes */
KX_MACRO_addTypesToDict ( d , KX_PARENT_SET , KX_ParentActuator : : KX_PARENT_SET ) ;
KX_MACRO_addTypesToDict ( d , KX_PARENT_REMOVE , KX_ParentActuator : : KX_PARENT_REMOVE ) ;
2009-09-24 21:22:24 +00:00
/* BL_ArmatureConstraint type */
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_TRACKTO , CONSTRAINT_TYPE_TRACKTO ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_KINEMATIC , CONSTRAINT_TYPE_KINEMATIC ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_ROTLIKE , CONSTRAINT_TYPE_ROTLIKE ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_LOCLIKE , CONSTRAINT_TYPE_LOCLIKE ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_MINMAX , CONSTRAINT_TYPE_MINMAX ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_SIZELIKE , CONSTRAINT_TYPE_SIZELIKE ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_LOCKTRACK , CONSTRAINT_TYPE_LOCKTRACK ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_STRETCHTO , CONSTRAINT_TYPE_STRETCHTO ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_CLAMPTO , CONSTRAINT_TYPE_CLAMPTO ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_TRANSFORM , CONSTRAINT_TYPE_TRANSFORM ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_TYPE_DISTLIMIT , CONSTRAINT_TYPE_DISTLIMIT ) ;
/* BL_ArmatureConstraint ik_type */
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_COPYPOSE , CONSTRAINT_IK_COPYPOSE ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_DISTANCE , CONSTRAINT_IK_DISTANCE ) ;
/* BL_ArmatureConstraint ik_mode */
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_MODE_INSIDE , LIMITDIST_INSIDE ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_MODE_OUTSIDE , LIMITDIST_OUTSIDE ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_MODE_ONSURFACE , LIMITDIST_ONSURFACE ) ;
/* BL_ArmatureConstraint ik_flag */
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_FLAG_TIP , CONSTRAINT_IK_TIP ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_FLAG_ROT , CONSTRAINT_IK_ROT ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_FLAG_STRETCH , CONSTRAINT_IK_STRETCH ) ;
KX_MACRO_addTypesToDict ( d , CONSTRAINT_IK_FLAG_POS , CONSTRAINT_IK_POS ) ;
/* KX_ArmatureSensor type */
KX_MACRO_addTypesToDict ( d , KX_ARMSENSOR_STATE_CHANGED , SENS_ARM_STATE_CHANGED ) ;
KX_MACRO_addTypesToDict ( d , KX_ARMSENSOR_LIN_ERROR_BELOW , SENS_ARM_LIN_ERROR_BELOW ) ;
KX_MACRO_addTypesToDict ( d , KX_ARMSENSOR_LIN_ERROR_ABOVE , SENS_ARM_LIN_ERROR_ABOVE ) ;
KX_MACRO_addTypesToDict ( d , KX_ARMSENSOR_ROT_ERROR_BELOW , SENS_ARM_ROT_ERROR_BELOW ) ;
KX_MACRO_addTypesToDict ( d , KX_ARMSENSOR_ROT_ERROR_ABOVE , SENS_ARM_ROT_ERROR_ABOVE ) ;
/* BL_ArmatureActuator type */
KX_MACRO_addTypesToDict ( d , KX_ACT_ARMATURE_RUN , ACT_ARM_RUN ) ;
KX_MACRO_addTypesToDict ( d , KX_ACT_ARMATURE_ENABLE , ACT_ARM_ENABLE ) ;
KX_MACRO_addTypesToDict ( d , KX_ACT_ARMATURE_DISABLE , ACT_ARM_DISABLE ) ;
KX_MACRO_addTypesToDict ( d , KX_ACT_ARMATURE_SETTARGET , ACT_ARM_SETTARGET ) ;
KX_MACRO_addTypesToDict ( d , KX_ACT_ARMATURE_SETWEIGHT , ACT_ARM_SETWEIGHT ) ;
2012-11-22 11:03:17 +00:00
KX_MACRO_addTypesToDict ( d , KX_ACT_ARMATURE_SETINFLUENCE , ACT_ARM_SETINFLUENCE ) ;
2009-09-24 21:22:24 +00:00
/* BL_Armature Channel rotation_mode */
2009-09-29 01:52:54 +00:00
KX_MACRO_addTypesToDict ( d , ROT_MODE_QUAT , ROT_MODE_QUAT ) ;
KX_MACRO_addTypesToDict ( d , ROT_MODE_XYZ , ROT_MODE_XYZ ) ;
KX_MACRO_addTypesToDict ( d , ROT_MODE_XZY , ROT_MODE_XZY ) ;
KX_MACRO_addTypesToDict ( d , ROT_MODE_YXZ , ROT_MODE_YXZ ) ;
KX_MACRO_addTypesToDict ( d , ROT_MODE_YZX , ROT_MODE_YZX ) ;
KX_MACRO_addTypesToDict ( d , ROT_MODE_ZXY , ROT_MODE_ZXY ) ;
KX_MACRO_addTypesToDict ( d , ROT_MODE_ZYX , ROT_MODE_ZYX ) ;
2009-09-24 21:22:24 +00:00
2010-07-21 09:16:27 +00:00
/* Steering actuator */
KX_MACRO_addTypesToDict ( d , KX_STEERING_SEEK , KX_SteeringActuator : : KX_STEERING_SEEK ) ;
KX_MACRO_addTypesToDict ( d , KX_STEERING_FLEE , KX_SteeringActuator : : KX_STEERING_FLEE ) ;
KX_MACRO_addTypesToDict ( d , KX_STEERING_PATHFOLLOWING , KX_SteeringActuator : : KX_STEERING_PATHFOLLOWING ) ;
/* KX_NavMeshObject render mode */
KX_MACRO_addTypesToDict ( d , RM_WALLS , KX_NavMeshObject : : RM_WALLS ) ;
KX_MACRO_addTypesToDict ( d , RM_POLYS , KX_NavMeshObject : : RM_POLYS ) ;
KX_MACRO_addTypesToDict ( d , RM_TRIS , KX_NavMeshObject : : RM_TRIS ) ;
2011-07-08 07:32:45 +00:00
/* BL_Action play modes */
KX_MACRO_addTypesToDict ( d , KX_ACTION_MODE_PLAY , BL_Action : : ACT_MODE_PLAY ) ;
KX_MACRO_addTypesToDict ( d , KX_ACTION_MODE_LOOP , BL_Action : : ACT_MODE_LOOP ) ;
KX_MACRO_addTypesToDict ( d , KX_ACTION_MODE_PING_PONG , BL_Action : : ACT_MODE_PING_PONG ) ;
2013-08-14 23:31:49 +00:00
/* BL_Action blend modes */
KX_MACRO_addTypesToDict ( d , KX_ACTION_BLEND_BLEND , BL_Action : : ACT_BLEND_BLEND ) ;
KX_MACRO_addTypesToDict ( d , KX_ACTION_BLEND_ADD , BL_Action : : ACT_BLEND_ADD ) ;
2002-10-12 11:37:38 +00:00
// Check for errors
if ( PyErr_Occurred ( ) )
2011-09-01 02:12:53 +00:00
{
2010-08-11 12:14:16 +00:00
Py_FatalError ( " can't initialize module bge.logic " ) ;
2011-09-01 02:12:53 +00:00
}
2002-10-12 11:37:38 +00:00
2008-07-14 00:47:07 +00:00
return m ;
2006-05-13 23:31:36 +00:00
}
2002-10-12 11:37:38 +00:00
2009-06-08 20:08:19 +00:00
/* Explanation of
*
* - backupPySysObjects ( ) : stores sys . path in gp_OrigPythonSysPath
* - initPySysObjects ( main ) : initializes the blendfile and library paths
* - restorePySysObjects ( ) : restores sys . path from gp_OrigPythonSysPath
*
* These exist so the current blend dir " // " can always be used to import modules from .
* the reason we need a few functions for this is that python is not only used by the game engine
* so we cant just add to sys . path all the time , it would leave pythons state in a mess .
2012-03-02 16:05:54 +00:00
* It would also be incorrect since loading blend files for new levels etc would always add to sys . path
2009-06-08 20:08:19 +00:00
*
* To play nice with blenders python , the sys . path is backed up and the current blendfile along
* with all its lib paths are added to the sys path .
* When loading a new blendfile , the original sys . path is restored and the new paths are added over the top .
*/
/**
* So we can have external modules mixed with our blend files .
*/
static void backupPySysObjects ( void )
{
PyObject * sys_path = PySys_GetObject ( " path " ) ; /* should never fail */
PyObject * sys_mods = PySys_GetObject ( " modules " ) ; /* should never fail */
/* paths */
2012-03-09 00:41:09 +00:00
Py_XDECREF ( gp_OrigPythonSysPath ) ; /* just in case its set */
2009-06-08 20:08:19 +00:00
gp_OrigPythonSysPath = PyList_GetSlice ( sys_path , 0 , INT_MAX ) ; /* copy the list */
/* modules */
2012-03-09 00:41:09 +00:00
Py_XDECREF ( gp_OrigPythonSysModules ) ; /* just in case its set */
2009-06-08 20:08:19 +00:00
gp_OrigPythonSysModules = PyDict_Copy ( sys_mods ) ; /* copy the list */
}
/* for initPySysObjects only,
* takes a blend path and adds a scripts dir from it
*
* " /home/me/foo.blend " - > " /home/me/scripts "
*/
2011-10-27 14:41:26 +00:00
static void initPySysObjects__append ( PyObject * sys_path , const char * filename )
2009-06-08 20:08:19 +00:00
{
PyObject * item ;
2011-11-26 04:07:38 +00:00
char expanded [ FILE_MAX ] ;
2009-06-08 20:08:19 +00:00
2011-10-21 02:13:36 +00:00
BLI_split_dir_part ( filename , expanded , sizeof ( expanded ) ) ; /* get the dir part of filename only */
2010-03-09 17:36:23 +00:00
BLI_path_abs ( expanded , gp_GamePythonPath ) ; /* filename from lib->filename is (always?) absolute, so this may not be needed but it wont hurt */
2012-03-18 07:38:51 +00:00
BLI_cleanup_file ( gp_GamePythonPath , expanded ) ; /* Don't use BLI_cleanup_dir because it adds a slash - BREAKS WIN32 ONLY */
2011-01-06 05:04:07 +00:00
item = PyUnicode_DecodeFSDefault ( expanded ) ;
2009-06-08 20:08:19 +00:00
// printf("SysPath - '%s', '%s', '%s'\n", expanded, filename, gp_GamePythonPath);
2012-03-24 07:52:14 +00:00
if ( PySequence_Index ( sys_path , item ) = = - 1 ) {
2009-06-08 20:08:19 +00:00
PyErr_Clear ( ) ; /* PySequence_Index sets a ValueError */
PyList_Insert ( sys_path , 0 , item ) ;
}
Py_DECREF ( item ) ;
}
static void initPySysObjects ( Main * maggie )
{
PyObject * sys_path = PySys_GetObject ( " path " ) ; /* should never fail */
if ( gp_OrigPythonSysPath = = NULL ) {
/* backup */
backupPySysObjects ( ) ;
}
else {
/* get the original sys path when the BGE started */
PyList_SetSlice ( sys_path , 0 , INT_MAX , gp_OrigPythonSysPath ) ;
}
Library * lib = ( Library * ) maggie - > library . first ;
2012-10-21 07:58:38 +00:00
while ( lib ) {
2009-06-08 20:08:19 +00:00
/* lib->name wont work in some cases (on win32),
* even when expanding with gp_GamePythonPath , using lib - > filename is less trouble */
2010-06-02 17:58:28 +00:00
initPySysObjects__append ( sys_path , lib - > filepath ) ;
2009-06-08 20:08:19 +00:00
lib = ( Library * ) lib - > id . next ;
}
initPySysObjects__append ( sys_path , gp_GamePythonPath ) ;
2011-09-06 23:46:20 +00:00
// fprintf(stderr, "\nNew Path: %d ", PyList_GET_SIZE(sys_path));
2009-06-08 20:08:19 +00:00
// PyObject_Print(sys_path, stderr, 0);
}
static void restorePySysObjects ( void )
{
if ( gp_OrigPythonSysPath = = NULL )
return ;
PyObject * sys_path = PySys_GetObject ( " path " ) ; /* should never fail */
PyObject * sys_mods = PySys_GetObject ( " modules " ) ; /* should never fail */
/* paths */
PyList_SetSlice ( sys_path , 0 , INT_MAX , gp_OrigPythonSysPath ) ;
Py_DECREF ( gp_OrigPythonSysPath ) ;
gp_OrigPythonSysPath = NULL ;
/* modules */
PyDict_Clear ( sys_mods ) ;
PyDict_Update ( sys_mods , gp_OrigPythonSysModules ) ;
Py_DECREF ( gp_OrigPythonSysModules ) ;
2012-09-16 04:58:18 +00:00
gp_OrigPythonSysModules = NULL ;
2009-06-08 20:08:19 +00:00
2011-09-06 23:46:20 +00:00
// fprintf(stderr, "\nRestore Path: %d ", PyList_GET_SIZE(sys_path));
2009-06-08 20:08:19 +00:00
// PyObject_Print(sys_path, stderr, 0);
}
2012-06-21 05:41:06 +00:00
void addImportMain ( struct Main * maggie )
{
bpy_import_main_extra_add ( maggie ) ;
}
void removeImportMain ( struct Main * maggie )
{
bpy_import_main_extra_remove ( maggie ) ;
}
2011-03-22 08:35:56 +00:00
// Copied from bpy_interface.c
2012-10-22 08:15:51 +00:00
static struct _inittab bge_internal_modules [ ] = {
2011-07-15 04:01:47 +00:00
{ ( char * ) " mathutils " , PyInit_mathutils } ,
2011-03-27 07:56:29 +00:00
{ ( char * ) " bgl " , BPyInit_bgl } ,
{ ( char * ) " blf " , BPyInit_blf } ,
{ ( char * ) " aud " , AUD_initPython } ,
2011-03-22 08:35:56 +00:00
{ NULL , NULL }
} ;
2004-05-21 09:18:42 +00:00
/**
2012-03-18 07:38:51 +00:00
* Python is not initialized .
2011-04-18 08:27:50 +00:00
* see bpy_interface . c ' s BPY_python_start ( ) which shares the same functionality in blender .
2004-05-21 09:18:42 +00:00
*/
2012-09-16 04:58:18 +00:00
PyObject * initGamePlayerPythonScripting ( const STR_String & progname , TPythonSecurityLevel level , Main * maggie , int argc , char * * argv )
2004-05-21 09:18:42 +00:00
{
2009-06-08 20:08:19 +00:00
/* Yet another gotcha in the py api
2013-04-07 15:09:06 +00:00
* Cant run PySys_SetArgv more than once because this adds the
2009-06-08 20:08:19 +00:00
* binary dir to the sys . path each time .
2011-10-20 05:30:26 +00:00
* Id have thought python being totally restarted would make this ok but
2009-06-08 20:08:19 +00:00
* somehow it remembers the sys . path - Campbell
*/
static bool first_time = true ;
2013-03-05 03:17:46 +00:00
const char * const py_path_bundle = BLI_get_folder ( BLENDER_SYSTEM_PYTHON , NULL ) ;
2012-05-18 10:19:49 +00:00
2009-08-10 00:07:34 +00:00
#if 0 // TODO - py3
2004-05-21 09:18:42 +00:00
STR_String pname = progname ;
Py_SetProgramName ( pname . Ptr ( ) ) ;
2009-06-08 20:08:19 +00:00
# endif
2012-05-18 10:19:49 +00:00
if ( py_path_bundle ! = NULL ) {
Py_NoSiteFlag = 1 ;
}
Py_FrozenFlag = 1 ;
2011-03-25 00:34:28 +00:00
/* must run before python initializes */
PyImport_ExtendInittab ( bge_internal_modules ) ;
2011-04-18 08:27:50 +00:00
/* find local python installation */
2012-05-18 10:19:49 +00:00
PyC_SetHomePath ( py_path_bundle ) ;
2011-04-18 08:27:50 +00:00
2004-05-21 09:18:42 +00:00
Py_Initialize ( ) ;
2009-04-20 15:06:46 +00:00
2012-03-24 07:52:14 +00:00
if ( argv & & first_time ) { /* browser plugins don't currently set this */
2009-08-10 00:07:34 +00:00
// Until python support ascii again, we use our own.
// PySys_SetArgv(argc, argv);
2009-07-08 09:23:49 +00:00
int i ;
PyObject * py_argv = PyList_New ( argc ) ;
for ( i = 0 ; i < argc ; i + + )
2011-01-06 05:04:07 +00:00
PyList_SET_ITEM ( py_argv , i , PyC_UnicodeFromByte ( argv [ i ] ) ) ;
2009-07-08 09:23:49 +00:00
PySys_SetObject ( " argv " , py_argv ) ;
Py_DECREF ( py_argv ) ;
}
2013-01-05 03:30:56 +00:00
/* Initialize thread support (also acquires lock) */
PyEval_InitThreads ( ) ;
2011-03-29 16:12:25 +00:00
bpy_import_init ( PyEval_GetBuiltins ( ) ) ;
2011-03-25 00:34:28 +00:00
2012-03-18 07:38:51 +00:00
/* mathutils types are used by the BGE even if we don't import them */
2011-03-25 00:34:28 +00:00
{
2013-03-17 18:30:31 +00:00
PyObject * mod = PyImport_ImportModuleLevel ( " mathutils " , NULL , NULL , NULL , 0 ) ;
2011-03-25 00:34:28 +00:00
Py_DECREF ( mod ) ;
}
2012-02-07 11:22:50 +00:00
# ifdef WITH_AUDASPACE
2012-03-18 07:38:51 +00:00
/* accessing a SoundActuator's sound results in a crash if aud is not initialized... */
2012-02-07 11:22:50 +00:00
{
2013-03-17 18:30:31 +00:00
PyObject * mod = PyImport_ImportModuleLevel ( " aud " , NULL , NULL , NULL , 0 ) ;
2012-02-07 11:22:50 +00:00
Py_DECREF ( mod ) ;
}
# endif
2009-06-13 17:25:54 +00:00
initPyTypes ( ) ;
2009-04-20 15:06:46 +00:00
2009-06-17 20:33:34 +00:00
bpy_import_main_set ( maggie ) ;
2009-04-20 15:06:46 +00:00
2009-06-08 20:08:19 +00:00
initPySysObjects ( maggie ) ;
2009-04-05 19:37:13 +00:00
2009-06-08 20:08:19 +00:00
first_time = false ;
PyObjectPlus : : ClearDeprecationWarning ( ) ;
2010-08-05 03:25:45 +00:00
2010-09-18 19:38:27 +00:00
return PyC_DefaultNameSpace ( NULL ) ;
2004-05-21 09:18:42 +00:00
}
void exitGamePlayerPythonScripting ( )
2012-09-16 04:58:18 +00:00
{
2010-10-09 01:31:20 +00:00
/* Clean up the Python mouse and keyboard */
delete gp_PythonKeyboard ;
gp_PythonKeyboard = NULL ;
delete gp_PythonMouse ;
gp_PythonMouse = NULL ;
2012-12-21 02:28:59 +00:00
for ( int i = 0 ; i < JOYINDEX_MAX ; + + i ) {
if ( gp_PythonJoysticks [ i ] ) {
delete gp_PythonJoysticks [ i ] ;
gp_PythonJoysticks [ i ] = NULL ;
}
}
2009-06-08 20:08:19 +00:00
/* since python restarts we cant let the python backup of the sys.path hang around in a global pointer */
restorePySysObjects ( ) ; /* get back the original sys.path and clear the backup */
2004-05-21 09:18:42 +00:00
Py_Finalize ( ) ;
2009-06-17 20:33:34 +00:00
bpy_import_main_set ( NULL ) ;
2009-06-08 20:08:19 +00:00
PyObjectPlus : : ClearDeprecationWarning ( ) ;
2004-05-21 09:18:42 +00:00
}
2009-06-08 20:08:19 +00:00
2004-05-21 09:18:42 +00:00
/**
* Python is already initialized .
*/
2012-09-16 04:58:18 +00:00
PyObject * initGamePythonScripting ( const STR_String & progname , TPythonSecurityLevel level , Main * maggie )
2002-10-12 11:37:38 +00:00
{
2009-08-10 00:07:34 +00:00
#if 0 // XXX TODO Py3
2002-10-12 11:37:38 +00:00
STR_String pname = progname ;
Py_SetProgramName ( pname . Ptr ( ) ) ;
2009-06-08 20:08:19 +00:00
# endif
2004-05-21 09:18:42 +00:00
2012-02-07 11:22:50 +00:00
# ifdef WITH_AUDASPACE
2012-03-18 07:38:51 +00:00
/* accessing a SoundActuator's sound results in a crash if aud is not initialized... */
2012-02-07 11:22:50 +00:00
{
2013-03-17 18:30:31 +00:00
PyObject * mod = PyImport_ImportModuleLevel ( " aud " , NULL , NULL , NULL , 0 ) ;
2012-02-07 11:22:50 +00:00
Py_DECREF ( mod ) ;
}
# endif
2009-06-13 17:25:54 +00:00
initPyTypes ( ) ;
2009-04-20 15:06:46 +00:00
2009-06-17 20:33:34 +00:00
bpy_import_main_set ( maggie ) ;
2009-04-20 15:06:46 +00:00
2009-06-08 20:08:19 +00:00
initPySysObjects ( maggie ) ;
2002-10-12 11:37:38 +00:00
2009-06-08 20:08:19 +00:00
PyObjectPlus : : NullDeprecationWarning ( ) ;
2010-08-05 03:25:45 +00:00
2010-09-18 19:38:27 +00:00
return PyC_DefaultNameSpace ( NULL ) ;
2002-10-12 11:37:38 +00:00
}
void exitGamePythonScripting ( )
{
2010-10-09 01:31:20 +00:00
/* Clean up the Python mouse and keyboard */
delete gp_PythonKeyboard ;
gp_PythonKeyboard = NULL ;
delete gp_PythonMouse ;
gp_PythonMouse = NULL ;
2012-12-21 02:28:59 +00:00
for ( int i = 0 ; i < JOYINDEX_MAX ; + + i ) {
if ( gp_PythonJoysticks [ i ] ) {
delete gp_PythonJoysticks [ i ] ;
gp_PythonJoysticks [ i ] = NULL ;
}
}
2009-06-08 20:08:19 +00:00
restorePySysObjects ( ) ; /* get back the original sys.path and clear the backup */
2009-06-17 20:33:34 +00:00
bpy_import_main_set ( NULL ) ;
2009-06-08 20:08:19 +00:00
PyObjectPlus : : ClearDeprecationWarning ( ) ;
2002-10-12 11:37:38 +00:00
}
2010-01-10 22:03:26 +00:00
/* similar to the above functions except it sets up the namespace
* and other more general things */
2012-09-16 04:58:18 +00:00
void setupGamePython ( KX_KetsjiEngine * ketsjiengine , KX_Scene * startscene , Main * blenderdata ,
PyObject * pyGlobalDict , PyObject * * gameLogic , PyObject * * gameLogic_keys , int argc , char * * argv )
2010-01-10 22:03:26 +00:00
{
2012-09-16 04:58:18 +00:00
PyObject * dictionaryobject ;
2010-01-10 22:03:26 +00:00
2012-03-24 07:52:14 +00:00
if ( argv ) /* player only */
2010-01-10 22:03:26 +00:00
dictionaryobject = initGamePlayerPythonScripting ( " Ketsji " , psl_Lowest , blenderdata , argc , argv ) ;
else
dictionaryobject = initGamePythonScripting ( " Ketsji " , psl_Lowest , blenderdata ) ;
ketsjiengine - > SetPyNamespace ( dictionaryobject ) ;
initRasterizer ( ketsjiengine - > GetRasterizer ( ) , ketsjiengine - > GetCanvas ( ) ) ;
* gameLogic = initGameLogic ( ketsjiengine , startscene ) ;
/* is set in initGameLogic so only set here if we want it to persist between scenes */
2012-03-24 07:52:14 +00:00
if ( pyGlobalDict )
2010-01-10 22:03:26 +00:00
PyDict_SetItemString ( PyModule_GetDict ( * gameLogic ) , " globalDict " , pyGlobalDict ) ; // Same as importing the module.
* gameLogic_keys = PyDict_Keys ( PyModule_GetDict ( * gameLogic ) ) ;
initGameKeys ( ) ;
initPythonConstraintBinding ( ) ;
initVideoTexture ( ) ;
2010-01-10 22:15:29 +00:00
/* could be done a lot more nicely, but for now a quick way to get bge.* working */
2011-12-17 00:52:36 +00:00
PyRun_SimpleString ( " sys = __import__('sys'); "
2012-08-06 14:29:25 +00:00
" bge = type(sys)('bge'); "
" bge.__dict__.update({'logic':__import__('GameLogic'), "
2011-12-17 00:52:36 +00:00
" 'render':__import__('Rasterizer'), "
" 'events':__import__('GameKeys'), "
" 'constraints':__import__('PhysicsConstraints'), "
2013-07-29 22:20:06 +00:00
" 'physics':__import__('PhysicsConstraints'), "
2011-12-17 00:52:36 +00:00
" 'types':__import__('GameTypes'), "
" 'texture':__import__('VideoTexture')}); "
2012-08-06 14:29:25 +00:00
/* so we can do 'import bge.foo as bar' */
" sys.modules.update({'bge': bge, "
" 'bge.logic':bge.logic, "
" 'bge.render':bge.render, "
" 'bge.events':bge.events, "
" 'bge.constraints':bge.constraints, "
2013-07-29 22:20:06 +00:00
" 'bge.physics':bge.physics, "
2012-08-06 14:29:25 +00:00
" 'bge.types':bge.types, "
" 'bge.texture':bge.texture}) "
2011-12-17 00:52:36 +00:00
) ;
2010-01-10 22:03:26 +00:00
}
2002-10-12 11:37:38 +00:00
2009-06-08 20:08:19 +00:00
static struct PyModuleDef Rasterizer_module_def = {
{ } , /* m_base */
" Rasterizer " , /* m_name */
Rasterizer_module_documentation , /* m_doc */
0 , /* m_size */
rasterizer_methods , /* m_methods */
0 , /* m_reload */
0 , /* m_traverse */
0 , /* m_clear */
0 , /* m_free */
} ;
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
PyObject * initRasterizer ( RAS_IRasterizer * rasty , RAS_ICanvas * canvas )
2002-10-12 11:37:38 +00:00
{
gp_Canvas = canvas ;
gp_Rasterizer = rasty ;
2012-09-16 04:58:18 +00:00
PyObject * m ;
PyObject * d ;
PyObject * item ;
2002-10-12 11:37:38 +00:00
2009-06-08 20:08:19 +00:00
/* Use existing module where possible
2012-03-09 18:28:30 +00:00
* be careful not to init any runtime vars after this */
2009-06-08 20:08:19 +00:00
m = PyImport_ImportModule ( " Rasterizer " ) ;
2012-03-24 07:52:14 +00:00
if ( m ) {
2009-06-08 20:08:19 +00:00
Py_DECREF ( m ) ;
return m ;
}
else {
PyErr_Clear ( ) ;
2011-09-01 02:12:53 +00:00
2009-06-08 20:08:19 +00:00
// Create the module and add the functions
m = PyModule_Create ( & Rasterizer_module_def ) ;
2009-06-16 07:16:51 +00:00
PyDict_SetItemString ( PySys_GetObject ( " modules " ) , Rasterizer_module_def . m_name , m ) ;
2009-06-08 20:08:19 +00:00
}
2002-10-12 11:37:38 +00:00
2011-09-01 02:12:53 +00:00
// Add some symbolic constants to the module
d = PyModule_GetDict ( m ) ;
ErrorObject = PyUnicode_FromString ( " Rasterizer.error " ) ;
PyDict_SetItemString ( d , " error " , ErrorObject ) ;
Py_DECREF ( ErrorObject ) ;
2002-10-12 11:37:38 +00:00
2011-09-01 02:12:53 +00:00
/* needed for get/setMaterialType */
KX_MACRO_addTypesToDict ( d , KX_BLENDER_MULTITEX_MATERIAL , KX_BLENDER_MULTITEX_MATERIAL ) ;
KX_MACRO_addTypesToDict ( d , KX_BLENDER_GLSL_MATERIAL , KX_BLENDER_GLSL_MATERIAL ) ;
2008-09-13 19:19:51 +00:00
2013-04-14 00:40:24 +00:00
KX_MACRO_addTypesToDict ( d , RAS_MIPMAP_NONE , RAS_IRasterizer : : RAS_MIPMAP_NONE ) ;
KX_MACRO_addTypesToDict ( d , RAS_MIPMAP_NEAREST , RAS_IRasterizer : : RAS_MIPMAP_NEAREST ) ;
KX_MACRO_addTypesToDict ( d , RAS_MIPMAP_LINEAR , RAS_IRasterizer : : RAS_MIPMAP_LINEAR ) ;
2013-07-29 22:31:32 +00:00
/* for get/setVsync */
KX_MACRO_addTypesToDict ( d , VSYNC_OFF , VSYNC_OFF ) ;
KX_MACRO_addTypesToDict ( d , VSYNC_ON , VSYNC_ON ) ;
KX_MACRO_addTypesToDict ( d , VSYNC_ADAPTIVE , VSYNC_ADAPTIVE ) ;
2011-09-01 02:12:53 +00:00
// XXXX Add constants here
2002-10-12 11:37:38 +00:00
2011-09-01 02:12:53 +00:00
// Check for errors
if ( PyErr_Occurred ( ) )
{
Py_FatalError ( " can't initialize module Rasterizer " ) ;
}
2002-10-12 11:37:38 +00:00
2011-09-01 02:12:53 +00:00
return d ;
2002-10-12 11:37:38 +00:00
}
/* ------------------------------------------------------------------------- */
/* GameKeys: symbolic constants for key mapping */
/* ------------------------------------------------------------------------- */
static char GameKeys_module_documentation [ ] =
" This modules provides defines for key-codes "
;
2008-08-29 03:15:17 +00:00
static char gPyEventToString_doc [ ] =
2009-04-20 15:06:46 +00:00
" EventToString(event) - Take a valid event from the GameKeys module or Keyboard Sensor and return a name "
2008-08-29 03:15:17 +00:00
;
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
static PyObject * gPyEventToString ( PyObject * , PyObject * value )
2008-08-29 03:15:17 +00:00
{
2012-09-16 04:58:18 +00:00
PyObject * mod , * dict , * key , * val , * ret = NULL ;
2008-08-29 06:32:42 +00:00
Py_ssize_t pos = 0 ;
2008-08-29 03:15:17 +00:00
mod = PyImport_ImportModule ( " GameKeys " ) ;
if ( ! mod )
return NULL ;
dict = PyModule_GetDict ( mod ) ;
while ( PyDict_Next ( dict , & pos , & key , & val ) ) {
2009-06-08 20:08:19 +00:00
if ( PyObject_RichCompareBool ( value , val , Py_EQ ) ) {
2008-08-29 03:15:17 +00:00
ret = key ;
break ;
}
}
2012-03-09 00:41:09 +00:00
PyErr_Clear ( ) ; // in case there was an error clearing
2008-08-29 03:15:17 +00:00
Py_DECREF ( mod ) ;
2009-04-20 15:06:46 +00:00
if ( ! ret ) PyErr_SetString ( PyExc_ValueError , " GameKeys.EventToString(int): expected a valid int keyboard event " ) ;
2008-08-29 03:15:17 +00:00
else Py_INCREF ( ret ) ;
return ret ;
}
2002-10-12 11:37:38 +00:00
2009-04-20 15:06:46 +00:00
static char gPyEventToCharacter_doc [ ] =
" EventToCharacter(event, is_shift) - Take a valid event from the GameKeys module or Keyboard Sensor and return a character "
;
2012-09-16 04:58:18 +00:00
static PyObject * gPyEventToCharacter ( PyObject * , PyObject * args )
2009-04-20 15:06:46 +00:00
{
int event , shift ;
if ( ! PyArg_ParseTuple ( args , " ii:EventToCharacter " , & event , & shift ) )
return NULL ;
2012-03-24 07:52:14 +00:00
if ( IsPrintable ( event ) ) {
2009-04-20 15:06:46 +00:00
char ch [ 2 ] = { ' \0 ' , ' \0 ' } ;
ch [ 0 ] = ToCharacter ( event , ( bool ) shift ) ;
2009-06-29 02:25:54 +00:00
return PyUnicode_FromString ( ch ) ;
2009-04-20 15:06:46 +00:00
}
else {
2009-06-29 02:25:54 +00:00
return PyUnicode_FromString ( " " ) ;
2009-04-20 15:06:46 +00:00
}
}
2002-10-12 11:37:38 +00:00
static struct PyMethodDef gamekeys_methods [ ] = {
2009-08-10 00:07:34 +00:00
{ " EventToCharacter " , ( PyCFunction ) gPyEventToCharacter , METH_VARARGS , ( const char * ) gPyEventToCharacter_doc } ,
{ " EventToString " , ( PyCFunction ) gPyEventToString , METH_O , ( const char * ) gPyEventToString_doc } ,
2002-10-12 11:37:38 +00:00
{ NULL , ( PyCFunction ) NULL , 0 , NULL }
} ;
2009-06-08 20:08:19 +00:00
static struct PyModuleDef GameKeys_module_def = {
{ } , /* m_base */
" GameKeys " , /* m_name */
GameKeys_module_documentation , /* m_doc */
0 , /* m_size */
gamekeys_methods , /* m_methods */
0 , /* m_reload */
0 , /* m_traverse */
0 , /* m_clear */
0 , /* m_free */
} ;
2002-10-12 11:37:38 +00:00
2012-09-16 04:58:18 +00:00
PyObject * initGameKeys ( )
2002-10-12 11:37:38 +00:00
{
2012-09-16 04:58:18 +00:00
PyObject * m ;
PyObject * d ;
PyObject * item ;
2009-06-08 20:08:19 +00:00
/* Use existing module where possible */
m = PyImport_ImportModule ( " GameKeys " ) ;
2012-03-24 07:52:14 +00:00
if ( m ) {
2009-06-08 20:08:19 +00:00
Py_DECREF ( m ) ;
return m ;
}
else {
PyErr_Clear ( ) ;
// Create the module and add the functions
m = PyModule_Create ( & GameKeys_module_def ) ;
2009-06-16 07:16:51 +00:00
PyDict_SetItemString ( PySys_GetObject ( " modules " ) , GameKeys_module_def . m_name , m ) ;
2009-06-08 20:08:19 +00:00
}
2002-10-12 11:37:38 +00:00
// Add some symbolic constants to the module
d = PyModule_GetDict ( m ) ;
// XXXX Add constants here
KX_MACRO_addTypesToDict ( d , AKEY , SCA_IInputDevice : : KX_AKEY ) ;
KX_MACRO_addTypesToDict ( d , BKEY , SCA_IInputDevice : : KX_BKEY ) ;
KX_MACRO_addTypesToDict ( d , CKEY , SCA_IInputDevice : : KX_CKEY ) ;
KX_MACRO_addTypesToDict ( d , DKEY , SCA_IInputDevice : : KX_DKEY ) ;
KX_MACRO_addTypesToDict ( d , EKEY , SCA_IInputDevice : : KX_EKEY ) ;
KX_MACRO_addTypesToDict ( d , FKEY , SCA_IInputDevice : : KX_FKEY ) ;
KX_MACRO_addTypesToDict ( d , GKEY , SCA_IInputDevice : : KX_GKEY ) ;
KX_MACRO_addTypesToDict ( d , HKEY , SCA_IInputDevice : : KX_HKEY ) ;
KX_MACRO_addTypesToDict ( d , IKEY , SCA_IInputDevice : : KX_IKEY ) ;
KX_MACRO_addTypesToDict ( d , JKEY , SCA_IInputDevice : : KX_JKEY ) ;
KX_MACRO_addTypesToDict ( d , KKEY , SCA_IInputDevice : : KX_KKEY ) ;
KX_MACRO_addTypesToDict ( d , LKEY , SCA_IInputDevice : : KX_LKEY ) ;
KX_MACRO_addTypesToDict ( d , MKEY , SCA_IInputDevice : : KX_MKEY ) ;
KX_MACRO_addTypesToDict ( d , NKEY , SCA_IInputDevice : : KX_NKEY ) ;
KX_MACRO_addTypesToDict ( d , OKEY , SCA_IInputDevice : : KX_OKEY ) ;
KX_MACRO_addTypesToDict ( d , PKEY , SCA_IInputDevice : : KX_PKEY ) ;
KX_MACRO_addTypesToDict ( d , QKEY , SCA_IInputDevice : : KX_QKEY ) ;
KX_MACRO_addTypesToDict ( d , RKEY , SCA_IInputDevice : : KX_RKEY ) ;
KX_MACRO_addTypesToDict ( d , SKEY , SCA_IInputDevice : : KX_SKEY ) ;
KX_MACRO_addTypesToDict ( d , TKEY , SCA_IInputDevice : : KX_TKEY ) ;
KX_MACRO_addTypesToDict ( d , UKEY , SCA_IInputDevice : : KX_UKEY ) ;
KX_MACRO_addTypesToDict ( d , VKEY , SCA_IInputDevice : : KX_VKEY ) ;
KX_MACRO_addTypesToDict ( d , WKEY , SCA_IInputDevice : : KX_WKEY ) ;
KX_MACRO_addTypesToDict ( d , XKEY , SCA_IInputDevice : : KX_XKEY ) ;
KX_MACRO_addTypesToDict ( d , YKEY , SCA_IInputDevice : : KX_YKEY ) ;
KX_MACRO_addTypesToDict ( d , ZKEY , SCA_IInputDevice : : KX_ZKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , ZEROKEY , SCA_IInputDevice : : KX_ZEROKEY ) ;
KX_MACRO_addTypesToDict ( d , ONEKEY , SCA_IInputDevice : : KX_ONEKEY ) ;
KX_MACRO_addTypesToDict ( d , TWOKEY , SCA_IInputDevice : : KX_TWOKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , THREEKEY , SCA_IInputDevice : : KX_THREEKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , FOURKEY , SCA_IInputDevice : : KX_FOURKEY ) ;
KX_MACRO_addTypesToDict ( d , FIVEKEY , SCA_IInputDevice : : KX_FIVEKEY ) ;
KX_MACRO_addTypesToDict ( d , SIXKEY , SCA_IInputDevice : : KX_SIXKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , SEVENKEY , SCA_IInputDevice : : KX_SEVENKEY ) ;
KX_MACRO_addTypesToDict ( d , EIGHTKEY , SCA_IInputDevice : : KX_EIGHTKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , NINEKEY , SCA_IInputDevice : : KX_NINEKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , CAPSLOCKKEY , SCA_IInputDevice : : KX_CAPSLOCKKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , LEFTCTRLKEY , SCA_IInputDevice : : KX_LEFTCTRLKEY ) ;
2012-10-21 05:46:41 +00:00
KX_MACRO_addTypesToDict ( d , LEFTALTKEY , SCA_IInputDevice : : KX_LEFTALTKEY ) ;
KX_MACRO_addTypesToDict ( d , RIGHTALTKEY , SCA_IInputDevice : : KX_RIGHTALTKEY ) ;
KX_MACRO_addTypesToDict ( d , RIGHTCTRLKEY , SCA_IInputDevice : : KX_RIGHTCTRLKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , RIGHTSHIFTKEY , SCA_IInputDevice : : KX_RIGHTSHIFTKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , LEFTSHIFTKEY , SCA_IInputDevice : : KX_LEFTSHIFTKEY ) ;
KX_MACRO_addTypesToDict ( d , ESCKEY , SCA_IInputDevice : : KX_ESCKEY ) ;
KX_MACRO_addTypesToDict ( d , TABKEY , SCA_IInputDevice : : KX_TABKEY ) ;
KX_MACRO_addTypesToDict ( d , RETKEY , SCA_IInputDevice : : KX_RETKEY ) ;
2010-10-05 05:44:15 +00:00
KX_MACRO_addTypesToDict ( d , ENTERKEY , SCA_IInputDevice : : KX_RETKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , SPACEKEY , SCA_IInputDevice : : KX_SPACEKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , LINEFEEDKEY , SCA_IInputDevice : : KX_LINEFEEDKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , BACKSPACEKEY , SCA_IInputDevice : : KX_BACKSPACEKEY ) ;
KX_MACRO_addTypesToDict ( d , DELKEY , SCA_IInputDevice : : KX_DELKEY ) ;
KX_MACRO_addTypesToDict ( d , SEMICOLONKEY , SCA_IInputDevice : : KX_SEMICOLONKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , PERIODKEY , SCA_IInputDevice : : KX_PERIODKEY ) ;
KX_MACRO_addTypesToDict ( d , COMMAKEY , SCA_IInputDevice : : KX_COMMAKEY ) ;
KX_MACRO_addTypesToDict ( d , QUOTEKEY , SCA_IInputDevice : : KX_QUOTEKEY ) ;
KX_MACRO_addTypesToDict ( d , ACCENTGRAVEKEY , SCA_IInputDevice : : KX_ACCENTGRAVEKEY ) ;
KX_MACRO_addTypesToDict ( d , MINUSKEY , SCA_IInputDevice : : KX_MINUSKEY ) ;
KX_MACRO_addTypesToDict ( d , SLASHKEY , SCA_IInputDevice : : KX_SLASHKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , BACKSLASHKEY , SCA_IInputDevice : : KX_BACKSLASHKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , EQUALKEY , SCA_IInputDevice : : KX_EQUALKEY ) ;
KX_MACRO_addTypesToDict ( d , LEFTBRACKETKEY , SCA_IInputDevice : : KX_LEFTBRACKETKEY ) ;
KX_MACRO_addTypesToDict ( d , RIGHTBRACKETKEY , SCA_IInputDevice : : KX_RIGHTBRACKETKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , LEFTARROWKEY , SCA_IInputDevice : : KX_LEFTARROWKEY ) ;
KX_MACRO_addTypesToDict ( d , DOWNARROWKEY , SCA_IInputDevice : : KX_DOWNARROWKEY ) ;
2012-09-16 04:58:18 +00:00
KX_MACRO_addTypesToDict ( d , RIGHTARROWKEY , SCA_IInputDevice : : KX_RIGHTARROWKEY ) ;
KX_MACRO_addTypesToDict ( d , UPARROWKEY , SCA_IInputDevice : : KX_UPARROWKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , PAD2 , SCA_IInputDevice : : KX_PAD2 ) ;
KX_MACRO_addTypesToDict ( d , PAD4 , SCA_IInputDevice : : KX_PAD4 ) ;
KX_MACRO_addTypesToDict ( d , PAD6 , SCA_IInputDevice : : KX_PAD6 ) ;
KX_MACRO_addTypesToDict ( d , PAD8 , SCA_IInputDevice : : KX_PAD8 ) ;
KX_MACRO_addTypesToDict ( d , PAD1 , SCA_IInputDevice : : KX_PAD1 ) ;
KX_MACRO_addTypesToDict ( d , PAD3 , SCA_IInputDevice : : KX_PAD3 ) ;
KX_MACRO_addTypesToDict ( d , PAD5 , SCA_IInputDevice : : KX_PAD5 ) ;
KX_MACRO_addTypesToDict ( d , PAD7 , SCA_IInputDevice : : KX_PAD7 ) ;
KX_MACRO_addTypesToDict ( d , PAD9 , SCA_IInputDevice : : KX_PAD9 ) ;
KX_MACRO_addTypesToDict ( d , PADPERIOD , SCA_IInputDevice : : KX_PADPERIOD ) ;
KX_MACRO_addTypesToDict ( d , PADSLASHKEY , SCA_IInputDevice : : KX_PADSLASHKEY ) ;
KX_MACRO_addTypesToDict ( d , PADASTERKEY , SCA_IInputDevice : : KX_PADASTERKEY ) ;
KX_MACRO_addTypesToDict ( d , PAD0 , SCA_IInputDevice : : KX_PAD0 ) ;
KX_MACRO_addTypesToDict ( d , PADMINUS , SCA_IInputDevice : : KX_PADMINUS ) ;
KX_MACRO_addTypesToDict ( d , PADENTER , SCA_IInputDevice : : KX_PADENTER ) ;
KX_MACRO_addTypesToDict ( d , PADPLUSKEY , SCA_IInputDevice : : KX_PADPLUSKEY ) ;
2012-08-11 22:12:32 +00:00
KX_MACRO_addTypesToDict ( d , F1KEY , SCA_IInputDevice : : KX_F1KEY ) ;
KX_MACRO_addTypesToDict ( d , F2KEY , SCA_IInputDevice : : KX_F2KEY ) ;
KX_MACRO_addTypesToDict ( d , F3KEY , SCA_IInputDevice : : KX_F3KEY ) ;
KX_MACRO_addTypesToDict ( d , F4KEY , SCA_IInputDevice : : KX_F4KEY ) ;
KX_MACRO_addTypesToDict ( d , F5KEY , SCA_IInputDevice : : KX_F5KEY ) ;
KX_MACRO_addTypesToDict ( d , F6KEY , SCA_IInputDevice : : KX_F6KEY ) ;
KX_MACRO_addTypesToDict ( d , F7KEY , SCA_IInputDevice : : KX_F7KEY ) ;
KX_MACRO_addTypesToDict ( d , F8KEY , SCA_IInputDevice : : KX_F8KEY ) ;
KX_MACRO_addTypesToDict ( d , F9KEY , SCA_IInputDevice : : KX_F9KEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , F10KEY , SCA_IInputDevice : : KX_F10KEY ) ;
KX_MACRO_addTypesToDict ( d , F11KEY , SCA_IInputDevice : : KX_F11KEY ) ;
KX_MACRO_addTypesToDict ( d , F12KEY , SCA_IInputDevice : : KX_F12KEY ) ;
2010-04-20 01:04:00 +00:00
KX_MACRO_addTypesToDict ( d , F13KEY , SCA_IInputDevice : : KX_F13KEY ) ;
KX_MACRO_addTypesToDict ( d , F14KEY , SCA_IInputDevice : : KX_F14KEY ) ;
KX_MACRO_addTypesToDict ( d , F15KEY , SCA_IInputDevice : : KX_F15KEY ) ;
KX_MACRO_addTypesToDict ( d , F16KEY , SCA_IInputDevice : : KX_F16KEY ) ;
KX_MACRO_addTypesToDict ( d , F17KEY , SCA_IInputDevice : : KX_F17KEY ) ;
KX_MACRO_addTypesToDict ( d , F18KEY , SCA_IInputDevice : : KX_F18KEY ) ;
KX_MACRO_addTypesToDict ( d , F19KEY , SCA_IInputDevice : : KX_F19KEY ) ;
2013-06-20 03:22:55 +00:00
KX_MACRO_addTypesToDict ( d , OSKEY , SCA_IInputDevice : : KX_OSKEY ) ;
2002-10-12 11:37:38 +00:00
2012-08-11 22:12:32 +00:00
KX_MACRO_addTypesToDict ( d , PAUSEKEY , SCA_IInputDevice : : KX_PAUSEKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , INSERTKEY , SCA_IInputDevice : : KX_INSERTKEY ) ;
2012-08-11 22:12:32 +00:00
KX_MACRO_addTypesToDict ( d , HOMEKEY , SCA_IInputDevice : : KX_HOMEKEY ) ;
2002-10-12 11:37:38 +00:00
KX_MACRO_addTypesToDict ( d , PAGEUPKEY , SCA_IInputDevice : : KX_PAGEUPKEY ) ;
KX_MACRO_addTypesToDict ( d , PAGEDOWNKEY , SCA_IInputDevice : : KX_PAGEDOWNKEY ) ;
KX_MACRO_addTypesToDict ( d , ENDKEY , SCA_IInputDevice : : KX_ENDKEY ) ;
2010-04-17 06:52:14 +00:00
// MOUSE
KX_MACRO_addTypesToDict ( d , LEFTMOUSE , SCA_IInputDevice : : KX_LEFTMOUSE ) ;
KX_MACRO_addTypesToDict ( d , MIDDLEMOUSE , SCA_IInputDevice : : KX_MIDDLEMOUSE ) ;
KX_MACRO_addTypesToDict ( d , RIGHTMOUSE , SCA_IInputDevice : : KX_RIGHTMOUSE ) ;
KX_MACRO_addTypesToDict ( d , WHEELUPMOUSE , SCA_IInputDevice : : KX_WHEELUPMOUSE ) ;
KX_MACRO_addTypesToDict ( d , WHEELDOWNMOUSE , SCA_IInputDevice : : KX_WHEELDOWNMOUSE ) ;
KX_MACRO_addTypesToDict ( d , MOUSEX , SCA_IInputDevice : : KX_MOUSEX ) ;
KX_MACRO_addTypesToDict ( d , MOUSEY , SCA_IInputDevice : : KX_MOUSEY ) ;
2002-10-12 11:37:38 +00:00
// Check for errors
if ( PyErr_Occurred ( ) )
2011-09-01 02:12:53 +00:00
{
2002-10-12 11:37:38 +00:00
Py_FatalError ( " can't initialize module GameKeys " ) ;
2011-09-01 02:12:53 +00:00
}
2002-10-12 11:37:38 +00:00
return d ;
}
2008-09-12 02:15:16 +00:00
// utility function for loading and saving the globalDict
int saveGamePythonConfig ( char * * marshal_buffer )
{
int marshal_length = 0 ;
2012-09-16 04:58:18 +00:00
PyObject * gameLogic = PyImport_ImportModule ( " GameLogic " ) ;
2008-09-12 02:15:16 +00:00
if ( gameLogic ) {
2012-09-16 04:58:18 +00:00
PyObject * pyGlobalDict = PyDict_GetItemString ( PyModule_GetDict ( gameLogic ) , " globalDict " ) ; // Same as importing the module
2008-09-12 02:15:16 +00:00
if ( pyGlobalDict ) {
2012-09-16 04:58:18 +00:00
# ifdef Py_MARSHAL_VERSION
PyObject * pyGlobalDictMarshal = PyMarshal_WriteObjectToString ( pyGlobalDict , 2 ) ; // Py_MARSHAL_VERSION == 2 as of Py2.5
2008-09-12 02:15:16 +00:00
# else
2012-09-16 04:58:18 +00:00
PyObject * pyGlobalDictMarshal = PyMarshal_WriteObjectToString ( pyGlobalDict ) ;
2008-09-12 02:15:16 +00:00
# endif
if ( pyGlobalDictMarshal ) {
// for testing only
// PyObject_Print(pyGlobalDictMarshal, stderr, 0);
2009-06-15 20:22:50 +00:00
char * marshal_cstring ;
2009-08-10 00:07:34 +00:00
marshal_cstring = PyBytes_AsString ( pyGlobalDictMarshal ) ; // py3 uses byte arrays
2009-06-15 20:22:50 +00:00
marshal_length = PyBytes_Size ( pyGlobalDictMarshal ) ;
2008-09-16 19:25:35 +00:00
* marshal_buffer = new char [ marshal_length + 1 ] ;
2009-06-15 20:22:50 +00:00
memcpy ( * marshal_buffer , marshal_cstring , marshal_length ) ;
2008-09-16 19:25:35 +00:00
Py_DECREF ( pyGlobalDictMarshal ) ;
2008-09-12 02:15:16 +00:00
} else {
2010-08-11 12:14:16 +00:00
printf ( " Error, bge.logic.globalDict could not be marshal'd \n " ) ;
2008-09-12 02:15:16 +00:00
}
} else {
2010-08-11 12:14:16 +00:00
printf ( " Error, bge.logic.globalDict was removed \n " ) ;
2008-09-12 02:15:16 +00:00
}
2008-09-16 19:25:35 +00:00
Py_DECREF ( gameLogic ) ;
2008-09-12 02:15:16 +00:00
} else {
2008-10-03 06:27:41 +00:00
PyErr_Clear ( ) ;
2010-08-11 12:14:16 +00:00
printf ( " Error, bge.logic failed to import bge.logic.globalDict will be lost \n " ) ;
2008-09-12 02:15:16 +00:00
}
return marshal_length ;
}
int loadGamePythonConfig ( char * marshal_buffer , int marshal_length )
{
/* Restore the dict */
if ( marshal_buffer ) {
2012-09-16 04:58:18 +00:00
PyObject * gameLogic = PyImport_ImportModule ( " GameLogic " ) ;
2008-09-16 19:25:35 +00:00
if ( gameLogic ) {
2012-09-16 04:58:18 +00:00
PyObject * pyGlobalDict = PyMarshal_ReadObjectFromString ( marshal_buffer , marshal_length ) ;
2008-09-16 19:25:35 +00:00
if ( pyGlobalDict ) {
2012-09-16 04:58:18 +00:00
PyObject * pyGlobalDict_orig = PyDict_GetItemString ( PyModule_GetDict ( gameLogic ) , " globalDict " ) ; // Same as importing the module.
2008-10-03 04:41:02 +00:00
if ( pyGlobalDict_orig ) {
PyDict_Clear ( pyGlobalDict_orig ) ;
PyDict_Update ( pyGlobalDict_orig , pyGlobalDict ) ;
} else {
/* this should not happen, but cant find the original globalDict, just assign it then */
PyDict_SetItemString ( PyModule_GetDict ( gameLogic ) , " globalDict " , pyGlobalDict ) ; // Same as importing the module.
}
2008-09-16 19:25:35 +00:00
Py_DECREF ( gameLogic ) ;
2008-10-03 04:41:02 +00:00
Py_DECREF ( pyGlobalDict ) ;
2008-09-16 19:25:35 +00:00
return 1 ;
} else {
Py_DECREF ( gameLogic ) ;
PyErr_Clear ( ) ;
printf ( " Error could not marshall string \n " ) ;
}
2012-09-16 04:58:18 +00:00
}
else {
2008-10-03 06:27:41 +00:00
PyErr_Clear ( ) ;
2010-08-11 12:14:16 +00:00
printf ( " Error, bge.logic failed to import bge.logic.globalDict will be lost \n " ) ;
2012-09-16 04:58:18 +00:00
}
2008-09-16 19:25:35 +00:00
}
2008-09-12 02:15:16 +00:00
return 0 ;
}
2011-10-27 14:41:26 +00:00
void pathGamePythonConfig ( char * path )
2008-09-12 02:15:16 +00:00
{
2009-06-08 20:08:19 +00:00
int len = strlen ( gp_GamePythonPathOrig ) ; // Always use the first loaded blend filename
2008-09-12 02:15:16 +00:00
2009-06-08 20:08:19 +00:00
BLI_strncpy ( path , gp_GamePythonPathOrig , sizeof ( gp_GamePythonPathOrig ) ) ;
2008-10-11 00:56:49 +00:00
2008-09-12 02:15:16 +00:00
/* replace extension */
if ( BLI_testextensie ( path , " .blend " ) ) {
strcpy ( path + ( len - 6 ) , " .bgeconf " ) ;
} else {
strcpy ( path + len , " .bgeconf " ) ;
}
}
2008-10-11 00:56:49 +00:00
2011-10-27 14:41:26 +00:00
void setGamePythonPath ( const char * path )
2008-10-11 00:56:49 +00:00
{
BLI_strncpy ( gp_GamePythonPath , path , sizeof ( gp_GamePythonPath ) ) ;
2009-06-08 20:08:19 +00:00
BLI_cleanup_file ( NULL , gp_GamePythonPath ) ; /* not absolutely needed but makes resolving path problems less confusing later */
if ( gp_GamePythonPathOrig [ 0 ] = = ' \0 ' )
BLI_strncpy ( gp_GamePythonPathOrig , path , sizeof ( gp_GamePythonPathOrig ) ) ;
2008-10-11 00:56:49 +00:00
}
2009-06-08 20:08:19 +00:00
// we need this so while blender is open (not blenderplayer)
// loading new blendfiles will reset this on starting the
// engine but loading blend files within the BGE wont overwrite gp_GamePythonPathOrig
void resetGamePythonPath ( )
{
2009-06-16 07:16:51 +00:00
gp_GamePythonPathOrig [ 0 ] = ' \0 ' ;
2009-06-08 20:08:19 +00:00
}
2009-09-29 21:42:40 +00:00
2010-10-31 04:11:39 +00:00
# endif // WITH_PYTHON