00001
00002
00003 extern "C" void write_screendump(char *name);
00004 extern "C" void RE_screendump();
00005
00006 #include "SCA_IInputDevice.h"
00007 #include "SCA_PropertySensor.h"
00008 #include "SCA_RandomActuator.h"
00009 #include "KX_ConstraintActuator.h"
00010 #include "KX_IpoActuator.h"
00011 #include "RAS_ICanvas.h"
00012
00013
00014 static RAS_ICanvas* gp_Canvas = NULL;
00015
00016
00017
00018 #define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyInt_FromLong(name))
00019
00020 #define KX_MACRO_addTypesToDict(dict, name, name2) PyDict_SetItemString(dict, #name, PyInt_FromLong(name2))
00021
00022
00023
00024 #include "Python.h"
00025 #include "SCA_PythonController.h"
00026
00027
00028 static PyObject* ErrorObject;
00029
00030 static struct PyMethodDef game_methods[] = {
00031 {"getCurrentController",
00032 (PyCFunction) SCA_PythonController::sPyGetCurrentController,
00033 METH_VARARGS, SCA_PythonController::sPyGetCurrentController__doc__},
00034 {"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator,
00035 METH_VARARGS, SCA_PythonController::sPyAddActiveActuator__doc__},
00036 { NULL, (PyCFunction) NULL, 0, NULL }
00037 };
00038
00039
00040 static PyObject* gPyGetWindowHeight(PyObject* self,
00041 PyObject* args,
00042 PyObject* kwds)
00043 {
00044 int height = (gp_Canvas ? gp_Canvas->GetHeight() : 0);
00045
00046 PyObject* heightval = PyInt_FromLong(height);
00047 return heightval;
00048 }
00049 static PyObject* gPyGetWindowWidth(PyObject* self,
00050 PyObject* args,
00051 PyObject* kwds)
00052 {
00053
00054
00055 int width = (gp_Canvas ? gp_Canvas->GetWidth() : 0);
00056
00057 PyObject* widthval = PyInt_FromLong(width);
00058 return widthval;
00059 }
00060
00061
00062 bool gUseVisibilityTemp = false;
00063
00064 static PyObject* gPyEnableVisibility(PyObject* self,
00065 PyObject* args,
00066 PyObject* kwds)
00067 {
00068 int visible;
00069 if (PyArg_ParseTuple(args,"i",&visible))
00070 {
00071 gUseVisibilityTemp = (visible != 0);
00072 }
00073 else
00074 {
00075 Py_Return;
00076 }
00077 Py_Return;
00078 }
00079
00080
00081
00082 static PyObject* gPyMakeScreenshot(PyObject* self,
00083 PyObject* args,
00084 PyObject* kwds)
00085 {
00086 char* filename;
00087 if (PyArg_ParseTuple(args,"s",&filename))
00088 {
00089 RE_screendump();
00090 write_screendump(filename);
00091 }
00092 Py_Return;
00093 }
00094
00095 CCString gPyGetWindowHeight__doc__="getWindowHeight doc";
00096 CCString gPyGetWindowWidth__doc__="getWindowWidth doc";
00097 CCString gPyEnableVisibility__doc__="enableVisibility doc";
00098 CCString gPyMakeScreenshot__doc__="make Screenshot doc";
00099
00100 static struct PyMethodDef rasterizer_methods[] = {
00101 {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
00102 METH_VARARGS, gPyGetWindowWidth__doc__.Ptr()},
00103 {"getWindowHeight",(PyCFunction) gPyGetWindowHeight,
00104 METH_VARARGS, gPyGetWindowHeight__doc__.Ptr()},
00105 {"makeScreenshot",(PyCFunction)gPyMakeScreenshot,
00106 METH_VARARGS, gPyMakeScreenshot__doc__.Ptr()},
00107 {"enableVisibility",(PyCFunction) gPyEnableVisibility,
00108 METH_VARARGS, gPyEnableVisibility__doc__.Ptr()},
00109 { NULL, (PyCFunction) NULL, 0, NULL }
00110 };
00111
00112
00113
00114 static char GameLogic_module_documentation[] =
00115 "This is the Python API for the game engine of GameLogic"
00116 ;
00117
00118 static char Rasterizer_module_documentation[] =
00119 "This is the Python API for the game engine of Rasterizer"
00120 ;
00121
00122
00123 PyObject*
00124 initGameLogic()
00125 {
00126 PyObject* m;
00127 PyObject* d;
00128
00129 gUseVisibilityTemp=false;
00130
00131
00132 m = Py_InitModule4("GameLogic", game_methods,
00133 GameLogic_module_documentation,
00134 (PyObject*)NULL,PYTHON_API_VERSION);
00135
00136
00137 d = PyModule_GetDict(m);
00138 ErrorObject = PyString_FromString("GameLogic.error");
00139 PyDict_SetItemString(d, "error", ErrorObject);
00140
00141
00142
00143
00144
00145
00146 KX_MACRO_addTypesToDict(d, KX_TRUE, SCA_ILogicBrick::KX_TRUE);
00147 KX_MACRO_addTypesToDict(d, KX_FALSE, SCA_ILogicBrick::KX_FALSE);
00148
00149
00150 KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EQUAL, SCA_PropertySensor::KX_PROPSENSOR_EQUAL);
00151 KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_NOTEQUAL, SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL);
00152 KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_INTERVAL, SCA_PropertySensor::KX_PROPSENSOR_INTERVAL);
00153 KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_CHANGED, SCA_PropertySensor::KX_PROPSENSOR_CHANGED);
00154 KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EXPRESSION, SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION);
00155
00156
00157 KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX);
00158 KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY);
00159 KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ);
00160 KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX);
00161 KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY);
00162 KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ);
00163
00164
00165 KX_MACRO_addTypesToDict(d, KX_IPOACT_PLAY, KX_IpoActuator::KX_ACT_IPO_PLAY);
00166 KX_MACRO_addTypesToDict(d, KX_IPOACT_PINGPONG, KX_IpoActuator::KX_ACT_IPO_PINGPONG);
00167 KX_MACRO_addTypesToDict(d, KX_IPOACT_FLIPPER, KX_IpoActuator::KX_ACT_IPO_FLIPPER);
00168 KX_MACRO_addTypesToDict(d, KX_IPOACT_LOOPSTOP, KX_IpoActuator::KX_ACT_IPO_LOOPSTOP);
00169 KX_MACRO_addTypesToDict(d, KX_IPOACT_LOOPEND, KX_IpoActuator::KX_ACT_IPO_LOOPEND);
00170
00171
00172 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_CONST, SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST);
00173 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_UNIFORM, SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM);
00174 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_BERNOUILLI, SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI);
00175 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_CONST, SCA_RandomActuator::KX_RANDOMACT_INT_CONST);
00176 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_UNIFORM, SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM);
00177 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_POISSON, SCA_RandomActuator::KX_RANDOMACT_INT_POISSON);
00178 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_CONST, SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST);
00179 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_UNIFORM, SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM);
00180 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NORMAL, SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL);
00181 KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL, SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL);
00182
00183
00184 if (PyErr_Occurred())
00185 {
00186 Py_FatalError("can't initialize module GameLogic");
00187 }
00188
00189 return d;
00190 }
00191
00192 PyObject* initGamePythonScripting(const CCString& progname)
00193 {
00194 CCString pname = progname;
00195 Py_SetProgramName(pname.Ptr());
00196 Py_Initialize();
00197
00198 PyObject* moduleobj = PyImport_AddModule("__main__");
00199 return PyModule_GetDict(moduleobj);
00200 }
00201
00202 void exitGamePythonScripting()
00203 {
00204 Py_Finalize();
00205 }
00206
00207 PyObject*
00208 initRasterizer(RAS_ICanvas* canvas)
00209 {
00210 gp_Canvas = canvas;
00211
00212 PyObject* m;
00213 PyObject* d;
00214
00215
00216 m = Py_InitModule4("Rasterizer", rasterizer_methods,
00217 Rasterizer_module_documentation,
00218 (PyObject*)NULL,PYTHON_API_VERSION);
00219
00220
00221 d = PyModule_GetDict(m);
00222 ErrorObject = PyString_FromString("Rasterizer.error");
00223 PyDict_SetItemString(d, "error", ErrorObject);
00224
00225
00226
00227
00228 if (PyErr_Occurred())
00229 {
00230 Py_FatalError("can't initialize module Rasterizer");
00231 }
00232
00233 return d;
00234 }
00235
00236
00237
00238
00239
00240 static char GameKeys_module_documentation[] =
00241 "This modules provides defines for key-codes"
00242 ;
00243
00244 static struct PyMethodDef gamekeys_methods[] = {
00245 { NULL, (PyCFunction) NULL, 0, NULL }
00246 };
00247
00248 PyObject* initGameKeys()
00249 {
00250 PyObject* m;
00251 PyObject* d;
00252
00253
00254 m = Py_InitModule4("GameKeys", gamekeys_methods,
00255 GameKeys_module_documentation,
00256 (PyObject*)NULL,PYTHON_API_VERSION);
00257
00258
00259 d = PyModule_GetDict(m);
00260
00261
00262
00263 KX_MACRO_addTypesToDict(d, AKEY, SCA_IInputDevice::KX_AKEY);
00264 KX_MACRO_addTypesToDict(d, BKEY, SCA_IInputDevice::KX_BKEY);
00265 KX_MACRO_addTypesToDict(d, CKEY, SCA_IInputDevice::KX_CKEY);
00266 KX_MACRO_addTypesToDict(d, DKEY, SCA_IInputDevice::KX_DKEY);
00267 KX_MACRO_addTypesToDict(d, EKEY, SCA_IInputDevice::KX_EKEY);
00268 KX_MACRO_addTypesToDict(d, FKEY, SCA_IInputDevice::KX_FKEY);
00269 KX_MACRO_addTypesToDict(d, GKEY, SCA_IInputDevice::KX_GKEY);
00270 KX_MACRO_addTypesToDict(d, HKEY, SCA_IInputDevice::KX_HKEY);
00271 KX_MACRO_addTypesToDict(d, IKEY, SCA_IInputDevice::KX_IKEY);
00272 KX_MACRO_addTypesToDict(d, JKEY, SCA_IInputDevice::KX_JKEY);
00273 KX_MACRO_addTypesToDict(d, KKEY, SCA_IInputDevice::KX_KKEY);
00274 KX_MACRO_addTypesToDict(d, LKEY, SCA_IInputDevice::KX_LKEY);
00275 KX_MACRO_addTypesToDict(d, MKEY, SCA_IInputDevice::KX_MKEY);
00276 KX_MACRO_addTypesToDict(d, NKEY, SCA_IInputDevice::KX_NKEY);
00277 KX_MACRO_addTypesToDict(d, OKEY, SCA_IInputDevice::KX_OKEY);
00278 KX_MACRO_addTypesToDict(d, PKEY, SCA_IInputDevice::KX_PKEY);
00279 KX_MACRO_addTypesToDict(d, QKEY, SCA_IInputDevice::KX_QKEY);
00280 KX_MACRO_addTypesToDict(d, RKEY, SCA_IInputDevice::KX_RKEY);
00281 KX_MACRO_addTypesToDict(d, SKEY, SCA_IInputDevice::KX_SKEY);
00282 KX_MACRO_addTypesToDict(d, TKEY, SCA_IInputDevice::KX_TKEY);
00283 KX_MACRO_addTypesToDict(d, UKEY, SCA_IInputDevice::KX_UKEY);
00284 KX_MACRO_addTypesToDict(d, VKEY, SCA_IInputDevice::KX_VKEY);
00285 KX_MACRO_addTypesToDict(d, WKEY, SCA_IInputDevice::KX_WKEY);
00286 KX_MACRO_addTypesToDict(d, XKEY, SCA_IInputDevice::KX_XKEY);
00287 KX_MACRO_addTypesToDict(d, YKEY, SCA_IInputDevice::KX_YKEY);
00288 KX_MACRO_addTypesToDict(d, ZKEY, SCA_IInputDevice::KX_ZKEY);
00289
00290 KX_MACRO_addTypesToDict(d, ZEROKEY, SCA_IInputDevice::KX_ZEROKEY);
00291 KX_MACRO_addTypesToDict(d, ONEKEY, SCA_IInputDevice::KX_ONEKEY);
00292 KX_MACRO_addTypesToDict(d, TWOKEY, SCA_IInputDevice::KX_TWOKEY);
00293 KX_MACRO_addTypesToDict(d, THREEKEY, SCA_IInputDevice::KX_THREEKEY);
00294 KX_MACRO_addTypesToDict(d, FOURKEY, SCA_IInputDevice::KX_FOURKEY);
00295 KX_MACRO_addTypesToDict(d, FIVEKEY, SCA_IInputDevice::KX_FIVEKEY);
00296 KX_MACRO_addTypesToDict(d, SIXKEY, SCA_IInputDevice::KX_SIXKEY);
00297 KX_MACRO_addTypesToDict(d, SEVENKEY, SCA_IInputDevice::KX_SEVENKEY);
00298 KX_MACRO_addTypesToDict(d, EIGHTKEY, SCA_IInputDevice::KX_EIGHTKEY);
00299 KX_MACRO_addTypesToDict(d, NINEKEY, SCA_IInputDevice::KX_NINEKEY);
00300
00301 KX_MACRO_addTypesToDict(d, CAPSLOCKKEY, SCA_IInputDevice::KX_CAPSLOCKKEY);
00302
00303 KX_MACRO_addTypesToDict(d, LEFTCTRLKEY, SCA_IInputDevice::KX_LEFTCTRLKEY);
00304 KX_MACRO_addTypesToDict(d, LEFTALTKEY, SCA_IInputDevice::KX_LEFTALTKEY);
00305 KX_MACRO_addTypesToDict(d, RIGHTALTKEY, SCA_IInputDevice::KX_RIGHTALTKEY);
00306 KX_MACRO_addTypesToDict(d, RIGHTCTRLKEY, SCA_IInputDevice::KX_RIGHTCTRLKEY);
00307 KX_MACRO_addTypesToDict(d, RIGHTSHIFTKEY, SCA_IInputDevice::KX_RIGHTSHIFTKEY);
00308 KX_MACRO_addTypesToDict(d, LEFTSHIFTKEY, SCA_IInputDevice::KX_LEFTSHIFTKEY);
00309
00310 KX_MACRO_addTypesToDict(d, ESCKEY, SCA_IInputDevice::KX_ESCKEY);
00311 KX_MACRO_addTypesToDict(d, TABKEY, SCA_IInputDevice::KX_TABKEY);
00312 KX_MACRO_addTypesToDict(d, RETKEY, SCA_IInputDevice::KX_RETKEY);
00313 KX_MACRO_addTypesToDict(d, SPACEKEY, SCA_IInputDevice::KX_SPACEKEY);
00314 KX_MACRO_addTypesToDict(d, LINEFEEDKEY, SCA_IInputDevice::KX_LINEFEEDKEY);
00315 KX_MACRO_addTypesToDict(d, BACKSPACEKEY, SCA_IInputDevice::KX_BACKSPACEKEY);
00316 KX_MACRO_addTypesToDict(d, DELKEY, SCA_IInputDevice::KX_DELKEY);
00317 KX_MACRO_addTypesToDict(d, SEMICOLONKEY, SCA_IInputDevice::KX_SEMICOLONKEY);
00318 KX_MACRO_addTypesToDict(d, PERIODKEY, SCA_IInputDevice::KX_PERIODKEY);
00319 KX_MACRO_addTypesToDict(d, COMMAKEY, SCA_IInputDevice::KX_COMMAKEY);
00320 KX_MACRO_addTypesToDict(d, QUOTEKEY, SCA_IInputDevice::KX_QUOTEKEY);
00321 KX_MACRO_addTypesToDict(d, ACCENTGRAVEKEY, SCA_IInputDevice::KX_ACCENTGRAVEKEY);
00322 KX_MACRO_addTypesToDict(d, MINUSKEY, SCA_IInputDevice::KX_MINUSKEY);
00323 KX_MACRO_addTypesToDict(d, VIRGULEKEY, SCA_IInputDevice::KX_VIRGULEKEY);
00324 KX_MACRO_addTypesToDict(d, SLASHKEY, SCA_IInputDevice::KX_SLASHKEY);
00325 KX_MACRO_addTypesToDict(d, BACKSLASHKEY, SCA_IInputDevice::KX_BACKSLASHKEY);
00326 KX_MACRO_addTypesToDict(d, EQUALKEY, SCA_IInputDevice::KX_EQUALKEY);
00327 KX_MACRO_addTypesToDict(d, LEFTBRACKETKEY, SCA_IInputDevice::KX_LEFTBRACKETKEY);
00328 KX_MACRO_addTypesToDict(d, RIGHTBRACKETKEY, SCA_IInputDevice::KX_RIGHTBRACKETKEY);
00329
00330 KX_MACRO_addTypesToDict(d, LEFTARROWKEY, SCA_IInputDevice::KX_LEFTARROWKEY);
00331 KX_MACRO_addTypesToDict(d, DOWNARROWKEY, SCA_IInputDevice::KX_DOWNARROWKEY);
00332 KX_MACRO_addTypesToDict(d, RIGHTARROWKEY, SCA_IInputDevice::KX_RIGHTARROWKEY);
00333 KX_MACRO_addTypesToDict(d, UPARROWKEY, SCA_IInputDevice::KX_UPARROWKEY);
00334
00335 KX_MACRO_addTypesToDict(d, PAD2 , SCA_IInputDevice::KX_PAD2);
00336 KX_MACRO_addTypesToDict(d, PAD4 , SCA_IInputDevice::KX_PAD4);
00337 KX_MACRO_addTypesToDict(d, PAD6 , SCA_IInputDevice::KX_PAD6);
00338 KX_MACRO_addTypesToDict(d, PAD8 , SCA_IInputDevice::KX_PAD8);
00339
00340 KX_MACRO_addTypesToDict(d, PAD1 , SCA_IInputDevice::KX_PAD1);
00341 KX_MACRO_addTypesToDict(d, PAD3 , SCA_IInputDevice::KX_PAD3);
00342 KX_MACRO_addTypesToDict(d, PAD5 , SCA_IInputDevice::KX_PAD5);
00343 KX_MACRO_addTypesToDict(d, PAD7 , SCA_IInputDevice::KX_PAD7);
00344 KX_MACRO_addTypesToDict(d, PAD9 , SCA_IInputDevice::KX_PAD9);
00345
00346 KX_MACRO_addTypesToDict(d, PADPERIOD, SCA_IInputDevice::KX_PADPERIOD);
00347 KX_MACRO_addTypesToDict(d, PADVIRGULEKEY, SCA_IInputDevice::KX_PADVIRGULEKEY);
00348 KX_MACRO_addTypesToDict(d, PADASTERKEY, SCA_IInputDevice::KX_PADASTERKEY);
00349
00350
00351 KX_MACRO_addTypesToDict(d, PAD0, SCA_IInputDevice::KX_PAD0);
00352 KX_MACRO_addTypesToDict(d, PADMINUS, SCA_IInputDevice::KX_PADMINUS);
00353 KX_MACRO_addTypesToDict(d, PADENTER, SCA_IInputDevice::KX_PADENTER);
00354 KX_MACRO_addTypesToDict(d, PADPLUSKEY, SCA_IInputDevice::KX_PADPLUSKEY);
00355
00356
00357 KX_MACRO_addTypesToDict(d, F1KEY , SCA_IInputDevice::KX_F1KEY);
00358 KX_MACRO_addTypesToDict(d, F2KEY , SCA_IInputDevice::KX_F2KEY);
00359 KX_MACRO_addTypesToDict(d, F3KEY , SCA_IInputDevice::KX_F3KEY);
00360 KX_MACRO_addTypesToDict(d, F4KEY , SCA_IInputDevice::KX_F4KEY);
00361 KX_MACRO_addTypesToDict(d, F5KEY , SCA_IInputDevice::KX_F5KEY);
00362 KX_MACRO_addTypesToDict(d, F6KEY , SCA_IInputDevice::KX_F6KEY);
00363 KX_MACRO_addTypesToDict(d, F7KEY , SCA_IInputDevice::KX_F7KEY);
00364 KX_MACRO_addTypesToDict(d, F8KEY , SCA_IInputDevice::KX_F8KEY);
00365 KX_MACRO_addTypesToDict(d, F9KEY , SCA_IInputDevice::KX_F9KEY);
00366 KX_MACRO_addTypesToDict(d, F10KEY, SCA_IInputDevice::KX_F10KEY);
00367 KX_MACRO_addTypesToDict(d, F11KEY, SCA_IInputDevice::KX_F11KEY);
00368 KX_MACRO_addTypesToDict(d, F12KEY, SCA_IInputDevice::KX_F12KEY);
00369
00370 KX_MACRO_addTypesToDict(d, PAUSEKEY, SCA_IInputDevice::KX_PAUSEKEY);
00371 KX_MACRO_addTypesToDict(d, INSERTKEY, SCA_IInputDevice::KX_INSERTKEY);
00372 KX_MACRO_addTypesToDict(d, HOMEKEY , SCA_IInputDevice::KX_HOMEKEY);
00373 KX_MACRO_addTypesToDict(d, PAGEUPKEY, SCA_IInputDevice::KX_PAGEUPKEY);
00374 KX_MACRO_addTypesToDict(d, PAGEDOWNKEY, SCA_IInputDevice::KX_PAGEDOWNKEY);
00375 KX_MACRO_addTypesToDict(d, ENDKEY, SCA_IInputDevice::KX_ENDKEY);
00376
00377
00378
00379 if (PyErr_Occurred())
00380 {
00381 Py_FatalError("can't initialize module GameKeys");
00382 }
00383
00384 return d;
00385 }
00386